blob: 8f48f5ee25cc085c7e204c652f7be3fbfff09a2b [file] [log] [blame]
Jerome Forissier90b30122025-04-18 16:09:43 +02001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Tests for spawn and wait commands
4 *
5 * Copyright 2025, Linaro Ltd.
6 */
7
8#include <command.h>
9#include <test/cmd.h>
10#include <test/test.h>
11#include <test/ut.h>
12
13static int test_cmd_spawn(struct unit_test_state *uts)
14{
15 ut_assertok(run_command("wait; spawn sleep 2; setenv j ${job_id}; "
16 "spawn setenv spawned true; "
17 "setenv jj ${job_id}; wait; "
18 "echo ${j} ${jj} ${spawned}", 0));
19 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
20 ut_asserteq_ptr(uts->actual_str,
21 strstr(uts->actual_str, "1 2 true"));
22
23 ut_assertok(run_command("spawn true; wait; setenv t $?; spawn false; "
24 "wait; setenv f $?; wait; echo $t $f $?", 0));
25 console_record_readline(uts->actual_str, sizeof(uts->actual_str));
26 ut_asserteq_ptr(uts->actual_str,
27 strstr(uts->actual_str, "0 1 0"));
28 ut_assert_console_end();
29
30 return 0;
31}
32CMD_TEST(test_cmd_spawn, UTF_CONSOLE);