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 2B8ACC433EF for ; Fri, 31 Dec 2021 16:18:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6363D83768; Fri, 31 Dec 2021 17:16:22 +0100 (CET) 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="X9fm3PYZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 988C8830BE; Fri, 31 Dec 2021 17:14:22 +0100 (CET) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 E6426830C3 for ; Fri, 31 Dec 2021 17:14:05 +0100 (CET) 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-x435.google.com with SMTP id s1so56779560wrg.1 for ; Fri, 31 Dec 2021 08:14:05 -0800 (PST) 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=SSyk/6xDwlNT6J+2ikYxBdC3I7Ks+0BDBYT8IfGXE+4=; b=X9fm3PYZ/wljaDHTCKz9clEJ4hoQC8R+2xht2Idamk0ScCDgWxPfn4vuToAcX2fRkY QR78TeXp6xTr4hxxeKkwriquMXM/asRgtvdRgM4okIyM7m0DBY2D5eIFWJ9+kU0Ac0EY YNPysKtwvfKJYm7P9PG0tD7g/v3F/jvaTSydM= 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=SSyk/6xDwlNT6J+2ikYxBdC3I7Ks+0BDBYT8IfGXE+4=; b=Qiwh1ix6p8E0QuAjFff/2D8Vp577b+uCeh4kuPr9LSue401GLYCQ4+cBCOAmaUrjiD Kl1EPO3hrFVGna7sEFsHdR49GykNGTZofZ4Zz4nLU24m3vc/k4SCPtPDBuPqn/IVDSPW YkHIlaDqWVOPaIMkRqExVn+30nfG2ail719yhalISTEIDN3e3nxxcCck1TvtaSU8w1yW j1QcHTX3uC10RXhi6kpcHCpLisigahY538OVnZ/dUtwIvDVN/xljnviMajppcCQeM4kD cm5ZKUnr6sBOTB16uaFKOaOcCc42RszgMTFZeBQ5YfroqinwtHXwhCjbh7Yw1FYeU89R wM2Q== X-Gm-Message-State: AOAM5338zl5Wdn8R7dD3BAgklAtJ66TfIB1S9NqTFnxucVDmtdWV6Sny EjNwtL8LPMmSgwEyYI5Cleh4nqtWcAJ50w== X-Google-Smtp-Source: ABdhPJzk97Tl5wZjflXhtXy9puOJ7WbKeJC47k2kdr7l3d/VVb0wWFA++TjDQgagV/8mLiEOawonmQ== X-Received: by 2002:a5d:4588:: with SMTP id p8mr29640633wrq.106.1640967245574; Fri, 31 Dec 2021 08:14:05 -0800 (PST) Received: from pwmachine.home ([2a01:cb14:983:1f00:eef7:8bf8:8ee0:cb1a]) by smtp.gmail.com with ESMTPSA id f6sm31855522wmq.6.2021.12.31.08.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Dec 2021 08:14:05 -0800 (PST) From: Francis Laniel To: u-boot@lists.denx.de Cc: Marek Behun , Michael Nazzareno Trimarchi , Simon Glass , Wolfgang Denk , Harald Seiler , Francis Laniel Subject: [RFC PATCH v1 06/21] test: hush: Test hush loops. Date: Fri, 31 Dec 2021 17:13:12 +0100 Message-Id: <20211231161327.24918-7-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211231161327.24918-1-francis.laniel@amarulasolutions.com> References: <20211231161327.24918-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.38 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 The added tests ensure correct behavior of for, while and until loops. Signed-off-by: Francis Laniel --- 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