[PATCH v6 0/8] Add printf attribute to kselftest functions

Maciej Wieczor-Retman posted 8 patches 2 years, 2 months ago
.../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(-)
[PATCH v6 0/8] Add printf attribute to kselftest functions
Posted by Maciej Wieczor-Retman 2 years, 2 months ago
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.

Changelog v5:
- Mention in the cover letter what methodology was used to find the
  mismatched format specifiers.
- No functional changes in the patches.

Changelog v4:
- Fix patch 1/8 subject typo.
- Add Reinette's reviewed-by tags.
- Rebase onto new kselftest/next patches.

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)

[v5] https://lore.kernel.org/all/cover.1697012398.git.maciej.wieczor-retman@intel.com/
[v4] https://lore.kernel.org/all/cover.1696846568.git.maciej.wieczor-retman@intel.com/
[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: 2531f374f922e77ba51f24d1aa6fa11c7f4c36b8
-- 
2.42.0
Re: [PATCH v6 0/8] Add printf attribute to kselftest functions
Posted by Shuah 2 years, 2 months ago
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
Re: [PATCH v6 0/8] Add printf attribute to kselftest functions
Posted by Maciej Wieczór-Retman 2 years, 2 months ago
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
Re: [PATCH v6 0/8] Add printf attribute to kselftest functions
Posted by Reinette Chatre 2 years, 2 months ago

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