[PATCH v2 3/5] test: cmd: hash: add unit test for sm3_256
Heinrich Schuchardt
xypron.glpk at gmx.de
Tue Nov 11 07:39:50 CET 2025
Am 11. November 2025 06:48:10 MEZ schrieb Heiko Schocher <hs at nabladev.com>:
>add simple test for sm3 256 hash
>
>Signed-off-by: Heiko Schocher <hs at nabladev.com>
>---
>I wonder why this tests are under DM and not under CMD
>Should we move them to CMD ?
We should use CMD_TEST() in the test/cmd/ directory.
Best regards
Heinrich
>
>Ignored checkpatch warnings for too long lines.
>
>(no changes since v1)
>
> test/cmd/hash.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
>diff --git a/test/cmd/hash.c b/test/cmd/hash.c
>index bb96380c351..3f7f64d27d3 100644
>--- a/test/cmd/hash.c
>+++ b/test/cmd/hash.c
>@@ -103,3 +103,49 @@ static int dm_test_cmd_hash_sha256(struct unit_test_state *uts)
> return 0;
> }
> DM_TEST(dm_test_cmd_hash_sha256, UTF_CONSOLE);
>+
>+static int dm_test_cmd_hash_sm3_256(struct unit_test_state *uts)
>+{
>+ const char *sum = "1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b";
>+
>+ if (!CONFIG_IS_ENABLED(SM3)) {
>+ ut_assert(run_command("hash sm3_256 $loadaddr 0", 0));
>+
>+ return 0;
>+ }
>+
>+ ut_assertok(run_command("hash sm3_256 $loadaddr 0", 0));
>+ console_record_readline(uts->actual_str, sizeof(uts->actual_str));
>+ ut_asserteq_ptr(uts->actual_str,
>+ strstr(uts->actual_str, "sm3_256 for "));
>+ ut_assert(strstr(uts->actual_str, sum));
>+ ut_assert_console_end();
>+
>+ ut_assertok(run_command("hash sm3_256 $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, "sm3_256 for "));
>+ ut_assert(strstr(uts->actual_str, sum));
>+ ut_assertok(ut_check_console_line(uts, sum));
>+
>+ if (!CONFIG_IS_ENABLED(HASH_VERIFY)) {
>+ ut_assert(run_command("hash -v sm3_256 $loadaddr 0 foo", 0));
>+ ut_assertok(ut_check_console_line(uts,
>+ "hash - compute hash message digest"));
>+
>+ return 0;
>+ }
>+
>+ ut_assertok(run_command("hash -v sm3_256 $loadaddr 0 foo", 0));
>+ ut_assert_console_end();
>+
>+ env_set("foo",
>+ "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
>+ ut_assert(run_command("hash -v sm3_256 $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_sm3_256, UTF_CONSOLE);
More information about the U-Boot
mailing list