/ tests / include / tests / test.h
test.h
 1  /* SPDX-License-Identifier: GPL-2.0-only */
 2  
 3  #ifndef _TESTS_TEST_H
 4  #define _TESTS_TEST_H
 5  
 6  /*
 7   * Standard test header that should be included in all tests. For now it just encapsulates the
 8   * include dependencies for Cmocka. Test-specific APIs that are so generic we would want them
 9   * available everywhere could also be added here.
10   */
11  
12  #include <stdarg.h>
13  #include <stddef.h>
14  #include <setjmp.h>
15  #include <cmocka.h>
16  
17  /* This macro basically does nothing but suppresses linter messages */
18  #define EMPTY_WRAP(...) __VA_ARGS__
19  
20  /*
21   * Set symbol value and make it global.
22   */
23  #define TEST_SYMBOL(symbol, value) asm(".set " #symbol ", " #value "\n\t.globl " #symbol)
24  
25  /*
26   * Define memory region for testing purpose.
27   *
28   * Create buffer with specified name and size.
29   * Create end symbol for it.
30   */
31  #define TEST_REGION(region, size) uint8_t _##region[size]; \
32  	TEST_SYMBOL(_e##region, _##region + size); \
33  	TEST_SYMBOL(_##region##_size, size)
34  
35  /*
36   * Set start, end and size symbols describing region without allocating memory for it.
37   */
38  #define TEST_REGION_UNALLOCATED(region, start, size) TEST_SYMBOL(_##region, start); \
39  	TEST_SYMBOL(_e##region, _##region + size); \
40  	TEST_SYMBOL(_##region##_size, size)
41  
42  /* Wrapper for running cmocka test groups using name provided by build system in __TEST_NAME__
43     This should be used instead of cmocka_run_group_tests(). If there is a need to use custom
44     group name, then please use cmocka_run_group_tests_name(). */
45  #define cb_run_group_tests(group_tests, group_setup, group_teardown)                           \
46  	cmocka_run_group_tests_name((__TEST_NAME__ "(" #group_tests ")"), group_tests,         \
47  				    group_setup, group_teardown)
48  
49  #endif /* _TESTS_TEST_H */