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

..03-May-2022-

data/H03-May-2022-

internal/H12-May-2020-307220

Makefile.inH A D12-May-20204.1 KiB11773

Makefile.winH A D12-May-20204 KiB11974

NWGNUmakefileH A D12-May-20204.5 KiB265211

READMEH A D12-May-20208 KiB234176

abts.cH A D12-May-20209.5 KiB414324

abts.hH A D12-May-20203.1 KiB9966

abts_tests.hH A D12-May-20201.7 KiB7353

aprtest.defH A D12-May-202037 42

aprtest.dspH A D12-May-20203.8 KiB196152

aprtest.winH A D12-May-2020471 1914

globalmutexchild.cH A D12-May-20201.8 KiB6542

mod_test.cH A D12-May-20201.1 KiB3313

nw_misc.cH A D12-May-2020226 177

nwgnuaprtestH A D12-May-20205.4 KiB300248

nwgnuglobalmutexchildH A D12-May-20204.4 KiB256204

nwgnumod_testH A D12-May-20204.4 KiB258206

nwgnuproc_childH A D12-May-20204.4 KiB256204

nwgnureadchildH A D12-May-20204.4 KiB256204

nwgnusockchildH A D12-May-20204.4 KiB256204

nwgnutestatmcH A D12-May-20204.4 KiB256205

nwgnutryreadH A D12-May-20204.3 KiB256204

occhild.cH A D12-May-2020453 2721

proc_child.cH A D12-May-2020369 2218

readchild.cH A D12-May-20201.4 KiB4724

sendfile.cH A D12-May-202022.3 KiB758637

sockchild.cH A D12-May-20202.2 KiB8152

testall.dspH A D12-May-20205.7 KiB322248

testall.dswH A D12-May-20202.1 KiB12388

testapp.cH A D12-May-2020185 117

testapp.dspH A D12-May-20203.1 KiB9179

testappnt.dspH A D12-May-20203.3 KiB10284

testargs.cH A D12-May-20206.1 KiB237190

testatomic.cH A D12-May-20208.5 KiB306225

testdir.cH A D12-May-20208.4 KiB277189

testdso.cH A D12-May-20207.2 KiB264194

testdup.cH A D12-May-20206 KiB195136

testenv.cH A D12-May-20204.5 KiB145101

testfile.cH A D12-May-202025.6 KiB870641

testfilecopy.cH A D12-May-20204.5 KiB13983

testfileinfo.cH A D12-May-20209.3 KiB264198

testflock.cH A D12-May-20203.1 KiB10267

testflock.hH A D12-May-2020966 287

testfmt.cH A D12-May-20203.9 KiB13696

testfnmatch.cH A D12-May-20202.2 KiB7742

testglobalmutex.cH A D12-May-20204.2 KiB136100

testglobalmutex.hH A D12-May-20201 KiB286

testhash.cH A D12-May-202013 KiB432321

testipsub.cH A D12-May-20207 KiB174140

testlfs.cH A D12-May-20208.2 KiB292197

testlock.cH A D12-May-20209.4 KiB334252

testlockperf.cH A D12-May-20208 KiB283210

testmmap.cH A D12-May-20204.1 KiB155105

testmutexscope.cH A D12-May-20205.8 KiB219172

testnames.cH A D12-May-20208.8 KiB292224

testoc.cH A D12-May-20203.4 KiB11877

testpath.cH A D12-May-20204.1 KiB139104

testpipe.cH A D12-May-20206 KiB203147

testpoll.cH A D12-May-202017.7 KiB592459

testpools.cH A D12-May-20204.3 KiB157107

testproc.cH A D12-May-20205.2 KiB170123

testprocmutex.cH A D12-May-20204.9 KiB176121

testrand.cH A D12-May-20201.4 KiB4721

testrand2.cH A D12-May-20209.3 KiB299251

testshm.cH A D12-May-20207.9 KiB273200

testshm.hH A D12-May-20201.1 KiB3413

testshmconsumer.cH A D12-May-20202.4 KiB9558

testshmproducer.cH A D12-May-20202.3 KiB9049

testsleep.cH A D12-May-20201.6 KiB5527

testsock.cH A D12-May-20208.8 KiB298207

testsock.hH A D12-May-20201.4 KiB356

testsockets.cH A D12-May-20206 KiB214160

testsockopt.cH A D12-May-20204 KiB14092

