1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
//------------------------------------------------------------------------------
// GB_assert.h: assertions
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#ifndef GB_ASSERT_H
#define GB_ASSERT_H
//------------------------------------------------------------------------------
// debugging definitions
//------------------------------------------------------------------------------
#undef ASSERT
#undef ASSERT_OK
#undef ASSERT_OK_OR_NULL
#ifdef GB_DEBUG
// assert X is true
#define ASSERT(X) \
{ \
if (!(X)) \
{ \
GBDUMP ("assertion failed: " __FILE__ " line %d\n", __LINE__) ; \
GB_Global_abort_function ( ) ; \
} \
}
// call a GraphBLAS method and assert that it returns GrB_SUCCESS
#define ASSERT_OK(X) \
{ \
GrB_Info Info = (X) ; \
ASSERT (Info == GrB_SUCCESS) ; \
}
// call a GraphBLAS method and assert that it returns GrB_SUCCESS
// or GrB_NULL_POINTER.
#define ASSERT_OK_OR_NULL(X) \
{ \
GrB_Info Info = (X) ; \
ASSERT (Info == GrB_SUCCESS || Info == GrB_NULL_POINTER) ; \
}
#else
// debugging disabled
#define ASSERT(X)
#define ASSERT_OK(X)
#define ASSERT_OK_OR_NULL(X)
#endif
#define GB_IMPLIES(p,q) (!(p) || (q))
// for finding tests that trigger statement coverage. If running a test
// in GraphBLAS/Tcov, the test does not terminate.
#if 1
#ifdef GBCOVER
#define GB_GOTCHA \
{ \
fprintf (stderr, "Gotcha: " __FILE__ " line: %d\n", __LINE__) ; \
GBDUMP ("Gotcha: " __FILE__ " line: %d\n", __LINE__) ; \
}
#else
#define GB_GOTCHA \
{ \
fprintf (stderr, "gotcha: " __FILE__ " line: %d\n", __LINE__) ; \
GBDUMP ("gotcha: " __FILE__ " line: %d\n", __LINE__) ; \
GB_Global_abort_function ( ) ; \
}
#endif
#endif
#ifndef GB_GOTCHA
#define GB_GOTCHA
#endif
#define GB_HERE GBDUMP ("%2d: Here: " __FILE__ "\n", __LINE__) ;
// ASSERT (GB_DEAD_CODE) marks code that is intentionally dead, leftover from
// prior versions of SuiteSparse:GraphBLAS but no longer used in the current
// version. The code is kept in case it is required for future versions (in
// which case, the ASSERT (GB_DEAD_CODE) statement would be removed).
#define GB_DEAD_CODE 0
//------------------------------------------------------------------------------
// assertions for checking specific objects
//------------------------------------------------------------------------------
#define ASSERT_TYPE_OK(t,name,pr) \
ASSERT_OK (GB_Type_check (t, name, pr, NULL))
#define ASSERT_TYPE_OK_OR_NULL(t,name,pr) \
ASSERT_OK_OR_NULL (GB_Type_check (t, name, pr, NULL))
#define ASSERT_BINARYOP_OK(op,name,pr) \
ASSERT_OK (GB_BinaryOp_check (op, name, pr, NULL))
#define ASSERT_INDEXUNARYOP_OK(op,name,pr) \
ASSERT_OK (GB_IndexUnaryOp_check (op, name, pr, NULL))
#define ASSERT_BINARYOP_OK_OR_NULL(op,name,pr) \
ASSERT_OK_OR_NULL (GB_BinaryOp_check (op, name, pr, NULL))
#define ASSERT_UNARYOP_OK(op,name,pr) \
ASSERT_OK (GB_UnaryOp_check (op, name, pr, NULL))
#define ASSERT_UNARYOP_OK_OR_NULL(op,name,pr) \
ASSERT_OK_OR_NULL (GB_UnaryOp_check (op, name, pr, NULL))
#define ASSERT_SELECTOP_OK(op,name,pr) \
ASSERT_OK (GB_SelectOp_check (op, name, pr, NULL))
#define ASSERT_SELECTOP_OK_OR_NULL(op,name,pr) \
ASSERT_OK_OR_NULL (GB_SelectOp_check (op, name, pr, NULL))
#define ASSERT_OP_OK(op,name,pr) \
ASSERT_OK (GB_Operator_check (op, name, pr, NULL))
#define ASSERT_OP_OK_OR_NULL(op,name,pr) \
ASSERT_OK_OR_NULL (GB_Operator_check (op, name, pr, NULL))
#define ASSERT_MONOID_OK(mon,name,pr) \
ASSERT_OK (GB_Monoid_check (mon, name, pr, NULL))
#define ASSERT_SEMIRING_OK(s,name,pr) \
ASSERT_OK (GB_Semiring_check (s, name, pr, NULL))
#define ASSERT_MATRIX_OK(A,name,pr) \
ASSERT_OK (GB_Matrix_check (A, name, pr, NULL))
#define ASSERT_MATRIX_OK_OR_NULL(A,name,pr) \
ASSERT_OK_OR_NULL (GB_Matrix_check (A, name, pr, NULL))
#define ASSERT_VECTOR_OK(v,name,pr) \
ASSERT_OK (GB_Vector_check (v, name, pr, NULL))
#define ASSERT_VECTOR_OK_OR_NULL(v,name,pr) \
ASSERT_OK_OR_NULL (GB_Vector_check (v, name, pr, NULL))
#define ASSERT_SCALAR_OK(s,name,pr) \
ASSERT_OK (GB_Scalar_check (s, name, pr, NULL))
#define ASSERT_SCALAR_OK_OR_NULL(s,name,pr) \
ASSERT_OK_OR_NULL (GB_Scalar_check (s, name, pr, NULL))
#define ASSERT_DESCRIPTOR_OK(d,name,pr) \
ASSERT_OK (GB_Descriptor_check (d, name, pr, NULL))
#define ASSERT_DESCRIPTOR_OK_OR_NULL(d,name,pr) \
ASSERT_OK_OR_NULL (GB_Descriptor_check (d, name, pr, NULL))
#endif
|