From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Mon, 11 Aug 2025 14:29:53 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1ulRez-009Keg-1L for lore@lore.pengutronix.de; Mon, 11 Aug 2025 14:29:53 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ulReh-0005gl-VH for lore@pengutronix.de; Mon, 11 Aug 2025 14:29:53 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ppUrFOZ3VDCgO9f3N8RPiv98GVvFlmDK7xKGY/mXunk=; b=4PKrjbfiZL+aNiidSvrxX9iHTr eUm6WX/g4L23kXhP3XzV4FrdN6KmrVoz24EJ+WA1b8xZXxRjncEAdJqUg9/e5SdfPBkkDzjSdWTg4 2yWaTAgGzxfdn8un0ygHi8td1ALu2YobWhWpzaK3McVd/D7DOxpsdb4OO6TP08gmuvH7V5ZtIBf+w TscaskrvThlUkrt5dEUohhsYzR8Wlpag2XOGKMrBVZ0NZxUy7+4iHOHf/9VX7KSUPBCnZgz+HtOtR 2K20uEuFzOCwSA1UC0jYNJuI+YWOuj7ZgfJVwnv6lU/l2J+EklQnFipCAUuEk/+aTnIg1ZR6sar4/ n5tKIbtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1ulRdk-00000007ddf-0hqE; Mon, 11 Aug 2025 12:28:36 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1ulRde-00000007dW1-2W6W for barebox@lists.infradead.org; Mon, 11 Aug 2025 12:28:33 +0000 Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=geraet.fritz.box) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1ulRdd-0004WP-CF; Mon, 11 Aug 2025 14:28:29 +0200 From: Ahmad Fatoum To: barebox@lists.infradead.org Cc: Ahmad Fatoum Date: Mon, 11 Aug 2025 14:27:51 +0200 Message-Id: <20250811122824.1667791-12-a.fatoum@barebox.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250811122824.1667791-1-a.fatoum@barebox.org> References: <20250811122824.1667791-1-a.fatoum@barebox.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250811_052830_665907_2202EBB4 X-CRM114-Status: GOOD ( 12.76 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.whiteo.stw.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-5.4 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH 11/44] test: add heuristic for guessing labgrid environment YAML X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.whiteo.stw.pengutronix.de) Now that each defconfig in barebox has its name carried into the build .config, we can teach pytest to query that and find out what labgrid environment YAML to use if none was specified by the user. That means when building e.g., multi_v8_defconfig, it's enough to just run pytest without arguments. Signed-off-by: Ahmad Fatoum --- common/Kconfig | 4 ++++ conftest.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/common/Kconfig b/common/Kconfig index 159cd271d748..21ce2ef97f2c 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -120,6 +120,10 @@ config NAME version command, but does not influence any runtime or compile-time behavior. + For testing, pytest will use this option to determine, which + Labgrid environment YAML to use if none was specified by the + user. + config LOCALVERSION string "Local version - append to the version string" help diff --git a/conftest.py b/conftest.py index e8de5952efb4..06321c938dba 100644 --- a/conftest.py +++ b/conftest.py @@ -26,6 +26,45 @@ def barebox_config(request, strategy, target): command = target.get_driver("BareboxDriver") return helper.get_config(command) + +def get_enabled_arch(config): + # Get the absolute path to the directory containing this script + base_dir = os.path.dirname(os.path.abspath(__file__)) + + # Path to the 'arch' directory relative to this script + arch_dir = os.path.join(base_dir, "arch") + + if not os.path.isdir(arch_dir): + return None + + # Optional mapping from directory names to config key suffixes + arch_map = {"powerpc": "ppc"} + + for entry in os.listdir(arch_dir): + path = os.path.join(arch_dir, entry) + if os.path.isdir(path): + key_suffix = arch_map.get(entry, entry).upper() + config_key = f"CONFIG_{key_suffix}" + if config.get(config_key): + return entry + + return None + + +def guess_lg_env(): + config_file = helper.open_config_file(os.environ['LG_BUILDDIR'] + "/.config") + config = helper.parse_config(config_file) + if not config or not config.get('CONFIG_NAME'): + return None + arch = get_enabled_arch(config) + if not arch: + return None + filename = os.path.join("test", arch, f"{config['CONFIG_NAME']}.yaml") + if os.path.exists(filename): + return filename + return None + + def pytest_configure(config): if 'LG_BUILDDIR' not in os.environ: if 'KBUILD_OUTPUT' in os.environ: @@ -38,6 +77,14 @@ def pytest_configure(config): if os.environ['LG_BUILDDIR'] is not None: os.environ['LG_BUILDDIR'] = os.path.realpath(os.environ['LG_BUILDDIR']) + lg_env = config.option.lg_env + if lg_env is None: + lg_env = os.environ.get('LG_ENV') + if lg_env is None: + if lg_env := guess_lg_env(): + os.environ['LG_ENV'] = lg_env + + def pytest_addoption(parser): def assignment(arg): return arg.split('=', 1) -- 2.39.5