busybox: update to 1.23.2
[tomato.git] / release / src / router / busybox / docs / unit-tests.txt
blob0fb5220869bbc9b8059bc26d77c41152dde126e7
1 Busybox unit test framework
2 ===========================
4 This document describes what you need to do to write test cases using the
5 Busybox unit test framework.
8 Building unit tests
9 -------------------
11 The framework and all tests are built as a regular Busybox applet if option
12 CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
15 Writing test cases
16 ------------------
18 Unit testing interface can be found in include/bbunit.h.
20 Tests can be placed in any .c file in Busybox tree - preferably right next to
21 the functions they test. Test cases should be enclosed within an #if, and
22 should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
23 the test curly brackets. If an assertion fails the test ends immediately, ie.
24 the following assertions will not be reached. Any code placed after
25 BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
27 #if ENABLE_UNIT_TEST
29 BBUNIT_DEFINE_TEST(test_name)
31         int *i;
33         i = malloc(sizeof(int));
34         BBUNIT_ASSERT_NOTNULL(i);
35         *i = 2;
36         BBUNIT_ASSERT_EQ((*i)*(*i), 4);
38         BBUNIT_ENDTEST;
40         free(i);
43 #endif /* ENABLE_UNIT_TEST */
46 Running the unit test suite
47 ---------------------------
49 To run the tests you can either directly run 'busybox unit' or use 'make test'
50 to run both the unit tests (if compiled) and regular test suite.