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 1D708C433F5 for ; Thu, 31 Mar 2022 23:43:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7BBF784379; Fri, 1 Apr 2022 01:32:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (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="lBeSoy2w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E7DFA83515; Fri, 1 Apr 2022 01:32:06 +0200 (CEST) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 067F584325 for ; Fri, 1 Apr 2022 01:28:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (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-x429.google.com with SMTP id d7so1805331wrb.7 for ; Thu, 31 Mar 2022 16:28:08 -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=nKyPUvF78V1JAQ1NC0jUWUVyqbNSLTReMLpPjrUD3bs=; b=lBeSoy2wUP6VbjePziwA8lhACXumhCsesHv6D8lNj6B/FoIQJfs8KFW8pV6f8+m13n MlTzWXde7LJ9yS0aKdBOoyTa/fYVaFPJy+P+dh+XCTIX+IGR7VULxL/VN+2t0OR+UIJL 4MWYKyG5RhLdlS8zOGxiMypT7JIEMI8IL+GU0= 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=nKyPUvF78V1JAQ1NC0jUWUVyqbNSLTReMLpPjrUD3bs=; b=k+iaGxrhI4LGK/OJctlGQO9wRo8JT4XQwD1sk7grVp5dH1IEva3Xs4wh/rSK12IIK7 QH7YWOokwbZyhqQFH8aut+twuMcHYRhNQTJO37n+8zxN6tJPCqO5XcstGrJeZk/wNhNK wO2A0duXKt/tji7JCPwmr0StOTrEbM8y1g34f8yL6bQMmSjE2jlZKxlaU83c4lweFO6U sSmbnLnL/CZ47WVs/mrUWiuEl71Tr5yv95KhlTYuU/yMH4B/aB+rJxfIXTsATYCSkz+E FBIGJiTTUxOWwsPwmqAloM3i0AkTb52oVO9/LvFqtpcIRaAoOIFmavkoU1GthCkSmAlB O7hg== X-Gm-Message-State: AOAM5332H4mgIxHFsf+dxTUoHCD/1oQEgBDuc36i0lJlJAV8ITqZO0h6 CTlfoIlockRiM5pAP6n6jrgPAjiqok1d8lNM X-Google-Smtp-Source: ABdhPJynIjG6Rgknk+9uDSUSdy2S0lPaOrACTgfpJUG+KouPcrmma37QfYxH3Xq+4iI1DanaOiq0/w== X-Received: by 2002:a5d:64ae:0:b0:205:908a:2bc3 with SMTP id m14-20020a5d64ae000000b00205908a2bc3mr5641770wrp.437.1648769282638; Thu, 31 Mar 2022 16:28:02 -0700 (PDT) Received: from pwmachine.home ([92.186.13.154]) by smtp.gmail.com with ESMTPSA id l20-20020a05600c1d1400b0038cba2f88c0sm11646395wms.26.2022.03.31.16.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 16:28:01 -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 v3 07/23] test: hush: Test hush loops Date: Fri, 1 Apr 2022 01:27:00 +0200 Message-Id: <20220331232716.241283-8-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331232716.241283-1-francis.laniel@amarulasolutions.com> References: <20220331232716.241283-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 The added tests verifies correct behavior of for, while and until loops. Signed-off-by: Francis Laniel Reviewed-by: Simon Glass --- test/hush/Makefile | 1 + test/hush/loop.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/hush/loop.c diff --git a/test/hush/Makefile b/test/hush/Makefile index ff4fe7700b..a2d98815e5 100644 --- a/test/hush/Makefile +++ b/test/hush/Makefile @@ -7,3 +7,4 @@ obj-y += cmd_ut_hush.o obj-y += if.o obj-y += dollar.o obj-y += list.o +obj-y += loop.o diff --git a/test/hush/loop.c b/test/hush/loop.c new file mode 100644 index 0000000000..519c78ef7e --- /dev/null +++ b/test/hush/loop.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) Copyright 2021 + * Francis Laniel, Amarula Solutions, francis.laniel@amarulasolutions.com + */ + +#include +#include +#include +#include +#include + +static int hush_test_for(struct unit_test_state *uts) +{ + console_record_reset_enable(); + + ut_assertok(run_command("for loop_i in foo bar quux; do echo $loop_i; done", 0)); + ut_assert_nextline("foo"); + ut_assert_nextline("bar"); + ut_assert_nextline("quux"); + ut_assert_console_end(); + + puts("Beware: this test set local variable loop_i and it cannot be unset!"); + + return 0; +} +HUSH_TEST(hush_test_for, 0); + +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)); + ut_assert_nextline("bar"); + ut_assert_console_end(); + + puts("Beware: this test set local variable loop_foo and it cannot be unset!"); + + return 0; +} +HUSH_TEST(hush_test_while, 0); + +static int hush_test_until(struct unit_test_state *uts) +{ + console_record_reset_enable(); + env_set("loop_bar", "bar"); + + /* + * WARNING We have to use environment variable because it is not possible + * resetting local variable. + */ + ut_assertok(run_command("until test -z \"$loop_bar\"; do echo quux; setenv loop_bar; done", 0)); + ut_assert_nextline("quux"); + ut_assert_console_end(); + + /* + * Loop normally resets foo environment variable, but we reset it here in + * case the test failed. + */ + env_set("loop_bar", NULL); + return 0; +} +HUSH_TEST(hush_test_until, 0); -- 2.25.1