[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <218f7a67-9be2-4094-b400-1cfad3fd9d0a@gmx.de>
Date: Fri, 23 Jan 2026 20:17:12 +0100
From: Armin Wolf <W_Armin@....de>
To: Nathan Chancellor <nathan@...nel.org>
Cc: hansg@...nel.org, ilpo.jarvinen@...ux.intel.com,
platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org,
linux@...ssschuh.net, Dell.Client.Kernel@...l.com, corbet@....net,
linux-doc@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH v3 4/9] platform/wmi: Add kunit test for the string
conversion code
Am 23.01.26 um 00:45 schrieb Nathan Chancellor:
> Hi Armin,
>
> On Fri, Jan 09, 2026 at 10:46:14PM +0100, Armin Wolf wrote:
>> The string conversion frunctions provided by the WMI driver core
>> have no dependencies on the remaining WMI API, making them suitable
>> for unit tests.
>>
>> Implement such a unit test using kunit. Those unit tests verify that
>> converting between WMI strings and UTF8 strings works as expected.
>> They also verify that edge cases are handled correctly.
>>
>> Signed-off-by: Armin Wolf <W_Armin@....de>
> ...
>> +++ b/drivers/platform/wmi/tests/string_kunit.c
> ...
>> +static const u8 oversized_test_utf8_string[] = "TEST!";
> ...
>> +static void wmi_string_to_utf8s_oversized_test(struct kunit *test)
>> +{
>> + u8 result[sizeof(oversized_test_utf8_string)];
>> + ssize_t ret;
>> +
>> + ret = wmi_string_to_utf8s(&oversized_test_wmi_string, result, sizeof(result));
>> +
>> + KUNIT_EXPECT_EQ(test, ret, sizeof(test_utf8_string) - 1);
>> + KUNIT_EXPECT_MEMEQ(test, result, test_utf8_string, sizeof(test_utf8_string));
>> +}
> After this change in -next as commit 0e1a8143e797 ("platform/wmi: Add
> kunit test for the string conversion code"), I am seeing a warning from
> clang around oversized_test_utf8_string:
>
> drivers/platform/wmi/tests/string_kunit.c:108:17: error: variable 'oversized_test_utf8_string' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]
> 108 | static const u8 oversized_test_utf8_string[] = "TEST!";
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~
>
> oversized_test_utf8_string is only used in sizeof() in
> wmi_string_to_utf8s_oversized_test(). clang warns because sizeof() is
> evaluated at compile time, so oversized_test_utf8_string won't end up in
> the final binary. This is typically a bug since the developer may have
> intended to use the variable elsewhere but I was not able to easily
> determine that in this case.
>
> If it is intentional that this variable is only needed in sizeof(), it
> could either be marked with __maybe_unused or eliminated in favor of a
> direct 'sizeof("TEST!")', depending on maintainer/developer preference.
> I am happy to send a patch.
>
> Cheers,
> Nathan
Good catch, it seems that i forgot to add the test case that was supposed to use oversized_test_utf8_string.
I will send a patch that adds this missing test case, fixing this warning in the process.
Thanks,
Armin Wolf
Powered by blists - more mailing lists