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 A8CABC7EE25 for ; Thu, 8 Jun 2023 18:37:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1E5D986124; Thu, 8 Jun 2023 20:35:36 +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="kpEUqxBj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C427086119; Thu, 8 Jun 2023 20:35:24 +0200 (CEST) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (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 1297D86128 for ; Thu, 8 Jun 2023 20:35:18 +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-x42f.google.com with SMTP id ffacd0b85a97d-307d58b3efbso764330f8f.0 for ; Thu, 08 Jun 2023 11:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1686249317; x=1688841317; 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=2n8jxt1ds5q7Q9H17EJfwFItauiA8vIOt8u046pmLRk=; b=kpEUqxBjSdws22K1sGp80HfnYFfU5jP0LxhGqohPcfssjOMAkLCgXsz7/FfebY2z1k 94uFKtrtuSajRDB/Gp4XMQcJ7ALZkwKm53lEgL7PvVqt9N+CH0HPGFGoKGh/VaK6srBH O8VARGbeNwQj/5yGu/VMHM3XXolG8h1xDZ6Gs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686249317; x=1688841317; 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=2n8jxt1ds5q7Q9H17EJfwFItauiA8vIOt8u046pmLRk=; b=Fehacqn9SfN5tDn7J+XDyHrmMtwL7cMa2nC6MCkEE61ePHi0w1SuLz3eKA0O0/u9wd Aip/NnBAQo2BWsqIZMLEs3+8gofc+5fP0Ayu6od37wZj/uRe0a4skEsG2dPP0tOuWP2z 3FWZtUHRCDhQFwLlL9SY+HkeyYPCup+zzar7PXRWDmIVMKf00Mlx02+ZDWxz4MApTSht L6u1nDjE/oPs3yMYLPulbDInIhWy+31p4KHHruZMzlFSz8b5jSlpPXijO58swu1jnCCs YpN0jWAu3K3NatAS0lSlMZgMnAA+oHHzh9kp65x6SIB140awk7Zg5cU8SzuygfkysMTn SuxQ== X-Gm-Message-State: AC+VfDxgXesEVgsyldh9guo2/oRz1XpCizyK/TAjDyaQtddKhI/j9pM/ gH4Zxt8GKKADoHsYTV/XovRcxaR9NsQaJvgOczyq+w== X-Google-Smtp-Source: ACHHUZ4llqgatEBb2ORgjR/HuuE8kpYI5mMmEkWHWzyY3gm9nBduaWGewOtftuZ8Wi4xF6C2YDAiNg== X-Received: by 2002:a05:6000:1209:b0:2dd:11b8:8aa9 with SMTP id e9-20020a056000120900b002dd11b88aa9mr7543863wrx.15.1686249317692; Thu, 08 Jun 2023 11:35:17 -0700 (PDT) Received: from pwmachine.home (120.124.191.92.dynamic.jazztel.es. [92.191.124.120]) by smtp.gmail.com with ESMTPSA id t10-20020a1c770a000000b003f8009be6c0sm408783wmi.3.2023.06.08.11.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 11:35:17 -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 v9 06/23] test: hush: Test hush loops Date: Thu, 8 Jun 2023 19:34:21 +0100 Message-Id: <20230608183438.16748-7-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230608183438.16748-1-francis.laniel@amarulasolutions.com> References: <20230608183438.16748-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 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 | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 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..ca777e38fe --- /dev/null +++ b/test/hush/loop.c @@ -0,0 +1,65 @@ +// 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 quux; do echo $loop_i; done", 0)); + ut_assert_nextline("foo"); + ut_assert_nextline("bar"); + ut_assert_nextline("quux"); + 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.34.1