1 // SPDX-License-Identifier: GPL-2.0
11 #include <asm/global_data.h>
13 static int hush_test_semicolon(struct unit_test_state *uts)
15 /* A; B = B truth table. */
16 ut_asserteq(1, run_command("false; false", 0));
17 ut_assertok(run_command("false; true", 0));
18 ut_assertok(run_command("true; true", 0));
19 ut_asserteq(1, run_command("true; false", 0));
23 HUSH_TEST(hush_test_semicolon, 0);
25 static int hush_test_and(struct unit_test_state *uts)
27 /* A && B truth table. */
28 ut_asserteq(1, run_command("false && false", 0));
29 ut_asserteq(1, run_command("false && true", 0));
30 ut_assertok(run_command("true && true", 0));
31 ut_asserteq(1, run_command("true && false", 0));
35 HUSH_TEST(hush_test_and, 0);
37 static int hush_test_or(struct unit_test_state *uts)
39 /* A || B truth table. */
40 ut_asserteq(1, run_command("false || false", 0));
41 ut_assertok(run_command("false || true", 0));
42 ut_assertok(run_command("true || true", 0));
43 ut_assertok(run_command("true || false", 0));
47 HUSH_TEST(hush_test_or, 0);
49 DECLARE_GLOBAL_DATA_PTR;
51 static int hush_test_and_or(struct unit_test_state *uts)
53 /* A && B || C truth table. */
54 ut_asserteq(1, run_command("false && false || false", 0));
56 if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
57 ut_asserteq(1, run_command("false && false || true", 0));
58 } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
60 * This difference seems to come from a bug solved in Busybox
63 * Indeed, the following expression can be seen like this:
64 * (false && false) || true
65 * So, (false && false) returns 1, the second false is not
66 * executed, and true is executed because of ||.
68 ut_assertok(run_command("false && false || true", 0));
71 if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
72 ut_asserteq(1, run_command("false && true || true", 0));
73 } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
75 * This difference seems to come from a bug solved in Busybox
78 * Indeed, the following expression can be seen like this:
79 * (false && true) || true
80 * So, (false && true) returns 1, the true is not executed, and
81 * true is executed because of ||.
83 ut_assertok(run_command("false && true || true", 0));
86 ut_asserteq(1, run_command("false && true || false", 0));
87 ut_assertok(run_command("true && true || false", 0));
88 ut_asserteq(1, run_command("true && false || false", 0));
89 ut_assertok(run_command("true && false || true", 0));
90 ut_assertok(run_command("true && true || true", 0));
94 HUSH_TEST(hush_test_and_or, 0);
96 static int hush_test_or_and(struct unit_test_state *uts)
98 /* A || B && C truth table. */
99 ut_asserteq(1, run_command("false || false && false", 0));
100 ut_asserteq(1, run_command("false || false && true", 0));
101 ut_assertok(run_command("false || true && true", 0));
102 ut_asserteq(1, run_command("false || true && false", 0));
104 if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
105 ut_assertok(run_command("true || true && false", 0));
106 } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
108 * This difference seems to come from a bug solved in Busybox
111 * Indeed, the following expression can be seen like this:
112 * (true || true) && false
113 * So, (true || true) returns 0, the second true is not
114 * executed, and then false is executed because of &&.
116 ut_asserteq(1, run_command("true || true && false", 0));
119 if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
120 ut_assertok(run_command("true || false && false", 0));
121 } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
123 * This difference seems to come from a bug solved in Busybox
126 * Indeed, the following expression can be seen like this:
127 * (true || false) && false
128 * So, (true || false) returns 0, the false is not executed, and
129 * then false is executed because of &&.
131 ut_asserteq(1, run_command("true || false && false", 0));
134 ut_assertok(run_command("true || false && true", 0));
135 ut_assertok(run_command("true || true && true", 0));
139 HUSH_TEST(hush_test_or_and, 0);