teststr.cH A D12-May-202011.3 KiB392292

teststrnatcmp.cH A D12-May-20202.4 KiB7951

testtable.cH A D12-May-20205.1 KiB191144

testtemp.cH A D12-May-20201.7 KiB5630

testthread.cH A D12-May-20203.5 KiB13492

testtime.cH A D12-May-20208.7 KiB307239

testud.cH A D12-May-20202.4 KiB9258

testuser.cH A D12-May-20205 KiB172125

testutil.cH A D12-May-20201.4 KiB4523

testutil.hH A D12-May-20203.2 KiB9361

testvsn.cH A D12-May-20201.6 KiB5729

tryread.cH A D12-May-20201.5 KiB5028

README

1Writing APR tests
2
3All APR tests should be executable in 2 ways, as an individual program, or
4as a part of the full test suite.  The full test suite is controlled with
5the testall program.  At the beginning of the testall.c file, there is an
6array of functions called tests.  The testall program loops through this
7array calling each function.  Each function returns a CuSuite variable, which
8is then added to the SuiteList.  Once all Suites have been added, the SuiteList
9is executed, and the output is printed to the screen.  All functions in the
10array should follow the same basic format:
11
12The Full Suite
13--------------
14
15/* The driver function.  This must return a CuSuite variable, which will
16 * then be used to actually run the tests.  Essentially, all Suites are a
17 * collection of tests.  The driver will take each Suite, and put it in a
18 * SuiteList, which is a collection of Suites.
19 */
20CuSuite *testtime(void)
21{
22    /* The actual suite, this must be created for each test program.  Please
23     * give it a useful name, that will inform the user of the feature being
24     * tested.
25     */
26    CuSuite *suite = CuSuiteNew("Test Time");
27
28    /* Each function must be added to the suite.  Each function represents
29     * a single test.  It is possible to test multiple features in a single
30     * function, although no tests currently do that.
31     */
32    SUITE_ADD_TEST(suite, test_now);
33    SUITE_ADD_TEST(suite, test_gmtstr);
34    SUITE_ADD_TEST(suite, test_localstr);
35    SUITE_ADD_TEST(suite, test_exp_get_gmt);
36    SUITE_ADD_TEST(suite, test_exp_get_lt);
37    SUITE_ADD_TEST(suite, test_imp_gmt);
38    SUITE_ADD_TEST(suite, test_rfcstr);
39    SUITE_ADD_TEST(suite, test_ctime);
40    SUITE_ADD_TEST(suite, test_strftime);
41    SUITE_ADD_TEST(suite, test_strftimesmall);
42    SUITE_ADD_TEST(suite, test_exp_tz);
43    SUITE_ADD_TEST(suite, test_strftimeoffset);
44
45    /* You must return the suite so that the driver knows which suites to
46     * run.
47     */
48    return suite;
49}
50
51Building the full driver
52------------------------
53
54All you need to do to build the full driver is run:
55
56    make testall
57
58To run it, run:
59
60    ./testall
61
62Running individual tests
63---------------------------------
64
65It is not possible to build individual tests, however it is possible to
66run individual tests.  When running the test suite, specify the name of the
67tests that you want to run on the command line.  For example:
68
69	./testall teststr testrand
70
71Will run the Strings and Random generator tests.
72
73Reading the test suite output
74-----------------------------
75
76Once you run the test suite, you will get output like:
77
78All APR Tests:
79    Test Strings:       ....
80    Test Time:  ............
81
8216 tests run:  16 passed, 0 failed, 0 not implemented.
83
84Known test failures are documented in ../STATUS.
85
86There are a couple of things to look at with this.  First, if you look at the
87first function in this document, you should notice that the string passed to
88the CuSuiteNew function is in the output.  That is why the string should
89explain the feature you are testing.
90
91Second, this test passed completely.  This is obvious in two ways.  First, and
92most obvious, the summary line tells you that 16 tests were run and 16 tests
93passed.  However, the results can also be found in the lines above.  Every
94'.' in the output represents a passed test.
95
96If a test fails, the output will look like:
97
98All APR Tests:
99    Test Strings:       ....
100    Test Time:  ..F.........
101
10216 tests run:  15 passed, 1 failed, 0 not implemented.
103
104This is not very useful, because you don't know which test failed.  However,
105once you know that a test failed, you can run the suite again, with the
106-v option.  If you do this, you will get something like:
107
108All APR Tests:
109    Test Strings:       ....
110    Test Time:  ..F.........
111
11216 tests run:  15 passed, 1 failed, 0 not implemented.
113Failed tests:
1141) test_localstr: assert failed
115
116In this case, we know the test_localstr function failed, and there is an
117Assert in this that failed (I modified the test to fail for this document).
118Now, you can look at what that test does, and why it would have failed.
119
120There is one other possible output for the test suite (run with -v):
121
122All APR Tests:
123    Test Strings:       ....
124    Test Time:  ..N.........
125
12616 tests run:  15 passed, 0 failed, 1 not implemented.
127
128Not Implemented tests:
129
130Not Implemented tests:
1311) test_localstr: apr_time_exp_lt not implemented on this platform
132
133The 'N' means that a function has returned APR_ENOTIMPL.  This should be
134treated as an error, and the function should be implemented as soon as
135possible.
136
137Adding New test Suites to the full driver
138-------------------------------------------
139
140To add a new Suite to the full driver, you must make a couple of modifications.
141
1421)  Edit test_apr.h, and add the prototype for the function.
1432)  Edit testall.c, and add the function and name to the tests array.
1443)  Edit Makefile.in, and add the .lo file to the testall target.
145
146Once those four things are done, your tests will automatically be added
147to the suite.
148
149Writing tests
150-------------
151
152There are a couple of rules for writing good tests for the test suite.
153
1541)  All tests can determine for themselves if it passed or not.  This means
155that there is no reason for the person running the test suite to interpret
156the results of the tests.
1572)  Never use printf to add to the output of the test suite.  The suite
158library should be able to print all of the information required to debug
159a problem.
1603)  Functions should be tested with both positive and negative tests.  This
161means that you should test things that should both succeed and fail.
1624)  Just checking the return code does _NOT_ make a useful test.  You must
163check to determine that the test actually did what you expected it to do.
164
165An example test
166---------------
167
168Finally, we will look at a quick test:
169
170/* All tests are passed a CuTest variable.  This is how the suite determines
171 * if the test succeeded or failed.
172 */
173static void test_localstr(CuTest *tc)
174{
175    apr_status_t rv;
176    apr_time_exp_t xt;
177    time_t os_now;
178
179    rv = apr_time_exp_lt(&xt, now);
180    os_now = now / APR_USEC_PER_SEC;
181
182    /* If the function can return APR_ENOTIMPL, then you should check for it.
183     * This allows platform implementors to know if they have to implement
184     * the function.
185     */
186    if (rv == APR_ENOTIMPL) {
187        CuNotImpl(tc, "apr_time_exp_lt");
188    }
189
190    /* It often helps to ensure that the return code was APR_SUCESS.  If it
191     * wasn't, then we know the test failed.
192     */
193    CuAssertTrue(tc, rv == APR_SUCCESS);
194
195    /* Now that we know APR thinks it worked properly, we need to check the
196     * output to ensure that we got what we expected.
197     */
198    CuAssertStrEquals(tc, "2002-08-14 12:05:36.186711 -25200 [257 Sat] DST",
199                      print_time(p, &xt));
200}
201
202Notice, the same test can fail for any of a number of reasons.  The first
203test to fail ends the test.
204
205CuTest
206------
207
208CuTest is an open source test suite written by Asim Jalis.  It has been
209released under the zlib/libpng license.  That license can be found in the
210CuTest.c and CuTest.h files.
211
212The version of CuTest that is included in the APR test suite has been modified
213from the original distribution in the following ways:
214
2151)  The original distribution does not have a -v flag, the details are always
216printed.
2172)  The NotImplemented result does not exist.
2183)  SuiteLists do not exist.  In the original distribution, you can add suites
219to suites, but it just adds the tests in the first suite to the list of tests
220in the original suite.  The output wasn't as detailed as I wanted, so I created
221SuiteLists.
222
223The first two modifications have been sent to the original author of CuTest,
224but they have not been integrated into the base distribution.  The SuiteList
225changes will be sent to the original author soon.
226
227The modified version of CuTest is not currently in any CVS or Subversion
228server.  In time, it will be hosted at rkbloom.net.
229
230There are currently no docs for how to write tests, but the teststr and
231testtime programs should give an idea of how it is done.  In time, a document
232should be written to define how tests are written.
233
234