Skip to content

Commit ba45037

Browse files
committed
Merge tag 'linux_kselftest-kunit-6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kunit updates from Shuah Khan: - Enable qemu_config for riscv32, sparc 64-bit, PowerPC 32-bit BE and 64-bit LE - Enable CONFIG_SPARC32 to clearly differentiate between sparc 32-bit and 64-bit configurations - Enable CONFIG_CPU_BIG_ENDIAN to clearly differentiate between powerpc LE and BE configurations - Add feature to list available architectures to kunit tool - Fixes to bugs and changes to documentation * tag 'linux_kselftest-kunit-6.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: Fix wrong parameter to kunit_deactivate_static_stub() kunit: tool: add test counts to JSON output Documentation: kunit: improve example on testing static functions kunit: executor: Remove const from kunit_filter_suites() allocation type kunit: qemu_configs: Disable faulting tests on 32-bit SPARC kunit: qemu_configs: Add 64-bit SPARC configuration kunit: qemu_configs: sparc: Explicitly enable CONFIG_SPARC32=y kunit: qemu_configs: Add PowerPC 32-bit BE and 64-bit LE kunit: qemu_configs: powerpc: Explicitly enable CONFIG_CPU_BIG_ENDIAN=y kunit: tool: Implement listing of available architectures kunit: qemu_configs: Add riscv32 config kunit: configs: Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests
2 parents 2d2435e + 772e50a commit ba45037

File tree

13 files changed

+120
-10
lines changed

13 files changed

+120
-10
lines changed

Documentation/dev-tools/kunit/run_wrapper.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ via UML. To run tests on qemu, by default it requires two flags:
182182
is ignored), the tests will run via UML. Non-UML architectures,
183183
for example: i386, x86_64, arm and so on; run on qemu.
184184

185+
``--arch help`` lists all valid ``--arch`` values.
186+
185187
- ``--cross_compile``: Specifies the Kbuild toolchain. It passes the
186188
same argument as passed to the ``CROSS_COMPILE`` variable used by
187189
Kbuild. As a reminder, this will be the prefix for the toolchain

Documentation/dev-tools/kunit/usage.rst

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,28 +670,50 @@ with ``kunit_remove_action``.
670670
Testing Static Functions
671671
------------------------
672672

673-
If we do not want to expose functions or variables for testing, one option is to
674-
conditionally export the used symbol. For example:
673+
If you want to test static functions without exposing those functions outside of
674+
testing, one option is conditionally export the symbol. When KUnit is enabled,
675+
the symbol is exposed but remains static otherwise. To use this method, follow
676+
the template below.
675677

676678
.. code-block:: c
677679
678-
/* In my_file.c */
680+
/* In the file containing functions to test "my_file.c" */
679681
680-
VISIBLE_IF_KUNIT int do_interesting_thing();
682+
#include <kunit/visibility.h>
683+
#include <my_file.h>
684+
...
685+
VISIBLE_IF_KUNIT int do_interesting_thing()
686+
{
687+
...
688+
}
681689
EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing);
682690
683-
/* In my_file.h */
691+
/* In the header file "my_file.h" */
684692
685693
#if IS_ENABLED(CONFIG_KUNIT)
686694
int do_interesting_thing(void);
687695
#endif
688696
689-
Alternatively, you could conditionally ``#include`` the test file at the end of
690-
your .c file. For example:
697+
/* In the KUnit test file "my_file_test.c" */
698+
699+
#include <kunit/visibility.h>
700+
#include <my_file.h>
701+
...
702+
MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
703+
...
704+
// Use do_interesting_thing() in tests
705+
706+
For a full example, see this `patch <https://lore.kernel.org/all/[email protected]/>`_
707+
where a test is modified to conditionally expose static functions for testing
708+
using the macros above.
709+
710+
As an **alternative** to the method above, you could conditionally ``#include``
711+
the test file at the end of your .c file. This is not recommended but works
712+
if needed. For example:
691713

692714
.. code-block:: c
693715
694-
/* In my_file.c */
716+
/* In "my_file.c" */
695717
696718
static int do_interesting_thing();
697719

lib/kunit/executor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set,
177177

178178
const size_t max = suite_set->end - suite_set->start;
179179

