From patchwork Tue Sep 9 15:18:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 268 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431144; bh=xVzwW5GOeVcVlpi1hdoYMCRJrdCacma/e1SaooRbXkA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ZqVzS8VF1KuXMFMnPwrfTrE2iQfGA1heJF95HO7ZU1oCCCxmITcCdrEOjfpS8wqSP QRwz0pknLjBEKgjsNqu2bglZr/UBdcMRdXPfek3Kprc+AnRGu0m/SNzCkd6epDx5Gq /q6NBWXmtRqPe78q02qDIyP/QOxjsRi+dCGBYeyRDHVPauVQ0CLe48wR9X/AZhk/mV aPVk0L+RzKjORxbuznxZ092ac+EQLWhgKLXxUg2iM5OojfQfSSEpxl08q0Ksxey54V xh0k9u2hgn5B3ErQ4APPR7yU9Kame0kM6usGJgfqCjPEOJhIsrKmX6lAgDc1Dwni20 PExdOlYbdJGEw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B56DA679FD for ; Tue, 9 Sep 2025 09:19:04 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id R8ZUEpFEICqP for ; Tue, 9 Sep 2025 09:19:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431144; bh=xVzwW5GOeVcVlpi1hdoYMCRJrdCacma/e1SaooRbXkA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ZqVzS8VF1KuXMFMnPwrfTrE2iQfGA1heJF95HO7ZU1oCCCxmITcCdrEOjfpS8wqSP QRwz0pknLjBEKgjsNqu2bglZr/UBdcMRdXPfek3Kprc+AnRGu0m/SNzCkd6epDx5Gq /q6NBWXmtRqPe78q02qDIyP/QOxjsRi+dCGBYeyRDHVPauVQ0CLe48wR9X/AZhk/mV aPVk0L+RzKjORxbuznxZ092ac+EQLWhgKLXxUg2iM5OojfQfSSEpxl08q0Ksxey54V xh0k9u2hgn5B3ErQ4APPR7yU9Kame0kM6usGJgfqCjPEOJhIsrKmX6lAgDc1Dwni20 PExdOlYbdJGEw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A4371679D7 for ; Tue, 9 Sep 2025 09:19:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431142; bh=FIyBVyZXgX7J21cxVzHC4LqItj+cwvVMH2FFTrECkMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IIaWrgzrcw9BANQaJPwAexdEeSP/lOCtXBcqDec0w9X2eAhTtR4LukrRrUvyDiSRE 5p5MW1GpW3feyxGc+mhpVcrOfO1mQs9iII5zYNCadHDxJVu7VZI0FrbhtEX8OL1sCt +KLzZslGqXAmqRy5wUaJGaj+xD9xM5M3g7DT4U41kJkClNUhJ/KZX7R5e2mi53GZhG DfD2x30al6kdNNbE9YzcX8fv0BQ/2PQjGIpA7w0O75oXn5cLCYAlDWXr+mviH6ko3U qRoSYAC3z2yx/3fQbIQoUfIcoKpJNz9Si0dDKKuzIvmrB8fhaQgJoWJHaVF3RvPfE2 g1jOjaIyWJjxQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5D02960026; Tue, 9 Sep 2025 09:19:02 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id AIen8EAOEXBq; Tue, 9 Sep 2025 09:19:02 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757431138; bh=NTEy86JVtyGTFbWwJbuht6EitnYgS6dGfkTyzlXxK7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dubkeqUzkwH9glTlLEGo3odFhvUJ5N9M9UPuBtAix+EAaRYYHJKiulSdmlqsWzISg MtiafqKi3pZE/EN/SYBO7DVXeaKBVGyZiNVUkD6ola9Z3+tAzu2IDISdjjQhOaDi8j 8hn8YKXc+XEwKDo6STX05BQPYTw9/Y8kS076g8Zr4SMl+b5DImYN7DQSdLDc6sDPWq ekl8WHcXxA2dQ5Mecpj8jNngHn3xCKdcRURDzfSEt0CS7JVmFTbzh0gag2PhGavSjw NILh+BnhMFVLB9NAKSNAgdfKDBwOpdvI1AhtEFmoEo+dCq81fVulci6PRDziZWOEKl 6A8n2931PFpPA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 29C46679D6; Tue, 9 Sep 2025 09:18:58 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 9 Sep 2025 09:18:03 -0600 Message-ID: <20250909151824.2327219-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250909151824.2327219-1-sjg@u-boot.org> References: <20250909151824.2327219-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: LU25LVCEV2XQ43DVP3ZGOHORYBKGWWFC X-Message-ID-Hash: LU25LVCEV2XQ43DVP3ZGOHORYBKGWWFC X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 06/18] test/py: Allow setting the cwd with run_and_log() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Sometimes it is useful to run a command in a particular subdirectory. Add support for this to the run_and_log() functions. Signed-off-by: Simon Glass --- test/py/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/py/utils.py b/test/py/utils.py index 05e2a16d3b4..7812b2a201b 100644 --- a/test/py/utils.py +++ b/test/py/utils.py @@ -157,7 +157,8 @@ def wait_until_file_open_fails(fn, ignore_errors): return raise Exception('File can still be opened') -def run_and_log_no_ubman(log, cmd, ignore_errors=False, stdin=None, env=None): +def run_and_log_no_ubman(log, cmd, ignore_errors=False, stdin=None, env=None, + cwd=None): """Run a command and log its output. This is useful when you don't want to use a ubman fixture @@ -173,6 +174,7 @@ def run_and_log_no_ubman(log, cmd, ignore_errors=False, stdin=None, env=None): such problems occur. stdin (str): Input string to pass to the command as stdin (or None) env (dict): Environment to use, or None to use the current one + cwd (str): directory to run the command in, or None for current dir Returns: The output as a string. @@ -180,11 +182,13 @@ def run_and_log_no_ubman(log, cmd, ignore_errors=False, stdin=None, env=None): if isinstance(cmd, str): cmd = cmd.split() runner = log.get_runner(cmd[0], sys.stdout) - output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env) + output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env, + cwd=cwd) runner.close() return output -def run_and_log(ubman, cmd, ignore_errors=False, stdin=None, env=None): +def run_and_log(ubman, cmd, ignore_errors=False, stdin=None, env=None, + cwd=None): """Run a command and log its output. Args: @@ -198,11 +202,12 @@ def run_and_log(ubman, cmd, ignore_errors=False, stdin=None, env=None): such problems occur. stdin (str): Input string to pass to the command as stdin (or None) env (dict): Environment to use, or None to use the current one + cwd (str): directory to run the command in, or None for current dir Returns: The output as a string. """ - return run_and_log_no_ubman(ubman.log, cmd, ignore_errors, stdin, env) + return run_and_log_no_ubman(ubman.log, cmd, ignore_errors, stdin, env, cwd) def run_and_log_expect_exception(ubman, cmd, retcode, msg): """Run a command that is expected to fail.