diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cmd/Makefile | 1 | ||||
-rw-r--r-- | test/cmd/bdinfo.c | 4 | ||||
-rw-r--r-- | test/cmd/hash.c | 104 | ||||
-rw-r--r-- | test/cmd/mbr.c | 6 | ||||
-rw-r--r-- | test/common/print.c | 6 | ||||
-rw-r--r-- | test/py/tests/test_spi.py | 18 |
6 files changed, 123 insertions, 16 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 5e4a2040d6c..583e7c2eec4 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_CMD_BDI) += bdinfo.o obj-$(CONFIG_COREBOOT_SYSINFO) += coreboot.o obj-$(CONFIG_CMD_FDT) += fdt.o obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o +obj-$(CONFIG_CMD_HASH) += hash.o obj-$(CONFIG_CMD_HISTORY) += history.o obj-$(CONFIG_CMD_LOADM) += loadm.o obj-$(CONFIG_CMD_MEMINFO) += meminfo.o diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c index 770b3bfb560..bb419ab2394 100644 --- a/test/cmd/bdinfo.c +++ b/test/cmd/bdinfo.c @@ -107,7 +107,7 @@ static int lmb_test_dump_region(struct unit_test_state *uts, enum lmb_flags flags; int i; - ut_assert_nextline(" %s.count = 0x%hx", name, lmb_rgn_lst->count); + ut_assert_nextline(" %s.count = %#x", name, lmb_rgn_lst->count); for (i = 0; i < lmb_rgn_lst->count; i++) { base = rgn[i].base; @@ -119,7 +119,7 @@ static int lmb_test_dump_region(struct unit_test_state *uts, ut_assert_nextlinen(" %s[%d]\t[", name, i); continue; } - ut_assert_nextlinen(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: ", + ut_assert_nextlinen(" %s[%d]\t[%#llx-%#llx], %#llx bytes, flags: ", name, i, base, end, size); } diff --git a/test/cmd/hash.c b/test/cmd/hash.c new file mode 100644 index 00000000000..296dd762b31 --- /dev/null +++ b/test/cmd/hash.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Tests for hash command + * + * Copyright 2024, Heinrich Schuchardt <heinrich.schuchardt@canoncal.com> + */ + +#include <command.h> +#include <dm.h> +#include <dm/test.h> +#include <test/test.h> +#include <test/ut.h> + +static int dm_test_cmd_hash_md5(struct unit_test_state *uts) +{ + if (!CONFIG_IS_ENABLED(MD5)) { + ut_assert(run_command("hash md5 $loadaddr 0", 0)); + + return 0; + } + + ut_assertok(run_command("hash md5 $loadaddr 0", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_ptr(uts->actual_str, + strstr(uts->actual_str, "md5 for ")); + ut_assert(strstr(uts->actual_str, + "d41d8cd98f00b204e9800998ecf8427e")); + ut_assert_console_end(); + + ut_assertok(run_command("hash md5 $loadaddr 0 foo; echo $foo", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_ptr(uts->actual_str, + strstr(uts->actual_str, "md5 for ")); + ut_assert(strstr(uts->actual_str, + "d41d8cd98f00b204e9800998ecf8427e")); + ut_assertok(ut_check_console_line(uts, + "d41d8cd98f00b204e9800998ecf8427e")); + + if (!CONFIG_IS_ENABLED(HASH_VERIFY)) { + ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0)); + ut_assertok(ut_check_console_line( + uts, "hash - compute hash message digest")); + + return 0; + } + + ut_assertok(run_command("hash -v md5 $loadaddr 0 foo", 0)); + ut_assert_console_end(); + + env_set("foo", "ffffffffffffffffffffffffffffffff"); + ut_assert(run_command("hash -v md5 $loadaddr 0 foo", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_assert(strstr(uts->actual_str, "!=")); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_cmd_hash_md5, UTF_CONSOLE); + +static int dm_test_cmd_hash_sha256(struct unit_test_state *uts) +{ + if (!CONFIG_IS_ENABLED(SHA256)) { + ut_assert(run_command("hash sha256 $loadaddr 0", 0)); + + return 0; + } + + ut_assertok(run_command("hash sha256 $loadaddr 0", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_ptr(uts->actual_str, + strstr(uts->actual_str, "sha256 for ")); + ut_assert(strstr(uts->actual_str, + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); + ut_assert_console_end(); + + ut_assertok(run_command("hash sha256 $loadaddr 0 foo; echo $foo", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_ptr(uts->actual_str, + strstr(uts->actual_str, "sha256 for ")); + ut_assert(strstr(uts->actual_str, + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); + ut_assertok(ut_check_console_line( + uts, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); + + if (!CONFIG_IS_ENABLED(HASH_VERIFY)) { + ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0)); + ut_assertok(ut_check_console_line( + uts, "hash - compute hash message digest")); + + return 0; + } + + ut_assertok(run_command("hash -v sha256 $loadaddr 0 foo", 0)); + ut_assert_console_end(); + + env_set("foo", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_assert(strstr(uts->actual_str, "!=")); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_cmd_hash_sha256, UTF_CONSOLE); diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c index b14137e589a..d137378a3be 100644 --- a/test/cmd/mbr.c +++ b/test/cmd/mbr.c @@ -257,8 +257,8 @@ static int mbr_test_run(struct unit_test_state *uts) strlen(mbr_parts_p3) + max(strlen(mbr_parts_p4), strlen(mbr_parts_p5)) + strlen(mbr_parts_tail); - ut_assertf(sizeof(mbr_parts_buf) >= mbr_parts_max, "Buffer avail: %ld; buffer req: %ld\n", - sizeof(mbr_parts_buf), mbr_parts_max); + ut_assertf(sizeof(mbr_parts_buf) >= mbr_parts_max, "Buffer avail: %zd; buffer req: %ld\n", + sizeof(mbr_parts_buf), mbr_parts_max); mbr_wbuf = map_sysmem(mbr_wa, BLKSZ); ebr_wbuf = map_sysmem(ebr_wa, BLKSZ); @@ -277,7 +277,7 @@ static int mbr_test_run(struct unit_test_state *uts) (ulong)0xbffe00 / BLKSZ)); /* Test one MBR partition */ - init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__); + init_write_buffers(mbr_wbuf, BLKSZ, ebr_wbuf, BLKSZ, __LINE__); ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 1)); ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa)); memset(rbuf, '\0', BLKSZ); diff --git a/test/common/print.c b/test/common/print.c index f1eb9072d97..464e425edee 100644 --- a/test/common/print.c +++ b/test/common/print.c @@ -115,8 +115,10 @@ static int print_printf(struct unit_test_state *uts) snprintf(str, 0, "testing none"); ut_asserteq('x', *str); - sprintf(big_str, "_%ls_", u"foo"); - ut_assertok(strcmp("_foo_", big_str)); + if (CONFIG_IS_ENABLED(EFI_LOADER) || IS_ENABLED(CONFIG_EFI_APP)) { + sprintf(big_str, "_%ls_", u"foo"); + ut_assertok(strcmp("_foo_", big_str)); + } /* Test the banner function */ s = display_options_get_banner(true, str, sizeof(str)); diff --git a/test/py/tests/test_spi.py b/test/py/tests/test_spi.py index 44e54738dd0..0abdfa78b76 100644 --- a/test/py/tests/test_spi.py +++ b/test/py/tests/test_spi.py @@ -75,7 +75,7 @@ def get_params_spi(u_boot_console): ''' Get SPI device test parameters from boardenv file ''' f = u_boot_console.config.env.get('env__spi_device_test', None) if not f: - pytest.skip('No env file to read for SPI family device test') + pytest.skip('No SPI test device configured') bus = f.get('bus', 0) cs = f.get('chip_select', 0) @@ -84,7 +84,7 @@ def get_params_spi(u_boot_console): timeout = f.get('timeout', None) if not part_name: - pytest.skip('No env file to read SPI family flash part name') + pytest.skip('No SPI test device configured') return bus, cs, mode, part_name, timeout @@ -92,7 +92,7 @@ def spi_find_freq_range(u_boot_console): '''Find out minimum and maximum frequnecies that SPI device can operate''' f = u_boot_console.config.env.get('env__spi_device_test', None) if not f: - pytest.skip('No env file to read for SPI family device test') + pytest.skip('No SPI test device configured') min_f = f.get('min_freq', None) max_f = f.get('max_freq', None) @@ -116,21 +116,21 @@ def spi_pre_commands(u_boot_console, freq): pytest.fail('No SPI device available') if not part_name in output: - pytest.fail('SPI flash part name not recognized') + pytest.fail('Not recognized the SPI flash part name') m = re.search('page size (.+?) Bytes', output) if m: try: page_size = int(m.group(1)) except ValueError: - pytest.fail('SPI page size not recognized') + pytest.fail('Not recognized the SPI page size') m = re.search('erase size (.+?) KiB', output) if m: try: erase_size = int(m.group(1)) except ValueError: - pytest.fail('SPI erase size not recognized') + pytest.fail('Not recognized the SPI erase size') erase_size *= 1024 @@ -139,7 +139,7 @@ def spi_pre_commands(u_boot_console, freq): try: total_size = int(m.group(1)) except ValueError: - pytest.fail('SPI total size not recognized') + pytest.fail('Not recognized the SPI total size') total_size *= 1024 * 1024 @@ -149,7 +149,7 @@ def spi_pre_commands(u_boot_console, freq): flash_part = m.group(1) assert flash_part == part_name except ValueError: - pytest.fail('SPI flash part not recognized') + pytest.fail('Not recognized the SPI flash part') global SPI_DATA SPI_DATA = { @@ -574,7 +574,7 @@ def test_spi_lock_unlock(u_boot_console): min_f, max_f, loop = spi_find_freq_range(u_boot_console) flashes = u_boot_console.config.env.get('env__spi_lock_unlock', False) if not flashes: - pytest.skip('No supported flash list for lock/unlock provided') + pytest.skip('No SPI test device configured for lock/unlock') i = 0 while i < loop: |