diff mbox series

[RFC,v1,15/21] test: hush: Fix instructions list tests for hush 2021.

Message ID 20211231161327.24918-16-francis.laniel@amarulasolutions.com
State RFC
Delegated to: Tom Rini
Headers show
Series Modernize U-Boot shell | expand

Commit Message

Francis Laniel Dec. 31, 2021, 4:13 p.m. UTC
This commit 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 <francis.laniel@amarulasolutions.com>
---
 test/hush/list.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

Comments

Simon Glass Jan. 12, 2022, 8:03 p.m. UTC | #1
On Fri, 31 Dec 2021 at 09:14, Francis Laniel
<francis.laniel@amarulasolutions.com> wrote:
>
> This commit 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 <francis.laniel@amarulasolutions.com>
> ---
>  test/hush/list.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/test/hush/list.c b/test/hush/list.c
index 052cf2783c..096bb4f034 100644
--- a/test/hush/list.c
+++ b/test/hush/list.c
@@ -50,8 +50,32 @@  static int hush_test_and_or(struct unit_test_state *uts)
 {
 	/* A && B || C truth table. */
 	ut_asserteq(1, run_command("false && false || false", 0));
+#ifdef CONFIG_HUSH_OLD_PARSER
 	ut_asserteq(1, run_command("false && false || true", 0));
+#elif defined(CONFIG_HUSH_2021_PARSER)
+	/*
+	 * This difference seems to come from a bug solved in Busybox hush.
+	 *
+	 * Indeed, the following expression can be seen like this:
+	 * (false && false) || true
+	 * So, (false && false) returns 1, the second false is not executed, and
+	 * true is executed because of ||.
+	 */
+	ut_assertok(run_command("false && false || true", 0));
+#endif  /* CONFIG_HUSH_2021_PARSER */
+#ifdef CONFIG_HUSH_OLD_PARSER
 	ut_asserteq(1, run_command("false && true || true", 0));
+#elif defined(CONFIG_HUSH_2021_PARSER)
+	/*
+	 * This difference seems to come from a bug solved in Busybox hush.
+	 *
+	 * Indeed, the following expression can be seen like this:
+	 * (false && true) || true
+	 * So, (false && true) returns 1, the true is not executed, and true is
+	 * executed because of ||.
+	 */
+	ut_assertok(run_command("false && true || true", 0));
+#endif  /* CONFIG_HUSH_2021_PARSER */
 	ut_asserteq(1, run_command("false && true || false", 0));
 	ut_assertok(run_command("true && true || false", 0));
 	ut_asserteq(1, run_command("true && false || false", 0));
@@ -69,8 +93,32 @@  static int hush_test_or_and(struct unit_test_state *uts)
 	ut_asserteq(1, run_command("false || false && true", 0));
 	ut_assertok(run_command("false || true && true", 0));
 	ut_asserteq(1, run_command("false || true && false", 0));
+#ifdef CONFIG_HUSH_OLD_PARSER
 	ut_assertok(run_command("true || true && false", 0));
+#elif defined(CONFIG_HUSH_2021_PARSER)
+	/*
+	 * This difference seems to come from a bug solved in Busybox hush.
+	 *
+	 * Indeed, the following expression can be seen like this:
+	 * (true || true) && false
+	 * So, (true || true) returns 0, the second true is not executed, and
+	 * then false is executed because of &&.
+	 */
+	ut_asserteq(1, run_command("true || true && false", 0));
+#endif  /* CONFIG_HUSH_2021_PARSER */
+#ifdef CONFIG_HUSH_OLD_PARSER
 	ut_assertok(run_command("true || false && false", 0));
+#elif defined(CONFIG_HUSH_2021_PARSER)
+	/*
+	 * This difference seems to come from a bug solved in Busybox hush.
+	 *
+	 * Indeed, the following expression can be seen like this:
+	 * (true || false) && false
+	 * So, (true || false) returns 0, the false is not executed, and then
+	 * false is executed because of &&.
+	 */
+	ut_asserteq(1, run_command("true || false && false", 0));
+#endif  /* CONFIG_HUSH_2021_PARSER */
 	ut_assertok(run_command("true || false && true", 0));
 	ut_assertok(run_command("true || true && true", 0));