* [PATCH v6 2/8] selftests/cachestat: Fix print_cachestat format
2023-10-13 11:36 [PATCH v6 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
@ 2023-10-13 11:36 ` Maciej Wieczor-Retman
2023-10-13 11:36 ` [PATCH v6 7/8] selftests/mm: Substitute attribute with a macro Maciej Wieczor-Retman
2023-10-13 21:03 ` [PATCH v6 0/8] Add printf attribute to kselftest functions Shuah
2 siblings, 0 replies; 6+ messages in thread
From: Maciej Wieczor-Retman @ 2023-10-13 11:36 UTC (permalink / raw)
To: Nhat Pham, Johannes Weiner, Shuah Khan
Cc: ilpo.jarvinen, linux-mm, linux-kselftest, linux-kernel
Compiling cachestat selftest after adding a __printf() attribute to
ksft_print_msg() exposes a -Wformat warning in print_cachestat().
The format specifier in printf() call expects long int variables and
received long long int.
Change format specifiers to long long int so they match passed
variables.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Acked-by: Nhat Pham <nphamcs@gmail.com>
---
Changelog v6:
- Add an explanation to the patch message on how the warnings that the
patch resolves were caught. (Shuah)
Changelog v2:
- Add Acked-by tag (Nhat)
tools/testing/selftests/cachestat/test_cachestat.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/tools/testing/selftests/cachestat/test_cachestat.c
index 4804c7dc7b31..b171fd53b004 100644
--- a/tools/testing/selftests/cachestat/test_cachestat.c
+++ b/tools/testing/selftests/cachestat/test_cachestat.c
@@ -27,7 +27,7 @@ static const char * const dev_files[] = {
void print_cachestat(struct cachestat *cs)
{
ksft_print_msg(
- "Using cachestat: Cached: %lu, Dirty: %lu, Writeback: %lu, Evicted: %lu, Recently Evicted: %lu\n",
+ "Using cachestat: Cached: %llu, Dirty: %llu, Writeback: %llu, Evicted: %llu, Recently Evicted: %llu\n",
cs->nr_cache, cs->nr_dirty, cs->nr_writeback,
cs->nr_evicted, cs->nr_recently_evicted);
}
--
2.42.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v6 7/8] selftests/mm: Substitute attribute with a macro
2023-10-13 11:36 [PATCH v6 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
2023-10-13 11:36 ` [PATCH v6 2/8] selftests/cachestat: Fix print_cachestat format Maciej Wieczor-Retman
@ 2023-10-13 11:36 ` Maciej Wieczor-Retman
2023-10-13 21:03 ` [PATCH v6 0/8] Add printf attribute to kselftest functions Shuah
2 siblings, 0 replies; 6+ messages in thread
From: Maciej Wieczor-Retman @ 2023-10-13 11:36 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan
Cc: ilpo.jarvinen, linux-mm, linux-kselftest, linux-kernel
Compiling mm selftest after adding a __printf() attribute to
ksft_print_msg() exposes -Wformat warning in remap_region().
Fix the wrong format specifier causing the warning.
The mm selftest uses the printf attribute in its full form. Since the
header file that uses it also includes kselftests.h it can use the macro
defined there.
Use __printf() included with kselftests.h instead of the full attribute.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
---
Changelog v6:
- Add an explanation to the patch message on how the warning that the
patch resolves was caught. (Shuah)
Changelog v2:
- Add this patch to the series.
tools/testing/selftests/mm/mremap_test.c | 2 +-
tools/testing/selftests/mm/pkey-helpers.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c
index 5c3773de9f0f..1dbfcf6df255 100644
--- a/tools/testing/selftests/mm/mremap_test.c
+++ b/tools/testing/selftests/mm/mremap_test.c
@@ -338,7 +338,7 @@ static long long remap_region(struct config c, unsigned int threshold_mb,
char c = (char) rand();
if (((char *) dest_addr)[i] != c) {
- ksft_print_msg("Data after remap doesn't match at offset %d\n",
+ ksft_print_msg("Data after remap doesn't match at offset %llu\n",
i);
ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff,
((char *) dest_addr)[i] & 0xff);
diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h
index 92f3be3dd8e5..1af3156a9db8 100644
--- a/tools/testing/selftests/mm/pkey-helpers.h
+++ b/tools/testing/selftests/mm/pkey-helpers.h
@@ -34,7 +34,7 @@ extern int test_nr;
extern int iteration_nr;
#ifdef __GNUC__
-__attribute__((format(printf, 1, 2)))
+__printf(1, 2)
#endif
static inline void sigsafe_printf(const char *format, ...)
{
--
2.42.0
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v6 0/8] Add printf attribute to kselftest functions
2023-10-13 11:36 [PATCH v6 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
2023-10-13 11:36 ` [PATCH v6 2/8] selftests/cachestat: Fix print_cachestat format Maciej Wieczor-Retman
2023-10-13 11:36 ` [PATCH v6 7/8] selftests/mm: Substitute attribute with a macro Maciej Wieczor-Retman
@ 2023-10-13 21:03 ` Shuah
2023-10-13 21:08 ` Reinette Chatre
2023-10-16 5:28 ` Maciej Wieczór-Retman
2 siblings, 2 replies; 6+ messages in thread
From: Shuah @ 2023-10-13 21:03 UTC (permalink / raw)
To: Maciej Wieczor-Retman, akpm, christian, fenghua.yu, keescook,
ndesaulniers, coltonlewis, dmatlack, vipinsh, seanjc, brauner,
pbonzini, hannes, nphamcs, reinette.chatre
Cc: ilpo.jarvinen, linux-kselftest, kvm, linux-kernel, linux-mm, Shuah Khan
On 10/13/23 05:36, Maciej Wieczor-Retman wrote:
> kselftest.h declares many variadic functions that can print some
> formatted message while also executing selftest logic. These
> declarations don't have any compiler mechanism to verify if passed
> arguments are valid in comparison with format specifiers used in
> printf() calls.
>
> Attribute addition can make debugging easier, the code more consistent
> and prevent mismatched or missing variables.
>
> The first patch adds __printf() macro and applies it to all functions
> in kselftest.h that use printf format specifiers. After compiling all
> selftests using:
> make -C tools/testing/selftests
> many instances of format specifier mismatching are exposed in the form
> of -Wformat warnings.
>
> Fix the mismatched format specifiers caught by __printf() attribute in
> multiple tests.
>
> Series is based on kselftests next branch.
>
> Changelog v6:
> - Add methodology notes to all patches.
> - No functional changes in the patches.
>
Applied this series and the following three - all 25 patches are
in linux-kselftest next for Linux 6.7-rc1.
[1] https://lore.kernel.org/all/cover.1696932728.git.maciej.wieczor-retman@intel.com/
[2] https://lore.kernel.org/all/20231002094813.6633-1-ilpo.jarvinen@linux.intel.com/
[3] https://lore.kernel.org/all/20230904095339.11321-1-ilpo.jarvinen@linux.intel.com/
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 0/8] Add printf attribute to kselftest functions
2023-10-13 21:03 ` [PATCH v6 0/8] Add printf attribute to kselftest functions Shuah
@ 2023-10-13 21:08 ` Reinette Chatre
2023-10-16 5:28 ` Maciej Wieczór-Retman
1 sibling, 0 replies; 6+ messages in thread
From: Reinette Chatre @ 2023-10-13 21:08 UTC (permalink / raw)
To: Shuah, Maciej Wieczor-Retman, akpm, christian, fenghua.yu,
keescook, ndesaulniers, coltonlewis, dmatlack, vipinsh, seanjc,
brauner, pbonzini, hannes, nphamcs
Cc: ilpo.jarvinen, linux-kselftest, kvm, linux-kernel, linux-mm, Shuah Khan
On 10/13/2023 2:03 PM, Shuah wrote:
> Applied this series and the following three - all 25 patches are
> in linux-kselftest next for Linux 6.7-rc1.
>
> [1] https://lore.kernel.org/all/cover.1696932728.git.maciej.wieczor-retman@intel.com/
> [2] https://lore.kernel.org/all/20231002094813.6633-1-ilpo.jarvinen@linux.intel.com/
> [3] https://lore.kernel.org/all/20230904095339.11321-1-ilpo.jarvinen@linux.intel.com/
>
Thank you very much Shuah.
Reinette
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v6 0/8] Add printf attribute to kselftest functions
2023-10-13 21:03 ` [PATCH v6 0/8] Add printf attribute to kselftest functions Shuah
2023-10-13 21:08 ` Reinette Chatre
@ 2023-10-16 5:28 ` Maciej Wieczór-Retman
1 sibling, 0 replies; 6+ messages in thread
From: Maciej Wieczór-Retman @ 2023-10-16 5:28 UTC (permalink / raw)
To: Shuah
Cc: akpm, christian, fenghua.yu, keescook, ndesaulniers, coltonlewis,
dmatlack, vipinsh, seanjc, brauner, pbonzini, hannes, nphamcs,
reinette.chatre, ilpo.jarvinen, linux-kselftest, kvm,
linux-kernel, linux-mm, Shuah Khan
On 2023-10-13 at 15:03:11 -0600, Shuah wrote:
>On 10/13/23 05:36, Maciej Wieczor-Retman wrote:
>> kselftest.h declares many variadic functions that can print some
>> formatted message while also executing selftest logic. These
>> declarations don't have any compiler mechanism to verify if passed
>> arguments are valid in comparison with format specifiers used in
>> printf() calls.
>>
>> Attribute addition can make debugging easier, the code more consistent
>> and prevent mismatched or missing variables.
>>
>> The first patch adds __printf() macro and applies it to all functions
>> in kselftest.h that use printf format specifiers. After compiling all
>> selftests using:
>> make -C tools/testing/selftests
>> many instances of format specifier mismatching are exposed in the form
>> of -Wformat warnings.
>>
>> Fix the mismatched format specifiers caught by __printf() attribute in
>> multiple tests.
>>
>> Series is based on kselftests next branch.
>>
>> Changelog v6:
>> - Add methodology notes to all patches.
>> - No functional changes in the patches.
>>
>
>Applied this series and the following three - all 25 patches are
>in linux-kselftest next for Linux 6.7-rc1.
>
>[1] https://lore.kernel.org/all/cover.1696932728.git.maciej.wieczor-retman@intel.com/
>[2] https://lore.kernel.org/all/20231002094813.6633-1-ilpo.jarvinen@linux.intel.com/
>[3] https://lore.kernel.org/all/20230904095339.11321-1-ilpo.jarvinen@linux.intel.com/
>
>thanks,
>-- Shuah
>
Thank you!
--
Kind regards
Maciej Wieczór-Retman
^ permalink raw reply [flat|nested] 6+ messages in thread