[RFC PATCH v2 19/21] test: hush: Fix if tests for hush 2021

Francis Laniel
2022-02-06T18:41:16Z

Modifies the command run for hush 2021 when using string comparison operator.
Indeed, '<' and '>' must be escaped to be used as these operators.

Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
test/hush/if.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)

diff --git a/test/hush/if.c b/test/hush/if.c
index a57d88850f..b2f1f247f5 100644
--- a/test/hush/if.c
+++ b/test/hush/if.c
@@ -39,6 +39,10 @@ static int hush_test_if_basic_operators(struct unit_test_state *uts)
{
char if_formatted[128];

+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+ console_record_reset_enable();
+#endif /* HUSH_2021_PARSER */
+
sprintf(if_formatted, if_format, "test aaa = aaa");
ut_assertok(run_command(if_formatted, 0));

@@ -52,15 +56,54 @@ static int hush_test_if_basic_operators(struct unit_test_state *uts)
ut_asserteq(1, run_command(if_formatted, 0));

sprintf(if_formatted, if_format, "test aaa < bbb");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+ /*
+ * We need to escape < and > to use as them as string comparison
+ * operator.
+ * Otherwise, they are interprated as redirection operators which is not
+ * supported in U-Boot.
+ */
+ ut_asserteq(1, run_command(if_formatted, 0));
+ /* Next lines contains error message (which is on two lines). */
+ ut_assert_skipline();
+ ut_assert_skipline();
+ ut_assert_console_end();
+
+ sprintf(if_formatted, if_format, R"(test aaa \< bbb)");
+#endif /* HUSH_2021_PARSER */
ut_assertok(run_command(if_formatted, 0));

sprintf(if_formatted, if_format, "test bbb < aaa");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_skipline();
+ ut_assert_skipline();
+ ut_assert_console_end();
+
+ sprintf(if_formatted, if_format, R"(test bbb \< aaa)");
+#endif /* HUSH_2021_PARSER */
ut_asserteq(1, run_command(if_formatted, 0));

sprintf(if_formatted, if_format, "test bbb > aaa");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_skipline();
+ ut_assert_skipline();
+ ut_assert_console_end();
+
+ sprintf(if_formatted, if_format, R"(test bbb \> aaa)");
+#endif /* HUSH_2021_PARSER */
ut_assertok(run_command(if_formatted, 0));

sprintf(if_formatted, if_format, "test aaa > bbb");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_skipline();
+ ut_assert_skipline();
+ ut_assert_console_end();
+
+ sprintf(if_formatted, if_format, R"(test aaa \> bbb)");
+#endif /* HUSH_2021_PARSER */
ut_asserteq(1, run_command(if_formatted, 0));

sprintf(if_formatted, if_format, "test 123 -eq 123");
--
2.25.1