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