Commit Graph

229 Commits

Author SHA1 Message Date
Lucas De Marchi b253f4c835 testsuite: Add tests for sleep calculation
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:23:46 -07:00
Lucas De Marchi 5622f1dae1 util: Add time-related functions from testsuite
This will be useful in future not only to testsuite, but also to tools
and library.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:23:46 -07:00
Lucas De Marchi 2ab4fbcb77 module-playground: Add debugfs entry in mod-simple
Add a debugfs file in mod-simple for manual tests: insert the module and
open the file to have its refcount increased.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-26 23:23:46 -07:00
Lucas De Marchi 9dc4e5ccd4 test-initstate: Check for negative value on error
Documentation says kmod_module_new_from_lookup() returns < 0 on error
and 0 otherwise. There are bugs in libkmod however making it return
a positive value in some situations, that need to be fixed. However
it's best to check for the error explicitly like is done in the rest
of the library to avoid this kind of issues.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
2022-02-20 20:58:11 -08:00
Lucas De Marchi b07bfb4a10 testsuite: update gitignore 2021-05-11 09:57:10 -07:00
Lucas De Marchi d8b31c34a6 test-modprobe: share single function for kcmdline tests 2021-02-15 11:53:43 -08:00
Lucas De Marchi b77251f08d testsuite: allow to re-use single function for tests
Add a new DEFINE_TEST_WITH_FUNC() that accepts the function
alongside the test name. This will allow us to share a single function
for different tests.
2021-02-15 11:53:43 -08:00
Lucas De Marchi d3a1fe67b6 libkmod-config: re-quote option from kernel cmdline
It was reported that grub mangles the kernel cmdline. It turns

	acpi_cpufreq.dyndbg="file drivers/cpufreq/acpi-cpufreq.c +mpf"

	into

	"acpi_cpufreq.dyndbg=file drivers/cpufreq/acpi-cpufreq.c +mpf"

However, even though we could blame grub for doing that, the kernel
happily accepts and re-quotes it when the module is built-in.
So, it's better if kmod also understands it this way and does the same.

Here we basically add additional code to un-mangle it, moving the quote
in way that is acceptable to pass through init_module(). Note that the
interface [f]init_module() gives us mandates the quote to be part of the
value: the module name is not passed and the options are separated by
space.

Reported-by: Jiri Slaby <jirislaby@kernel.org>
Tested-by: Jessica Yu <jeyu@kernel.org>
Link: https://bugzilla.suse.com/show_bug.cgi?id=1181111#c10
2021-02-15 11:53:43 -08:00
Lucas De Marchi fd71604da9 testsuite: also test xz compression
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-02-05 19:54:31 -08:00
Lucas De Marchi 1921c370c2 testsuite: compress modules if feature is enabled
Since the output needs to be the same, regardless if the module is
compressed, change populate-modules.sh to conditionally compress the
module if that feature is enabled.

This way we can execute the tests with any build-time configuration and
it should still pass.

Suggested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Michal Suchánek <msuchanek@suse.de>
Tested-by: Michal Suchánek <msuchanek@suse.de>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
2021-02-05 19:52:00 -08:00
Dave Reisner 3cee67ddd7 populate-modules: Use more bash, more quotes
We're already using associatives arrays, so there's no reason we should
be using 'test'.
2021-01-23 11:06:15 -08:00
Marius Bakke 847247a4a8 testsuite: Automatically skip tests that fail when sysconfdir != /etc. 2021-01-07 19:44:50 -08:00
Marius Bakke b5683f45d9 testsuite: Add facility to skip tests.
The Makefile helpfully warns that some tests will fail when
--sysconfdir != /etc, but there are no provisions to easily disable
those.  This commit provides an escape hatch.

[ Lucas: add comment detailing the purpose of the field ]
2021-01-07 19:44:20 -08:00
Lucas De Marchi 30c9c4d90f testsuite: add test for empty modules.builtin.aliases.bin 2020-12-27 16:40:08 -08:00
Lucas De Marchi e4a72e4754 shared: fix UNIQ definition
We need a macro indirection for UNIQ to work. Otherwise it won't be
unique at all since it will just append "UNIQ" to the name:

In file included from testsuite/test-init.c:30:

testsuite/testsuite.h:142:27: error: redefinition of ‘stest_load_resourcesUNIQ’
2020-12-27 16:40:08 -08:00
Torge Matthies 2e4ef3da55 testsuite: add test for zstd-compressed module
I took away one module from the gzip-compressed modules for this purpose.

Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2020-09-10 21:55:01 -07:00
Torge Matthies 3821e1971e add Zstandard compression support
I changed the style of the hackargs variable in autogen.sh to multiline
because said line was becoming a bit long with the new --with-zstd arg
added.

