KUnit installation

Hello!

Sorry for naive questions. I’m trying to write a simple unit test (using KUnit https://www.kernel.org/doc/html/latest/dev-tools/kunit/) for my kernel module but looks like KUnit is not “enabled” by default in openSUSE (TUMBLEWEED). By not “enabled” I mean that there is only a header file “kunit/test.h” but appropriate kunit.ko and kunit.symvers are absent, so it’s not possible to compile a module that uses this lib.

What I’ve already tried to do is:

  1. Install linux sources
  2. Run **make menuconfig**
  3. Enable KUnit and specify SUSE_VERSION (5) and SUSE_PATCHLEVEL (12)
  4. Run **make** **modules_install**

After that I’ve found that kunit.ko generated but when I tried to insert it, I’ve got an error:
version magic '5.12.0 mod_unload ’ should be '5.12.0-2-default SMP mod_unload modversions '

Also, after make module_install /usr/src/linux-5.12.0-2/Module.symvers contains kunit’s methods but when I build my module with this symvers
**make -C /lib/modules/$(shell uname -r)/build M=$(PWD)/test modules KBUILD_EXTRA_SYMBOLS+=/usr/src/linux-5.12.0-2/Module.symvers
**I’ve got a lot of warnings that methods are exported twice
WARNING: modpost: vmlinux: ‘si_meminfo’ exported twice. Previous export was in vmlinux
WARNING: modpost: vmlinux: ‘poll_freewait’ exported twice. Previous export was in vmlinux
WARNING: modpost: vmlinux: ‘vfs_fsync’ exported twice. Previous export was in vmlinux

So, ideally I would prefer to have a symservs file that contains only kunit’s methods.

I would really appreciate any advice what else I can try (most probably I need to specify some special version in config file to have build exactly for my kernel version 5.12.0-2-default). May be it’s possible to enable KUnit without kernel re-compilation?

Thanks a lot!

P.S.
If it’s important, for my experiments I use Vagrant+VirtualBox.

Hi
OBS and build as a kmp (kernel module package)… Here you go;
https://build.opensuse.org/package/show/home:malcolmlewis:TESTING/kunit


 zypper if kunit-kmp-default

Information for package kunit-kmp-default:
------------------------------------------
Repository     : @System
Name           : kunit-kmp-default
Version        : 5.12.0_k5.12.0_2-0
Arch           : x86_64
Vendor         : obs://build.opensuse.org/home:malcolmlewis:TESTING
Installed Size : 521.6 KiB
Installed      : Yes
Status         : up-to-date
Source package : kunit-5.12.0-0.src
Summary        : Unit Testing for the Linux Kernel
Description    : 
    KUnit is a lightweight unit testing and mocking framework for the Linux kernel.


modinfo kunit

filename:       /lib/modules/5.12.0-2-default/updates/kunit.ko
license:        GPL v2
suserelease:    openSUSE Tumbleweed
srcversion:     BED1FAF279EEE1D0F54D060
depends:        
retpoline:      Y
name:           kunit
vermagic:       5.12.0-2-default SMP mod_unload modversions 

modprobe kunit

lsmod | grep kunit
kunit                  28672  0

Thank you very very much! You’ve really saved hours of my life :slight_smile: And special thanks for pointing to “Open Build Service”, I didn’t know about this service!

If you don’t mind, one more question. I’ve installed your rpm and kunit.ko can be successfully inserted now but may be you know the right way how to generate a Module.symvers for kunit?

Otherwise I have these errors during compilation

ERROR: modpost: "kunit_binary_assert_format" [/vagrant/test/mt-unit-test.ko] undefined!
ERROR: modpost: "__kunit_test_suites_init" [/vagrant/test/mt-unit-test.ko] undefined!
ERROR: modpost: "__kunit_test_suites_exit" [/vagrant/test/mt-unit-test.ko] undefined!

Hi
Hard to say, I’m assuming this is your code? Have you seen the kunit-example-test.c file?

Yep, I’ve got the same errors when tried to compile it.
Now for compilation I use just

make -C /lib/modules/$(shell uname -r)/build M=$(PWD)/test modules

and looks like the system cannot identify kunit methods. Previously, when I built kunit locally, there was generated Module.symvers that contained all these __kunit_test_suites_init/__kunit_test_suites_exit, so adding

KBUILD_EXTRA_SYMBOLS+=/usr/src/linux-5.12.0-2/Module.symvers

to make command helped.