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 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 B51DDC433EF for ; Thu, 16 Jun 2022 22:36:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C94B844EB; Fri, 17 Jun 2022 00:34:16 +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="lg5eKnvB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 413AB844E1; Fri, 17 Jun 2022 00:34:10 +0200 (CEST) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 EEE5884403 for ; Fri, 17 Jun 2022 00:33:21 +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-wm1-x32f.google.com with SMTP id i81-20020a1c3b54000000b0039c76434147so3504404wma.1 for ; Thu, 16 Jun 2022 15:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+igK1uVxGWYJfrXaWKpUQqix0bBuHl6FSvlQ7O/QIWk=; b=lg5eKnvBAr66zxjHzIFUekBdkDCsjX4Yy4ELiEsJtpW94gci23h26bpTTkylZTtsZv Ma8rZEHNThu9WudlVQrt2yKfAw9H2WuMQbTqXqnTJbWYRJaB/2QqPHA8GKDiF+xeUxr4 VBTaSW8hw9g1+9o6zx3gxc77YDVpG/nHl7Z2o= 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=+igK1uVxGWYJfrXaWKpUQqix0bBuHl6FSvlQ7O/QIWk=; b=GlHg1/XFAwspf7HT14WMGydUy6dMn8S/mVNitkx094yTM9i/SRxKqreVJEKOzbCK8n bpR6/nNpxiGIWjFh7BUiGyTNWHiorrGnftscDc99YWuC46KZh46zldigLhd5gDl/0ED/ S9RFF9QFeupDB5c8ccb2LSE1DKbXEkWexbO+Qd6IucKFF8in3i9Z9HQc1v3w2pCCQ0n9 H5glvQ5fBw3RxR1+JcdFStG/KLjm2mJJ9q6kZR/4M8dkppXsCYO2AqeYQpuVW6PxnBjD CX+bXM8ItNAcwID8X1ewFR2wxk1Tm0+yDaG0FOYSWkHijWxstB/rMCJGOi3+x5hcqdsq qPUg== X-Gm-Message-State: AOAM531RF0HOlP73XD0w4b1bOBDrKmiAOz4EdLjfoD4d5A7ZKGvmLnq6 prqouC4tcqtS30cn1xurX3PgVnD73F6neA== X-Google-Smtp-Source: ABdhPJzOjltzJdq0ngcfUHbkKmuaRUTpfan8BBQWTPryBLcL9UDccW0jHQ1xSQ+2djajw1JN5c7zvA== X-Received: by 2002:a7b:c5cb:0:b0:397:47ae:188f with SMTP id n11-20020a7bc5cb000000b0039747ae188fmr17734217wmk.137.1655418801708; Thu, 16 Jun 2022 15:33:21 -0700 (PDT) Received: from pwmachine.home (17.pool80-103-97.dynamic.orange.es. [80.103.97.17]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c4f8400b003971fc23185sm7912044wmq.20.2022.06.16.15.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 15:33:21 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Tom Rini , Francis Laniel Subject: [RFC PATCH v4 23/28] test: hush: Fix loop tests for hush 2021 Date: Fri, 17 Jun 2022 00:31:53 +0200 Message-Id: <20220616223158.9225-24-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616223158.9225-1-francis.laniel@amarulasolutions.com> References: <20220616223158.9225-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.5 at phobos.denx.de X-Virus-Status: Clean Modifies return code got from while loop as hush 2021 always returns 0 from while loop. 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 519c78ef7e..d3a55b27fa 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) { @@ -20,7 +23,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; } @@ -30,12 +38,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.25.1