mbox series

[v2,0/4] kselftests: vdso: conform tests to TAP output

Message ID 20240610054129.1527389-1-usama.anjum@collabora.com
Headers show
Series kselftests: vdso: conform tests to TAP output | expand

Message

Muhammad Usama Anjum June 10, 2024, 5:41 a.m. UTC
Conform individual tests to TAP output. One patch conform one test. With
this series, all vDSO tests become TAP conformant.

First patch conform the test by using kselftest_harness.h. Other patches
are conforming using default kselftest.h helpers.

All tests have been tested multiple times before and after these
patches. They are working correctly and outputting TAP messaging to find
failures quikly when they happen.
---
Changes since v1:
- Update cover letter
- Update commit message of first patch

Muhammad Usama Anjum (4):
  kselftests: vdso: vdso_test_clock_getres: conform test to TAP output
  kselftests: vdso: vdso_test_correctness: conform test to TAP output
  kselftests: vdso: vdso_test_getcpu: conform test to TAP output
  kselftests: vdso: vdso_test_gettimeofday: conform test to TAP output

 .../selftests/vDSO/vdso_test_clock_getres.c   |  68 ++++----
 .../selftests/vDSO/vdso_test_correctness.c    | 146 +++++++++---------
 .../testing/selftests/vDSO/vdso_test_getcpu.c |  16 +-
 .../selftests/vDSO/vdso_test_gettimeofday.c   |  23 +--
 4 files changed, 126 insertions(+), 127 deletions(-)

Comments

Shuah Khan June 11, 2024, 8:32 p.m. UTC | #1
On 6/9/24 23:41, Muhammad Usama Anjum wrote:
> Conform the layout, informational and status messages to TAP. No
> functional change is intended other than the layout of output messages.
> Use kselftest_harness.h to conform to TAP as the number of tests depend
> on the available options at build time. The kselftest_harness makes the


How does converting to kselftest_harness help with available options ay
build time? Can you explain?

I am not seeing any value in converting this test to the harness? I want
to see a better justification.

