1 //------------------------------------------------------------------------------ 2 // GB_mex_errors.h: error handling macros 3 //------------------------------------------------------------------------------ 4 5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 6 // SPDX-License-Identifier: Apache-2.0 7 8 //------------------------------------------------------------------------------ 9 10 #define FAIL(s) \ 11 { \ 12 fprintf (f,"\nTest failure: %s line %d\n", __FILE__, __LINE__) ; \ 13 fprintf (f, "%s\n", GB_STR(s)) ; \ 14 fclose (f) ; \ 15 mexErrMsgTxt (GB_STR(s) " line: " GB_XSTR(__LINE__)) ; \ 16 } 17 18 #undef CHECK 19 #define CHECK(x) if (!(x)) FAIL(x) ; 20 #define CHECK2(x,s) if (!(x)) FAIL(s) ; 21 22 // assert that a method should return a particular error code 23 #define ERR(method) \ 24 { \ 25 info = method ; \ 26 fprintf (f, "line %d: info %d\n", __LINE__, info) ; \ 27 if (info != expected) fprintf (f, "got %d expected %d\n", \ 28 info, expected) ; \ 29 CHECK2 (info == expected, method) ; \ 30 } 31 32 // assert that a method should return a particular error code: with logger, 33 // for a GrB_Matrix, GrB_Vector, or GxB_Scalar 34 #define ERR1(C,method) \ 35 { \ 36 info = method ; \ 37 fprintf (f, "\nline %d: info %d, error logger:\n", __LINE__, info) ; \ 38 char *error_logger ; \ 39 GrB_Matrix_error_(&error_logger, ((GrB_Matrix) C)) ; \ 40 fprintf (f, "logger is %p\n", error_logger) ; \ 41 if (error_logger != NULL) fprintf (f,"[%s]\n", error_logger) ; \ 42 if (info != expected) fprintf (f, "got %d expected %d\n", \ 43 info, expected) ; \ 44 CHECK2 (info == expected, method) ; \ 45 } 46 47 // assert that a method should return a particular error code: with logger, 48 // for a GrB_Descriptor 49 #define ERRD(descriptor,method) \ 50 { \ 51 info = method ; \ 52 fprintf (f, "\nline %d: info %d, error logger:\n", __LINE__, info) ; \ 53 char *error_logger ; \ 54 GrB_Descriptor_error_(&error_logger, descriptor) ; \ 55 if (error_logger != NULL) fprintf (f,"[%s]\n", error_logger) ; \ 56 if (info != expected) fprintf (f, "got %d expected %d\n", \ 57 info, expected) ; \ 58 CHECK2 (info == expected, method) ; \ 59 } 60 61 // assert that a method should succeed 62 #define OK(method) \ 63 { \ 64 info = method ; \ 65 if (! (info == GrB_SUCCESS || info == GrB_NO_VALUE)) \ 66 { \ 67 fprintf (f,"[%d] >>>>>>>>\n", info) ; \ 68 mexPrintf ("[%d] Test failed\n", info) ; \ 69 FAIL (method) ; \ 70 } \ 71 } 72 73