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 04065C43334 for ; Thu, 16 Jun 2022 22:41:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EF523844D4; Fri, 17 Jun 2022 00:41:29 +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="h8p+wLG8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4914484479; Fri, 17 Jun 2022 00:41:04 +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 488278447E for ; Fri, 17 Jun 2022 00:33:43 +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-x429.google.com with SMTP id q9so3547252wrd.8 for ; Thu, 16 Jun 2022 15:33:43 -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=Hk0lSWJiII4LuJi2KXRSPmqZnM7v80ZhxeryyFxbycE=; b=h8p+wLG8Eyajv1KwSJprRL5kR0kZX8UylpfY0QoNl0V3lVOPeWUF2peT2idTkOuz3H TqH5r1EDGUr1KkA5u+EvwhOrhphbwReFYTnaLfZM6T4JuuAXsDXoJmQFhe1U6Ttmn4YE ykwppNBbRFjHkv1bCZUTTjCFbVCPHQ/L9Xksk= 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=Hk0lSWJiII4LuJi2KXRSPmqZnM7v80ZhxeryyFxbycE=; b=cXl9WTS8VAJkp/3aMuDYqgCtFfp5/J9FnwW80aO/ELYhHOqQZHGDe7qYnocicq+KkL 2nAXR4u5YdprmwUKZJA+pOk41+CJsX++IniozfaGVQxa9F9quPtet29DZCFEx8lx9HQG 66pWUKYdBiZ7FLYhQU/mZI0Qe+n1qdljXdQUkU0vpAg6ZcDuWKo+gOdi0csyCgSs9Bxn jRobrwd8Gpg/R/7tRp228j1gEc8ZTKQKvO0O3hVOEAHQ8aHy3x6wSsCohRwvaclhuzjX F26bFBXQzLAwMyZA+qexNts3fCk86jvQg7DtzGxSVRpfkf9urlu2F9z5TnPnNLUOKm1O OGGA== X-Gm-Message-State: AJIora8HoryPOAwauQNFg8EH0W7Z7G8jXAkCBQwTTHTGlEEx6QoVk86k O52JD7fIBWfSUZsolUnu73qtWfA1+rzIeQ== X-Google-Smtp-Source: AGRyM1t8w3KmxI64JdkeEeZHkBMjxvh6aBfs7X0RVDXCCJvCa3ftHdUWTBgTP3K7/Iu541SI77LVCg== X-Received: by 2002:adf:f3ce:0:b0:211:55a:a604 with SMTP id g14-20020adff3ce000000b00211055aa604mr6478104wrp.213.1655418794409; Thu, 16 Jun 2022 15:33:14 -0700 (PDT) Received: from pwmachine.home (17.pool80-103-97.dynamic.orange.es. [80.103.97.17]) by smtp.gmail.com with ESMTPSA id n4-20020a05600c4f8400b003971fc23185sm7912044wmq.20.2022.06.16.15.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 15:33:14 -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 v4 18/28] test: hush: Fix variable expansion tests for hush 2021 Date: Fri, 17 Jun 2022 00:31:48 +0200 Message-Id: <20220616223158.9225-19-francis.laniel@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220616223158.9225-1-francis.laniel@amarulasolutions.com> References: <20220616223158.9225-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 --- test/hush/dollar.c | 79 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/test/hush/dollar.c b/test/hush/dollar.c index 27feda2970..0ca799b6b1 100644 --- a/test/hush/dollar.c +++ b/test/hush/dollar.c @@ -9,6 +9,9 @@ #include #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; static int hush_test_simple_dollar(struct unit_test_state *uts) { @@ -51,13 +54,29 @@ 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(); - ut_assert_console_end(); + + if (gd->flags & GD_FLG_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 if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_assert_console_end(); + } ut_asserteq(1, run_command("dollar_foo=bar quux\"", 0)); /* Two next lines contain error message */ ut_assert_skipline(); ut_assert_skipline(); - ut_assert_console_end(); + + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* See above comments. */ + console_record_reset_enable(); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_assert_console_end(); + } ut_assertok(run_command("dollar_foo='bar \"quux'", 0)); @@ -71,17 +90,35 @@ static int hush_test_simple_dollar(struct unit_test_state *uts) */ console_record_reset_enable(); - ut_asserteq(1, run_command("dollar_foo=\"bar 'quux\"", 0)); - /* Next line contains error message */ - ut_assert_skipline(); - ut_assert_console_end(); + if (gd->flags & GD_FLG_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("dollar_foo=\"bar 'quux\"", 0)); + + ut_assertok(run_command("echo $dollar_foo", 0)); + ut_assert_nextline("bar 'quux"); + ut_assert_console_end(); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_asserteq(1, run_command("dollar_foo=\"bar 'quux\"", 0)); + /* Next line contains error message */ + ut_assert_skipline(); + ut_assert_console_end(); + } 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(); - puts("Beware: this test set local variable dollar_foo and it cannot be unset!"); + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* Reset local variable. */ + ut_assertok(run_command("dollar_foo=", 0)); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + puts("Beware: this test set local variable dollar_foo and it cannot be unset!"); + } return 0; } @@ -109,7 +146,12 @@ static int hush_test_env_dollar(struct unit_test_state *uts) /* Clean up setting the variable */ env_set("env_foo", NULL); - puts("Beware: this test set local variable env_foo and it cannot be unset!"); + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* Reset local variable. */ + ut_assertok(run_command("env_foo=", 0)); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + puts("Beware: this test set local variable env_foo and it cannot be unset!"); + } return 0; } @@ -144,7 +186,18 @@ static int hush_test_command_dollar(struct unit_test_state *uts) ut_assertok(run_command("dollar_bar='echo bar\\n'", 0)); ut_assertok(run_command("$dollar_bar", 0)); - ut_assert_nextline("barn"); + + if (gd->flags & GD_FLG_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("bar\\n"); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_assert_nextline("barn"); + } + ut_assert_console_end(); ut_assertok(run_command("dollar_bar='echo $bar'", 0)); @@ -160,7 +213,13 @@ static int hush_test_command_dollar(struct unit_test_state *uts) ut_assert_nextline("quux"); ut_assert_console_end(); - puts("Beware: this test sets local variable dollar_bar and dollar_quux and they cannot be unset!"); + if (gd->flags & GD_FLG_HUSH_2021_PARSER) { + /* Reset local variables. */ + ut_assertok(run_command("dollar_bar=", 0)); + ut_assertok(run_command("dollar_quux=", 0)); + } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + puts("Beware: this test sets local variable dollar_bar and dollar_quux and they cannot be unset!"); + } return 0; } -- 2.25.1