xref: /aosp_15_r20/external/kmod/testsuite/README (revision cc4ad7da8cefe208cb129ac2aa9a357c7c72deb2)
1*cc4ad7daSAndroid Build Coastguard Workertestsuite
2*cc4ad7daSAndroid Build Coastguard Worker
3*cc4ad7daSAndroid Build Coastguard WorkerOVERVIEW
4*cc4ad7daSAndroid Build Coastguard Worker========
5*cc4ad7daSAndroid Build Coastguard Worker
6*cc4ad7daSAndroid Build Coastguard WorkerKmod's testsuite was designed to automate the process of running tests with
7*cc4ad7daSAndroid Build Coastguard Workerdifferent scenarios, configurations and architectures. The idea is that once we
8*cc4ad7daSAndroid Build Coastguard Workerreceived a bug report, we reproduce it using the testsuite so we avoid
9*cc4ad7daSAndroid Build Coastguard Workerrecurring on the same bug in future.
10*cc4ad7daSAndroid Build Coastguard Worker
11*cc4ad7daSAndroid Build Coastguard Worker
12*cc4ad7daSAndroid Build Coastguard WorkerFEATURES
13*cc4ad7daSAndroid Build Coastguard Worker========
14*cc4ad7daSAndroid Build Coastguard Worker
15*cc4ad7daSAndroid Build Coastguard Worker- Isolate each test by running them in separate processes;
16*cc4ad7daSAndroid Build Coastguard Worker- Exec a binary, so we can test the tools and not only the lib API
17*cc4ad7daSAndroid Build Coastguard Worker- Fake accesses to filesystem so we can provide a test rootfs with all the
18*cc4ad7daSAndroid Build Coastguard Worker  configuration, indexes, etc that test needs to be executed.
19*cc4ad7daSAndroid Build Coastguard Worker- Fake calls to init_module(), delete_module() and uname(), so we don't have to
20*cc4ad7daSAndroid Build Coastguard Worker  run tests as root and figure out how to deal with different architectures.
21*cc4ad7daSAndroid Build Coastguard Worker
22*cc4ad7daSAndroid Build Coastguard WorkerHOW TO ADD A TEST
23*cc4ad7daSAndroid Build Coastguard Worker=================
24*cc4ad7daSAndroid Build Coastguard Worker
25*cc4ad7daSAndroid Build Coastguard WorkerThe simplest way to add a test is to copy and paste one already there. Most of
26*cc4ad7daSAndroid Build Coastguard Workerthe options you can have are covered by another tests. This is what you need to
27*cc4ad7daSAndroid Build Coastguard Workerpay attention when writing a test:
28*cc4ad7daSAndroid Build Coastguard Worker
29*cc4ad7daSAndroid Build Coastguard Worker1 - Look at testsuite.h, struct test, to see all the options available.
30*cc4ad7daSAndroid Build Coastguard Worker
31*cc4ad7daSAndroid Build Coastguard Worker2 - Use TESTSUITE_MAIN and DEFINE_TEST to add new tests. Don't forget to fill
32*cc4ad7daSAndroid Build Coastguard Worker    its description.
33*cc4ad7daSAndroid Build Coastguard Worker
34*cc4ad7daSAndroid Build Coastguard Worker3 - If you want testsuite to compare the stdout/stderr of your tests in order
35*cc4ad7daSAndroid Build Coastguard Worker    to check if it worked or not, fill in output.{stderr,stdout} the file with
36*cc4ad7daSAndroid Build Coastguard Worker    the expected output. Bear in mind the same file is used for all
37*cc4ad7daSAndroid Build Coastguard Worker    architectures, so don't print arch-dependent content if you are comparing
38*cc4ad7daSAndroid Build Coastguard Worker    the output.
39*cc4ad7daSAndroid Build Coastguard Worker
40*cc4ad7daSAndroid Build Coastguard Worker4 - Fill in the config vector. Setting any of these configuration will make
41*cc4ad7daSAndroid Build Coastguard Worker    testsuite to export LD_PRELOAD with the necessary override libs before
42*cc4ad7daSAndroid Build Coastguard Worker    executing the test. If you are not exec'ing an external binary, you need to
43*cc4ad7daSAndroid Build Coastguard Worker    pass "need_spawn = true" below, otherwise it will not work (LD_PRELOAD is
44*cc4ad7daSAndroid Build Coastguard Worker    only applied when exec'ing a binary). See each config description in
45*cc4ad7daSAndroid Build Coastguard Worker    testsuite.h
46*cc4ad7daSAndroid Build Coastguard Worker
47*cc4ad7daSAndroid Build Coastguard Worker5 - need_spawn: if testsuite will exec itself before running a test
48*cc4ad7daSAndroid Build Coastguard Worker
49*cc4ad7daSAndroid Build Coastguard Worker6 - expected_fail: if that test is expected to fail, i.e. the return code is
50*cc4ad7daSAndroid Build Coastguard Worker    expected not to be 0.
51*cc4ad7daSAndroid Build Coastguard Worker
52*cc4ad7daSAndroid Build Coastguard Worker7 - The rootfs is populated by copying the entire contents of rootfs-pristine
53*cc4ad7daSAndroid Build Coastguard Worker    then running populate-modules.sh to copy generated modules from
54*cc4ad7daSAndroid Build Coastguard Worker    module-playground. Update the latter script to include any modules your
55*cc4ad7daSAndroid Build Coastguard Worker    test need.
56*cc4ad7daSAndroid Build Coastguard Worker
57*cc4ad7daSAndroid Build Coastguard Worker8 - Tests can be run individually, outside of 'make check'. strace and gdb work
58*cc4ad7daSAndroid Build Coastguard Worker    too, as long as you tell them to operate on child process.
59*cc4ad7daSAndroid Build Coastguard Worker
60*cc4ad7daSAndroid Build Coastguard Worker9 - Make sure test passes when using "default" build flags, i.e. by running
61*cc4ad7daSAndroid Build Coastguard Worker    'autogen.sh c'
62