History

Merge tag 'linux-kselftest-kunit-fixes-5.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull Kunit fixes from Shuah Khan: - Fixes to address the structleak plugin causing the stack frame size to grow immensely when used with KUnit. Fixes include adding a new makefile to disable structleak and using it from KUnit iio, device property, thunderbolt, and bitfield tests to disable it. - KUnit framework reference count leak in kfree_at_end - KUnit tool fix to resolve conflict between --json and --raw_output and generate correct test output in either case. - kernel-doc warnings due to mismatched arg names * tag 'linux-kselftest-kunit-fixes-5.15-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: kunit: fix kernel-doc warnings due to mismatched arg names bitfield: build kunit tests without structleak plugin thunderbolt: build kunit tests without structleak plugin device property: build kunit tests without structleak plugin iio/test-format: build kunit tests without structleak plugin gcc-plugins/structleak: add makefile var for disabling structleak kunit: fix reference count leak in kfree_at_end kunit: tool: better handling of quasi-bool args (--json, --raw_output)

Linus Torvalds committed 5 years ago

Commit fa587872 parents 459ea72 361b57d9 files · +43 −9Browse files

Unified · Split

9 files
  1. drivers/base/test/Makefile +1 −1
  2. drivers/iio/test/Makefile +1 −0
  3. drivers/thunderbolt/Makefile +1 −0
  4. include/kunit/test.h +3 −3
  5. lib/Makefile +1 −1
  6. lib/kunit/executor_test.c +2 −2
  7. scripts/Makefile.gcc-plugins +4 −0
  8. tools/testing/kunit/kunit.py +22 −2
  9. tools/testing/kunit/kunit_tool_test.py +8 −0
