Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
.gitignore | D | 22-Nov-2023 | 18 | 2 | 1 | |
Makefile | D | 23-Nov-2023 | 597 | 24 | 13 | |
README | D | 22-Nov-2023 | 2.3 KiB | 65 | 44 | |
libsemanage-tests.c | D | 22-Nov-2023 | 2.8 KiB | 112 | 71 | |
nc_sort_malformed | D | 22-Nov-2023 | 1.1 KiB | 26 | 25 | |
nc_sort_sorted | D | 22-Nov-2023 | 1 KiB | 26 | 25 | |
nc_sort_unsorted | D | 22-Nov-2023 | 1.2 KiB | 28 | 27 | |
test_semanage_store.c | D | 22-Nov-2023 | 9 KiB | 376 | 234 | |
test_semanage_store.h | D | 22-Nov-2023 | 1.2 KiB | 35 | 10 | |
test_utilities.c | D | 22-Nov-2023 | 8.1 KiB | 335 | 262 | |
test_utilities.h | D | 22-Nov-2023 | 160 | 6 | 4 | |
utilities.c | D | 22-Nov-2023 | 1.2 KiB | 33 | 5 | |
utilities.h | D | 22-Nov-2023 | 974 | 24 | 3 |
README
1Notes on tests 2============================ 3The semanage_access_check test in the semanage_store suite simulates a 4read-only filesystem by using DAC permissions. Consequently, these tests 5will fail if run as root, as root can override DAC permissions. 6 7 8How to add and use unit tests 9============================= 10 11We are using the CUnit unit testing framework. This framework--and the 12official documentation of the framework--may be found here: 13 14http://cunit.sourceforge.net/ 15 16If you have not yet installed CUnit, first do that. (There is an RPM, 17or you can compile from source.) Once installed, follow these steps to 18add unit tests for your code: 19 201. Create a .h and .c file corresponding to the .c file you want to test. 21 For example, test_semanage_store.c provides tests of the functions in 22 semanage_store.c. Your new .h/.c files represent a suite of related 23 tests. 24 252. Write or add new tests to a suite. Tests are simply functions that 26 take the form: 27 28 void test_my_function(void) 29 30 These tests are where you will make calls to the CUnit assertions. 31 32 If you are making a new test suite, also add the suite init/cleanup 33 functions. These take the form: 34 35 int <suite_name>_test_init(void) 36 int <suite_name>_cleanup(void) 37 38 These functions will be called before and after the test functions 39 in your suite, respectively. They return 0 on success, 1 on failure. 40 413. Update libsemanage-tests.c to add your new suite and/or your new tests 42 using the DECLARE_SUITE macro in do_tests(). 43 444. Update the Makefile: 45 + Make sure that the TESTSRC variable is set to the location 46 of the libsemanage source code you want to test. 47 485. Compile the libsemanage source code you will be testing, to ensure 49 the object files are available and up to date. 50 516. Run your tests. Rejoice or despair, as appropriate. 52 53 54A note on the the utilities.c: Add functions that can be commonly used 55here. For example, it is handy to have a dummy message callback 56function to silence error messages produced by libsemanage and keep 57your output pretty. To do this, include utilities.h and specify the 58callback like so: 59 60 semanage_handle_t *sh; 61 sh = semanage_handle_create(); 62 sh->msg_callback = test_msg_handler; 63 64Feel free to add other such functions here as well. 65