From patchwork Tue Jan 21 21:16:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 13946648 X-Patchwork-Delegate: brendanhiggins@google.com Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE6761B2EFB for ; Tue, 21 Jan 2025 21:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737494208; cv=none; b=sdNnUIASNO+0tjH40SEIMrUrKmfLpxLcMepV8Jv8UFQks5if32gyIkiUtvXpO/bjgOwRs4+WskXtCK7jy19okRdk9qoQw5FOOYYq4mkCVqEr9MF6BKUxmCeR8t7v50KK5gE6RX0F/pfuz7bnarthCqnRUd7l3rcwenTQgb+Og3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737494208; c=relaxed/simple; bh=LiYyQjSn8/Ogrz53aGmr5g28X/Q2LgJPxWJUoYLkiqU=; h=Content-Type:Message-ID:Date:MIME-Version:To:From:Subject:Cc; b=iRstmyRcNRGuRkFQuPqnP8EFaPN/hPr6Ezl1wweNWhPfIlHL/bSgiWrcVvoZaIIevitI7d9ss1tUmqNvWvAQmG9YEIWnCPSjnxUnYMVXSCIjqzGeScSzLtc7Tn9quRUWc7B2DkZtGf1mSlYCW6HhQP60XXL2q36W94hg8vcny/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Gx/q5RgJ; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Gx/q5RgJ" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3ebb2d8dac4so3603107b6e.0 for ; Tue, 21 Jan 2025 13:16:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1737494206; x=1738099006; darn=vger.kernel.org; h=cc:subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=t0Y/E9LA5hslv08mHBG0j2fcfubf1KfMvovCy+4e7Pk=; b=Gx/q5RgJ7WRy2e554q7/WtJnBM0l/eUIKYPcsAud6p0iz1t90zI04qASrAmXg8KkVL s87pwlgkGbjbpMWg1YSw3ic/pxq6wfxn9t2ep0+5dVTLe74IqNvQOtBiEnpcHBHmFCOg Oo8EbnY9kdkvChcgNEn4hLvoVxCDYcp93Nswk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737494206; x=1738099006; h=cc:subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t0Y/E9LA5hslv08mHBG0j2fcfubf1KfMvovCy+4e7Pk=; b=q7IyTDslHnwuF3XoUQlHjVXjOY0Cnj5hVmKmqbrKmwWRXdlAfec4mQmSrw8vmr0TMx TB2oisCZOP237DxiwkvRivbGfj4mfjqvrjQUYL+Rj7bJQyheqYWMmCUiwOJvA8xL6+sY 5cLho68werZSnz6E0bwxrBbEMvM06rAW3qoa2jQtk0HGLAv8fKEHp6ioGJnyZmLmh9DL YcF8kBNZJZ4DLfCRIh5pNSw/Vek93v6p9MTyt3FnYqzv6JeYOAQhJZbv6sIL6bdXJSE1 UoJD0Ey474w3aA7nMO9vuEvP9opgjqhg4eWgPy0EtSnVsdKBLzbiRlxUMwKew0t+Y0uL +D2g== X-Forwarded-Encrypted: i=1; AJvYcCWnhS6a5Lq0r31EDrQcDjuae5bRirFOJrgGs0o+eH7hFL3dJOoOnC5oUTAg/T/RAnTf4zCbnRtd2DQ8IlM7aow=@vger.kernel.org X-Gm-Message-State: AOJu0YzBbZ45RIXrz3st8T5BE+NW2mvpzyZipvIEyXSm3a9OcqoITt53 fLtaNCfAZSWhQJ+gO0kTAVZhda936Qsn/ULoqczhJnH5snAY6B0iiSGTtkDw/mY= X-Gm-Gg: ASbGncsmjUQsI1HsbfCiK0AxNWbUN2elTykjOLHBauqn3FBKe0VhzznLarQXmLSt4z1 vAGVNLHxw9ilfk0hZjNRs+05PaCBzOS9peG8JlMyneotl49ne+EWheQQpR8sJfmRP2OYTLdLMCO ZfpCFAu/VyzRAswkaY9XZFLVOomknLKssGz7kqeyFX8bhZzJJ9QzohSwYy0TO4bLqZG57OpxNXN NMpyxFOX+CZ3/j5f3JVz5fnlSEGq6kZnMiP5bVjDPHuZltFw6+RuTvAxbk5NVZHZqbY3KQnlXYf Qdso X-Google-Smtp-Source: AGHT+IEgQJ7un/yhJfcl29kZW4Xd6ZOqxRbG5jgg7C2Hw1ZsSghAwf7b6lBHh7LNhj+FkjeXBai1Jw== X-Received: by 2002:a05:6808:4494:b0:3e6:6097:847d with SMTP id 5614622812f47-3f19fc3b35amr13461858b6e.7.1737494205891; Tue, 21 Jan 2025 13:16:45 -0800 (PST) Received: from [192.168.1.14] ([38.175.170.29]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3f19db9e8bfsm3222504b6e.44.2025.01.21.13.16.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jan 2025 13:16:45 -0800 (PST) Message-ID: <70eb3d1b-6f91-48da-8854-21f25bd3f289@linuxfoundation.org> Date: Tue, 21 Jan 2025 14:16:44 -0700 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Linus Torvalds From: Shuah Khan Subject: [GIT PULL] kunit next update for Linux 6.14-rc1 Cc: sfr@canb.auug.org.au, gregkh@linuxfoundation.org, skhan@linuxfoundation.org, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, brendan.higgins@linux.dev, davidgow@google.com Hi Linus, Please pull the following kunit next update for Linux 6.14-rc1. - fixes struct completion warning - introduces autorun option - adds fallback for os.sched_getaffinity - enables hardware acceleration when available Note: Stephen reported duplicate patch in kunit and driver-core: The following commit is also in the driver-core tree as a different commit (but the same patch): 875aec2357cd ("kunit: platform: Resolve 'struct completion' warning") This is commit 7687c66c18c6 ("kunit: platform: Resolve 'struct completion' warning") in the driver-core tree. diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit 40384c840ea1944d7c5a392e8975ed088ecf0b37: Linux 6.13-rc1 (2024-12-01 14:28:56 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux_kselftest-kunit-6.14-rc1 for you to fetch changes up to 31691914c392675bdc65d1e72dd8d129a1f0014f: kunit: Introduce autorun option (2025-01-15 09:04:06 -0700) ---------------------------------------------------------------- linux_kselftest-kunit-6.14-rc1 - fixes struct completion warning - introduces autorun option - adds fallback for os.sched_getaffinity - enables hardware acceleration when available ---------------------------------------------------------------- Brian Norris (1): kunit: platform: Resolve 'struct completion' warning Stanislav Kinsburskii (1): kunit: Introduce autorun option Tamir Duberstein (2): kunit: add fallback for os.sched_getaffinity kunit: enable hardware acceleration when available include/kunit/platform_device.h | 1 + include/kunit/test.h | 4 +++- lib/kunit/Kconfig | 12 ++++++++++++ lib/kunit/debugfs.c | 2 +- lib/kunit/executor.c | 21 +++++++++++++++++++-- lib/kunit/test.c | 6 ++++-- tools/testing/kunit/kunit.py | 11 ++++++++++- tools/testing/kunit/kunit_kernel.py | 3 +++ tools/testing/kunit/qemu_configs/arm64.py | 2 +- 9 files changed, 54 insertions(+), 8 deletions(-) ---------------------------------------------------------------- diff --git a/include/kunit/platform_device.h b/include/kunit/platform_device.h index 0fc0999d2420..f8236a8536f7 100644 --- a/include/kunit/platform_device.h +++ b/include/kunit/platform_device.h @@ -2,6 +2,7 @@ #ifndef _KUNIT_PLATFORM_DRIVER_H #define _KUNIT_PLATFORM_DRIVER_H +struct completion; struct kunit; struct platform_device; struct platform_driver; diff --git a/include/kunit/test.h b/include/kunit/test.h index 34b71e42fb10..58dbab60f853 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -312,6 +312,7 @@ static inline void kunit_set_failure(struct kunit *test) } bool kunit_enabled(void); +bool kunit_autorun(void); const char *kunit_action(void); const char *kunit_filter_glob(void); char *kunit_filter(void); @@ -334,7 +335,8 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set, int *err); void kunit_free_suite_set(struct kunit_suite_set suite_set); -int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites); +int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites, + bool run_tests); void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites); diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index 34d7242d526d..a97897edd964 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -81,4 +81,16 @@ config KUNIT_DEFAULT_ENABLED In most cases this should be left as Y. Only if additional opt-in behavior is needed should this be set to N. +config KUNIT_AUTORUN_ENABLED + bool "Default value of kunit.autorun" + default y + help + Sets the default value of kunit.autorun. If set to N then KUnit + tests will not run after initialization unless kunit.autorun=1 is + passed to the kernel command line. The test can still be run manually + via debugfs interface. + + In most cases this should be left as Y. Only if additional opt-in + behavior is needed should this be set to N. + endif # KUNIT diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c index af71911f4a07..9c326f1837bd 100644 --- a/lib/kunit/debugfs.c +++ b/lib/kunit/debugfs.c @@ -145,7 +145,7 @@ static ssize_t debugfs_run(struct file *file, struct inode *f_inode = file->f_inode; struct kunit_suite *suite = (struct kunit_suite *) f_inode->i_private; - __kunit_test_suites_init(&suite, 1); + __kunit_test_suites_init(&suite, 1, true); return count; } diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 34b7b6833df3..3f39955cb0f1 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -29,6 +29,22 @@ const char *kunit_action(void) return action_param; } +/* + * Run KUnit tests after initialization + */ +#ifdef CONFIG_KUNIT_AUTORUN_ENABLED +static bool autorun_param = true; +#else +static bool autorun_param; +#endif +module_param_named(autorun, autorun_param, bool, 0); +MODULE_PARM_DESC(autorun, "Run KUnit tests after initialization"); + +bool kunit_autorun(void) +{ + return autorun_param; +} + static char *filter_glob_param; static char *filter_param; static char *filter_action_param; @@ -260,13 +276,14 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set, void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin) { size_t num_suites = suite_set->end - suite_set->start; + bool autorun = kunit_autorun(); - if (builtin || num_suites) { + if (autorun && (builtin || num_suites)) { pr_info("KTAP version 1\n"); pr_info("1..%zu\n", num_suites); } - __kunit_test_suites_init(suite_set->start, num_suites); + __kunit_test_suites_init(suite_set->start, num_suites, autorun); } void kunit_exec_list_tests(struct kunit_suite_set *suite_set, bool include_attr) diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 089c832e3cdb..146d1b48a096 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -708,7 +708,8 @@ bool kunit_enabled(void) return enable_param; } -int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites) +int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites, + bool run_tests) { unsigned int i; @@ -731,7 +732,8 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_ for (i = 0; i < num_suites; i++) { kunit_init_suite(suites[i]); - kunit_run_tests(suites[i]); + if (run_tests) + kunit_run_tests(suites[i]); } static_branch_dec(&kunit_running); diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py index 676fa99a8b19..7f9ae55fd6d5 100755 --- a/tools/testing/kunit/kunit.py +++ b/tools/testing/kunit/kunit.py @@ -312,7 +312,16 @@ def massage_argv(argv: Sequence[str]) -> Sequence[str]: return list(map(massage_arg, argv)) def get_default_jobs() -> int: - return len(os.sched_getaffinity(0)) + if sys.version_info >= (3, 13): + if (ncpu := os.process_cpu_count()) is not None: + return ncpu + raise RuntimeError("os.process_cpu_count() returned None") + # See https://github.com/python/cpython/blob/b61fece/Lib/os.py#L1175-L1186. + if sys.platform != "darwin": + return len(os.sched_getaffinity(0)) + if (ncpu := os.cpu_count()) is not None: + return ncpu + raise RuntimeError("os.cpu_count() returned None") def add_common_opts(parser: argparse.ArgumentParser) -> None: parser.add_argument('--build_dir', diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py index e76d7894b6c5..d30f90eae9a4 100644 --- a/tools/testing/kunit/kunit_kernel.py +++ b/tools/testing/kunit/kunit_kernel.py @@ -125,6 +125,9 @@ class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations): '-append', ' '.join(params + [self._kernel_command_line]), '-no-reboot', '-nographic', + '-accel', 'kvm', + '-accel', 'hvf', + '-accel', 'tcg', '-serial', self._serial] + self._extra_qemu_params # Note: shlex.join() does what we want, but requires python 3.8+. print('Running tests with:\n$', ' '.join(shlex.quote(arg) for arg in qemu_command)) diff --git a/tools/testing/kunit/qemu_configs/arm64.py b/tools/testing/kunit/qemu_configs/arm64.py index d3ff27024755..5c44d3a87e6d 100644 --- a/tools/testing/kunit/qemu_configs/arm64.py +++ b/tools/testing/kunit/qemu_configs/arm64.py @@ -9,4 +9,4 @@ CONFIG_SERIAL_AMBA_PL011_CONSOLE=y''', qemu_arch='aarch64', kernel_path='arch/arm64/boot/Image.gz', kernel_command_line='console=ttyAMA0', - extra_qemu_params=['-machine', 'virt', '-cpu', 'max,pauth-impdef=on']) + extra_qemu_params=['-machine', 'virt', '-cpu', 'max'])