Consider the file assert_test.c
, whose contents are as follows:
#include <assert.h>
int main(int argc, char** argv) {
assert(argc > 1);
return 0;
}
When this file is run thru the C preprocessor without any options, the assert(argc > 1)
line becomes:
((void) sizeof ((
argc > 1
) ? 1 : 0), __extension__ ({ if (
argc > 1
) ; else __assert_fail (
"argc > 1"
, "assert_test.c", 4, __extension__ __PRETTY_FUNCTION__); }))
But with the -DNDEBUG
option, the line becomes:
((void) (0))
The ear output contains the ASTs of the above preprocessed code. For example, you can get the ear output as follows:
cd /host/code/acr/test
../ear.py -o out/assert_test.ear-out.json -s assert_test.c -c autogen
../ear.py -o out/assert_test.ear-out.NDEBUG.json -s assert_test.c -c assert_test.compile_cmds.NDEBUG.json
where assert_test.compile_cmds.NDEBUG.json
specifies the -DNDEBUG
argument.
So, to check whether an assert
in a given translation unit is disabled, you can grep for __assert_fail
in the ear output. With test_runner.py
, the ear output goes in the step directory (default: /host/code/acr/test/step
), provided that pytest_keep
is true
.