> test easy to convert and presents better maintainability.
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> Changes since v1:
> - Update commit message to include that kselftest_harness has been used
>    to conform to TAP and why
> ---
>   .../selftests/vDSO/vdso_test_clock_getres.c   | 68 +++++++++----------
>   1 file changed, 33 insertions(+), 35 deletions(-)
> 
> diff --git a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
> index 38d46a8bf7cba..c1ede40521f05 100644
> --- a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
> +++ b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
> @@ -25,7 +25,7 @@
>   #include <unistd.h>
>   #include <sys/syscall.h>
>   
> -#include "../kselftest.h"
> +#include "../kselftest_harness.h"
>   
>   static long syscall_clock_getres(clockid_t _clkid, struct timespec *_ts)
>   {
> @@ -54,18 +54,8 @@ const char *vdso_clock_name[12] = {
>   /*
>    * This function calls clock_getres in vdso and by system call
>    * with different values for clock_id.
> - *
> - * Example of output:
> - *
> - * clock_id: CLOCK_REALTIME [PASS]
> - * clock_id: CLOCK_BOOTTIME [PASS]
> - * clock_id: CLOCK_TAI [PASS]
> - * clock_id: CLOCK_REALTIME_COARSE [PASS]
> - * clock_id: CLOCK_MONOTONIC [PASS]
> - * clock_id: CLOCK_MONOTONIC_RAW [PASS]
> - * clock_id: CLOCK_MONOTONIC_COARSE [PASS]
>    */
> -static inline int vdso_test_clock(unsigned int clock_id)
> +static inline void vdso_test_clock(struct __test_metadata *_metadata, unsigned int clock_id)
>   {
>   	struct timespec x, y;
>   
> @@ -73,52 +63,60 @@ static inline int vdso_test_clock(unsigned int clock_id)
>   	clock_getres(clock_id, &x);
>   	syscall_clock_getres(clock_id, &y);
>   
> -	if ((x.tv_sec != y.tv_sec) || (x.tv_nsec != y.tv_nsec)) {
> -		printf(" [FAIL]\n");
> -		return KSFT_FAIL;
> -	}
> -
> -	printf(" [PASS]\n");
> -	return KSFT_PASS;
> +	ASSERT_EQ(0, ((x.tv_sec != y.tv_sec) || (x.tv_nsec != y.tv_nsec)));
>   }
>   
> -int main(int argc, char **argv)
> -{
> -	int ret = 0;
> -
>   #if _POSIX_TIMERS > 0
>   
>   #ifdef CLOCK_REALTIME
> -	ret += vdso_test_clock(CLOCK_REALTIME);
> +TEST(clock_realtime)
> +{
> +	vdso_test_clock(_metadata, CLOCK_REALTIME);
> +}
>   #endif
>   
>   #ifdef CLOCK_BOOTTIME
> -	ret += vdso_test_clock(CLOCK_BOOTTIME);
> +TEST(clock_boottime)
> +{
> +	vdso_test_clock(_metadata, CLOCK_BOOTTIME);
> +}
>   #endif
>   
>   #ifdef CLOCK_TAI
> -	ret += vdso_test_clock(CLOCK_TAI);
> +TEST(clock_tai)
> +{
> +	vdso_test_clock(_metadata, CLOCK_TAI);
> +}
>   #endif
>   
>   #ifdef CLOCK_REALTIME_COARSE
> -	ret += vdso_test_clock(CLOCK_REALTIME_COARSE);
> +TEST(clock_realtime_coarse)
> +{
> +	vdso_test_clock(_metadata, CLOCK_REALTIME_COARSE);
> +}
>   #endif
>   
>   #ifdef CLOCK_MONOTONIC
> -	ret += vdso_test_clock(CLOCK_MONOTONIC);
> +TEST(clock_monotonic)
> +{
> +	vdso_test_clock(_metadata, CLOCK_MONOTONIC);
> +}
>   #endif
>   
>   #ifdef CLOCK_MONOTONIC_RAW
> -	ret += vdso_test_clock(CLOCK_MONOTONIC_RAW);
> +TEST(clock_monotonic_raw)
> +{
> +	vdso_test_clock(_metadata, CLOCK_MONOTONIC_RAW);
> +}
>   #endif
>   
>   #ifdef CLOCK_MONOTONIC_COARSE
> -	ret += vdso_test_clock(CLOCK_MONOTONIC_COARSE);
> +TEST(clock_monotonic_coarse)
> +{
> +	vdso_test_clock(_metadata, CLOCK_MONOTONIC_COARSE);
> +}
>   #endif
>   
> -#endif
> -	if (ret > 0)
> -		return KSFT_FAIL;
> +#endif /* _POSIX_TIMERS > 0 */
>   
> -	return KSFT_PASS;
> -}
> +TEST_HARNESS_MAIN

thanks,
-- Shuah
Shuah Khan June 11, 2024, 8:37 p.m. UTC | #2
On 6/9/24 23:41, Muhammad Usama Anjum wrote:
> Conform individual tests to TAP output. One patch conform one test. With
> this series, all vDSO tests become TAP conformant.
> 
> First patch conform the test by using kselftest_harness.h. Other patches
> are conforming using default kselftest.h helpers.
> 
> All tests have been tested multiple times before and after these
> patches. They are working correctly and outputting TAP messaging to find
> failures quikly when they happen.
> ---
> Changes since v1:
> - Update cover letter
> - Update commit message of first patch
> 
> Muhammad Usama Anjum (4):
>    kselftests: vdso: vdso_test_clock_getres: conform test to TAP output
>    kselftests: vdso: vdso_test_correctness: conform test to TAP output
>    kselftests: vdso: vdso_test_getcpu: conform test to TAP output
>    kselftests: vdso: vdso_test_gettimeofday: conform test to TAP output
> 
>   .../selftests/vDSO/vdso_test_clock_getres.c   |  68 ++++----
>   .../selftests/vDSO/vdso_test_correctness.c    | 146 +++++++++---------
>   .../testing/selftests/vDSO/vdso_test_getcpu.c |  16 +-
>   .../selftests/vDSO/vdso_test_gettimeofday.c   |  23 +--
>   4 files changed, 126 insertions(+), 127 deletions(-)
> 

I see two changes:

- concvering this test to use kselftes_harness. I am not seeing a value to this.
- Second converting every single print to TAP. This isn't necessary since the
   kselftest wrapper prints appropriate summary message based on the KSFT_ code

I want to output before and after to assess the value of this change. TAP conversions
make sense if and when they add value.

thanks,
-- Shuah
Muhammad Usama Anjum June 12, 2024, 8:17 a.m. UTC | #3
On 6/12/24 1:32 AM, Shuah Khan wrote:
> On 6/9/24 23:41, Muhammad Usama Anjum wrote:
>> Conform the layout, informational and status messages to TAP. No
>> functional change is intended other than the layout of output messages.
>> Use kselftest_harness.h to conform to TAP as the number of tests depend
>> on the available options at build time. The kselftest_harness makes the
> 
> 
> How does converting to kselftest_harness help with available options ay
> build time? Can you explain?
> 
> I am not seeing any value in converting this test to the harness? I want
> to see a better justification.

Before:
./vdso_test_clock_getres
clock_id: CLOCK_REALTIME [PASS]
clock_id: CLOCK_BOOTTIME [PASS]
clock_id: CLOCK_TAI [PASS]
clock_id: CLOCK_REALTIME_COARSE [PASS]
clock_id: CLOCK_MONOTONIC [PASS]
clock_id: CLOCK_MONOTONIC_RAW [PASS]
clock_id: CLOCK_MONOTONIC_COARSE [PASS]

Here is the output of the test before this patch. The test output test
names and if they are passed or failed. It doesn't output information
related to error when it occurs. I wanted to convert it to standard format
by using kselftest.h where we can get the error related information as
well. But as the number of tests depend on how many of CLOCK_BOOTTIME,
CLOCK_TAI etc are defined, static counting is difficult. Test harness is
best suited for this. Output:

./vdso_test_clock_getres
TAP version 13
1..7
# Starting 7 tests from 1 test cases.
#  RUN           global.clock_realtime ...
#            OK  global.clock_realtime
ok 1 global.clock_realtime
#  RUN           global.clock_boottime ...
#            OK  global.clock_boottime
ok 2 global.clock_boottime
#  RUN           global.clock_tai ...
#            OK  global.clock_tai
ok 3 global.clock_tai
#  RUN           global.clock_realtime_coarse ...
#            OK  global.clock_realtime_coarse
ok 4 global.clock_realtime_coarse
#  RUN           global.clock_monotonic ...
#            OK  global.clock_monotonic
ok 5 global.clock_monotonic
#  RUN           global.clock_monotonic_raw ...
#            OK  global.clock_monotonic_raw
ok 6 global.clock_monotonic_raw
#  RUN           global.clock_monotonic_coarse ...
#            OK  global.clock_monotonic_coarse
ok 7 global.clock_monotonic_coarse
# PASSED: 7 / 7 tests passed.
# Totals: pass:7 fail:0 xfail:0 xpass:0 skip:0 error:0

Not only the code is simplified, the descriptive error is printed on
console that what went wrong. Example if a test case fails:

#  RUN           global.clock_realtime ...
# vdso_test_clock_getres.c:66:clock_realtime:Expected 1 (1) == ((x.tv_sec
!= y.tv_sec) || (x.tv_nsec != y.tv_nsec)) (0)
# clock_realtime: Test terminated by assertion
#          FAIL  global.clock_realtime
not ok 1 global.clock_realtime

