]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
a72007d9 SG |
2 | /* |
3 | * Copyright (c) 2012, The Chromium Authors | |
a72007d9 SG |
4 | */ |
5 | ||
6 | #define DEBUG | |
7 | ||
8 | #include <common.h> | |
9 | ||
10 | static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; " | |
11 | "setenv list ${list}3\0" | |
12 | "setenv list ${list}4"; | |
13 | ||
14 | static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
15 | { | |
16 | printf("%s: Testing commands\n", __func__); | |
67486728 | 17 | run_command("env default -f -a", 0); |
a72007d9 | 18 | |
a72007d9 SG |
19 | /* commands separated by \n */ |
20 | run_command_list("setenv list 1\n setenv list ${list}1", -1, 0); | |
00caae6d | 21 | assert(!strcmp("11", env_get("list"))); |
a72007d9 SG |
22 | |
23 | /* command followed by \n and nothing else */ | |
24 | run_command_list("setenv list 1${list}\n", -1, 0); | |
00caae6d | 25 | assert(!strcmp("111", env_get("list"))); |
a72007d9 | 26 | |
a72007d9 SG |
27 | /* a command string with \0 in it. Stuff after \0 should be ignored */ |
28 | run_command("setenv list", 0); | |
29 | run_command_list(test_cmd, sizeof(test_cmd), 0); | |
00caae6d | 30 | assert(!strcmp("123", env_get("list"))); |
a72007d9 SG |
31 | |
32 | /* | |
33 | * a command list where we limit execution to only the first command | |
34 | * using the length parameter. | |
35 | */ | |
36 | run_command_list("setenv list 1\n setenv list ${list}2; " | |
37 | "setenv list ${list}3", strlen("setenv list 1"), 0); | |
00caae6d | 38 | assert(!strcmp("1", env_get("list"))); |
a72007d9 | 39 | |
93ce7561 SG |
40 | assert(run_command("false", 0) == 1); |
41 | assert(run_command("echo", 0) == 0); | |
42 | assert(run_command_list("false", -1, 0) == 1); | |
43 | assert(run_command_list("echo", -1, 0) == 0); | |
44 | ||
f1f9d4fa | 45 | #ifdef CONFIG_HUSH_PARSER |
87b6398b SG |
46 | run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0); |
47 | run_command("run foo", 0); | |
00caae6d SG |
48 | assert(env_get("black") != NULL); |
49 | assert(!strcmp("1", env_get("black"))); | |
50 | assert(env_get("adder") != NULL); | |
51 | assert(!strcmp("2", env_get("adder"))); | |
f2afe701 SW |
52 | #endif |
53 | ||
484408fb RV |
54 | assert(run_command("", 0) == 0); |
55 | assert(run_command(" ", 0) == 0); | |
56 | ||
2302b3ab RV |
57 | assert(run_command("'", 0) == 1); |
58 | ||
a72007d9 SG |
59 | printf("%s: Everything went swimmingly\n", __func__); |
60 | return 0; | |
61 | } | |
62 | ||
63 | U_BOOT_CMD( | |
64 | ut_cmd, 5, 1, do_ut_cmd, | |
65 | "Very basic test of command parsers", | |
66 | "" | |
67 | ); |