2 * Copyright (c) 2012, The Chromium Authors
4 * SPDX-License-Identifier: GPL-2.0+
11 static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
12 "setenv list ${list}3\0"
13 "setenv list ${list}4";
15 static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17 printf("%s: Testing commands\n", __func__);
18 run_command("env default -f", 0);
20 /* run a single command */
21 run_command("setenv single 1", 0);
22 assert(!strcmp("1", getenv("single")));
24 /* make sure that compound statements work */
25 #ifdef CONFIG_SYS_HUSH_PARSER
26 run_command("if test -n ${single} ; then setenv check 1; fi", 0);
27 assert(!strcmp("1", getenv("check")));
28 run_command("setenv check", 0);
31 /* commands separated by ; */
32 run_command_list("setenv list 1; setenv list ${list}1", -1, 0);
33 assert(!strcmp("11", getenv("list")));
35 /* commands separated by \n */
36 run_command_list("setenv list 1\n setenv list ${list}1", -1, 0);
37 assert(!strcmp("11", getenv("list")));
39 /* command followed by \n and nothing else */
40 run_command_list("setenv list 1${list}\n", -1, 0);
41 assert(!strcmp("111", getenv("list")));
43 /* three commands in a row */
44 run_command_list("setenv list 1\n setenv list ${list}2; "
45 "setenv list ${list}3", -1, 0);
46 assert(!strcmp("123", getenv("list")));
48 /* a command string with \0 in it. Stuff after \0 should be ignored */
49 run_command("setenv list", 0);
50 run_command_list(test_cmd, sizeof(test_cmd), 0);
51 assert(!strcmp("123", getenv("list")));
54 * a command list where we limit execution to only the first command
55 * using the length parameter.
57 run_command_list("setenv list 1\n setenv list ${list}2; "
58 "setenv list ${list}3", strlen("setenv list 1"), 0);
59 assert(!strcmp("1", getenv("list")));
61 printf("%s: Everything went swimmingly\n", __func__);
66 ut_cmd, 5, 1, do_ut_cmd,
67 "Very basic test of command parsers",