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 1D0FAC77B7F for ; Fri, 12 May 2023 20:10:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3876C86387; Fri, 12 May 2023 22:07:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com 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=amarulasolutions.com header.i=@amarulasolutions.com header.b="QKC66sEW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1008986369; Fri, 12 May 2023 22:07:33 +0200 (CEST) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (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 09A338635A for ; Fri, 12 May 2023 22:07:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=francis.laniel@amarulasolutions.com Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-306f2b42a86so6901711f8f.3 for ; Fri, 12 May 2023 13:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1683922037; x=1686514037; 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=F9K9LjGrI/UaVuFLtYeutB3YYgPxzyJaSx0JXslnwlo=; b=QKC66sEWFAIPu/pChEBUS4HJESMw99JQGYKweT02S8LbslwwHiy3ICZLoZdKYx0QqM CleGsawkNPlu6h+Ckb93U2CGSV6q5NwjuxjAbHgDPF7QK/hHStxPuC/0yMYJh6EgFEgP DBEaMO4Hw5tgJ6sdPVrw5Kp3xg+B3yiU9yaKU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683922037; x=1686514037; 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=F9K9LjGrI/UaVuFLtYeutB3YYgPxzyJaSx0JXslnwlo=; b=J74T645CJoyGo0O9T8Y+a6hbF2PDr7kTuAP1NJR8VRMM82DK3Cyyev6bnDbIwVPbLw z9xeX2PFQXu1SR22snA/8kTps4VZ+SfhAiVlBf5KPPsrp2bPYlg2wV6qrzWoMcVAsdJY D/05jvl084hioLbD8NssmzbgeZXG2rn5FPQSbF3Mk19Ug4IZDj9y/EMCe2d57+vmy6BP huaJn26AeY4Bf9sxYOWQOsW4Mx8beE8d7JzE4CqPTn3s50jFaK2x1L8g48OlnA2ZaaHe SI/gztng575JNXNWpHie6GUX1P8+RspGH3jUm6dIAfF8Q6NGsv9qLYzu6Qf1bTT8lSzH DwbA== X-Gm-Message-State: AC+VfDwi+edSbmOP/f2IwYN7Q+X+mQGBAWl4zLjwIXdxVuHfUaO+4bzq wZ45MJ5ZMa7JkUc74KbgpBreaQ/WRZ6NBpe20vI= X-Google-Smtp-Source: ACHHUZ7eFnlBaLIaYyDrZOoay256Vmi4PB3iiZETcf3uUl7Km05tvXVG2zYwH+hc+fqGbijr3dTCjQ== X-Received: by 2002:a5d:460c:0:b0:2f2:9198:f0f with SMTP id t12-20020a5d460c000000b002f291980f0fmr19219573wrq.10.1683922036989; Fri, 12 May 2023 13:07:16 -0700 (PDT) Received: from pwmachine.numericable.fr ([213.94.16.214]) by smtp.gmail.com with ESMTPSA id n6-20020a7bcbc6000000b003f33f8f0a05sm29565859wmi.9.2023.05.12.13.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 13:07:16 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Francis Laniel Subject: [RFC PATCH v8 21/23] test: hush: Fix loop tests for hush 2021 Date: Fri, 12 May 2023 21:03:29 +0100 Message-Id: <20230512200331.51457-22-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> References: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> 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.8 at phobos.denx.de X-Virus-Status: Clean Modifies return code got from while loop as hush 2021 always returns 0 from while loop. Reviewed-by: Simon Glass Signed-off-by: Francis Laniel --- test/hush/loop.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/test/hush/loop.c b/test/hush/loop.c index ca777e38fe..add5402a32 100644 --- a/test/hush/loop.c +++ b/test/hush/loop.c @@ -9,6 +9,9 @@ #include #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; static int hush_test_for(struct unit_test_state *uts) { @@ -21,7 +24,12 @@ static int hush_test_for(struct unit_test_state *uts) ut_assert_nextline("quux"); ut_assert_console_end(); - puts("Beware: this test set local variable loop_i and it cannot be unset!"); + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* Reset local variable. */ + ut_assertok(run_command("loop_i=", 0)); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + puts("Beware: this test set local variable loop_i and it cannot be unset!"); + } return 0; } @@ -31,12 +39,30 @@ static int hush_test_while(struct unit_test_state *uts) { console_record_reset_enable(); - /* Exit status is that of test, so 1 since test is false to quit the loop. */ - ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0)); + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* + * Hush 2021 always returns 0 from while loop... + * You can see code snippet near this line to have a better + * understanding: + * debug_printf_exec(": while expr is false: breaking (exitcode:EXIT_SUCCESS)\n"); + */ + ut_assertok(run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0)); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + /* + * Exit status is that of test, so 1 since test is false to quit + * the loop. + */ + ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0)); + } ut_assert_nextline("bar"); ut_assert_console_end(); - puts("Beware: this test set local variable loop_foo and it cannot be unset!"); + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* Reset local variable. */ + ut_assertok(run_command("loop_foo=", 0)); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + puts("Beware: this test set local variable loop_foo and it cannot be unset!"); + } return 0; } -- 2.34.1