* [PATCH v4 0/8] Add printf attribute to kselftest functions
@ 2023-10-09 10:28 Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 2/8] selftests/cachestat: Fix print_cachestat format Maciej Wieczor-Retman
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Maciej Wieczor-Retman @ 2023-10-09 10:28 UTC (permalink / raw)
To: akpm, christian, fenghua.yu, keescook, ndesaulniers, coltonlewis,
dmatlack, vipinsh, seanjc, brauner, pbonzini, shuah, hannes,
nphamcs, reinette.chatre
Cc: ilpo.jarvinen, linux-kselftest, kvm, linux-kernel, linux-mm
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.
Add a __printf() macro that validates types of variables passed to the
format string. The macro is similarly used in other tools in the kernel.
Add __printf() attributes to function definitions inside kselftest.h that
use printing.
Adding the __printf() macro exposes some mismatches in format strings
across different selftests.
Fix the mismatched format specifiers in multiple tests.
Series is based on kselftests next branch.
Changelog v4:
- Fix patch 1/8 subject typo.
- Add Reinette's reviewed-by tags.
- Rebased onto updated kselftests next branch.
Changelog v3:
- Changed git signature from Wieczor-Retman Maciej to Maciej
Wieczor-Retman.
- Added one review tag.
- Rebased onto updated kselftests next branch.
Changelog v2:
- Add review and fixes tags to patches.
- Add two patches with mismatch fixes.
- Fix missed attribute in selftests/kvm. (Andrew)
- Fix previously missed issues in selftests/mm (Ilpo)
[v3] https://lore.kernel.org/all/cover.1695373131.git.maciej.wieczor-retman@intel.com/
[v2] https://lore.kernel.org/all/cover.1693829810.git.maciej.wieczor-retman@intel.com/
[v1] https://lore.kernel.org/all/cover.1693216959.git.maciej.wieczor-retman@intel.com/
Maciej Wieczor-Retman (8):
selftests: Add printf attribute to kselftest prints
selftests/cachestat: Fix print_cachestat format
selftests/openat2: Fix wrong format specifier
selftests/pidfd: Fix ksft print formats
selftests/sigaltstack: Fix wrong format specifier
selftests/kvm: Replace attribute with macro
selftests/mm: Substitute attribute with a macro
selftests/resctrl: Fix wrong format specifier
.../selftests/cachestat/test_cachestat.c | 2 +-
tools/testing/selftests/kselftest.h | 18 ++++++++++--------
.../testing/selftests/kvm/include/test_util.h | 8 ++++----
tools/testing/selftests/mm/mremap_test.c | 2 +-
tools/testing/selftests/mm/pkey-helpers.h | 2 +-
tools/testing/selftests/openat2/openat2_test.c | 2 +-
.../selftests/pidfd/pidfd_fdinfo_test.c | 2 +-
tools/testing/selftests/pidfd/pidfd_test.c | 12 ++++++------
tools/testing/selftests/resctrl/cache.c | 2 +-
tools/testing/selftests/sigaltstack/sas.c | 2 +-
10 files changed, 27 insertions(+), 25 deletions(-)
base-commit: f1020c687153609f246f3314db5b74821025c185
--
2.42.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 2/8] selftests/cachestat: Fix print_cachestat format
2023-10-09 10:28 [PATCH v4 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
@ 2023-10-09 10:30 ` Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 7/8] selftests/mm: Substitute attribute with a macro Maciej Wieczor-Retman
2023-10-09 17:28 ` [PATCH v4 0/8] Add printf attribute to kselftest functions Shuah Khan
2 siblings, 0 replies; 5+ messages in thread
From: Maciej Wieczor-Retman @ 2023-10-09 10:30 UTC (permalink / raw)
To: Nhat Pham, Johannes Weiner, Shuah Khan
Cc: ilpo.jarvinen, linux-mm, linux-kselftest, linux-kernel
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 v2:
- Added 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] 5+ messages in thread
* [PATCH v4 7/8] selftests/mm: Substitute attribute with a macro
2023-10-09 10:28 [PATCH v4 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 2/8] selftests/cachestat: Fix print_cachestat format Maciej Wieczor-Retman
@ 2023-10-09 10:30 ` Maciej Wieczor-Retman
2023-10-09 17:28 ` [PATCH v4 0/8] Add printf attribute to kselftest functions Shuah Khan
2 siblings, 0 replies; 5+ messages in thread
From: Maciej Wieczor-Retman @ 2023-10-09 10:30 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan
Cc: ilpo.jarvinen, linux-mm, linux-kselftest, linux-kernel
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.
Fix a wrong format specifier in ksft_print_msg().
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
---
Changelog v2:
- Added 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] 5+ messages in thread
* Re: [PATCH v4 0/8] Add printf attribute to kselftest functions
2023-10-09 10:28 [PATCH v4 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 2/8] selftests/cachestat: Fix print_cachestat format Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 7/8] selftests/mm: Substitute attribute with a macro Maciej Wieczor-Retman
@ 2023-10-09 17:28 ` Shuah Khan
2023-10-10 5:53 ` Maciej Wieczór-Retman
2 siblings, 1 reply; 5+ messages in thread
From: Shuah Khan @ 2023-10-09 17:28 UTC (permalink / raw)
To: Maciej Wieczor-Retman, akpm, christian, fenghua.yu, keescook,
ndesaulniers, coltonlewis, dmatlack, vipinsh, seanjc, brauner,
pbonzini, shuah, hannes, nphamcs, reinette.chatre
Cc: ilpo.jarvinen, linux-kselftest, kvm, linux-kernel, linux-mm, Shuah Khan
On 10/9/23 04:28, 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.
>
> Add a __printf() macro that validates types of variables passed to the
> format string. The macro is similarly used in other tools in the kernel.
>
> Add __printf() attributes to function definitions inside kselftest.h that
> use printing.
>
> Adding the __printf() macro exposes some mismatches in format strings
> across different selftests.
>
> Fix the mismatched format specifiers in multiple tests.
>
> Series is based on kselftests next branch.
How did you find these problems? I don't see any information
how these problems are found in the commit logs.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v4 0/8] Add printf attribute to kselftest functions
2023-10-09 17:28 ` [PATCH v4 0/8] Add printf attribute to kselftest functions Shuah Khan
@ 2023-10-10 5:53 ` Maciej Wieczór-Retman
0 siblings, 0 replies; 5+ messages in thread
From: Maciej Wieczór-Retman @ 2023-10-10 5:53 UTC (permalink / raw)
To: Shuah Khan
Cc: akpm, christian, fenghua.yu, keescook, ndesaulniers, coltonlewis,
dmatlack, vipinsh, seanjc, brauner, pbonzini, shuah, hannes,
nphamcs, reinette.chatre, ilpo.jarvinen, linux-kselftest, kvm,
linux-kernel, linux-mm
On 2023-10-09 at 11:28:30 -0600, Shuah Khan wrote:
>On 10/9/23 04:28, 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.
>>
>> Add a __printf() macro that validates types of variables passed to the
>> format string. The macro is similarly used in other tools in the kernel.
>>
>> Add __printf() attributes to function definitions inside kselftest.h that
>> use printing.
>>
>> Adding the __printf() macro exposes some mismatches in format strings
>> across different selftests.
>>
>> Fix the mismatched format specifiers in multiple tests.
>>
>> Series is based on kselftests next branch.
>
>How did you find these problems? I don't see any information
>how these problems are found in the commit logs.
>
>thanks,
>-- Shuah
I wrote the first patch that adds the check to functions with format
specifiers and I compiled all selftests. Then I just corrected any
warnings that were found by the __printf attribute.
Should I mention the methodology in the cover letter?
--
Kind regards
Maciej Wieczór-Retman
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-10 5:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 10:28 [PATCH v4 0/8] Add printf attribute to kselftest functions Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 2/8] selftests/cachestat: Fix print_cachestat format Maciej Wieczor-Retman
2023-10-09 10:30 ` [PATCH v4 7/8] selftests/mm: Substitute attribute with a macro Maciej Wieczor-Retman
2023-10-09 17:28 ` [PATCH v4 0/8] Add printf attribute to kselftest functions Shuah Khan
2023-10-10 5:53 ` Maciej Wieczór-Retman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox