Commit Graph

239 Commits

Author SHA1 Message Date
Lucas De Marchi 3d38e322f9 testsuite: Handle different sysconfdir
Instead of skipping tests if sysconfdir isn't /etc, just handle it
during the rootfs setup logic.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-02-10 14:29:28 -08:00
Lucas De Marchi 184a070733 testsuite: Move setup-rootfs logic from Makefile to script
It's easier to implement the logic outside of the Makefile, so rename
the populate-modules.sh script to setup-rootfs.sh and move the
additional logic from the makefile to the script.

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-02-10 14:27:27 -08:00
Emil Velikov 96152dd687 testsuite/depmod: use defines for the rootfs/lib_modules
The uname used across the tests is same, so drop "_ORDER" from the macro
name and use it throughout. Similarly - add respective LIB_MODULES
defines and use them in the tests.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09 11:11:40 -08:00
Emil Velikov 6661e5970a testsuite: add function declarations for __xstat family
As the inline comment says - the declarations have been dropped with
glibc 2.32.9000, as a result the build throws a set of lovely warnings.

Inspired by umockdev, which bears the same license as this project.
f1b4164004

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09 07:16:06 -08:00
Emil Velikov efc2e4b467 treewide: add some static const notations
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-02-09 07:15:56 -08:00
Emil Velikov 1712a1548e depmod: Introduce outdir option
This option is equivalent to basedir, with the small difference being
that's where the meta-data files are generated. In other words, this
allows us to have read-only input modules and modules.dep, while still
being able to generate the meta-data files.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
[ Move files to a different dir so input files (produced by kernel build
  system is separate from the files generated by depmod (output) ]
Signed-off-by: Lucas De Marchi <lucas.demarchi@gmail.com>
2023-02-09 07:09:06 -08:00
Gustavo Sousa 883d931d1b modprobe: Allow passing path to module
This is useful to kernel module developers for testing a just compiled
module: instead of using insmod, they can load the module from the path
while getting all the benefits of modprobe (e.g. module dependency
resolution).

v2:
  - Add test for relative path as well. (Lucas)
  - Add note warning about modules with dependencies not matching the
    installed depmod database. (Lucas)

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13 16:48:02 -08:00
Gustavo Sousa e54f74c4f7 testsuite: Wrap chdir()
One of the tests in an upcoming patch will need to change into a
specific directory to test loading a module from a relative path.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2023-01-13 16:48:02 -08:00
Julien Cristau b4d281f962 testsuite: fix override of `stat` on 32-bit architectures
When _FILE_OFFSET_BITS is 64, glibc headers turn `stat` calls into
`stat64`, and our `stat` override into a `stat64` function.  However,
because we use dlsym to get the address of libc's `stat`, we end up
calling into the "real" `stat` function, which deals with 32-bit off_t,
and we treat its result as if it were returned from stat64.  On most
architectures this seems to have been harmless, but on 32-bit mips,
st_mode's offset in struct stat and struct stat64 are different, so we
read garbage.

To fix this, explicitly unset _FILE_OFFSET_BITS in path.c, to turn off
the redirect magic in glibc headers, and override both the 32-bit and
64-bit functions so each call ends up wrapping the right libc function.

Fixes #16 (https://github.com/kmod-project/kmod/issues/16)
2022-09-05 13:35:09 -07:00
Jan Engelhardt 16c086f48c testsuite: repair read of uninitialized memory
Function ``test_backoff_time`` does not initialize ``delta``, and
``get_backoff_delta_msec`` then performs a read from uninitialized
memory with the ``!*delta`` expression.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
2022-06-30 09:54:23 -07:00
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