Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 290BEC4338F for ; Fri, 20 Aug 2021 15:50:26 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 87A03610FF for ; Fri, 20 Aug 2021 15:50:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87A03610FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 123D282E67; Fri, 20 Aug 2021 17:49:50 +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="AoX1fVax"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 80F7C82E08; Fri, 20 Aug 2021 17:49:20 +0200 (CEST) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 75F0382C0A for ; Fri, 20 Aug 2021 17:49:13 +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-x42d.google.com with SMTP id q6so14909247wrv.6 for ; Fri, 20 Aug 2021 08:49:13 -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=SSyk/6xDwlNT6J+2ikYxBdC3I7Ks+0BDBYT8IfGXE+4=; b=AoX1fVax9QrAPsiACkL511+Cpw3QiP9ZDXxn8xRPXDWvD0hNc8TzF2IPhltEgDwC0C S61IYbHoiSLuRz3X60EumkSYkz1+xiD3gJ4fVeSULMct/npWQcvuc1WDrB7M6M+/yvsJ h5xmdWN5J7vZXMAm/bNsAPoSmshAMiW8xk+yI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=WJwkoWDC7chvW1lm2xbFTPrs2N6jr6iuBtUO53x4ZPktM6jcJvVTeMvGdaX8m3VOBU kb1Tu0/8v12OKi8vCo8t9ZJXz0yNquJuTu/PVvKOAuqvTUWryfViqmnebcfml1Uwu8nw tzVc1Fxs1Mo409/u/pR5zC65yD6kX3nTWanMkzTeBPbuoGew/Hzs15FqdmAPiap1LHu/ JHnD7Ox9pvJA19IZM5Ljl9guGDD5wleYnrBPz0bpTNbdU3EKce+mcaiS7l0tC3sIBMln LLCRXt1D9h7o+2bjkejRjjnqW029iSSQcNJAY2PymsgilEbIpAYxqscoasusOvRxazhi 3e4A== X-Gm-Message-State: AOAM530bARwppC8ndeCObldXGNhv8TwAcSXlJ4K2I77TSz6K/NAuvsAo W2wtWZEaohm0+vmZVfTLhIw+TgUrnVc4Hg== X-Google-Smtp-Source: ABdhPJzLo8dRCz9tNyqsP0wlt7KFuqqmRIIppkPR6GDM2epKO6NDnRUTsjSocfbI8Qjflf7bMdsZKQ== X-Received: by 2002:adf:eb02:: with SMTP id s2mr11002553wrn.294.1629474553048; Fri, 20 Aug 2021 08:49:13 -0700 (PDT) Received: from pwmachine.home ([2a01:cb14:983:1f00:4e0c:e96d:5c36:fa68]) by smtp.gmail.com with ESMTPSA id c13sm2108846wru.73.2021.08.20.08.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 08:49:12 -0700 (PDT) From: Francis Laniel To: u-boot@lists.denx.de Cc: michael@amarulasolutions.com, Francis Laniel Subject: [RFC PATCH 6/6] test: hush: Test hush loops. Date: Fri, 20 Aug 2021 17:48:39 +0200 Message-Id: <20210820154839.101107-7-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210820154839.101107-1-francis.laniel@amarulasolutions.com> References: <20210820154839.101107-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.34 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