Skip to contentSkip to conversation

selftests/seccomp: report errno and add hints on failure

PATCH In review Sameeksha Sankpal 3 participants 7 messages May 17, 2025 – Nov 25, 2025 2 messages not in the archive

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

PATCH 1/1 selftests/seccomp: report errno and add hints on failure

---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +7 -1
index 14ba51b52095..d6a85d7b26da 100644
@@ -4508,7 +4508,11 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 
 	snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
 	ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
-
+	int rc = get_nth(_metadata, proc_path, 3, &line);
+    	if (rc != 1) {
+        	printf("[ERROR] user_notification_fifo: failed to read stat for PID %d (rc=%d)\n", pid, rc);
+    	}
+    	ASSERT_EQ(rc, 1);
 	status = *line;
 	free(line);
 
@@ -4518,6 +4522,7 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 TEST(user_notification_fifo)
 {
 	struct seccomp_notif_resp resp = {};
+	ksft_print_msg("[INFO] Starting FIFO notification test\n");
 	struct seccomp_notif req = {};
 	int i, status, listener;
 	pid_t pid, pids[3];
@@ -4535,6 +4540,7 @@ TEST(user_notification_fifo)
 	listener = user_notif_syscall(__NR_getppid,
 				      SECCOMP_FILTER_FLAG_NEW_LISTENER);
 	ASSERT_GE(listener, 0);
+	ksft_print_msg("[INFO] user_notification_fifo: listener PID is %d\n", listener);
 
 	pid = fork();
 	ASSERT_GE(pid, 0);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 10 lines · Sameeksha Sankpal
---
 tools/testing/selftests/seccomp/seccomp_bpf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +0 -0
index 14ba51b52095..d6a85d7b26da 100644

tools/testing/selftests/seccomp/seccomp_bpf.c static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid) · line 4515

Quoted 9 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +5 -1
@@ -4508,7 +4508,11 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 
 	snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
 	ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
-
+	int rc = get_nth(_metadata, proc_path, 3, &line);
+    	if (rc != 1) {
+        	printf("[ERROR] user_notification_fifo: failed to read stat for PID %d (rc=%d)\n", pid, rc);
+    	}
+    	ASSERT_EQ(rc, 1);

An ASSERT will stop execution, so if it fails, you'll never reach the printf. And a "printf" shouldn't be used. What you want to use is TH_LOG, probably like this:

	rc = get_nth(_metadata, proc_path, 3, &line);
  	ASSERT_EQ(rc, 1) {
		TH_LOG("user_notification_fifo: failed to read stat for PID %d (rc=%d)", pid, rc);
	}

And please don't introduce new variables in the middle -- they need to be declared at the top of the function.

-Kees

Signature · 1 line
Kees Cook
#2 lore raw

PATCH v2 1/1 selftests/seccomp: Improve error logging in get_proc_stat()

Use TH_LOG to report failure when reading /proc/<pid>/stat in get_proc_stat(), following kernel test framework conventions.

Previously, printf() was used which is discouraged.

---
v1 -> v2:
- Used TH_LOG instead of printf for error logging
- Moved variable declaration to the top of the function
- Applied review suggestion by Kees Cook

 tools/testing/selftests/seccomp/seccomp_bpf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +5 -5
index d6a85d7b26da..0f12052ef1c7 100644
@@ -4505,14 +4505,14 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 	char proc_path[100] = {0};
 	char status;
 	char *line;
+	int rc;
 
 	snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
 	ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
-	int rc = get_nth(_metadata, proc_path, 3, &line);
-    	if (rc != 1) {
-        	printf("[ERROR] user_notification_fifo: failed to read stat for PID %d (rc=%d)\n", pid, rc);
-    	}
-    	ASSERT_EQ(rc, 1);
+	rc = get_nth(_metadata, proc_path, 3, &line);
+    ASSERT_EQ(rc, 1) {
+		TH_LOG("user_notification_fifo: failed to read stat for PID %d (rc=%d)", pid, rc);
+	}
 	status = *line;
 	free(line);
 
Signature · 1 line
2.43.0
maintainer
#3 lore raw

Re: [PATCH v2] selftests/seccomp: Improve error logging in get_proc_stat()

Quoted 4 lines · Sameeksha Sankpal

Use TH_LOG to report failure when reading /proc/<pid>/stat in get_proc_stat(), following kernel test framework conventions.

Previously, printf() was used which is discouraged.

printf wasn't used previous, that was in your v1. :)

Quoted 3 lines

No blank line here -- other tags should all be together with the S-o-b line.

Quoted 17 lines

---
v1 -> v2:
- Used TH_LOG instead of printf for error logging
- Moved variable declaration to the top of the function
- Applied review suggestion by Kees Cook

 tools/testing/selftests/seccomp/seccomp_bpf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +0 -0
index d6a85d7b26da..0f12052ef1c7 100644
@@ -4505,14 +4505,14 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 	char proc_path[100] = {0};
 	char status;

tools/testing/selftests/seccomp/seccomp_bpf.c static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid) · line 4515

Quoted 10 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -5
 	char *line;
+	int rc;
 
 	snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
 	ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
-	int rc = get_nth(_metadata, proc_path, 3, &line);
-    	if (rc != 1) {
-        	printf("[ERROR] user_notification_fifo: failed to read stat for PID %d (rc=%d)\n", pid, rc);
-    	}
-    	ASSERT_EQ(rc, 1);

