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 32B4DC433EF for ; Sun, 6 Feb 2022 18:40:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D7E6583C52; Sun, 6 Feb 2022 19:38:39 +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="IVxtx7Md"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2BD2D83BC5; Sun, 6 Feb 2022 19:38:38 +0100 (CET) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 8F3EB83C10 for ; Sun, 6 Feb 2022 19:37:52 +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-x42e.google.com with SMTP id v19so6252448wrv.6 for ; Sun, 06 Feb 2022 10:37:52 -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=jIiRo0wbGszwfW/0pZa1KZLxpZk/I7KuCauHYTeyV+U=; b=IVxtx7Md/Cc+xC+0VYXAased7/h7EhHqtiop2vqIf9/e+t50wW1uz9PaQe5p0Vi9uE sCDoEpIFRyoQICoUI7oDh7SnLtKh5cQbtUsbvamuWBwKkUROfUYoN/OajlWkKPj6idfg ZZQxbFCJkQduUDNItWvHzhVY2QPRL49aAWZ+Y= 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=jIiRo0wbGszwfW/0pZa1KZLxpZk/I7KuCauHYTeyV+U=; b=t0Zdmxqa39CiZ54mcL9XIsqWRSg4KfvtFqz5Zpa27WveTBRV5gag0y05EMYixyRnI5 vq174uKtfJtRFS8Cbr78M0SIri8uIOzsILxJ789fQBf4SThpL+19qUfIlNf4u/qQRYIW OqXyBAWGrD3Fu9VkLNLdCx1Q+ccw5+QTV4D8XNUur6yFPqHkI8iGjM3G4W4uvpkd/ygR 47FGzHA18tkbXDdEh1ytM117qDzBoOdaBI+3cLKXsTXrVX/uRD2pFHV7Rd9eaEculFzL fYgfv375ODRTPu43BBiHtDUj5WwKBHlSAaOHMRU1ITVy3aZ6iKZZE4yjaT17hCMTcLjU VpFg== X-Gm-Message-State: AOAM530C6OMtmMFvF8qzxaLNtOnhqvC2d8bzzjBkjwRPBhRh9WMsraSh dT3O+pbO2X3HkrRpR3NzSyTZbSLsqH4UCg== X-Google-Smtp-Source: ABdhPJzaRZ5B7vKJpGYfWTyn4p4Y4JBlGFz1hn6Mq8xM1uG4mt8OcLcQ8Fcor2dPcxkXi9mbTjUqPw== X-Received: by 2002:a05:6000:2aa:: with SMTP id l10mr7094983wry.191.1644172672180; Sun, 06 Feb 2022 10:37:52 -0800 (PST) Received: from pwmachine.home ([2a01:cb14:983:1f00:e5b3:218b:cb92:2549]) by smtp.gmail.com with ESMTPSA id ay29sm7095011wmb.38.2022.02.06.10.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 10:37:51 -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 v2 16/21] test: hush: Fix variable expansion tests for hush 2021 Date: Sun, 6 Feb 2022 19:37:12 +0100 Message-Id: <20220206183717.57446-17-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220206183717.57446-1-francis.laniel@amarulasolutions.com> References: <20220206183717.57446-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 the expected result for hush 2021. Indeed, there were bugs in actual U-Boot hush which were fixed in upstream Busybox. As hush 2021 is based on upstream Busybox, these bugs no longer exist. Signed-off-by: Francis Laniel Reviewed-by: Simon Glass --- test/hush/dollar.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/hush/dollar.c b/test/hush/dollar.c index 2614517cd2..3701521f69 100644 --- a/test/hush/dollar.c +++ b/test/hush/dollar.c @@ -57,13 +57,27 @@ static int hush_test_simple_dollar(struct unit_test_state *uts) ut_asserteq(1, run_command("dollar_foo='bar quux", 0)); /* Next line contains error message */ ut_assert_skipline(); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* + * For some strange reasons, the console is not empty after running + * above command. + * So, we reset it to not have side effects for other tests. + */ + console_record_reset_enable(); +#else /* HUSH_OLD_PARSER */ ut_assert_console_end(); +#endif /* HUSH_OLD_PARSER */ ut_asserteq(1, run_command(R"(dollar_foo=bar quux")", 0)); /* Two next lines contain error message */ ut_assert_skipline(); ut_assert_skipline(); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* See above comments. */ + console_record_reset_enable(); +#else /* HUSH_OLD_PARSER */ ut_assert_console_end(); +#endif /* HUSH_OLD_PARSER */ ut_assertok(run_command(R"(dollar_foo='bar "quux')", 0)); @@ -77,17 +91,35 @@ static int hush_test_simple_dollar(struct unit_test_state *uts) */ console_record_reset_enable(); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* + * Old parser returns an error because it waits for closing '\'', but + * this behavior is wrong as the '\'' is surrounded by '"', so no need + * to wait for a closing one. + */ + ut_assertok(run_command(R"(dollar_foo="bar 'quux")", 0)); + + ut_assertok(run_command("echo $dollar_foo", 0)); + ut_assert_nextline("bar 'quux"); + ut_assert_console_end(); +#else /* HUSH_OLD_PARSER */ ut_asserteq(1, run_command(R"(dollar_foo="bar 'quux")", 0)); /* Next line contains error message */ ut_assert_skipline(); ut_assert_console_end(); +#endif /* HUSH_OLD_PARSER */ ut_assertok(run_command("dollar_foo='bar quux'", 0)); ut_assertok(run_command("echo $dollar_foo", 0)); ut_assert_nextline("bar quux"); ut_assert_console_end(); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* Reset local variable. */ + ut_assertok(run_command("dollar_foo=", 0)); +#else /* HUSH_OLD_PARSER */ puts("Beware: this test set local variable dollar_foo and it cannot be unset!"); +#endif /* HUSH_OLD_PARSER */ return 0; } @@ -115,7 +147,12 @@ static int hush_test_env_dollar(struct unit_test_state *uts) /* Clean up setting the variable */ env_set("env_foo", NULL); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* Reset local variable. */ + ut_assertok(run_command("env_foo=", 0)); +#else /* HUSH_OLD_PARSER */ puts("Beware: this test set local variable env_foo and it cannot be unset!"); +#endif /* HUSH_OLD_PARSER */ return 0; } @@ -152,7 +189,15 @@ static int hush_test_command_dollar(struct unit_test_state *uts) ut_assertok(run_command(R"(dollar_bar='echo bar\n')", 0)); ut_assertok(run_command("$dollar_bar", 0)); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* + * This difference seems to come from a bug solved in Busybox hush. + * Behavior of hush 2021 is coherent with bash and other shells. + */ + ut_assert_nextline(R"(bar\n)"); +#else /* HUSH_OLD_PARSER */ ut_assert_nextline("barn"); +#endif /* HUSH_OLD_PARSER */ ut_assert_console_end(); ut_assertok(run_command("dollar_bar='echo $bar'", 0)); @@ -168,7 +213,13 @@ static int hush_test_command_dollar(struct unit_test_state *uts) ut_assert_nextline("quux"); ut_assert_console_end(); +#if CONFIG_IS_ENABLED(HUSH_2021_PARSER) + /* Reset local variables. */ + ut_assertok(run_command("dollar_bar=", 0)); + ut_assertok(run_command("dollar_quux=", 0)); +#else /* HUSH_OLD_PARSER */ puts("Beware: this test sets local variable dollar_bar and dollar_quux and they cannot be unset!"); +#endif /* HUSH_OLD_PARSER */ return 0; } -- 2.25.1