Skip to contentSkip to conversation

selftests/bpf: fix subtest number formatting in test_progs

PATCH Applied Mykola Lysenko 4 participants 4 messages May 20, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: fix subtest number formatting in test_progs

Remove weird spaces around / while preserving proper indentation

---
 tools/testing/selftests/bpf/test_progs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/test_progs.c +12 -3
index ecf69fce036e..262b7577b0ef 100644
@@ -230,9 +230,14 @@ static void print_test_log(char *log_buf, size_t log_cnt)
 		fprintf(env.stdout, "\n");
 }
 
+#define TEST_NUM_WIDTH 7
+#define STRINGIFY(value) #value
+#define QUOTE(macro) STRINGIFY(macro)
+#define TEST_NUM_WIDTH_STR QUOTE(TEST_NUM_WIDTH)
+
 static void print_test_name(int test_num, const char *test_name, char *result)
 {
-	fprintf(env.stdout, "#%-9d %s", test_num, test_name);
+	fprintf(env.stdout, "#%-" TEST_NUM_WIDTH_STR "d %s", test_num, test_name);
 
 	if (result)
 		fprintf(env.stdout, ":%s", result);
@@ -244,8 +249,12 @@ static void print_subtest_name(int test_num, int subtest_num,
 			       const char *test_name, char *subtest_name,
 			       char *result)
 {
-	fprintf(env.stdout, "#%-3d/%-5d %s/%s",
-		test_num, subtest_num,
+	char test_num_str[TEST_NUM_WIDTH + 1];
+
+	snprintf(test_num_str, sizeof(test_num_str), "%d/%d", test_num, subtest_num);
+
+	fprintf(env.stdout, "#%-" TEST_NUM_WIDTH_STR "s %s/%s",
+		test_num_str,
 		test_name, subtest_name);
 
 	if (result)
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 46 lines · Mykola Lysenko

Remove weird spaces around / while preserving proper indentation

---
 tools/testing/selftests/bpf/test_progs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/test_progs.c +12 -3
index ecf69fce036e..262b7577b0ef 100644
@@ -230,9 +230,14 @@ static void print_test_log(char *log_buf, size_t log_cnt)
 		fprintf(env.stdout, "\n");
 }
 
+#define TEST_NUM_WIDTH 7
+#define STRINGIFY(value) #value
+#define QUOTE(macro) STRINGIFY(macro)
+#define TEST_NUM_WIDTH_STR QUOTE(TEST_NUM_WIDTH)
+
 static void print_test_name(int test_num, const char *test_name, char *result)
 {
-	fprintf(env.stdout, "#%-9d %s", test_num, test_name);
+	fprintf(env.stdout, "#%-" TEST_NUM_WIDTH_STR "d %s", test_num, test_name);
 
 	if (result)
 		fprintf(env.stdout, ":%s", result);
@@ -244,8 +249,12 @@ static void print_subtest_name(int test_num, int subtest_num,
 			       const char *test_name, char *subtest_name,
 			       char *result)
 {
-	fprintf(env.stdout, "#%-3d/%-5d %s/%s",
-		test_num, subtest_num,
+	char test_num_str[TEST_NUM_WIDTH + 1];
+
+	snprintf(test_num_str, sizeof(test_num_str), "%d/%d", test_num, subtest_num);
+
+	fprintf(env.stdout, "#%-" TEST_NUM_WIDTH_STR "s %s/%s",
+		test_num_str,
 		test_name, subtest_name);
 
 	if (result)
Signature · 1 line
2.30.2

Looks good to me, thanks.

#2 lore raw
In reply to Mykola Lysenko
Quoted 16 lines · Mykola Lysenko

Remove weird spaces around / while preserving proper indentation

---
 tools/testing/selftests/bpf/test_progs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/test_progs.c +0 -0
index ecf69fce036e..262b7577b0ef 100644
@@ -230,9 +230,14 @@ static void print_test_log(char *log_buf, size_t log_cnt)
                fprintf(env.stdout, "\n");
 }

tools/testing/selftests/bpf/test_progs.c static void print_test_log(char *log_buf, size_t log_cnt) · line 240

Quoted 10 lines
tools/testing/selftests/bpf/test_progs.c +6 -1
 
+#define TEST_NUM_WIDTH 7
+#define STRINGIFY(value) #value
+#define QUOTE(macro) STRINGIFY(macro)
+#define TEST_NUM_WIDTH_STR QUOTE(TEST_NUM_WIDTH)
+
 static void print_test_name(int test_num, const char *test_name, char *result)
 {
-       fprintf(env.stdout, "#%-9d %s", test_num, test_name);
+       fprintf(env.stdout, "#%-" TEST_NUM_WIDTH_STR "d %s", test_num, test_name);

this is equivalent to

fprintf(env.stdout, "#%-*d %s", TEST_NUM_WIDTH, test_num, test_name);

but doesn't require macro stringify sequence, so I dropped STRINGIFY, QUOTE and TEST_NU_WIDTH_STR and replaced it with * argument here and below

Quoted 21 lines
tools/testing/selftests/bpf/test_progs.c +6 -3
        if (result)
                fprintf(env.stdout, ":%s", result);
@@ -244,8 +249,12 @@ static void print_subtest_name(int test_num, int subtest_num,
                               const char *test_name, char *subtest_name,
                               char *result)
 {
-       fprintf(env.stdout, "#%-3d/%-5d %s/%s",
-               test_num, subtest_num,
+       char test_num_str[TEST_NUM_WIDTH + 1];
+
+       snprintf(test_num_str, sizeof(test_num_str), "%d/%d", test_num, subtest_num);
+
+       fprintf(env.stdout, "#%-" TEST_NUM_WIDTH_STR "s %s/%s",
+               test_num_str,
                test_name, subtest_name);
 
        if (result)
--

2.30.2

#3 lore raw
In reply to Mykola Lysenko
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 7 lines · On Fri, 20 May 2022 00:01:44 -0700 you wrote:

Remove weird spaces around / while preserving proper indentation

---
 tools/testing/selftests/bpf/test_progs.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Here is the summary with links:
- [bpf-next] selftests/bpf: fix subtest number formatting in test_progs

    https://git.kernel.org/bpf/bpf-next/c/fa3768606582

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html