This patch is against your v1 patch -- it doesn't apply to the seccomp tree as-is. Please rebase your v2 off of the upstream tree rather than your v1.

tools/testing/selftests/seccomp/seccomp_bpf.c static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid) · line 4513

Quoted 2 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +2 -0
+	rc = get_nth(_metadata, proc_path, 3, &line);
+    ASSERT_EQ(rc, 1) {

Indenting looks wrong here, double-check you're using tabs. (And please use scripts/checkpatch.pl to check your patch for common errors.)

tools/testing/selftests/seccomp/seccomp_bpf.c static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid) · line 4517

Quoted 4 lines
tools/testing/selftests/seccomp/seccomp_bpf.c +2 -0
+		TH_LOG("user_notification_fifo: failed to read stat for PID %d (rc=%d)", pid, rc);
+	}
 	status = *line;
 	free(line);

Code-wise, it looks good. Please respin for a v3 and this change should be good to land.

-Kees

Signature · 1 line
Kees Cook
#4 lore raw

PATCH v3 1/1 selftests/seccomp: Fix indentation and rebase error logging patch

Rebase the error logging enhancement for get_proc_stat() against the upstream seccomp tree with proper indentation formatting.

---
v1 -> v2:
- Used TH_LOG instead of printf for error logging
- Moved variable declaration to the top of the function
- Applied review suggestion by Kees Cook

v2 -> v3:
- Rebased against upstream seccomp tree (was previously against v1)
- Fixed indentation to use tabs instead of spaces
- Used scripts/checkpatch.pl to check the patch for common errors
- Removed the blank line beforeS S-o-b added in v2

 tools/testing/selftests/seccomp/seccomp_bpf.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/testing/selftests/seccomp/seccomp_bpf.c +5 -0
index 61acbd45ffaa..dbd7e705a2af 100644
@@ -4508,9 +4508,14 @@ static char get_proc_stat(struct __test_metadata *_metadata, pid_t pid)
 	char proc_path[100] = {0};
 	char status;
 	char *line;
+	int rc;
 
 	snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
 	ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
+	rc = get_nth(_metadata, proc_path, 3, &line);
+	ASSERT_EQ(rc, 1) {
+		TH_LOG("user_notification_fifo: failed to read stat for PID %d (rc=%d)", pid, rc);
+	}
 
 	status = *line;
 	free(line);
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v3] selftests/seccomp: Fix indentation and rebase error logging patch

In reply to a message not in the archive

Hi Shuah,

Thanks for pointing that out. Apologies for missing the mailing lists earlier. Resending this follow-up with the correct CC list and in plain text format.

Please let me know if there’s anything else I should improve in this patch. I’m happy to resend it as v4 if needed.

Thanks,
Sameeksha

Quoted 66 lines · Shuah Khan
Quoted 4 lines · Sameeksha Sankpal

Hi,
Just following up on this patch.
It’s been a few months, so I wanted to check if there is anything else I should address or improve to move it forward.

I see that you didn't cc any mailing list on this email? Please keep everybody in the loop when you send responses.

Quoted 47 lines

Thanks,
Sameeksha Sankpal

Quoted 40 lines · Sameeksha Sankpal

Rebase the error logging enhancement for get_proc_stat() against the upstream seccomp tree with proper indentation formatting.

---
v1 -> v2:
- Used TH_LOG instead of printf for error logging
- Moved variable declaration to the top of the function
- Applied review suggestion by Kees Cook

v2 -> v3:
- Rebased against upstream seccomp tree (was previously against v1)
- Fixed indentation to use tabs instead of spaces
- Used scripts/checkpatch.pl to check the patch for common errors
- Removed the blank line beforeS S-o-b added in v2

  tools/testing/selftests/seccomp/seccomp_bpf.c | 5 +++++
  1 file changed, 5 insertions(+)
tools/testing/selftests/seccomp/seccomp_bpf.c +5 -0
index 61acbd45ffaa..dbd7e705a2af 100644
@@ -4508,9 +4508,14 @@ static char get_proc_stat(struct __test_metadata
 *_metadata, pid_t pid)
         char proc_path[100] = {0};
         char status;
         char *line;
+       int rc;
 
         snprintf(proc_path, sizeof(proc_path), "/proc/%d/stat", pid);
         ASSERT_EQ(get_nth(_metadata, proc_path, 3, &line), 1);
+       rc = get_nth(_metadata, proc_path, 3, &line);
+       ASSERT_EQ(rc, 1) {
+               TH_LOG("user_notification_fifo: failed to read stat for
 PID %d (rc=%d)", pid, rc);
+       }
 
Quoted 7 lines
Quoted 6 lines
         status = *line;
         free(line);

--
2.43.0

thanks,
-- Shuah

maintainer
#8 lore raw

Re: [PATCH v3] selftests/seccomp: Fix indentation and rebase error logging patch

Quoted 7 lines · Sameeksha Sankpal

Hi Shuah,

Thanks for pointing that out. Apologies for missing the mailing lists earlier. Resending this follow-up with the correct CC list and in plain text format.

Please let me know if there’s anything else I should improve in this patch. I’m happy to resend it as v4 if needed.

No top post to start with. Resend v3 for review instead of adding mailing lists and everybody getmaintainers script suggests.

thanks,
-- Shuah