* [PATCH 0/6] Add printf attribute to kselftest functions
@ 2023-08-28 10:48 Wieczor-Retman, Maciej
2023-08-28 10:49 ` [PATCH 2/6] selftests/cachestat: Fix print_cachestat format Wieczor-Retman, Maciej
0 siblings, 1 reply; 4+ messages in thread
From: Wieczor-Retman, Maciej @ 2023-08-28 10:48 UTC (permalink / raw)
To: linux-kernel, Christian Brauner
Cc: kvm, linux-kselftest, linux-mm, keescook, ndesaulniers,
coltonlewis, dmatlack, vipinsh, seanjc, pbonzini, shuah, hannes,
nphamcs, reinette.chatre, ilpo.jarvinen, Wieczor-Retman, Maciej
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 similiarly 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.
Wieczor-Retman, Maciej (6):
selftests: Add printf attribute to ksefltest 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/cachestat/test_cachestat.c | 2 +-
tools/testing/selftests/kselftest.h | 18 ++++++++++--------
.../testing/selftests/kvm/include/test_util.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/sigaltstack/sas.c | 2 +-
7 files changed, 21 insertions(+), 19 deletions(-)
base-commit: 13eb52f6293dbda02890698d92f3d9913d8d5aeb
--
2.42.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/6] selftests/cachestat: Fix print_cachestat format
2023-08-28 10:48 [PATCH 0/6] Add printf attribute to kselftest functions Wieczor-Retman, Maciej
@ 2023-08-28 10:49 ` Wieczor-Retman, Maciej
2023-08-28 14:00 ` Nhat Pham
0 siblings, 1 reply; 4+ messages in thread
From: Wieczor-Retman, Maciej @ 2023-08-28 10:49 UTC (permalink / raw)
To: Nhat Pham, Johannes Weiner, Shuah Khan
Cc: ilpo.jarvinen, reinette.chatre, Wieczor-Retman, Maciej,
Wieczor-Retman, 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: Wieczor-Retman, Maciej <maciej.wieczor-retman@intel.com>
---
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 77620e7ecf56..a7adf42afb20 100644
--- a/tools/testing/selftests/cachestat/test_cachestat.c
+++ b/tools/testing/selftests/cachestat/test_cachestat.c
@@ -25,7 +25,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 related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/6] selftests/cachestat: Fix print_cachestat format
2023-08-28 10:49 ` [PATCH 2/6] selftests/cachestat: Fix print_cachestat format Wieczor-Retman, Maciej
@ 2023-08-28 14:00 ` Nhat Pham
2023-08-28 14:04 ` Nhat Pham
0 siblings, 1 reply; 4+ messages in thread
From: Nhat Pham @ 2023-08-28 14:00 UTC (permalink / raw)
To: Wieczor-Retman, Maciej
Cc: Johannes Weiner, Shuah Khan, ilpo.jarvinen, reinette.chatre,
linux-mm, linux-kselftest, linux-kernel
On Mon, Aug 28, 2023 at 6:50 AM Wieczor-Retman, Maciej
<maciej.wieczor-retman@intel.com> wrote:
>
> 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: Wieczor-Retman, Maciej <maciej.wieczor-retman@intel.com>
> ---
> 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 77620e7ecf56..a7adf42afb20 100644
> --- a/tools/testing/selftests/cachestat/test_cachestat.c
> +++ b/tools/testing/selftests/cachestat/test_cachestat.c
> @@ -25,7 +25,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",
The fields of struct cachestat should all be unsigned longs,
Is there a compiler warning that prompt this change?
> cs->nr_cache, cs->nr_dirty, cs->nr_writeback,
> cs->nr_evicted, cs->nr_recently_evicted);
> }
> --
> 2.42.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/6] selftests/cachestat: Fix print_cachestat format
2023-08-28 14:00 ` Nhat Pham
@ 2023-08-28 14:04 ` Nhat Pham
0 siblings, 0 replies; 4+ messages in thread
From: Nhat Pham @ 2023-08-28 14:04 UTC (permalink / raw)
To: Wieczor-Retman, Maciej
Cc: Johannes Weiner, Shuah Khan, ilpo.jarvinen, reinette.chatre,
linux-mm, linux-kselftest, linux-kernel
On Mon, Aug 28, 2023 at 10:00 AM Nhat Pham <nphamcs@gmail.com> wrote:
>
> On Mon, Aug 28, 2023 at 6:50 AM Wieczor-Retman, Maciej
> <maciej.wieczor-retman@intel.com> wrote:
> >
> > 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: Wieczor-Retman, Maciej <maciej.wieczor-retman@intel.com>
> > ---
> > 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 77620e7ecf56..a7adf42afb20 100644
> > --- a/tools/testing/selftests/cachestat/test_cachestat.c
> > +++ b/tools/testing/selftests/cachestat/test_cachestat.c
> > @@ -25,7 +25,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",
> The fields of struct cachestat should all be unsigned longs,
> Is there a compiler warning that prompt this change?
Ah nvm, it's _u64. %llu is probably the better format specifier indeed.
Acked-by: Nhat Pham <nphamcs@gmail.com>
> > cs->nr_cache, cs->nr_dirty, cs->nr_writeback,
> > cs->nr_evicted, cs->nr_recently_evicted);
> > }
> > --
> > 2.42.0
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-28 14:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-28 10:48 [PATCH 0/6] Add printf attribute to kselftest functions Wieczor-Retman, Maciej
2023-08-28 10:49 ` [PATCH 2/6] selftests/cachestat: Fix print_cachestat format Wieczor-Retman, Maciej
2023-08-28 14:00 ` Nhat Pham
2023-08-28 14:04 ` Nhat Pham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).