u-boot/test/cmd/test_echo.c
Peng Fan 0f90b1e715 treewide: Clean up DECLARE_GLOBAL_DATA_PTR usage
Remove DECLARE_GLOBAL_DATA_PTR from files where gd is not used, and
drop the unnecessary inclusion of asm/global_data.h.

Headers should be included directly by the files that need them,
rather than indirectly via global_data.h.

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com> #STMicroelectronics boards and STM32MP1 ram test driver
Tested-by: Anshul Dalal <anshuld@ti.com> #TI boards
Acked-by: Yao Zi <me@ziyao.cc> #TH1520
Signed-off-by: Peng Fan <peng.fan@nxp.com>
2026-02-17 13:50:22 -06:00

54 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Tests for echo command
*
* Copyright 2020, Heinrich Schuchadt <xypron.glpk@gmx.de>
*/
#include <command.h>
#include <display_options.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
struct test_data {
char *cmd;
char *expected;
};
static struct test_data echo_data[] = {
{"echo 1 2 3",
"1 2 3"},
/* Test new line handling */
{"echo -n 1 2 3; echo a b c",
"1 2 3a b c"},
/*
* Test handling of environment variables.
*
* j, q, x are among the least frequent letters in English.
* Hence no collision for the variable name jQx is expected.
*/
{"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c) ${jQx}; setenv jQx",
"a) X b) ${jQx} c) X"},
/* Test shell variable assignments without substitutions */
{"foo=bar echo baz", "baz"},
/* Test handling of shell variables. */
{"setenv jQx; for jQx in 1 2 3; do echo -n \"${jQx}, \"; done; echo;",
"1, 2, 3, "},
};
static int lib_test_hush_echo(struct unit_test_state *uts)
{
int i;
for (i = 0; i < ARRAY_SIZE(echo_data); ++i) {
ut_assertok(run_command(echo_data[i].cmd, 0));
console_record_readline(uts->actual_str,
sizeof(uts->actual_str));
ut_asserteq_str(echo_data[i].expected, uts->actual_str);
ut_assert_console_end();
}
return 0;
}
LIB_TEST(lib_test_hush_echo, UTF_CONSOLE);