• Home
Name Date Size #Lines LOC

..--

.gitignoreD03-May-202427 32

MakefileD03-May-2024755 2917

READMED03-May-20242.3 KiB6544

libsemanage-tests.cD03-May-20243.2 KiB13089

nc_sort_malformedD03-May-20241.1 KiB2625

nc_sort_sortedD03-May-20241 KiB2625

nc_sort_unsortedD03-May-20241.2 KiB2827

test_bool.cD03-May-202421.7 KiB933650

test_bool.cilD03-May-2024637 2524

test_bool.hD03-May-20241 KiB328

test_fcontext.cD03-May-202427.1 KiB1,046726

test_fcontext.cilD03-May-2024648 2625

test_fcontext.hD03-May-20241 KiB317

test_handle.cD03-May-20247.7 KiB330212

test_handle.cilD03-May-2024556 2221

test_handle.hD03-May-20241,016 317

test_ibendport.cD03-May-202413.7 KiB526358

test_ibendport.cilD03-May-2024951 2928

test_ibendport.hD03-May-20241 KiB317

test_iface.cD03-May-202416.4 KiB667433

test_iface.cilD03-May-20241,005 2928

test_iface.hD03-May-20241,011 317

test_node.cD03-May-202420 KiB808536

test_node.cilD03-May-2024952 2928

test_node.hD03-May-20241,006 317

test_other.cD03-May-20243.7 KiB12164

test_other.hD03-May-20241,011 317

test_port.cD03-May-202422.1 KiB910611

test_port.cilD03-May-2024822 2827

test_port.hD03-May-20241,006 317

test_semanage_store.cD03-May-20249 KiB376234

test_semanage_store.hD03-May-20241.2 KiB3510

test_user.cD03-May-202416.7 KiB691435

test_user.cilD03-May-2024698 2827

test_user.hD03-May-20241,006 317

test_utilities.cD03-May-20248.5 KiB348274

test_utilities.hD03-May-2024160 64

utilities.cD03-May-20245.3 KiB279182

utilities.hD03-May-20242.8 KiB9961

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