> 
>> test easy to convert and presents better maintainability.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>> Changes since v1:
>> - Update commit message to include that kselftest_harness has been used
>>    to conform to TAP and why
>> ---
>>   .../selftests/vDSO/vdso_test_clock_getres.c   | 68 +++++++++----------
>>   1 file changed, 33 insertions(+), 35 deletions(-)
>>
>> diff --git a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> index 38d46a8bf7cba..c1ede40521f05 100644
>> --- a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> +++ b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> @@ -25,7 +25,7 @@
>>   #include <unistd.h>
>>   #include <sys/syscall.h>
>>   -#include "../kselftest.h"
>> +#include "../kselftest_harness.h"
>>     static long syscall_clock_getres(clockid_t _clkid, struct timespec *_ts)
>>   {
>> @@ -54,18 +54,8 @@ const char *vdso_clock_name[12] = {
>>   /*
>>    * This function calls clock_getres in vdso and by system call
>>    * with different values for clock_id.
>> - *
>> - * Example of output:
>> - *
>> - * clock_id: CLOCK_REALTIME [PASS]
>> - * clock_id: CLOCK_BOOTTIME [PASS]
>> - * clock_id: CLOCK_TAI [PASS]
>> - * clock_id: CLOCK_REALTIME_COARSE [PASS]
>> - * clock_id: CLOCK_MONOTONIC [PASS]
>> - * clock_id: CLOCK_MONOTONIC_RAW [PASS]
>> - * clock_id: CLOCK_MONOTONIC_COARSE [PASS]
>>    */
>> -static inline int vdso_test_clock(unsigned int clock_id)
>> +static inline void vdso_test_clock(struct __test_metadata *_metadata,
>> unsigned int clock_id)
>>   {
>>       struct timespec x, y;
>>   @@ -73,52 +63,60 @@ static inline int vdso_test_clock(unsigned int
>> clock_id)
>>       clock_getres(clock_id, &x);
>>       syscall_clock_getres(clock_id, &y);
>>   -    if ((x.tv_sec != y.tv_sec) || (x.tv_nsec != y.tv_nsec)) {
>> -        printf(" [FAIL]\n");
>> -        return KSFT_FAIL;
>> -    }
>> -
>> -    printf(" [PASS]\n");
>> -    return KSFT_PASS;
>> +    ASSERT_EQ(0, ((x.tv_sec != y.tv_sec) || (x.tv_nsec != y.tv_nsec)));
>>   }
>>   -int main(int argc, char **argv)
>> -{
>> -    int ret = 0;
>> -
>>   #if _POSIX_TIMERS > 0
>>     #ifdef CLOCK_REALTIME
>> -    ret += vdso_test_clock(CLOCK_REALTIME);
>> +TEST(clock_realtime)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_REALTIME);
>> +}
>>   #endif
>>     #ifdef CLOCK_BOOTTIME
>> -    ret += vdso_test_clock(CLOCK_BOOTTIME);
>> +TEST(clock_boottime)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_BOOTTIME);
>> +}
>>   #endif
>>     #ifdef CLOCK_TAI
>> -    ret += vdso_test_clock(CLOCK_TAI);
>> +TEST(clock_tai)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_TAI);
>> +}
>>   #endif
>>     #ifdef CLOCK_REALTIME_COARSE
>> -    ret += vdso_test_clock(CLOCK_REALTIME_COARSE);
>> +TEST(clock_realtime_coarse)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_REALTIME_COARSE);
>> +}
>>   #endif
>>     #ifdef CLOCK_MONOTONIC
>> -    ret += vdso_test_clock(CLOCK_MONOTONIC);
>> +TEST(clock_monotonic)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_MONOTONIC);
>> +}
>>   #endif
>>     #ifdef CLOCK_MONOTONIC_RAW
>> -    ret += vdso_test_clock(CLOCK_MONOTONIC_RAW);
>> +TEST(clock_monotonic_raw)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_MONOTONIC_RAW);
>> +}
>>   #endif
>>     #ifdef CLOCK_MONOTONIC_COARSE
>> -    ret += vdso_test_clock(CLOCK_MONOTONIC_COARSE);
>> +TEST(clock_monotonic_coarse)
>> +{
>> +    vdso_test_clock(_metadata, CLOCK_MONOTONIC_COARSE);
>> +}
>>   #endif
>>   -#endif
>> -    if (ret > 0)
>> -        return KSFT_FAIL;
>> +#endif /* _POSIX_TIMERS > 0 */
>>   -    return KSFT_PASS;
>> -}
>> +TEST_HARNESS_MAIN
> 
> thanks,
> -- Shuah
> 
>
Muhammad Usama Anjum June 12, 2024, 8:22 a.m. UTC | #4
On 6/12/24 1:37 AM, Shuah Khan wrote:
> On 6/9/24 23:41, Muhammad Usama Anjum wrote:
>> Conform individual tests to TAP output. One patch conform one test. With
>> this series, all vDSO tests become TAP conformant.
>>
>> First patch conform the test by using kselftest_harness.h. Other patches
>> are conforming using default kselftest.h helpers.
>>
>> All tests have been tested multiple times before and after these
>> patches. They are working correctly and outputting TAP messaging to find
>> failures quikly when they happen.
>> ---
>> Changes since v1:
>> - Update cover letter
>> - Update commit message of first patch
>>
>> Muhammad Usama Anjum (4):
>>    kselftests: vdso: vdso_test_clock_getres: conform test to TAP output
>>    kselftests: vdso: vdso_test_correctness: conform test to TAP output
>>    kselftests: vdso: vdso_test_getcpu: conform test to TAP output
>>    kselftests: vdso: vdso_test_gettimeofday: conform test to TAP output
>>
>>   .../selftests/vDSO/vdso_test_clock_getres.c   |  68 ++++----
>>   .../selftests/vDSO/vdso_test_correctness.c    | 146 +++++++++---------
>>   .../testing/selftests/vDSO/vdso_test_getcpu.c |  16 +-
>>   .../selftests/vDSO/vdso_test_gettimeofday.c   |  23 +--
>>   4 files changed, 126 insertions(+), 127 deletions(-)
>>
> 
> I see two changes:
> 
> - concvering this test to use kselftes_harness. I am not seeing a value to
> this.
> - Second converting every single print to TAP. This isn't necessary since the
>   kselftest wrapper prints appropriate summary message based on the KSFT_ code
If a test prints standard output, only then CI and regression detection
scripts identify if a test (and test case) was passed or failed. Or when it
started failing. The attempt here to conform to TAP to get output which is
recognizable and can easily be processed.