A previous version of this patch has been running on my two Arch Linux
installations (with an accompanying mkinitcpio patch) for several months
over many kernel updates without any issues.
Any additional testing and/or patch review would of course be appreciated.

Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2020-09-10 21:55:01 -07:00
Lucas De Marchi f5434cf5fc testsuite: add check for kmod_load_resources
Make sure we can call kmod_load_resources when we do have all the
mandatory indexes in place.
2020-03-23 12:39:58 -07:00
Lucas De Marchi 3c1073e17a testsuite: check for ill-formed kcmdline
Commit ca3bf5d47cec ("iommu/amd: Introduces ivrs_acpihid kernel parameter")
in the kernel introduced an ill-formed kernel parameter, ivrs_acpihid.
The problem is that it may have a dot on the key side:
"ivrs_acpihid[00:14.5]=AMD0020:0". This could potentially trip our
parser of module options, but right now it's working as intended: the
only thing that happens is that after deciding "ivrs_acpihid[00:14" is a
module name, it will fail the underscores() routine and the option will
be ignored from the kmod pov (not kernel's pov since that driver parsers
the kernel command line by itself).
2020-03-13 09:23:58 -07:00
Lucas De Marchi 8ea4f7c554 gitignore: ignore .cache.mk when building modules 2020-03-09 21:47:37 -07:00
Lucas De Marchi 6436260f73 testsuite: update gitignore 2019-11-06 23:37:34 -08:00
Lucas De Marchi ada929e0c5 testsuite: mkosi: update files
- Add openssl
  - Disable python (quick hack to avoid more dependencies)
  - Update Fedora to 29
2019-02-04 16:09:38 -08:00
Lucas De Marchi 0f37cf1c18 testsuite: fix modinfo test without openssl 2019-02-04 14:25:03 -08:00
Yauheni Kaliuta dec990483b testsuite: add modinfo pkcs7 signature test
Use the same approach to generate the signed module, like in the
old signature test: just append the pregenerated binary signature
to the module (the signature check will fail).

In case of need of generating correct signature, from the linux
kernel makefiles (certs/Makefile) it could be like:

$ openssl req -new -nodes -utf8  -sha256 -days 36500 -batch -x509
-config  ./x509.genkey -outform PEM -out signing_key.pem -keyout signing_key.pem
$ /lib/modules/$(uname -r)/build/scripts/extract-cert signing_key.pem signing_key.x509
$ /lib/modules/$(uname -r)/build/scripts/sign-file sha256 signing_key.pem signing_key.x509 module.ko

where x509.genkey is:

```
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts

[ req_distinguished_name ]
CN = Build time autogenerated kernel key

[ myexts ]
basicConstraints=critical,CA:FALSE
keyUsage=digitalSignature
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
```

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-02-04 13:49:13 -08:00
Yauheni Kaliuta ea37a74246 testsuite: factor out fd related parameters to a structure
This is a more abstract implementation of "file descriptor
comparation". With the current implementation the code is full of
conditions based on the descriptor type. It makes sense to
initialize the parameters once based on the descriptor type.

stdout and stderr are handled in almost the same way, but for
monitor descriptor branch, based on the type check is necessary in
some cases.

Since epoll's context now contains pointers to the structures, so no
direct manipulations there.

Most of the patch is just replacing direct buffer manipulations with
the structures' ones.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-01-04 14:39:39 -08:00
Yauheni Kaliuta b7cd0fdab0 testsuite: track number of descriptors instead of their state
use the number of tracked descriptors to determine the end of the
loop.