drivers/base/test/Makefile+1−1
@@ -2,4 +2,4 @@ · 1 unmodified line
22 obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o
33
44 obj-$(CONFIG_DRIVER_PE_KUNIT_TEST) += property-entry-test.o
5−CFLAGS_REMOVE_property-entry-test.o += -fplugin-arg-structleak_plugin-byref -fplugin-arg-structleak_plugin-byref-all
5+CFLAGS_property-entry-test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
drivers/iio/test/Makefile+1−0
@@ -5,3 +5,4 @@ · 4 unmodified lines
55
66 # Keep in alphabetical order
77 obj-$(CONFIG_IIO_TEST_FORMAT) += iio-test-format.o
8+CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
drivers/thunderbolt/Makefile+1−0
@@ -7,6 +7,7 @@ thunderbolt-objs += usb4_port.o nvm.o retimer.o quirks.o · 6 unmodified lines
77 thunderbolt-${CONFIG_ACPI} += acpi.o
88 thunderbolt-$(CONFIG_DEBUG_FS) += debugfs.o
99 thunderbolt-${CONFIG_USB4_KUNIT_TEST} += test.o
10+CFLAGS_test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
1011
1112 thunderbolt_dma_test-${CONFIG_USB4_DMA_TEST} += dma_test.o
1213 obj-$(CONFIG_USB4_DMA_TEST) += thunderbolt_dma_test.o
include/kunit/test.h+3−3
@@ -613,7 +613,7 @@ void kunit_remove_resource(struct kunit *test, struct kunit_resource *res); · 612 unmodified lines
613613 * and is automatically cleaned up after the test case concludes. See &struct
614614 * kunit_resource for more information.
615615 */
616−void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t flags);
616+void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp);
617617
618618 /**
619619 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
@@ -657,9 +657,9 @@ static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp) · 37 unmodified lines
657657 *
658658 * See kcalloc() and kunit_kmalloc_array() for more information.
659659 */
660−static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp_t flags)
660+static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp_t gfp)
661661 {
662− return kunit_kmalloc_array(test, n, size, flags | __GFP_ZERO);
662+ return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO);
663663 }
664664
665665 void kunit_cleanup(struct kunit *test);
lib/Makefile+1−1
@@ -351,7 +351,7 @@ obj-$(CONFIG_OBJAGG) += objagg.o · 350 unmodified lines
351351 obj-$(CONFIG_PLDMFW) += pldmfw/
352352
353353 # KUnit tests
354−CFLAGS_bitfield_kunit.o := $(call cc-option,-Wframe-larger-than=10240)
354+CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
355355 obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
356356 obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
357357 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
lib/kunit/executor_test.c+2−2
@@ -116,8 +116,8 @@ static void kfree_at_end(struct kunit *test, const void *to_free) · 115 unmodified lines
116116 /* kfree() handles NULL already, but avoid allocating a no-op cleanup. */
117117 if (IS_ERR_OR_NULL(to_free))
118118 return;
119− kunit_alloc_and_get_resource(test, NULL, kfree_res_free, GFP_KERNEL,
120− (void *)to_free);
119+ kunit_alloc_resource(test, NULL, kfree_res_free, GFP_KERNEL,
120+ (void *)to_free);
121121 }
122122
123123 static struct kunit_suite *alloc_fake_suite(struct kunit *test,
scripts/Makefile.gcc-plugins+4−0
@@ -19,6 +19,10 @@ gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF) \ · 18 unmodified lines
1919 += -fplugin-arg-structleak_plugin-byref
2020 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) \
2121 += -fplugin-arg-structleak_plugin-byref-all
22+ifdef CONFIG_GCC_PLUGIN_STRUCTLEAK
23+ DISABLE_STRUCTLEAK_PLUGIN += -fplugin-arg-structleak_plugin-disable
24+endif
25+export DISABLE_STRUCTLEAK_PLUGIN
2226 gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) \
2327 += -DSTRUCTLEAK_PLUGIN
2428
tools/testing/kunit/kunit.py+22−2
@@ -16,7 +16,7 @@ assert sys.version_info >= (3, 7), "Python version is too old" · 15 unmodified lines
1616
1717 from collections import namedtuple
1818 from enum import Enum, auto
19−from typing import Iterable
19+from typing import Iterable, Sequence
2020
2121 import kunit_config
2222 import kunit_json
@@ -186,6 +186,26 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree, · 163 unmodified lines
186186 exec_result.elapsed_time))
187187 return parse_result
188188
189+# Problem:
190+# $ kunit.py run --json
191+# works as one would expect and prints the parsed test results as JSON.
192+# $ kunit.py run --json suite_name
193+# would *not* pass suite_name as the filter_glob and print as json.
194+# argparse will consider it to be another way of writing
195+# $ kunit.py run --json=suite_name
196+# i.e. it would run all tests, and dump the json to a `suite_name` file.
197+# So we hackily automatically rewrite --json => --json=stdout
198+pseudo_bool_flag_defaults = {
199+ '--json': 'stdout',
200+ '--raw_output': 'kunit',
201+}
202+def massage_argv(argv: Sequence[str]) -> Sequence[str]:
203+ def massage_arg(arg: str) -> str:
204+ if arg not in pseudo_bool_flag_defaults:
205+ return arg
206+ return f'{arg}={pseudo_bool_flag_defaults[arg]}'
207+ return list(map(massage_arg, argv))
208+
189209 def add_common_opts(parser) -> None:
190210 parser.add_argument('--build_dir',
191211 help='As in the make command, it specifies the build '
@@ -303,7 +323,7 @@ def main(argv, linux=None): · 111 unmodified lines
303323 help='Specifies the file to read results from.',
304324 type=str, nargs='?', metavar='input_file')
305325
306− cli_args = parser.parse_args(argv)
326+ cli_args = parser.parse_args(massage_argv(argv))
307327
308328 if get_kernel_root_path():
309329 os.chdir(get_kernel_root_path())
tools/testing/kunit/kunit_tool_test.py+8−0
@@ -408,6 +408,14 @@ class KUnitMainTest(unittest.TestCase): · 407 unmodified lines
408408 self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
409409 self.assertNotEqual(call, mock.call(StrContains(' 0 tests run')))
410410
411+ def test_run_raw_output_does_not_take_positional_args(self):
412+ # --raw_output is a string flag, but we don't want it to consume
413+ # any positional arguments, only ones after an '='
414+ self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
415+ kunit.main(['run', '--raw_output', 'filter_glob'], self.linux_source_mock)
416+ self.linux_source_mock.run_kernel.assert_called_once_with(
417+ args=None, build_dir='.kunit', filter_glob='filter_glob', timeout=300)
418+
411419 def test_exec_timeout(self):
412420 timeout = 3453
413421 kunit.main(['exec', '--timeout', str(timeout)], self.linux_source_mock)