Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CAE37C636D4 for ; Mon, 13 Feb 2023 15:58:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CB00D85754; Mon, 13 Feb 2023 16:58:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="c5R67z0A"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 402958579E; Mon, 13 Feb 2023 16:57:46 +0100 (CET) Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C03CF857B0 for ; Mon, 13 Feb 2023 16:57:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x136.google.com with SMTP id v13so3802087iln.4 for ; Mon, 13 Feb 2023 07:57:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LSvEIsoUkV5zPD0JuJJ+uKID66/3Otf2O16UdfozpZA=; b=c5R67z0AVHvnqp3nC1q87TBKK75gpCuRc8o2GYcSe2DDOSjq+IfGoUNPR9urrU9B6I X8MjTTYzm10E+Jz+mnKj5jAS9H+ySEqw8NW2hy7+npu+ZNt7teKgEUWnuU7CD4Jznioi 7tIeyJ7u65vgQ4mxwfUQNypwig2XVLr9eaXSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LSvEIsoUkV5zPD0JuJJ+uKID66/3Otf2O16UdfozpZA=; b=uin95QSsIpStDcaXc8zsVIe6tLM5mfzjAVQIq4LTtmru9kqANqPLzTRAVZhxPW6mUz S0xtdnhAdvLwTtLh1eAhI0BiitkA8m+cetY3ah1d5bGu8u5eIJyfzXyIu5yR7k8KRWRK cE5ZGF7h/S3gBSPJqgE2R1nu1EH25Sh1nH/hbwShExueImCwa+GCLMauKDQYxrkwhsIl fc0vgBsGqroyBG1QUSFrpT6Ms2bHy7MsDnCQOHflR/weRIbx63ziKXjRhOkhXz9tGkoS IlMdwckgtuq/hbDE1E3KzKRJS7itOEAI18O1C8Pa7GsFYOlrcSicnawPkSY9Mw3CVYat sp0w== X-Gm-Message-State: AO0yUKWdtZD0HKY8SpU90lVmbbs1nbChbBlHz2/jr8E1WJSvgnu7f51f zit8QIOUcySsM0LPpE5I5BHSb2kkD4PVqLGQ X-Google-Smtp-Source: AK7set+CN8hTc4h5iJsjVzw1YLokuEAfkFfmSjDbhkkhhcHIAzeaOFvHHVl1Sv9g7oybbY0g5cH2vQ== X-Received: by 2002:a92:cd83:0:b0:310:ce1f:44fd with SMTP id r3-20020a92cd83000000b00310ce1f44fdmr27562103ilb.3.1676303825423; Mon, 13 Feb 2023 07:57:05 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id b2-20020a923402000000b003154a4a039esm647463ila.5.2023.02.13.07.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 07:57:05 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , U-Boot Custodians , Simon Glass Subject: [PATCH v5 10/11] test: Add a way to set the environment for a pytest Date: Mon, 13 Feb 2023 08:56:40 -0700 Message-Id: <20230213155641.1208774-11-sjg@chromium.org> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog In-Reply-To: <20230213155641.1208774-1-sjg@chromium.org> References: <20230213155641.1208774-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean This is useful when we need to control a particular environment variable. Add a way to handle this. Signed-off-by: Simon Glass --- (no changes since v4) Changes in v4: - Add new patch with a way to set the environment for a pytest test/py/multiplexed_log.py | 5 +++-- test/py/u_boot_utils.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index 5e79075f2e6..63237594bb4 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -111,7 +111,7 @@ class RunAndLog(object): """Clean up any resources managed by this object.""" pass - def run(self, cmd, cwd=None, ignore_errors=False, stdin=None): + def run(self, cmd, cwd=None, ignore_errors=False, stdin=None, env=None): """Run a command as a sub-process, and log the results. The output is available at self.output which can be useful if there is @@ -126,6 +126,7 @@ class RunAndLog(object): or exits with an error code, otherwise an exception will be raised if such problems occur. stdin: Input string to pass to the command as stdin (or None) + env: Environment to use, or None to use the current one Returns: The output as a string. @@ -139,7 +140,7 @@ class RunAndLog(object): try: p = subprocess.Popen(cmd, cwd=cwd, stdin=subprocess.PIPE if stdin else None, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) (stdout, stderr) = p.communicate(input=stdin) if stdout is not None: stdout = stdout.decode('utf-8') diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py index c4fc23aeda3..9e161fbc238 100644 --- a/test/py/u_boot_utils.py +++ b/test/py/u_boot_utils.py @@ -157,7 +157,7 @@ def wait_until_file_open_fails(fn, ignore_errors): return raise Exception('File can still be opened') -def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None): +def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None): """Run a command and log its output. Args: @@ -170,6 +170,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None): an error code, otherwise an exception will be raised if such problems occur. stdin: Input string to pass to the command as stdin (or None) + env: Environment to use, or None to use the current one Returns: The output as a string. @@ -177,7 +178,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None): if isinstance(cmd, str): cmd = cmd.split() runner = u_boot_console.log.get_runner(cmd[0], sys.stdout) - output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin) + output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env) runner.close() return output -- 2.39.1.581.gbfd45094c4-goog