LCOV - code coverage report
Current view: top level - src/test - test_vector.c (source / functions) Hit Total Coverage
Test: LAGraph code coverage report. Commit id: cc56ed4. Current time (UTC): 2024-08-30T17:14:30Z Lines: 39 39 100.0 %
Date: 2024-08-30 17:16:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : //------------------------------------------------------------------------------
       2             : // LAGraph/src/test/test_vector.c:  test LG_check_vector
       3             : //------------------------------------------------------------------------------
       4             : 
       5             : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
       6             : // SPDX-License-Identifier: BSD-2-Clause
       7             : //
       8             : // For additional details (including references to third party source code and
       9             : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See
      10             : // Contributors.txt for a full list of contributors. Created, in part, with
      11             : // funding and support from the U.S. Government (see Acknowledgments.txt file).
      12             : // DM22-0790
      13             : 
      14             : // Contributed by Timothy A. Davis, Texas A&M University
      15             : 
      16             : //------------------------------------------------------------------------------
      17             : 
      18             : #include "LAGraph_test.h"
      19             : 
      20             : //------------------------------------------------------------------------------
      21             : // global variables
      22             : //------------------------------------------------------------------------------
      23             : 
      24             : GrB_Vector X = NULL ;
      25             : int64_t *x = NULL ;
      26             : GrB_Index n = 10000 ;
      27             : int64_t missing = 42 ;
      28             : char msg [LAGRAPH_MSG_LEN] ;
      29             : 
      30             : //------------------------------------------------------------------------------
      31             : // test_vector
      32             : //------------------------------------------------------------------------------
      33             : 
      34           1 : void test_vector (void)
      35             : {
      36           1 :     OK (LAGraph_Init (msg)) ;
      37           1 :     OK (GrB_Vector_new (&X, GrB_INT64, n)) ;
      38          11 :     for (int i = 0 ; i < 10 ; i++)
      39             :     {
      40          10 :         OK (GrB_Vector_setElement (X, i, i)) ;
      41             :     }
      42           1 :     OK (LAGraph_Malloc ((void **) &x, n, sizeof (int64_t), msg)) ;
      43           1 :     OK (LG_check_vector (x, X, n, missing)) ;
      44       10001 :     for (int i = 0 ; i < n ; i++)
      45             :     {
      46       10000 :         TEST_CHECK (x [i] == ((i < 10) ? i : missing)) ;
      47             :     }
      48           1 :     OK (GrB_free (&X)) ;
      49           1 :     OK (LAGraph_Free ((void **) &x, NULL)) ;
      50           1 :     OK (LAGraph_Finalize (msg)) ;
      51           1 : }
      52             : 
      53             : //------------------------------------------------------------------------------
      54             : // test_vector_brutal
      55             : //------------------------------------------------------------------------------
      56             : 
      57             : #if LAGRAPH_SUITESPARSE
      58           1 : void test_vector_brutal (void)
      59             : {
      60           1 :     OK (LG_brutal_setup (msg)) ;
      61           1 :     printf ("\n") ;
      62             : 
      63           1 :     OK (LAGraph_Malloc ((void **) &x, n, sizeof (int64_t), msg)) ;
      64             : 
      65           1 :     for (int nbrutal = 0 ; ; nbrutal++)
      66          21 :     {
      67             :         /* allow for only nbrutal mallocs before 'failing' */
      68          22 :         LG_brutal = nbrutal ;
      69             :         /* try the method with brutal malloc */
      70          22 :         GrB_free (&X) ;
      71          22 :         int brutal_result = GrB_Vector_new (&X, GrB_INT64, n) ;
      72          22 :         if (brutal_result != GrB_SUCCESS) continue ;
      73         127 :         for (int i = 0 ; i < 10 ; i++)
      74             :         {
      75         117 :             brutal_result = GrB_Vector_setElement (X, i, i) ;
      76         117 :             if (brutal_result != GrB_SUCCESS) break ;
      77             :         }
      78          20 :         if (brutal_result != GrB_SUCCESS) continue ;
      79          10 :         brutal_result = LG_check_vector (x, X, n, missing) ;
      80          10 :         if (brutal_result >= 0)
      81             :         {
      82             :             /* the method finally succeeded */
      83           1 :             printf ("Finally: %d\n", nbrutal) ;
      84           1 :             break ;
      85             :         }
      86           9 :         if (nbrutal > 10000) { printf ("Infinite!\n") ; abort ( ) ; }
      87             :     }
      88           1 :     LG_brutal = -1 ;  /* turn off brutal mallocs */
      89             : 
      90       10001 :     for (int i = 0 ; i < n ; i++)
      91             :     {
      92       10000 :         TEST_CHECK (x [i] == ((i < 10) ? i : missing)) ;
      93             :     }
      94           1 :     OK (GrB_free (&X)) ;
      95           1 :     OK (LAGraph_Free ((void **) &x, NULL)) ;
      96           1 :     OK (LG_brutal_teardown (msg)) ;
      97           1 : }
      98             : #endif
      99             : 
     100             : //-----------------------------------------------------------------------------
     101             : // TEST_LIST: the list of tasks for this entire test
     102             : //-----------------------------------------------------------------------------
     103             : 
     104             : TEST_LIST =
     105             : {
     106             :     { "vector", test_vector },
     107             :     #if LAGRAPH_SUITESPARSE
     108             :     { "vector_brutal", test_vector_brutal },
     109             :     #endif
     110             :     { NULL, NULL }
     111             : } ;

Generated by: LCOV version 1.14