> 
> I want to output before and after to assess the value of this change. TAP
> conversions
> make sense if and when they add value.
Sure. Attaching before and after output for easy comparison. Please let me
know about your thoughts.

> 
> thanks,
> -- Shuah
>
Shuah Khan July 9, 2024, 11:15 p.m. UTC | #5
On 6/12/24 02:17, Muhammad Usama Anjum wrote:
> On 6/12/24 1:32 AM, Shuah Khan wrote:
>> On 6/9/24 23:41, Muhammad Usama Anjum wrote:
>>> Conform the layout, informational and status messages to TAP. No
>>> functional change is intended other than the layout of output messages.
>>> Use kselftest_harness.h to conform to TAP as the number of tests depend
>>> on the available options at build time. The kselftest_harness makes the
>>
>>
>> How does converting to kselftest_harness help with available options ay
>> build time? Can you explain?
>>
>> I am not seeing any value in converting this test to the harness? I want
>> to see a better justification.
> 
> Before:
> ./vdso_test_clock_getres
> clock_id: CLOCK_REALTIME [PASS]
> clock_id: CLOCK_BOOTTIME [PASS]
> clock_id: CLOCK_TAI [PASS]
> clock_id: CLOCK_REALTIME_COARSE [PASS]
> clock_id: CLOCK_MONOTONIC [PASS]
> clock_id: CLOCK_MONOTONIC_RAW [PASS]
> clock_id: CLOCK_MONOTONIC_COARSE [PASS]
> 
> Here is the output of the test before this patch. The test output test
> names and if they are passed or failed. It doesn't output information
> related to error when it occurs. I wanted to convert it to standard format
> by using kselftest.h where we can get the error related information as
> well. But as the number of tests depend on how many of CLOCK_BOOTTIME,
> CLOCK_TAI etc are defined, static counting is difficult. Test harness is
> best suited for this. Output:
> 
> ./vdso_test_clock_getres

The reason I don't want to take this patch is if you run the test
using the recommended method:

make -C tools/testing/selftests/vDSO/ run_tests you will get the
TAP output because lib.mk runtests framework takes care of this.

or

make kselftest TARGETS=vDSO will do the same.

Please don't send TAP conversions for individual runs. You will
start seeing duplicate TAP output which will make it unreadable.

Run the test using make -C or make kselftest TARGETS before
investing time to concert to TAP. I am not going to take TAP
conversions patches if make -C or make kselftest TARGETS
shows TAP.

thanks,
-- Shuah