summaryrefslogtreecommitdiff
path: root/test/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'test/cmd')
-rw-r--r--test/cmd/Makefile3
-rw-r--r--test/cmd/command.c31
-rw-r--r--test/cmd/spawn.c32
3 files changed, 50 insertions, 16 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index d8a5e77402d..595e4cfcada 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -3,7 +3,7 @@
# Copyright (c) 2013 Google, Inc
# Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
-obj-$(CONFIG_$(XPL_)CMDLINE) += command.o
+obj-$(CONFIG_$(PHASE_)CMDLINE) += command.o
ifdef CONFIG_HUSH_PARSER
obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
endif
@@ -39,3 +39,4 @@ obj-$(CONFIG_CMD_WGET) += wget.o
endif
obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
endif
+obj-$(CONFIG_CMD_SPAWN) += spawn.o
diff --git a/test/cmd/command.c b/test/cmd/command.c
index 5ec93d490ba..5b1e5a77e5d 100644
--- a/test/cmd/command.c
+++ b/test/cmd/command.c
@@ -45,31 +45,32 @@ static int command_test(struct unit_test_state *uts)
"setenv list ${list}3", strlen("setenv list 1"), 0);
ut_assert(!strcmp("1", env_get("list")));
- ut_asserteq(1, run_command("false", 0));
ut_assertok(run_command("echo", 0));
- ut_asserteq(1, run_command_list("false", -1, 0));
ut_assertok(run_command_list("echo", -1, 0));
-#ifdef CONFIG_HUSH_PARSER
- run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
- run_command("run foo", 0);
- ut_assertnonnull(env_get("black"));
- ut_asserteq(0, strcmp("1", env_get("black")));
- ut_assertnonnull(env_get("adder"));
- ut_asserteq(0, strcmp("2", env_get("adder")));
-#endif
-
- ut_assertok(run_command("", 0));
- ut_assertok(run_command(" ", 0));
+ if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
+ ut_asserteq(1, run_command("false", 0));
+ ut_asserteq(1, run_command_list("false", -1, 0));
+ run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
+ run_command("run foo", 0);
+ ut_assertnonnull(env_get("black"));
+ ut_asserteq(0, strcmp("1", env_get("black")));
+ ut_assertnonnull(env_get("adder"));
+ ut_asserteq(0, strcmp("2", env_get("adder")));
+ ut_assertok(run_command("", 0));
+ ut_assertok(run_command(" ", 0));
+ }
ut_asserteq(1, run_command("'", 0));
/* Variadic function test-cases */
+ if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-zero-length"
- ut_assertok(run_commandf(""));
+ ut_assertok(run_commandf(""));
#pragma GCC diagnostic pop
- ut_assertok(run_commandf(" "));
+ ut_assertok(run_commandf(" "));
+ }
ut_asserteq(1, run_commandf("'"));
ut_assertok(run_commandf("env %s %s", "delete -f", "list"));
diff --git a/test/cmd/spawn.c b/test/cmd/spawn.c
new file mode 100644
index 00000000000..8f48f5ee25c
--- /dev/null
+++ b/test/cmd/spawn.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Tests for spawn and wait commands
+ *
+ * Copyright 2025, Linaro Ltd.
+ */
+
+#include <command.h>
+#include <test/cmd.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int test_cmd_spawn(struct unit_test_state *uts)
+{
+ ut_assertok(run_command("wait; spawn sleep 2; setenv j ${job_id}; "
+ "spawn setenv spawned true; "
+ "setenv jj ${job_id}; wait; "
+ "echo ${j} ${jj} ${spawned}", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "1 2 true"));
+
+ ut_assertok(run_command("spawn true; wait; setenv t $?; spawn false; "
+ "wait; setenv f $?; wait; echo $t $f $?", 0));
+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+ ut_asserteq_ptr(uts->actual_str,
+ strstr(uts->actual_str, "0 1 0"));
+ ut_assert_console_end();
+
+ return 0;
+}
+CMD_TEST(test_cmd_spawn, UTF_CONSOLE);