1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, The Chromium Authors
13 static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
14 "setenv list ${list}3\0"
15 "setenv list ${list}4";
17 static int do_ut_cmd(struct cmd_tbl *cmdtp, int flag, int argc,
20 printf("%s: Testing commands\n", __func__);
21 run_command("env default -f -a", 0);
23 /* commands separated by \n */
24 run_command_list("setenv list 1\n setenv list ${list}1", -1, 0);
25 assert(!strcmp("11", env_get("list")));
27 /* command followed by \n and nothing else */
28 run_command_list("setenv list 1${list}\n", -1, 0);
29 assert(!strcmp("111", env_get("list")));
31 /* a command string with \0 in it. Stuff after \0 should be ignored */
32 run_command("setenv list", 0);
33 run_command_list(test_cmd, sizeof(test_cmd), 0);
34 assert(!strcmp("123", env_get("list")));
37 * a command list where we limit execution to only the first command
38 * using the length parameter.
40 run_command_list("setenv list 1\n setenv list ${list}2; "
41 "setenv list ${list}3", strlen("setenv list 1"), 0);
42 assert(!strcmp("1", env_get("list")));
44 assert(run_command("false", 0) == 1);
45 assert(run_command("echo", 0) == 0);
46 assert(run_command_list("false", -1, 0) == 1);
47 assert(run_command_list("echo", -1, 0) == 0);
49 #ifdef CONFIG_HUSH_PARSER
50 run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
51 run_command("run foo", 0);
52 assert(env_get("black") != NULL);
53 assert(!strcmp("1", env_get("black")));
54 assert(env_get("adder") != NULL);
55 assert(!strcmp("2", env_get("adder")));
58 assert(run_command("", 0) == 0);
59 assert(run_command(" ", 0) == 0);
61 assert(run_command("'", 0) == 1);
63 printf("%s: Everything went swimmingly\n", __func__);
68 ut_cmd, 5, 1, do_ut_cmd,
69 "Very basic test of command parsers",