Blame tests/README

Packit 366192
Notes on tests
Packit 366192
============================
Packit 366192
The semanage_access_check test in the semanage_store suite simulates a
Packit 366192
read-only filesystem by using DAC permissions. Consequently, these tests
Packit 366192
will fail if run as root, as root can override DAC permissions.
Packit 366192
Packit 366192
Packit 366192
How to add and use unit tests 
Packit 366192
=============================
Packit 366192
Packit 366192
We are using the CUnit unit testing framework.  This framework--and the
Packit 366192
official documentation of the framework--may be found here:
Packit 366192
Packit 366192
http://cunit.sourceforge.net/
Packit 366192
Packit 366192
If you have not yet installed CUnit, first do that.  (There is an RPM,
Packit 366192
or you can compile from source.)  Once installed, follow these steps to
Packit 366192
add unit tests for your code:
Packit 366192
Packit 366192
1. Create a .h and .c file corresponding to the .c file you want to test.
Packit 366192
   For example, test_semanage_store.c provides tests of the functions in
Packit 366192
   semanage_store.c.   Your new .h/.c files represent a suite of related
Packit 366192
   tests.
Packit 366192
Packit 366192
2. Write or add new tests to a suite.  Tests are simply functions that 
Packit 366192
   take the form:
Packit 366192
Packit 366192
	void test_my_function(void)
Packit 366192
Packit 366192
   These tests are where you will make calls to the CUnit assertions.
Packit 366192
 
Packit 366192
   If you are making a new test suite, also add the suite init/cleanup
Packit 366192
   functions.  These take the form:
Packit 366192
Packit 366192
   	int <suite_name>_test_init(void)
Packit 366192
    int <suite_name>_cleanup(void)
Packit 366192
Packit 366192
   These functions will be called before and after the test functions
Packit 366192
   in your suite, respectively.  They return 0 on success, 1 on failure.
Packit 366192
Packit 366192
3. Update libsemanage-tests.c to add your new suite and/or your new tests
Packit 366192
   using the DECLARE_SUITE macro in do_tests().
Packit 366192
Packit 366192
4. Update the Makefile:
Packit 366192
     + Make sure that the TESTSRC variable is set to the location
Packit 366192
	   of the libsemanage source code you want to test.
Packit 366192
Packit 366192
5. Compile the libsemanage source code you will be testing, to ensure
Packit 366192
   the object files are available and up to date.
Packit 366192
Packit 366192
6. Run your tests.  Rejoice or despair, as appropriate.
Packit 366192
Packit 366192
Packit 366192
A note on the the utilities.c: Add functions that can be commonly used 
Packit 366192
here.  For example, it is handy to have a dummy message callback 
Packit 366192
function to silence error messages produced by libsemanage and keep 
Packit 366192
your output pretty.  To do this, include utilities.h and specify the
Packit 366192
callback like so:
Packit 366192
Packit 366192
        semanage_handle_t *sh;
Packit 366192
        sh = semanage_handle_create();
Packit 366192
        sh->msg_callback = test_msg_handler;
Packit 366192
Packit 366192
Feel free to add other such functions here as well.