diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 45 | ||||
-rw-r--r-- | test/command_ut.c | 85 |
2 files changed, 130 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000000..83594f3290 --- /dev/null +++ b/test/Makefile | |||
@@ -0,0 +1,45 @@ | |||
1 | # | ||
2 | # (C) Copyright 2012 The Chromium Authors | ||
3 | # | ||
4 | # See file CREDITS for list of people who contributed to this | ||
5 | # project. | ||
6 | # | ||
7 | # This program is free software; you can redistribute it and/or | ||
8 | # modify it under the terms of the GNU General Public License as | ||
9 | # published by the Free Software Foundation; either version 2 of | ||
10 | # the License, or (at your option) any later version. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License | ||
18 | # along with this program; if not, write to the Free Software | ||
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
20 | # MA 02111-1307 USA | ||
21 | # | ||
22 | |||
23 | include $(TOPDIR)/config.mk | ||
24 | |||
25 | LIB = $(obj)libtest.o | ||
26 | |||
27 | COBJS-$(CONFIG_SANDBOX) += command_ut.o | ||
28 | |||
29 | COBJS := $(sort $(COBJS-y)) | ||
30 | SRCS := $(COBJS:.o=.c) | ||
31 | OBJS := $(addprefix $(obj),$(COBJS)) | ||
32 | |||
33 | all: $(LIB) $(XOBJS) | ||
34 | |||
35 | $(LIB): $(obj).depend $(OBJS) | ||
36 | $(call cmd_link_o_target, $(OBJS)) | ||
37 | |||
38 | ######################################################################### | ||
39 | |||
40 | # defines $(obj).depend target | ||
41 | include $(SRCTREE)/rules.mk | ||
42 | |||
43 | sinclude $(obj).depend | ||
44 | |||
45 | ######################################################################### | ||
diff --git a/test/command_ut.c b/test/command_ut.c new file mode 100644 index 0000000000..dfddc22d99 --- /dev/null +++ b/test/command_ut.c | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2012, The Chromium Authors | ||
3 | * | ||
4 | * See file CREDITS for list of people who contributed to this | ||
5 | * project. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License as | ||
9 | * published by the Free Software Foundation; either version 2 of | ||
10 | * the License, or (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
20 | * MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #define DEBUG | ||
24 | |||
25 | #include <common.h> | ||
26 | |||
27 | static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; " | ||
28 | "setenv list ${list}3\0" | ||
29 | "setenv list ${list}4"; | ||
30 | |||
31 | static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | ||
32 | { | ||
33 | printf("%s: Testing commands\n", __func__); | ||
34 | run_command("env default -f", 0); | ||
35 | |||
36 | /* run a single command */ | ||
37 | run_command("setenv single 1", 0); | ||
38 | assert(!strcmp("1", getenv("single"))); | ||
39 | |||
40 | /* make sure that compound statements work */ | ||
41 | #ifdef CONFIG_SYS_HUSH_PARSER | ||
42 | run_command("if test -n ${single} ; then setenv check 1; fi", 0); | ||
43 | assert(!strcmp("1", getenv("check"))); | ||
44 | run_command("setenv check", 0); | ||
45 | #endif | ||
46 | |||
47 | /* commands separated by ; */ | ||
48 | run_command_list("setenv list 1; setenv list ${list}1", -1, 0); | ||
49 | assert(!strcmp("11", getenv("list"))); | ||
50 | |||
51 | /* commands separated by \n */ | ||
52 | run_command_list("setenv list 1\n setenv list ${list}1", -1, 0); | ||
53 | assert(!strcmp("11", getenv("list"))); | ||
54 | |||
55 | /* command followed by \n and nothing else */ | ||
56 | run_command_list("setenv list 1${list}\n", -1, 0); | ||
57 | assert(!strcmp("111", getenv("list"))); | ||
58 | |||
59 | /* three commands in a row */ | ||
60 | run_command_list("setenv list 1\n setenv list ${list}2; " | ||
61 | "setenv list ${list}3", -1, 0); | ||
62 | assert(!strcmp("123", getenv("list"))); | ||
63 | |||
64 | /* a command string with \0 in it. Stuff after \0 should be ignored */ | ||
65 | run_command("setenv list", 0); | ||
66 | run_command_list(test_cmd, sizeof(test_cmd), 0); | ||
67 | assert(!strcmp("123", getenv("list"))); | ||
68 | |||
69 | /* | ||
70 | * a command list where we limit execution to only the first command | ||
71 | * using the length parameter. | ||
72 | */ | ||
73 | run_command_list("setenv list 1\n setenv list ${list}2; " | ||
74 | "setenv list ${list}3", strlen("setenv list 1"), 0); | ||
75 | assert(!strcmp("1", getenv("list"))); | ||
76 | |||
77 | printf("%s: Everything went swimmingly\n", __func__); | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | U_BOOT_CMD( | ||
82 | ut_cmd, 5, 1, do_ut_cmd, | ||
83 | "Very basic test of command parsers", | ||
84 | "" | ||
85 | ); | ||