This is a preparation for more abstract descriptor comparation
implementation where checking of the descriptor state may be more
expensive than just checking of the local variables.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2019-01-04 14:39:39 -08:00
Lucas De Marchi eb862179c0 testsuite: move --show-exports test to use regex
This allows it to pass if the kernel is configured with
CONFIG_MODVERSIONS.
2019-01-03 12:43:18 -08:00
Lucas De Marchi c0937526b2 testsuite: add support for testing output against regex
Allow to test outputs when they don't match exactly, but should follow
some regex patterns. This can be used when the info we are printing is
randomized or depends on kernel configuration.
2019-01-03 12:43:18 -08:00
Lucas De Marchi a5cc3521d8 testsuite: split out function to compare outputs exactly
Move functionality to compare the exact output to a separate function
and allocate one buffer per output/match pair. This will allow us to
extend this to allow other types of comparisons. Since now we are using
heap-allocated buffer, keep the buffer allocation to the caller, so we
don't have to allocate and free it on every invocation. It also avoids
the different comparison functions to have to deal with it.
2019-01-03 12:03:27 -08:00
Lucas De Marchi 028d4df365 Remove bootstrap* scripts
Let's just use autogen.sh, no need for wrapper scripts. Now
`autogen.sh c` uses the same recommended options for developing kmod and
also accepts extra arguments.
2018-12-17 09:52:05 -08:00
Lucas De Marchi 068729e368 testsuite: add simple test for --show-exports 2018-11-13 10:45:00 -08:00
Lucas De Marchi 8353284d83 mkosi: allow Clear to use test modules
Now Clear has a bundle for the kernel headers, let's use it.
2018-10-10 13:47:50 -07:00
Lucas De Marchi bdf946d2cf testsuite: raise arch image to 3GB 2018-02-09 09:20:21 -08:00
Caio Marcelo de Oliveira Filho a76f997f4d testsuite: add Clear's mkosi configuration
Adapted the mkosi.build script to account for not building
test-modules in Clear. It doesn't have the headers available yet.
2018-02-08 16:38:08 -08:00
Lucas De Marchi 7acc5daeec testsuite: also wrap gettid in syscall()
Not a perfect solution for overriding syscall(), but at least
it makes the testsuite to pass in a modified nsswitch.conf (one that has
a module which calls syscall() to get the thread id).
2018-01-08 13:32:38 -08:00
Lucas De Marchi 77d7bd9eca testsuite: explain why overriding function may fail
On my computer `testsuite/test-modprobe modprobe_install_cmd_loop` was
failing because when it forks off the shell the child process ends up
calling syscall() which are are supposed to wrap. Here's the backtrace:

	#0  0x00007ffff6fdb66b in raise () from /lib64/libc.so.6
	#1  0x00007ffff6fdd381 in abort () from /lib64/libc.so.6
	#2  0x00007ffff77bac97 in syscall (__sysno=<optimized out>)
	    at testsuite/init_module.c:362
	#3  0x00007fffef92d4e7 in hashmap_base_new.lto_priv () from /lib64/libnss_systemd.so.2
	#4  0x00007fffef953f50 in sd_bus_open_system () from /lib64/libnss_systemd.so.2
	#5  0x00007fffef943123 in _nss_systemd_getpwuid_r () from /lib64/libnss_systemd.so.2
	#6  0x00007ffff707eea5 in getpwuid_r@@GLIBC_2.2.5 () from /lib64/libc.so.6
	#7  0x00007ffff707e608 in getpwuid () from /lib64/libc.so.6
	#8  0x00005555555859e1 in get_current_user_info.part ()
	#9  0x00005555555a375a in initialize_shell_variables ()
	#10 0x0000555555580fde in shell_initialize ()
	#11 0x00005555555846ff in main ()<Paste>

The reason it fails on my system and not on, for e.g., a new one set up with
mkosi is that the call to getpwuid() depends on the contents
/etc/nsswitch.conf. The systemd module calls syscall() to implement gettid()
which we can't forward due to being a variadic function.

No fix is provided here, but at least it's explained why this happens.
2018-01-03 14:23:31 -08:00
Lucas De Marchi 568b1c86cc testsuite: add missing error handling
If we passed an invalid argument to a test it would segfault rather than
returning an error code.
2018-01-03 14:22:11 -08:00
Lucas De Marchi dde2770ee6 testsuite: add Fedora's mkosi configuration
To use the Fedora configuration rather than the default, one should
use:

	# make DISTRO=fedora mkosi

While at it also reduce the root partition size for Arch, since it
doesn't need that much.
2018-01-03 14:22:11 -08:00
Lucas De Marchi 7bc6b67dc6 testsuite: generalize mkosi support for other distros
Instead of using the mkosi.default symlink, use an env var passed from
the build system. We would need to pass the --default switch nonetheless
or change the symlink, making the git tree dirty.

Also, search for installed kernel headers in a way that's compatible
with more distros. On Fedora, for example, the
/usr/lib/modules/<kver>/build symlink is only available if there's a
kernel installed. We don't care about a kernel installed since we don't
need to boot it on a real machine: the only thing we need is the
kernel-devel package.
2018-01-03 14:22:05 -08:00
Lucas De Marchi cc71e0a589 build: add mkosi hooks
Right now there's support for building on Archlinux only.
2018-01-02 15:05:44 -08:00
Yauheni Kaliuta 809b9fb6cf testsuite: depmod: add override test
Simple test to check if depmod honors override keyword. Uses
mod-simple.ko for foo/ and override/ directories, search.conf to
search in foo and built-in and simple override configuration:

