kmod/testsuite
Emil Velikov e16d92b429 Swap rsync for cp --archive for module sources copying
As Tobias reported, rsync is a bit of heavyweight dependency. We
introduced it, as a replacement for the rm/cp -r previously used.

The rsync was inspired since, unlike make, meson will build all the test
binaries/artefacts even without calling "meson test".

We can go back to cp with --archive (--preserve=timestamps at least),
which will ensure we don't get stale files. To ensure the second run
doesn't copy the source folder as _subfolder_ of the dest we need to
wildcard the copy... Plus we need a proper destination folder in the
first place.

With this, we get a no-op second+ builds - be that with meson or make.
Since the explicit always-dirty state is by design, drop the meson TODO
and document the output variable.

Confirmed by comparing both the `make --debug` output and the execution
times.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/192
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2024-10-17 16:57:43 -05:00
..
module-playground build: Fix KDIR again 2024-09-11 14:39:10 -05:00
rootfs-pristine shared: Fix EOF handling in freadline_wrapped 2024-09-27 23:17:38 -05:00
.gitignore testsuite: Rename test-user 2024-08-16 16:47:33 -05:00
COPYING testsuite: re-license under LGPL 2012-07-10 10:31:57 -03:00
delete_module.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
init_module.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
Makefile build-sys: add small redirecting Makefiles 2014-03-06 01:59:58 -03:00
meson.build Swap rsync for cp --archive for module sources copying 2024-10-17 16:57:43 -05:00
path.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
README testsuite: Adjust README 2024-09-27 23:14:04 -05:00
stripped-module.h testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-array.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-blacklist.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-dependencies.c Use SPDX header for license 2024-07-26 13:41:56 -05:00
test-depmod.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-hash.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-init.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-initstate.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-list.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-loaded.c Use SPDX header for license 2024-07-26 13:41:56 -05:00
test-modinfo.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-modprobe.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-new-module.c testsuite: reformat and clang-format off arrays 2024-09-08 23:39:19 -05:00
test-scratchbuf.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
test-strbuf.c testsuite/test-strbuf: use const char * for strbuf_str() 2024-10-15 09:30:59 -05:00
test-testsuite.c testsuite: preserve the existing LD_PRELOAD 2024-10-17 08:35:10 -05:00
test-util.c shared: introduce umul{32,64}_overflow() helpers 2024-10-15 12:42:56 -05:00
test-weakdep.c testsuite: Fix test-weakdep with autoconf defaults 2024-09-27 23:14:04 -05:00
testsuite.c testsuite: preserve the existing LD_PRELOAD 2024-10-17 08:35:10 -05:00
testsuite.h testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00
uname.c testsuite: mass convert with clang-format 2024-09-24 09:59:20 -05:00

testsuite

OVERVIEW
========

Kmod's testsuite was designed to automate the process of running tests with
different scenarios, configurations and architectures. The idea is that once we
received a bug report, we reproduce it using the testsuite so we avoid
recurring on the same bug in future.


FEATURES
========

- Isolate each test by running them in separate processes;
- Exec a binary, so we can test the tools and not only the lib API
- Fake accesses to filesystem so we can provide a test rootfs with all the
  configuration, indexes, etc that test needs to be executed.
- Fake calls to init_module(), delete_module() and uname(), so we don't have to
  run tests as root and figure out how to deal with different architectures.

HOW TO ADD A TEST
=================

The simplest way to add a test is to copy and paste one already there. Most of
the options you can have are covered by another tests. This is what you need to
pay attention when writing a test:

1 - Look at testsuite.h, struct test, to see all the options available.

2 - Use TESTSUITE_MAIN and DEFINE_TEST to add new tests. Don't forget to fill
    its description.

3 - If you want testsuite to compare the stdout/stderr of your tests in order
    to check if it worked or not, fill in output.{stderr,stdout} the file with
    the expected output. Bear in mind the same file is used for all
    architectures, so don't print arch-dependent content if you are comparing
    the output.

4 - Fill in the config vector. Setting any of these configuration will make
    testsuite to export LD_PRELOAD with the necessary override libs before
    executing the test. If you are not exec'ing an external binary, you need to
    pass "need_spawn = true" below, otherwise it will not work (LD_PRELOAD is
    only applied when exec'ing a binary). See each config description in
    testsuite.h

5 - need_spawn: if testsuite will exec itself before running a test

6 - expected_fail: if that test is expected to fail, i.e. the return code is
    expected not to be 0.

7 - The rootfs is populated by copying the entire contents of rootfs-pristine
    through setup-rootfs.sh then running setup-modules.sh to copy generated
    modules from module-playground. Update the latter script to include any
    modules your test needs.

8 - Tests can be run individually, outside of 'make check'. strace and gdb work
    too, as long as you tell them to operate on child process.

9 - Make sure test passes when using "default" build flags, i.e. by running
    'autogen.sh c'