• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

MakefileD22-Nov-2023854 3318

READMED22-Nov-20232.3 KiB6544

libsemanage-tests.cD22-Nov-20232.7 KiB10968

nc_sort_malformedD22-Nov-20231.1 KiB2625

nc_sort_sortedD22-Nov-20231 KiB2625

nc_sort_unsortedD22-Nov-20231.2 KiB2827

test_semanage_store.cD22-Nov-20239 KiB376234

test_semanage_store.hD22-Nov-20231.2 KiB3510

test_utilities.cD22-Nov-20236.9 KiB286224

test_utilities.hD22-Nov-2023160 64

utilities.cD22-Nov-20231.2 KiB335

utilities.hD22-Nov-2023974 243

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