180-
copy = kcalloc(max, sizeof(*filtered.start), GFP_KERNEL);
180+
copy = kcalloc(max, sizeof(*copy), GFP_KERNEL);
181181
if (!copy) { /* won't be able to run anything, return an empty set */
182182
return filtered;
183183
}

lib/kunit/static_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void __kunit_activate_static_stub(struct kunit *test,
9696

9797
/* If the replacement address is NULL, deactivate the stub. */
9898
if (!replacement_addr) {
99-
kunit_deactivate_static_stub(test, replacement_addr);
99+
kunit_deactivate_static_stub(test, real_fn_addr);
100100
return;
101101
}
102102

tools/testing/kunit/configs/all_tests.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CONFIG_KUNIT_EXAMPLE_TEST=y
1010
CONFIG_KUNIT_ALL_TESTS=y
1111

1212
CONFIG_FORTIFY_SOURCE=y
13+
CONFIG_INIT_STACK_ALL_PATTERN=y
1314

1415
CONFIG_IIO=y
1516

tools/testing/kunit/kunit_json.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ def _get_group_json(test: Test, common_fields: JsonObj) -> JsonObj:
3939
status = _status_map.get(subtest.status, "FAIL")
4040
test_cases.append({"name": subtest.name, "status": status})
4141

42+
test_counts = test.counts
43+
counts_json = {
44+
"tests": test_counts.total(),
45+
"passed": test_counts.passed,
46+
"failed": test_counts.failed,
47+
"crashed": test_counts.crashed,
48+
"skipped": test_counts.skipped,
49+
"errors": test_counts.errors,
50+
}
4251
test_group = {
4352
"name": test.name,
4453
"sub_groups": sub_groups,
4554
"test_cases": test_cases,
55+
"misc": counts_json
4656
}
4757
test_group.update(common_fields)
4858
return test_group

tools/testing/kunit/kunit_kernel.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import shlex
1515
import shutil
1616
import signal
17+
import sys
1718
import threading
1819
from typing import Iterator, List, Optional, Tuple
1920
from types import FrameType
@@ -201,6 +202,13 @@ def _default_qemu_config_path(arch: str) -> str:
201202
return config_path
202203

203204
options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')]
205+
206+
if arch == 'help':
207+
print('um')
208+
for option in options:
209+
print(option)
210+
sys.exit()
211+
204212
raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options)))
205213

206214
def _get_qemu_ops(config_path: str,

tools/testing/kunit/qemu_configs/powerpc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
QEMU_ARCH = QemuArchParams(linux_arch='powerpc',
44
kconfig='''
55
CONFIG_PPC64=y
6+
CONFIG_CPU_BIG_ENDIAN=y
67
CONFIG_SERIAL_8250=y
78
CONFIG_SERIAL_8250_CONSOLE=y
89
CONFIG_HVC_CONSOLE=y''',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
from ..qemu_config import QemuArchParams
4+
5+
QEMU_ARCH = QemuArchParams(linux_arch='powerpc',
6+
kconfig='''
7+
CONFIG_PPC32=y
8+
CONFIG_CPU_BIG_ENDIAN=y
9+
CONFIG_ADB_CUDA=y
10+
CONFIG_SERIAL_PMACZILOG=y
11+
CONFIG_SERIAL_PMACZILOG_TTYS=y
12+
CONFIG_SERIAL_PMACZILOG_CONSOLE=y
13+
''',
14+
qemu_arch='ppc',
15+
kernel_path='vmlinux',
16+
kernel_command_line='console=ttyS0',
17+
extra_qemu_params=['-M', 'g3beige', '-cpu', 'max'])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
from ..qemu_config import QemuArchParams
4+
5+
QEMU_ARCH = QemuArchParams(linux_arch='powerpc',
6+
kconfig='''
7+
CONFIG_PPC64=y
8+
CONFIG_CPU_LITTLE_ENDIAN=y
9+
CONFIG_HVC_CONSOLE=y
10+
''',
11+
qemu_arch='ppc64',
12+
kernel_path='vmlinux',
13+
kernel_command_line='console=ttyS0',
14+
extra_qemu_params=['-M', 'pseries', '-cpu', 'power8'])

0 commit comments

Comments
 (0)