diff mbox series

[2/3] selftest/exec: conform test to TAP format output

Message ID 20240304155928.1818928-2-usama.anjum@collabora.com (mailing list archive)
State Accepted
Commit c4095067736b7ed50316a2bc7c9577941e87ad45
Headers show
Series [1/3] selftests/exec: Add the overall result line accourding to TAP | expand

Commit Message

Muhammad Usama Anjum March 4, 2024, 3:59 p.m. UTC
Conform the layout, informational and status messages to TAP. No
functional change is intended other than the layout of output messages.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 tools/testing/selftests/exec/load_address.c | 34 +++++++++------------
 1 file changed, 15 insertions(+), 19 deletions(-)

Comments

Kees Cook March 4, 2024, 8:58 p.m. UTC | #1
On Mon, Mar 04, 2024 at 08:59:24PM +0500, 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.
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>  tools/testing/selftests/exec/load_address.c | 34 +++++++++------------
>  1 file changed, 15 insertions(+), 19 deletions(-)
> 
> diff --git a/tools/testing/selftests/exec/load_address.c b/tools/testing/selftests/exec/load_address.c
> index d487c2f6a6150..17e3207d34ae7 100644
> --- a/tools/testing/selftests/exec/load_address.c
> +++ b/tools/testing/selftests/exec/load_address.c
> @@ -5,6 +5,7 @@
>  #include <link.h>
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include "../kselftest.h"
>  
>  struct Statistics {
>  	unsigned long long load_address;
> @@ -41,28 +42,23 @@ int main(int argc, char **argv)
>  	unsigned long long misalign;
>  	int ret;
>  
> +	ksft_print_header();
> +	ksft_set_plan(1);
> +
>  	ret = dl_iterate_phdr(ExtractStatistics, &extracted);
> -	if (ret != 1) {
> -		fprintf(stderr, "FAILED\n");
> -		return 1;
> -	}
> +	if (ret != 1)
> +		ksft_exit_fail_msg("FAILED: dl_iterate_phdr\n");

I'm for this series, but I do note a weird glitch in the ksft API.
ksft_exit_fail_msg does:

        va_start(args, msg);
        printf("Bail out! ");
        errno = saved_errno;
        vprintf(msg, args);
        va_end(args);

"Bail out!" is not very descriptive. I think I'd rather this should be:

	"FAILED: "

and then that added prefix doesn't need to be added everywhere in this
patch, nor the "error: " prefix in the next patch.
Muhammad Usama Anjum March 5, 2024, 6:26 a.m. UTC | #2
On 3/5/24 1:58 AM, Kees Cook wrote:
> On Mon, Mar 04, 2024 at 08:59:24PM +0500, 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.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>>  tools/testing/selftests/exec/load_address.c | 34 +++++++++------------
>>  1 file changed, 15 insertions(+), 19 deletions(-)
>>
>> diff --git a/tools/testing/selftests/exec/load_address.c b/tools/testing/selftests/exec/load_address.c
>> index d487c2f6a6150..17e3207d34ae7 100644
>> --- a/tools/testing/selftests/exec/load_address.c
>> +++ b/tools/testing/selftests/exec/load_address.c
>> @@ -5,6 +5,7 @@
>>  #include <link.h>
>>  #include <stdio.h>
>>  #include <stdlib.h>
>> +#include "../kselftest.h"
>>  
>>  struct Statistics {
>>  	unsigned long long load_address;
>> @@ -41,28 +42,23 @@ int main(int argc, char **argv)
>>  	unsigned long long misalign;
>>  	int ret;
>>  
>> +	ksft_print_header();
>> +	ksft_set_plan(1);
>> +
>>  	ret = dl_iterate_phdr(ExtractStatistics, &extracted);
>> -	if (ret != 1) {
>> -		fprintf(stderr, "FAILED\n");
>> -		return 1;
>> -	}
>> +	if (ret != 1)
>> +		ksft_exit_fail_msg("FAILED: dl_iterate_phdr\n");
> 
> I'm for this series, but I do note a weird glitch in the ksft API.
> ksft_exit_fail_msg does:
> 
>         va_start(args, msg);
>         printf("Bail out! ");
>         errno = saved_errno;
>         vprintf(msg, args);
>         va_end(args);
> 
> "Bail out!" is not very descriptive. I think I'd rather this should be:
> 
> 	"FAILED: "
> 
> and then that added prefix doesn't need to be added everywhere in this
> patch, nor the "error: " prefix in the next patch.
If we want to make this change, FAILED should be removed from all the
tests. We should do it in separate patch. I've taken note and will do it
separate from this series.
diff mbox series

Patch

diff --git a/tools/testing/selftests/exec/load_address.c b/tools/testing/selftests/exec/load_address.c
index d487c2f6a6150..17e3207d34ae7 100644
--- a/tools/testing/selftests/exec/load_address.c
+++ b/tools/testing/selftests/exec/load_address.c
@@ -5,6 +5,7 @@ 
 #include <link.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "../kselftest.h"
 
 struct Statistics {
 	unsigned long long load_address;
@@ -41,28 +42,23 @@  int main(int argc, char **argv)
 	unsigned long long misalign;
 	int ret;
 
+	ksft_print_header();
+	ksft_set_plan(1);
+
 	ret = dl_iterate_phdr(ExtractStatistics, &extracted);
-	if (ret != 1) {
-		fprintf(stderr, "FAILED\n");
-		return 1;
-	}
+	if (ret != 1)
+		ksft_exit_fail_msg("FAILED: dl_iterate_phdr\n");
 
-	if (extracted.alignment == 0) {
-		fprintf(stderr, "No alignment found\n");
-		return 1;
-	} else if (extracted.alignment & (extracted.alignment - 1)) {
-		fprintf(stderr, "Alignment is not a power of 2\n");
-		return 1;
-	}
+	if (extracted.alignment == 0)
+		ksft_exit_fail_msg("FAILED: No alignment found\n");
+	else if (extracted.alignment & (extracted.alignment - 1))
+		ksft_exit_fail_msg("FAILED: Alignment is not a power of 2\n");
 
 	misalign = extracted.load_address & (extracted.alignment - 1);
-	if (misalign) {
-		printf("alignment = %llu, load_address = %llu\n",
-			extracted.alignment, extracted.load_address);
-		fprintf(stderr, "FAILED\n");
-		return 1;
-	}
+	if (misalign)
+		ksft_exit_fail_msg("FAILED: alignment = %llu, load_address = %llu\n",
+				   extracted.alignment, extracted.load_address);
 
-	fprintf(stderr, "PASS\n");
-	return 0;
+	ksft_test_result_pass("Completed\n");
+	ksft_finished();
 }