[PATCH 1/1] test: cmd/hash: check return value of ut_check_console_line

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Wed Nov 20 14:05:06 CET 2024


On 20.11.24 13:40, Simon Glass wrote:
> Hi Heinrich,
> 
> On Sat, 16 Nov 2024 at 13:09, Heinrich Schuchardt
> <heinrich.schuchardt at canonical.com> wrote:
>>
>> ut_check_console_line() does include an assert.
>> Pass the result to ut_assertok().
>>
>> Addresses-Coverity-ID:  514958 Error handling issues
>> Fixes: 7dfafcd65ef3 ("test: unit test for hash command")
>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
>> ---
>>   test/cmd/hash.c | 13 ++++++++-----
>>   1 file changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/test/cmd/hash.c b/test/cmd/hash.c
>> index 2fcec9cadcd..296dd762b31 100644
>> --- a/test/cmd/hash.c
>> +++ b/test/cmd/hash.c
>> @@ -33,11 +33,13 @@ static int dm_test_cmd_hash_md5(struct unit_test_state *uts)
>>                          strstr(uts->actual_str, "md5 for "));
>>          ut_assert(strstr(uts->actual_str,
>>                           "d41d8cd98f00b204e9800998ecf8427e"));
>> -       ut_check_console_line(uts, "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_check_console_line(uts, "hash - compute hash message digest");
>> +               ut_assertok(ut_check_console_line(
>> +                               uts, "hash - compute hash message digest"));
> 
> ut_assert_nextline("hash - compute hash message digest")

Unfortunately your review comes too late. Tom already merged the patch.

There a number of usages of the function combination.

test/cmd/hash.c:36:     ut_assertok(ut_check_console_line(uts,
test/cmd/hash.c:41:             ut_assertok(ut_check_console_line(
test/cmd/hash.c:82:     ut_assertok(ut_check_console_line(
test/cmd/hash.c:87:             ut_assertok(ut_check_console_line(
test/log/cont_test.c:33:        ut_assertok(ut_check_console_line(uts, 
"ERR.arch, ea1"));
test/log/cont_test.c:34:        ut_assertok(ut_check_console_line(uts, 
"ERR.arch, cc2"));
test/log/cont_test.c:45:        ut_assertok(ut_check_console_line(uts, 
"INFO.efi, ie3"));
test/log/cont_test.c:57:        ut_assertok(ut_check_console_line(uts, 
"ERR.arch, ea1 cc2"));
test/log/nolog_ndebug.c:32: 
ut_assertok(ut_check_console_line(uts, "testing level %d", i));
test/log/nolog_test.c:30:       ut_assertok(ut_check_console_line(uts, 
"testing log_err"));
test/log/nolog_test.c:43:       ut_assertok(ut_check_console_line(uts, 
"testing log_warning"));
test/log/nolog_test.c:56:       ut_assertok(ut_check_console_line(uts, 
"testing log_notice"));
test/log/nolog_test.c:69:       ut_assertok(ut_check_console_line(uts, 
"testing log_info"));
test/log/nolog_test.c:111:      ut_assertok(ut_check_console_line(uts, 
"testing debug"));
test/log/nolog_test.c:125:      ut_assertok(ut_check_console_line(uts, 
"testing log_debug"));
test/log/nolog_test.c:126:      ut_assertok(ut_check_console_line(uts, 
"more log_debug"));
test/log/pr_cont_test.c:36:     ut_assertok(ut_check_console_line(uts, 
"ea1 cc2"));

Looking at the macro definitions your suggestion would add "console" to 
the error output but not lead to a functional change.

If we change it, we should do so for all occurrences.

Best regards

Heinrich

> 
>>
>>                  return 0;
>>          }
>> @@ -77,12 +79,13 @@ static int dm_test_cmd_hash_sha256(struct unit_test_state *uts)
>>                          strstr(uts->actual_str, "sha256 for "));
>>          ut_assert(strstr(uts->actual_str,
>>                           "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
>> -       ut_check_console_line(uts,
>> -                             "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_check_console_line(uts, "hash - compute hash message digest");
>> +               ut_assertok(ut_check_console_line(
>> +                               uts, "hash - compute hash message digest"));
>>
>>                  return 0;
>>          }
>> --
>> 2.45.2
>>
> 
> Regards,
> Simon



More information about the U-Boot mailing list