Message ID | 20240103145820.2c39860ffa9c.Iecbc3fa660e78e8339d25231c12750dd00caf1f4@changeid |
---|---|
State | Accepted |
Headers | show |
Series | tests: hwsim: kernel: add a test for kunit | expand |
On Wed, Jan 03, 2024 at 02:58:21PM +0100, Johannes Berg wrote: > Add a test that runs the cfg80211/mac80211 kunit tests > (they must be built as modules to run at this point), > and checks the results. The test is skipped if all the > modules fail to load. Thanks, applied. What would happen if this test case were run multiple times in the same VM? Would the kernel module need to be unloaded at the end of the test case to make that work? Could the current version result in failing the first run and then claiming that the second attempt passed since the modules were not loaded again?
On Sun, 2024-01-14 at 18:26 +0200, Jouni Malinen wrote: > > What would happen if this test case were run multiple times in the same > VM? Would the kernel module need to be unloaded at the end of the test > case to make that work? Could the current version result in failing the > first run and then claiming that the second attempt passed since the > modules were not loaded again? I had never even thought about that, but I think literally nothing will happen. The module load will appear to succeed since it's already there, and no 'fail=N' string will show up in dmesg due to it. I had considered parsing out the tests, but over time we've had this be somewhat brittle even with the parsing scripts that are shipped as part of the kernel, requiring updates every once a while. That didn't seem great. Having the hostap test know about the expected kunit tests also seemed awkward, so I settled for just making sure this fails if it fails. johannes
diff --git a/tests/hwsim/test_kernel.py b/tests/hwsim/test_kernel.py index d8bb3fb8b3c5..5d007cb705cf 100644 --- a/tests/hwsim/test_kernel.py +++ b/tests/hwsim/test_kernel.py @@ -10,9 +10,11 @@ import hostapd import binascii import os, time import struct +import subprocess, re from test_wnm import expect_ack from tshark import run_tshark from utils import clear_regdom, long_duration_test +from utils import HwsimSkip def _test_kernel_bss_leak(dev, apdev, deauth): ssid = "test-bss-leak" @@ -148,3 +150,17 @@ def test_kernel_reg_disconnect(dev, apdev): finally: dev[0].request("DISCONNECT") clear_regdom(hapd, dev) + +def test_kernel_kunit(dev, apdev): + modules = ('cfg80211-tests', 'mac80211-tests') + results = (subprocess.call(['modprobe', mod], stderr=subprocess.PIPE) + for mod in modules) + + if all((r != 0 for r in results)): + raise HwsimSkip("KUnit tests not available") + + dmesg = subprocess.check_output(['dmesg']) + fail_rx = re.compile(b'fail:[^0]') + for line in dmesg.split(b'\n'): + if fail_rx.search(line): + raise Exception(f'kunit test failed: {line.decode("utf-8")}')