From 6d3914f9c1f6df21b46a544e0e5419de4d9888b4 Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Fri, 22 Dec 2023 22:02:36 +0100 Subject: [PATCH] test: hush: Fix instructions list tests for modern hush Modifies the expected result for modern hush. Indeed, there were bugs in actual U-Boot hush which were fixed in upstream Busybox. As modern hush is based on upstream Busybox, these bugs no longer exist. Reviewed-by: Simon Glass Signed-off-by: Francis Laniel --- test/hush/list.c | 69 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/test/hush/list.c b/test/hush/list.c index 052cf2783c..73ae36e88f 100644 --- a/test/hush/list.c +++ b/test/hush/list.c @@ -9,6 +9,7 @@ #include #include #include +#include static int hush_test_semicolon(struct unit_test_state *uts) { @@ -46,12 +47,43 @@ static int hush_test_or(struct unit_test_state *uts) } HUSH_TEST(hush_test_or, 0); +DECLARE_GLOBAL_DATA_PTR; + 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)); - ut_asserteq(1, run_command("false && false || true", 0)); - ut_asserteq(1, run_command("false && true || true", 0)); + + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_asserteq(1, run_command("false && false || true", 0)); + } else if (gd->flags & GD_FLG_HUSH_MODERN_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)); + } + + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_asserteq(1, run_command("false && true || true", 0)); + } else if (gd->flags & GD_FLG_HUSH_MODERN_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)); + } + 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 +101,37 @@ 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)); - ut_assertok(run_command("true || true && false", 0)); - ut_assertok(run_command("true || false && false", 0)); + + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_assertok(run_command("true || true && false", 0)); + } else if (gd->flags & GD_FLG_HUSH_MODERN_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)); + } + + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { + ut_assertok(run_command("true || false && false", 0)); + } else if (gd->flags & GD_FLG_HUSH_MODERN_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)); + } + ut_assertok(run_command("true || false && true", 0)); ut_assertok(run_command("true || true && true", 0)); -- 2.39.5