override mod-simple 4.4.4 override

The resulting modules.dep should point to the override directory.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-12-07 13:08:00 -08:00
Yauheni Kaliuta df492f5ca3 testsuite: add tests for external directory support
The following tests added:

- depmod_search_order_external_first -- checks if external module
  is taken in use when it has higher priority;
- depmod_search_order_external_last -- checks if external module
  is skipped when it has lower priority;
- test_modinfo_external -- checks if modinfo is able to look up
  correct external module;
- modprobe_external -- checks if modprobe is able to look up
  correct external module and loads it.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-06-01 20:31:37 -07:00
Lucas De Marchi e0ff310d87 test-depmod: avoid warning when we don't have zlib
testsuite/test-depmod.c:31:21: warning: ‘depmod_modules_order_for_compressed’ defined but not used [-Wunused-function]
 static noreturn int depmod_modules_order_for_compressed(const struct test *t)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-06-01 20:26:23 -07:00
Yauheni Kaliuta 9be03c52cc testsuite: depmod: check netsted loops reporting
The patch adds nested loops configuration for the loop test:

mod-loop-h -> mod-loop-i -> mod-loop-j -> mod-loop-k
   ^                           |               |
    ---------------------------                |
   |                                           |
    -------------------------------------------

making 2 loops with common edges:

mod-loop-h -> mod-loop-i -> mod-loop-j -> mod-loop-h
mod-loop-h -> mod-loop-i -> mod-loop-j -> mod-loop-k -> mod-loop-h

The actual output for the loops is:

depmod: ERROR: Cycle detected: mod_loop_h -> mod_loop_h
depmod: ERROR: Cycle detected: mod_loop_i -> mod_loop_j -> mod_loop_k -> mod_loop_h -> mod_loop_i

(the order in the second doesn't matter, but the first one is
incorrect)

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
2017-02-22 04:50:22 -08:00
Lucas De Marchi 31dd40a6b8 libkmod-config: fix parsing quoted kernel cmdline on params
We can only accept quoted values, not module names or parameter names.
2017-02-16 09:18:35 -08:00
Lucas De Marchi ded0bebca8 testsuite: add test for kernel cmdline with quotes
Add some tests in which we quotes in kernel cmdline and also spaces
inside quotes.  This doesn't yet cover the case in which quotes are used
for module name, wihch should be forbidden.
2017-01-23 11:59:31 -08:00
Lucas De Marchi 55f8286fcd testsuite: fix typo in description 2017-01-23 11:58:29 -08:00
Lucas De Marchi 67d1534318 build: fix build with disabled test modules
install: cannot stat 'testsuite/module-playground/mod-loop-f.ko': No
such file or directory
Makefile:2881: recipe for target 'rootfs' failed
make[1]: *** [rootfs] Error 1
make[1]: *** Waiting for unfinished jobs....
Makefile:2101: recipe for target 'check-recursive' failed

We need to ship pre-compiled binaries so it's possible to run
"make check" on servers without kernel headers.

Also add them to EXTRA_DIST as other sources.
2016-11-10 23:47:19 -02:00
Mian Yousaf Kaukab 6b77f18896 depmod: ignore related modules in depmod_report_cycles
Only print actual cyclic dependencies. Print count of all the modules
in cyclic dependency at the end of the function so that dependent
modules which are not in cyclic chain can be ignored.

Printing dependent modules which are not in cyclic chain causes buffer
overflow as m->modnamesz is not included in buffer size calculations
(loop == m is never true). This buffer overflow causes kmod to crash.

Update depmod test to reflect the change as well.

Reported-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
2016-11-08 22:38:34 -02:00
Mian Yousaf Kaukab 965886b55a testsuite: depmod: add module dependency outside cyclic chain
Check that depmod do not report modules outside cyclic chain

Two modules f and g are added which do not have any dependency.
modules a and b are made dependent on f and g.

Here is the output of loop dependency check test after adding this
patch:

TESTSUITE: ERR: wrong:
depmod: ERROR: Found 7 modules in dependency cycles!
depmod: ERROR: Cycle detected: mod_loop_d -> mod_loop_e -> mod_loop_d
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_b
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_g
depmod: ERROR: Cycle detected: mod_loop_b -> mod_loop_c -> mod_loop_a -> mod_loop_f

Buffer overflow occurs in the loop when last two lines are printed.
43 bytes buffer is allocated and 53 bytes are used.

Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
2016-11-08 22:28:40 -02:00