diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cmd/Makefile | 2 | ||||
-rw-r--r-- | test/cmd/exit.c | 135 | ||||
-rw-r--r-- | test/cmd_ut.c | 1 | ||||
-rw-r--r-- | test/compression.c | 55 | ||||
-rwxr-xr-x | test/fs/fs-test.sh | 10 | ||||
-rw-r--r-- | test/py/tests/test_env.py | 24 |
6 files changed, 195 insertions, 32 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile index bc961df3dc..09e410ec30 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -8,7 +8,7 @@ endif ifdef CONFIG_CONSOLE_RECORD obj-$(CONFIG_CMD_PAUSE) += test_pause.o endif -obj-y += mem.o +obj-y += exit.o mem.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_FDT) += fdt.o obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o diff --git a/test/cmd/exit.c b/test/cmd/exit.c new file mode 100644 index 0000000000..ca34abef89 --- /dev/null +++ b/test/cmd/exit.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for exit command + * + * Copyright 2022 Marek Vasut <marex@denx.de> + */ + +#include <common.h> +#include <console.h> +#include <mapmem.h> +#include <asm/global_data.h> +#include <test/suites.h> +#include <test/ut.h> + +DECLARE_GLOBAL_DATA_PTR; + +/* Declare a new exit test */ +#define EXIT_TEST(_name, _flags) UNIT_TEST(_name, _flags, exit_test) + +/* Test 'exit addr' getting/setting address */ +static int cmd_exit_test(struct unit_test_state *uts) +{ + int i; + + /* + * Test 'exit' with parameter -3, -2, -1, 0, 1, 2, 3 . Use all those + * parameters to cover also the special return value -2 that is used + * in HUSH to detect exit command. + * + * Always test whether 'exit' command: + * - exits out of the 'run' command + * - return value is propagated out of the 'run' command + * - return value can be tested on outside of 'run' command + * - return value can be printed outside of 'run' command + */ + for (i = -3; i <= 3; i++) { + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("%d", i > 0 ? i : 0); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo && echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + if (i <= 0) + ut_assert_nextline("quux"); + ut_assert_nextline("%d", i > 0 ? i : 0); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo || echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + if (i > 0) + ut_assert_nextline("quux"); + /* Either 'exit' returns 0, or 'echo quux' returns 0 */ + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + } + + /* Validate that 'exit' behaves the same way as 'exit 0' */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo && echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("quux"); + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo || echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + /* Either 'exit' returns 0, or 'echo quux' returns 0 */ + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + /* Validate that return value still propagates from 'run' command */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo && echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("quux"); + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo || echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + /* The 'true' returns 0 */ + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("1"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo && echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("1"); + ut_assertok(ut_check_console_end(uts)); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo || echo quux ; echo $?", i)); + ut_assert_nextline("bar"); + ut_assert_nextline("quux"); + /* The 'echo quux' returns 0 */ + ut_assert_nextline("0"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} + +EXIT_TEST(cmd_exit_test, UT_TESTF_CONSOLE_REC); + +int do_ut_exit(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + struct unit_test *tests = UNIT_TEST_SUITE_START(exit_test); + const int n_ents = UNIT_TEST_SUITE_COUNT(exit_test); + + return cmd_ut_category("cmd_exit", "exit_test_", tests, n_ents, + argc, argv); +} diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 2736582f11..067bd0828a 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -65,6 +65,7 @@ static struct cmd_tbl cmd_ut_sub[] = { #if defined(CONFIG_UT_ENV) U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""), #endif + U_BOOT_CMD_MKENT(exit, CONFIG_SYS_MAXARGS, 1, do_ut_exit, "", ""), #ifdef CONFIG_CMD_FDT U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""), #endif diff --git a/test/compression.c b/test/compression.c index 82e29c9b86..ba98d21802 100644 --- a/test/compression.c +++ b/test/compression.c @@ -321,42 +321,48 @@ static int run_test_internal(struct unit_test_state *uts, char *name, /* Compress works as expected. */ printf("\torig_size:%lu\n", buf->orig_size); memset(buf->compressed_buf, 'A', TEST_BUFFER_SIZE); - errcheck(compress(uts, buf->orig_buf, buf->orig_size, + ut_assertok(compress(uts, buf->orig_buf, buf->orig_size, buf->compressed_buf, buf->compressed_size, - &buf->compressed_size) == 0); + &buf->compressed_size)); printf("\tcompressed_size:%lu\n", buf->compressed_size); - errcheck(buf->compressed_size > 0); - errcheck(buf->compressed_size < buf->orig_size); - errcheck(((char *)buf->compressed_buf)[buf->compressed_size - 1] != - 'A'); - errcheck(((char *)buf->compressed_buf)[buf->compressed_size] == 'A'); + ut_assert(buf->compressed_size > 0); + ut_assert(buf->compressed_size < buf->orig_size); + ut_assert(((char *)buf->compressed_buf)[buf->compressed_size - 1] + != 'A'); + ut_asserteq(((char *)buf->compressed_buf)[buf->compressed_size], 'A'); /* Uncompresses with space remaining. */ - errcheck(uncompress(uts, buf->compressed_buf, buf->compressed_size, + ut_assertok(uncompress(uts, buf->compressed_buf, buf->compressed_size, buf->uncompressed_buf, buf->uncompressed_size, - &buf->uncompressed_size) == 0); + &buf->uncompressed_size)); printf("\tuncompressed_size:%lu\n", buf->uncompressed_size); - errcheck(buf->uncompressed_size == buf->orig_size); - errcheck(memcmp(buf->orig_buf, buf->uncompressed_buf, - buf->orig_size) == 0); + ut_asserteq(buf->uncompressed_size, buf->orig_size); + ut_asserteq_mem(buf->orig_buf, buf->uncompressed_buf, buf->orig_size); /* Uncompresses with exactly the right size output buffer. */ memset(buf->uncompressed_buf, 'A', TEST_BUFFER_SIZE); - errcheck(uncompress(uts, buf->compressed_buf, buf->compressed_size, + ut_assertok(uncompress(uts, buf->compressed_buf, buf->compressed_size, buf->uncompressed_buf, buf->orig_size, - &buf->uncompressed_size) == 0); - errcheck(buf->uncompressed_size == buf->orig_size); - errcheck(memcmp(buf->orig_buf, buf->uncompressed_buf, - buf->orig_size) == 0); - errcheck(((char *)buf->uncompressed_buf)[buf->orig_size] == 'A'); + &buf->uncompressed_size)); + ut_asserteq(buf->uncompressed_size, buf->orig_size); + ut_asserteq_mem(buf->orig_buf, buf->uncompressed_buf, buf->orig_size); + ut_asserteq(((char *)buf->uncompressed_buf)[buf->orig_size], 'A'); + + /* Uncompresses with trailing garbage in input buffer. */ + memset(buf->uncompressed_buf, 'A', TEST_BUFFER_SIZE); + ut_assertok(uncompress(uts, buf->compressed_buf, buf->compressed_size + 4, + buf->uncompressed_buf, buf->uncompressed_size, + &buf->uncompressed_size)); + ut_asserteq(buf->uncompressed_size, buf->orig_size); + ut_asserteq_mem(buf->orig_buf, buf->uncompressed_buf, buf->orig_size); /* Make sure compression does not over-run. */ memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE); ret = compress(uts, buf->orig_buf, buf->orig_size, buf->compare_buf, buf->compressed_size - 1, NULL); - errcheck(((char *)buf->compare_buf)[buf->compressed_size] == 'A'); - errcheck(ret != 0); + ut_asserteq(((char *)buf->compare_buf)[buf->compressed_size], 'A'); + ut_assert(ret != 0); printf("\tcompress does not overrun\n"); /* Make sure decompression does not over-run. */ @@ -364,15 +370,12 @@ static int run_test_internal(struct unit_test_state *uts, char *name, ret = uncompress(uts, buf->compressed_buf, buf->compressed_size, buf->compare_buf, buf->uncompressed_size - 1, NULL); - errcheck(((char *)buf->compare_buf)[buf->uncompressed_size - 1] == 'A'); - errcheck(ret != 0); + ut_asserteq(((char *)buf->compare_buf)[buf->uncompressed_size - 1], 'A'); + ut_assert(ret != 0); printf("\tuncompress does not overrun\n"); /* Got here, everything is fine. */ - ret = 0; - -out: - return ret; + return 0; } static int run_test(struct unit_test_state *uts, char *name, diff --git a/test/fs/fs-test.sh b/test/fs/fs-test.sh index b87748106c..dec2634de3 100755 --- a/test/fs/fs-test.sh +++ b/test/fs/fs-test.sh @@ -462,22 +462,22 @@ function check_results() { FAIL=0 # Check if the ls is showing correct results for 2.5 gb file - grep -A7 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4" + grep -A7 "Test Case 1 " "$1" | grep -Eiq "2621440000 *$4" pass_fail "TC1: ls of $4" # Check if the ls is showing correct results for 1 mb file - grep -A7 "Test Case 1 " "$1" | egrep -iq "1048576 *$3" + grep -A7 "Test Case 1 " "$1" | grep -Eiq "1048576 *$3" pass_fail "TC1: ls of $3" # Check size command on 1MB.file - egrep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000" + grep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000" pass_fail "TC2: size of $3" # Check size command on 1MB.file via a path using '..' - egrep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000" + grep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000" pass_fail "TC2: size of $3 via a path using '..'" # Check size command on 2.5GB.file - egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000" + grep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000" pass_fail "TC3: size of $4" # Check read full mb of 1MB.file diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index 6d08565f0b..00bcccd65f 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -8,6 +8,7 @@ Test operation of shell commands relating to environment variables. import os import os.path +import re from subprocess import call, CalledProcessError import tempfile @@ -173,6 +174,29 @@ def validate_set(state_test_env, var, value): response = state_test_env.u_boot_console.run_command('printenv %s' % var) assert response == ('%s=%s' % (var, value)) +@pytest.mark.boardspec('sandbox') +def test_env_initial_env_file(u_boot_console): + """Test that the u-boot-initial-env make target works""" + cons = u_boot_console + builddir = 'O=' + cons.config.build_dir + envfile = cons.config.build_dir + '/u-boot-initial-env' + + # remove if already exists from an older run + try: + os.remove(envfile) + except: + pass + + u_boot_utils.run_and_log(cons, ['make', builddir, 'u-boot-initial-env']) + + assert os.path.exists(envfile) + + # assume that every environment has a board variable, e.g. board=sandbox + with open(envfile, 'r') as file: + env = file.read() + regex = re.compile('board=.+\\n') + assert re.search(regex, env) + def test_env_echo_exists(state_test_env): """Test echoing a variable that exists.""" |