unit-test: fix 'env default' invocation
PATCH 1/2 unit-test: fix 'env default' invocation
From: Stephen Warren <[email protected]>
"env default -f" doesn't work any more; replace it with "env default -f -a". This avoids the following when running the ut command:
do_ut_cmd: Testing commands
env - environment handling commands
Usage:
env default [-f] -a - [forcibly] reset default environment
...
--- test/command_ut.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/command_ut.c +1 -1
@@ -15,7 +15,7 @@ static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "static int do_ut_cmd (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {printf ("%s: Testing commands\n" , __func__); -run_command ("env default -f" ,0 ); +run_command ("env default -f -a" ,0 );/* run a single command */ run_command ("setenv single 1" ,0 );
Signature · 1 line
1.8.1.5
PATCH 2/2 unit-test: add lots of tests for the Hush 'test' command
From: Stephen Warren <[email protected]>
I recently re-wrote cmd_test() to add new features. Add a bunch of unit- tests to make sure I didn't break anything.
---
This patch depends on my 12-entry patch series that implements "test -e", since it tests that new feature.
--- test/command_ut.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
test/command_ut.c +89 -0
@@ -58,6 +58,95 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) "setenv list ${list}3", strlen("setenv list 1"), 0);assert (!strcmp ("1" ,getenv ("list" ))); +#ifdef CONFIG_SYS_HUSH_PARSER +/* Test the 'test' command */ + +#define HUSH_TEST (name, expr, expected_result) \ + run_command("if test " expr " ; then " \ + "setenv " #name "_" #expected_result " y; else " \ + "setenv " #name "_" #expected_result " n; fi", 0); \ + assert(!strcmp(#expected_result, getenv(#name "_" #expected_result))); + +/* Basic operators */ +HUSH_TEST (streq,"aaa = aaa" , y); +HUSH_TEST (streq,"aaa = bbb" , n); + +HUSH_TEST (strneq,"aaa != bbb" , y); +HUSH_TEST (strneq,"aaa != aaa" , n); + +HUSH_TEST (strlt,"aaa < bbb" , y); +HUSH_TEST (strlt,"bbb < aaa" , n); + +HUSH_TEST (strgt,"bbb > aaa" , y); +HUSH_TEST (strgt,"aaa > bbb" , n); + +HUSH_TEST (eq,"123 -eq 123" , y); +HUSH_TEST (eq,"123 -eq 456" , n); + +HUSH_TEST (ne,"123 -ne 456" , y); +HUSH_TEST (ne,"123 -ne 123" , n); + +HUSH_TEST (lt,"123 -lt 456" , y); +HUSH_TEST (lt_eq,"123 -lt 123" , n); +HUSH_TEST (lt,"456 -lt 123" , n); + +HUSH_TEST (le,"123 -le 456" , y); +HUSH_TEST (le_eq,"123 -le 123" , y); +HUSH_TEST (le,"456 -le 123" , n); + +HUSH_TEST (gt,"456 -gt 123" , y); +HUSH_TEST (gt_eq,"123 -gt 123" , n); +HUSH_TEST (gt,"123 -gt 456" , n); + +HUSH_TEST (ge,"456 -ge 123" , y); +HUSH_TEST (ge_eq,"123 -ge 123" , y); +HUSH_TEST (ge,"123 -ge 456" , n); + +HUSH_TEST (z,"-z \"\"" , y); +HUSH_TEST (z,"-z \"aaa\"" , n); + +HUSH_TEST (n,"-n \"aaa\"" , y); +HUSH_TEST (n,"-n \"\"" , n); + +/* Inversion of simple tests */ +HUSH_TEST (streq_inv,"! aaa = aaa" , n); +HUSH_TEST (streq_inv,"! aaa = bbb" , y); + +HUSH_TEST (streq_inv_inv,"! ! aaa = aaa" , y); +HUSH_TEST (streq_inv_inv,"! ! aaa = bbb" , n); + +/* Binary operators */ +HUSH_TEST (or_0_0,"aaa != aaa -o bbb != bbb" , n); +HUSH_TEST (or_0_1,"aaa != aaa -o bbb = bbb" , y); +HUSH_TEST (or_1_0,"aaa = aaa -o bbb != bbb" , y); +HUSH_TEST (or_1_1,"aaa = aaa -o bbb = bbb" , y); + +HUSH_TEST (and_0_0,"aaa != aaa -a bbb != bbb" , n); +HUSH_TEST (and_0_1,"aaa != aaa -a bbb = bbb" , n); +HUSH_TEST (and_1_0,"aaa = aaa -a bbb != bbb" , n); +HUSH_TEST (and_1_1,"aaa = aaa -a bbb = bbb" , y); + +/* Inversion within binary operators */ +HUSH_TEST (or_0_0_inv,"! aaa != aaa -o ! bbb != bbb" , y); +HUSH_TEST (or_0_1_inv,"! aaa != aaa -o ! bbb = bbb" , y); +HUSH_TEST (or_1_0_inv,"! aaa = aaa -o ! bbb != bbb" , y); +HUSH_TEST (or_1_1_inv,"! aaa = aaa -o ! bbb = bbb" , n); + +HUSH_TEST (or_0_0_inv_inv,"! ! aaa != aaa -o ! ! bbb != bbb" , n); +HUSH_TEST (or_0_1_inv_inv,"! ! aaa != aaa -o ! ! bbb = bbb" , y); +HUSH_TEST (or_1_0_inv_inv,"! ! aaa = aaa -o ! ! bbb != bbb" , y); +HUSH_TEST (or_1_1_inv_inv,"! ! aaa = aaa -o ! ! bbb = bbb" , y); + +#ifdef CONFIG_SANDBOX +/* +* File existence +* This assume U-Boot sandbox is run from the U-Boot build directory +*/ +HUSH_TEST (e,"-e host - u-boot" , y); +HUSH_TEST (e,"-e host - creating_this_file_breaks_uboot_unit_test" , n); +#endif +#endif +printf ("%s: Everything went swimmingly\n" , __func__);return 0 ; }
Signature · 1 line
1.8.1.5
PATCH 2/2 unit-test: add lots of tests for the Hush 'test' command
Quoted 7 lines · Stephen Warren
From: Stephen Warren <[email protected]>
I recently re-wrote
cmd_test()to add new features. Add a bunch of unit- tests to make sure I didn't break anything.Suggested-by Simon Glass <[email protected]>Signed-off-by Stephen Warren <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140204/c3707fae/attachment.pgp>
PATCH 1/2 unit-test: fix 'env default' invocation
In reply to Stephen WarrenQuoted 6 lines · Stephen Warren
From: Stephen Warren <[email protected]>
"env default -f" doesn't work any more; replace it with "env default -f -a". This avoids the following when running the ut command:
Quoted 8 lines
do_ut_cmd: Testing commands
env - environment handling commandsUsage:
env default [-f] -a - [forcibly] reset default environment
...Signed-off-by Stephen Warren <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140204/a6be37b9/attachment.pgp>