mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Gow <davidgow@google.com>
To: Brendan Higgins <brendan.higgins@linux.dev>,
	Rae Moar <rmoar@google.com>,
	 Shuah Khan <skhan@linuxfoundation.org>
Cc: David Gow <davidgow@google.com>,
	linux-kselftest@vger.kernel.org,  kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/2] kunit: tool: Move qemu architecture dependency checks into a function
Date: Thu, 31 Jul 2025 11:53:35 +0800	[thread overview]
Message-ID: <20250731035341.2598127-1-davidgow@google.com> (raw)

Currently the RISC-V qemu architecture config has some code to check for
the presence of the BIOS files before loading, printing a message and
quitting if it's not present.

However, this prevents us from loading the architecture file even just
to inspect it if the dependencies are not present. Instead, have kunit.py
look for a check_dependencies function, and call it if present only when
the architecture config is being used.

This is necessary for future changes which enumerate or automatically
select an architecture.

Signed-off-by: David Gow <davidgow@google.com>
---
 tools/testing/kunit/kunit_kernel.py       |  5 +++++
 tools/testing/kunit/qemu_configs/riscv.py | 10 ++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 260d8d9aa1db..c3201a76da24 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -230,6 +230,11 @@ def _get_qemu_ops(config_path: str,
 	assert isinstance(spec.loader, importlib.abc.Loader)
 	spec.loader.exec_module(config)
 
+	# Check for any per-architecture dependencies
+	if hasattr(config, 'check_dependencies'):
+		if not config.check_dependencies():
+			raise ValueError('Missing dependencies for ' + config_path)
+
 	if not hasattr(config, 'QEMU_ARCH'):
 		raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path)
 	params: qemu_config.QemuArchParams = config.QEMU_ARCH
diff --git a/tools/testing/kunit/qemu_configs/riscv.py b/tools/testing/kunit/qemu_configs/riscv.py
index c87758030ff7..3c271d1005d9 100644
--- a/tools/testing/kunit/qemu_configs/riscv.py
+++ b/tools/testing/kunit/qemu_configs/riscv.py
@@ -6,10 +6,12 @@ import sys
 OPENSBI_FILE = 'opensbi-riscv64-generic-fw_dynamic.bin'
 OPENSBI_PATH = '/usr/share/qemu/' + OPENSBI_FILE
 
-if not os.path.isfile(OPENSBI_PATH):
-	print('\n\nOpenSBI bios was not found in "' + OPENSBI_PATH + '".\n'
-	      'Please ensure that qemu-system-riscv is installed, or edit the path in "qemu_configs/riscv.py"\n')
-	sys.exit()
+def check_dependencies() -> bool:
+    if not os.path.isfile(OPENSBI_PATH):
+	    print('\n\nOpenSBI bios was not found in "' + OPENSBI_PATH + '".\n'
+	          'Please ensure that qemu-system-riscv is installed, or edit the path in "qemu_configs/riscv.py"\n')
+	    return False
+    return True
 
 QEMU_ARCH = QemuArchParams(linux_arch='riscv',
 			   kconfig='''
-- 
2.50.1.552.g942d659e1b-goog


             reply	other threads:[~2025-07-31  3:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31  3:53 David Gow [this message]
2025-07-31  3:53 ` [RFC PATCH 2/2] kunit: tool: Automatically pick a default architecture if none is specified David Gow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250731035341.2598127-1-davidgow@google.com \
    --to=davidgow@google.com \
    --cc=brendan.higgins@linux.dev \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rmoar@google.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®