From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 913CCC433EF for ; Sat, 23 Oct 2021 23:27:34 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E160160E9C for ; Sat, 23 Oct 2021 23:27:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E160160E9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7B02D83529; Sun, 24 Oct 2021 01:27:20 +0200 (CEST) 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="CjPV7b8m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E2AD5834CD; Sun, 24 Oct 2021 01:26:56 +0200 (CEST) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (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 7E94E8343C for ; Sun, 24 Oct 2021 01:26:48 +0200 (CEST) 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-ot1-x329.google.com with SMTP id z5-20020a9d4685000000b005537cbe6e5aso2589186ote.1 for ; Sat, 23 Oct 2021 16:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nj/fbEk6q75c4QxzmbqWpvQ33IToaDtFJTyygH6YC2E=; b=CjPV7b8mvanuin7XZNJW8NfehyADmZYlZYKNa1GLFpQ1OEbNdhsnzjrU6kuZIo3yCZ 93G5dVO5er8aHCXCb0gtAw1LJyjtHGVtYrL7dc/8huXWiq4kS+EnCfL09vHUz+JQbs5g HFOS3MvcfKYAQA9rcNNw7219W7njYInEZduhM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nj/fbEk6q75c4QxzmbqWpvQ33IToaDtFJTyygH6YC2E=; b=e7OFRt7THseM1ax/w4XEnGPxzEJ5funZMD1jZMVWGgjcIfz/Kwx96nlqn2bnMj7C5g twdq0zM2XpPdeYxVqCLxka6sP6GObq1gLTW24DWz6v6q8C7RiFddzU0YvhhMtaDH+nQH Tg2qBTYdG1E6GeErrSr3hECL6JkzlqL09FmdTjxDlxG6wfq71ohEOUOxFtA2XAMiNO2L vMlY1mmp1gAWQ1dFf7+QM93IvqR67pwtV6XKDq82sAlEdYtlciLR5UPflGfV85b22yv0 GVzQgcXUef8b6bI0Faj66gnANVuX+eQ3rJxLJq3qw7WQ3iBt+jN1r6JVCL0XwIVQhcBl WTCQ== X-Gm-Message-State: AOAM533fGMPTu9P/4a/iJNbA7zAWIDld4fTLAwYfpPzWc7mnxsEPRdj/ tr7KfqH1myAMA7Zz2CdyvzdBovq/mjF4gA== X-Google-Smtp-Source: ABdhPJx/2WIMXM/pxLPaPagm5Aq+UQaFEZgHZkMn/z/VuvRmuzeQQ15dMGDCWlmPhNMwPHPaFHgaIg== X-Received: by 2002:a05:6830:1f5c:: with SMTP id u28mr6702080oth.3.1635031607030; Sat, 23 Oct 2021 16:26:47 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:26:46 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass , Stephen Warren , Stephen Warren Subject: [PATCH v2 03/41] test/py: Allow passing input to a program Date: Sat, 23 Oct 2021 17:25:57 -0600 Message-Id: <20211023232635.9195-4-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean When running a program on the host, allow input to be passed in as stdin. This is needed for running sfdisk, for example. Signed-off-by: Simon Glass --- (no changes since v1) test/py/multiplexed_log.py | 8 +++++--- test/py/u_boot_utils.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py index 545a7743022..9325fae46d2 100644 --- a/test/py/multiplexed_log.py +++ b/test/py/multiplexed_log.py @@ -109,7 +109,7 @@ class RunAndLog(object): """Clean up any resources managed by this object.""" pass - def run(self, cmd, cwd=None, ignore_errors=False): + def run(self, cmd, cwd=None, ignore_errors=False, stdin=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 @@ -123,6 +123,7 @@ class RunAndLog(object): function will simply return if the command cannot be executed 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) Returns: The output as a string. @@ -135,8 +136,9 @@ class RunAndLog(object): try: p = subprocess.Popen(cmd, cwd=cwd, - stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - (stdout, stderr) = p.communicate() + stdin=subprocess.PIPE if stdin else None, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (stdout, stderr) = p.communicate(input=stdin) if stdout is not None: stdout = stdout.decode('utf-8') if stderr is not None: diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py index e816c7fbb6a..f44442e0c77 100644 --- a/test/py/u_boot_utils.py +++ b/test/py/u_boot_utils.py @@ -154,7 +154,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): +def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None): """Run a command and log its output. Args: @@ -166,6 +166,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False): will simply return if the command cannot be executed 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) Returns: The output as a string. @@ -173,7 +174,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False): 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) + output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin) runner.close() return output -- 2.33.0.1079.g6e70778dc9-goog