xref: /netbsd-src/external/mpl/dhcp/dist/tests/HOWTO-unit-test (revision 6fb29d29285c26a62fae51364e3aa9f51d403424)
1*6fb29d29SchristosIntroduction
2*6fb29d29Schristos------------
3*6fb29d29Schristos
4*6fb29d29SchristosThat is only a brief overview of tests in ISC DHCP. For more thorough
5*6fb29d29Schristosdescription, see ISC DHCP Developer's Guide. You can generate it, by
6*6fb29d29Schristoshaving Doxygen installed and doing:
7*6fb29d29Schristos
8*6fb29d29Schristos cd doc
9*6fb29d29Schristos make devel
10*6fb29d29Schristos
11*6fb29d29Schristosand then opening doc/html/index.html
12*6fb29d29Schristos
13*6fb29d29SchristosTests Overview
14*6fb29d29Schristos--------------
15*6fb29d29Schristos
16*6fb29d29SchristosIn DHCP, a unit test exercises a particular piece of code in
17*6fb29d29Schristosisolation. There is a separate unit test per module or API. Each unit
18*6fb29d29Schristostest lives in a directory beneath the code it is designed to exercise.
19*6fb29d29SchristosSo, we (will eventually) have:
20*6fb29d29Schristos
21*6fb29d29Schristos    server/tests/
22*6fb29d29Schristos    client/tests/
23*6fb29d29Schristos    common/tests/
24*6fb29d29Schristos    dhcpctl/tests/
25*6fb29d29Schristos
26*6fb29d29SchristosAnd so on.
27*6fb29d29Schristos
28*6fb29d29SchristosWe are using ATF (Automated Test Framework) as a framework to run our
29*6fb29d29Schristosunit tests. See ISC DHCP Developer's Guide for much more thorough
30*6fb29d29Schristosdescription of unit-test and ATF framework in general.
31*6fb29d29Schristos
32*6fb29d29SchristosInstalling ATF
33*6fb29d29Schristos--------------
34*6fb29d29SchristosATF sources can be downloaded from https://github.com/jmmv/kyua. ATF
35*6fb29d29Schristosmust be configured, compiled and then installed to be available during
36*6fb29d29Schristosthe DHCP configure procedure. Please follow INSTALL file supplied with
37*6fb29d29SchristosATF sources (it's essentially the typical ./configure && make &&
38*6fb29d29Schristosmake install procedure).
39*6fb29d29Schristos
40*6fb29d29SchristosBeginning with ATF version 0.16, it is necessary to include the following
41*6fb29d29Schristosoptions --enable-tools and --disable-shared when configuring ATF:
42*6fb29d29Schristos
43*6fb29d29Schristos    configure --prefix=<prefix> --enable-tools --disable-shared
44*6fb29d29Schristos
45*6fb29d29SchristosISC DHCP unittests will run with ATF releases upto 0.19.  Beginning with
46*6fb29d29SchristosATF 0.20, the tools, atf-run and atf-report required by ISC DHCP, were
47*6fb29d29Schristosdeprecated and are no longer included with ATF.
48*6fb29d29Schristos
49*6fb29d29SchristosRunning Unit Tests
50*6fb29d29Schristos------------------
51*6fb29d29Schristos
52*6fb29d29SchristosIn order to run the unit tests for DHCP, enable ATF support during configure:
53*6fb29d29Schristos
54*6fb29d29Schristos$ ./configure --with-atf{=<atf-path>}
55*6fb29d29Schristos
56*6fb29d29Schristos    where <atf-path> is the path into which ATF was installed.  This would
57*6fb29d29Schristos    be same value used for --prefix when ATF was configured (default is
58*6fb29d29Schristos    /usr/local).
59*6fb29d29Schristos
60*6fb29d29SchristosAnd then build ISC_DHCP with:
61*6fb29d29Schristos
62*6fb29d29Schristos$ make
63*6fb29d29Schristos
64*6fb29d29SchristosFinally build and run unit tests with:
65*6fb29d29Schristos
66*6fb29d29Schristos$ make check
67*6fb29d29Schristos
68*6fb29d29SchristosThis will traverse the source tree running the unit tests in each unit test
69*6fb29d29Schristossubdirectory.  Note that if one or more tests in a unit test subdirectory fail
70*6fb29d29Schristosthe make process will stop.  To run all of the tests regardless of outcome,
71*6fb29d29Schristosuse:
72*6fb29d29Schristos
73*6fb29d29Schristos$ make -k check
74*6fb29d29Schristos
75*6fb29d29SchristosYou can run a single test by going to the appropriate test directory
76*6fb29d29Schristosand invoking the test directly:
77*6fb29d29Schristos
78*6fb29d29Schristos$ cd server/tests
79*6fb29d29Schristos$ make check
80*6fb29d29Schristos
81*6fb29d29SchristosAdding a New Unit Test
82*6fb29d29Schristos----------------------
83*6fb29d29Schristos
84*6fb29d29SchristosSee ISC DHCP Developer's Guide.
85*6fb29d29Schristos
86*6fb29d29SchristosAdding a New Unit Test Program
87*6fb29d29Schristos------------------------------
88*6fb29d29Schristos
89*6fb29d29SchristosSee ISC DHCP Developer's Guide.
90