[PATCH v2 3/5] test: cmd: hash: add unit test for sm3_256
Heiko Schocher
hs at nabladev.com
Wed Nov 12 05:44:56 CET 2025
Hello Heinrich,
On 11.11.25 07:39, Heinrich Schuchardt wrote:
> 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.
I aggree... candidates would be:
$ grep -lr DM_TEST test/cmd
test/cmd/temperature.c
test/cmd/pwm.c
test/cmd/hash.c
test/cmd/pinmux.c
test/cmd/rw.c
test/cmd/armffa.c
test/cmd/loadm.c
test/cmd/i3c.c
but that change should be done in seperate series...
I can make such a series, if this one is acceppted?
Thanks!
bye,
Heiko
>
> 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);
>
--
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: office at nabladev.com
Geschäftsführer : Stefano Babic
More information about the U-Boot
mailing list