Re: [PATCH v2 0/2] kunit: add boot time parameter to enable KUnit
From: Tales Aparecida
Date: Sat Sep 24 2022 - 20:44:13 EST
Hi,
This series is
Tested-by: Tales Aparecida <tales.aparecida@xxxxxxxxx>
1. Tested using kunit_tool: running tests and showing output as expected.
2. Tested further by running QEMU through virtme-run with:
$ ../virtme/virtme-run --show-command --kdir ../linux/.for-amd/ --mods=auto --kopt kunit.enable=1
2.a. "KUNIT_DEFAULT_ENABLED" works as expected when "kunit.enable" is omitted
2.b. kunit.enable=0 results in printing "kunit: disabled" on boot and on loading test modules, as expected
3.c. kunit.enable=1 runs tests on boot and allows them to run when loading test modules
3. Regarding taint
3.a. /proc/sys/kernel/tainted is 0 when kunit.enable=0 and does not change when trying to load test modules.
3.b. /proc/sys/kernel/tainted is 0 when kunit.enable=1 until the first test runs, then it becomes 262144 (2^18) as expected.
On other note, there's something I would like to delve into below.
On 23/08/2022 11:24, Joe Fradley wrote:
> v2:
> - Added enable check in executor.c to prevent wrong error output from
> kunit_tool.py when run against a KUnit disabled kernel
> - kunit_tool.py now passes kunit.enable=1
> - Flipped around logic of new config to KUNIT_DEFAULT_ENABLED
> - Now load modules containing tests but not executing them
> - Various message/description text clean up
>
> There are some use cases where the kernel binary is desired to be the same
> for both production and testing. This poses a problem for users of KUnit
> as built-in tests will automatically run at startup and test modules
> can still be loaded leaving the kernel in an unsafe state. There is a
> "test" taint flag that gets set if a test runs but nothing to prevent
> the execution.
Do you have any info on whether these use cases would have something against writing tests for static functions using the documented approach of including the tests into the actual runtime code?
https://docs.kernel.org/dev-tools/kunit/usage.html#testing-static-functions
Otherwise, would them agree to export the symbols that need to be tested?
I would really like to understand better what are these use cases :)
>
> This patch adds the kunit.enable module parameter that will need to be
> set to true in addition to KUNIT being enabled for KUnit tests to run.
> The default value is true giving backwards compatibility. However, for
> the production+testing use case the new config option KUNIT_DEFAULT_ENABLED
> can be set to N requiring the tester to opt-in by passing kunit.enable=1 to
> the kernel.
>
> Joe Fradley (2):
> kunit: add kunit.enable to enable/disable KUnit test
> kunit: no longer call module_info(test, "Y") for kunit modules
>
> .../admin-guide/kernel-parameters.txt | 6 +++++
> include/kunit/test.h | 3 ++-
> lib/kunit/Kconfig | 11 +++++++++
> lib/kunit/executor.c | 4 ++++
> lib/kunit/test.c | 24 +++++++++++++++++++
> tools/testing/kunit/kunit_kernel.py | 1 +
> 6 files changed, 48 insertions(+), 1 deletion(-)
>
Great work!
Kind regards,
Tales