Skip to contentSkip to conversation

selftests: firmware: Add details in error logging

PATCH In review Harshal 2 participants 4 messages Jul 14, 2025 – Jul 24, 2025 Kselftest

lore
Share & tools
lore

Harshal

author
#0 lore raw

PATCH v2 1/1 selftests: firmware: Add details in error logging

Specify details in logs of failed cases

---
v2:
- revert back to exit() instead of die() to avoid modifying system behaviour

v1: https://lore.kernel.org/all/[email protected]/

 tools/testing/selftests/firmware/fw_namespace.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/testing/selftests/firmware/fw_namespace.c +7 -7
index 04757dc7e546..5b0032498ede 100644
@@ -38,7 +38,7 @@ static void trigger_fw(const char *fw_name, const char *sys_path)
 
 	fd = open(sys_path, O_WRONLY);
 	if (fd < 0)
-		die("open failed: %s\n",
+		die("open of sys_path failed: %s\n",
 		    strerror(errno));
 	if (write(fd, fw_name, strlen(fw_name)) != strlen(fw_name))
 		exit(EXIT_FAILURE);
@@ -52,10 +52,10 @@ static void setup_fw(const char *fw_path)
 
 	fd = open(fw_path, O_WRONLY | O_CREAT, 0600);
 	if (fd < 0)
-		die("open failed: %s\n",
+		die("open of firmware file failed: %s\n",
 		    strerror(errno));
 	if (write(fd, fw, sizeof(fw) -1) != sizeof(fw) -1)
-		die("write failed: %s\n",
+		die("write to firmware file failed: %s\n",
 		    strerror(errno));
 	close(fd);
 }
@@ -66,7 +66,7 @@ static bool test_fw_in_ns(const char *fw_name, const char *sys_path, bool block_
 
 	if (block_fw_in_parent_ns)
 		if (mount("test", "/lib/firmware", "tmpfs", MS_RDONLY, NULL) == -1)
-			die("blocking firmware in parent ns failed\n");
+			die("blocking firmware in parent namespace failed\n");
 
 	child = fork();
 	if (child == -1) {
@@ -99,11 +99,11 @@ static bool test_fw_in_ns(const char *fw_name, const char *sys_path, bool block_
 			strerror(errno));
 	}
 	if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL) == -1)
-		die("remount root in child ns failed\n");
+		die("remount root in child namespace failed\n");
 
 	if (!block_fw_in_parent_ns) {
 		if (mount("test", "/lib/firmware", "tmpfs", MS_RDONLY, NULL) == -1)
-			die("blocking firmware in child ns failed\n");
+			die("blocking firmware in child namespace failed\n");
 	} else
 		umount("/lib/firmware");
 
@@ -129,8 +129,8 @@ int main(int argc, char **argv)
 		die("error: failed to build full fw_path\n");
 
 	setup_fw(fw_path);
-
 	setvbuf(stdout, NULL, _IONBF, 0);
+
 	/* Positive case: firmware in PID1 mount namespace */
 	printf("Testing with firmware in parent namespace (assumed to be same file system as PID1)\n");
 	if (!test_fw_in_ns(fw_name, sys_path, false))
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Harshal

Specify details in logs of failed cases

How about changing the above to:

Improve error messages adding details on failuires

Quoted 15 lines

---
v2:
- revert back to exit() instead of die() to avoid modifying system behaviour

v1: https://lore.kernel.org/all/[email protected]/

  tools/testing/selftests/firmware/fw_namespace.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
tools/testing/selftests/firmware/fw_namespace.c +0 -0
index 04757dc7e546..5b0032498ede 100644

tools/testing/selftests/firmware/fw_namespace.c static void trigger_fw(const char *fw_name, const char *sys_path) · line 41

Quoted 5 lines
tools/testing/selftests/firmware/fw_namespace.c +1 -1
@@ -38,7 +38,7 @@ static void trigger_fw(const char *fw_name, const char *sys_path)
 
  	fd = open(sys_path, O_WRONLY);
  	if (fd < 0)
-		die("open failed: %s\n",
+		die("open of sys_path failed: %s\n",

Why not just use sys_path as a input parameter to die()?

tools/testing/selftests/firmware/fw_namespace.c static void setup_fw(const char *fw_path) · line 55

Quoted 9 lines
tools/testing/selftests/firmware/fw_namespace.c +1 -1
  		    strerror(errno));
  	if (write(fd, fw_name, strlen(fw_name)) != strlen(fw_name))
  		exit(EXIT_FAILURE);
@@ -52,10 +52,10 @@ static void setup_fw(const char *fw_path)
 
  	fd = open(fw_path, O_WRONLY | O_CREAT, 0600);
  	if (fd < 0)
-		die("open failed: %s\n",
+		die("open of firmware file failed: %s\n",

Why not just use fw_path as a input parameter to die()?

tools/testing/selftests/firmware/fw_namespace.c static void setup_fw(const char *fw_path) · line 58

Quoted 4 lines
tools/testing/selftests/firmware/fw_namespace.c +1 -1
  		    strerror(errno));
  	if (write(fd, fw, sizeof(fw) -1) != sizeof(fw) -1)
-		die("write failed: %s\n",
+		die("write to firmware file failed: %s\n",

Same here

Quoted 27 lines
tools/testing/selftests/firmware/fw_namespace.c +3 -3
  		    strerror(errno));
  	close(fd);
  }
@@ -66,7 +66,7 @@ static bool test_fw_in_ns(const char *fw_name, const char *sys_path, bool block_
 
  	if (block_fw_in_parent_ns)
  		if (mount("test", "/lib/firmware", "tmpfs", MS_RDONLY, NULL) == -1)
-			die("blocking firmware in parent ns failed\n");
+			die("blocking firmware in parent namespace failed\n");
 
  	child = fork();
  	if (child == -1) {
@@ -99,11 +99,11 @@ static bool test_fw_in_ns(const char *fw_name, const char *sys_path, bool block_
  			strerror(errno));
  	}
  	if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL) == -1)
-		die("remount root in child ns failed\n");
+		die("remount root in child namespace failed\n");
 
  	if (!block_fw_in_parent_ns) {
  		if (mount("test", "/lib/firmware", "tmpfs", MS_RDONLY, NULL) == -1)
-			die("blocking firmware in child ns failed\n");
+			die("blocking firmware in child namespace failed\n");
  	} else
  		umount("/lib/firmware");
 

tools/testing/selftests/firmware/fw_namespace.c int main(int argc, char **argv) · line 132

Quoted 4 lines
tools/testing/selftests/firmware/fw_namespace.c +0 -1
@@ -129,8 +129,8 @@ int main(int argc, char **argv)
  		die("error: failed to build full fw_path\n");
 
  	setup_fw(fw_path);
-

Why did you remove this line?

tools/testing/selftests/firmware/fw_namespace.c int main(int argc, char **argv) · line 133

Quoted 2 lines
tools/testing/selftests/firmware/fw_namespace.c +1 -0
  	setvbuf(stdout, NULL, _IONBF, 0);
+

Why is this line added

tools/testing/selftests/firmware/fw_namespace.c int main(int argc, char **argv) · line 136

Quoted 3 lines
tools/testing/selftests/firmware/fw_namespace.c +0 -0
  	/* Positive case: firmware in PID1 mount namespace */
  	printf("Testing with firmware in parent namespace (assumed to be same file system as PID1)\n");
  	if (!test_fw_in_ns(fw_name, sys_path, false))

The rest looks good to me.

thanks,
-- Shuah

#2 lore raw
Quoted 6 lines · Shuah Khan
Quoted 1 line · Harshal

Specify details in logs of failed cases

How about changing the above to:

Improve error messages adding details on failuires

Will change this in next patch

Quoted 6 lines

tools/testing/selftests/firmware/fw_namespace.c static void trigger_fw(const char *fw_name, const char *sys_path) · line 41

Quoted 4 lines
  	fd = open(sys_path, O_WRONLY);
  	if (fd < 0)
tools/testing/selftests/firmware/fw_namespace.c +1 -1
-		die("open failed: %s\n",
+		die("open of sys_path failed: %s\n",

Why not just use sys_path as a input parameter to die()?

Sure, that's great. Is there a way to test these changes ?

Quoted 7 lines

tools/testing/selftests/firmware/fw_namespace.c int main(int argc, char **argv) · line 131

Quoted 4 lines
tools/testing/selftests/firmware/fw_namespace.c +0 -1
@@ -129,8 +129,8 @@ int main(int argc, char **argv)
  		die("error: failed to build full fw_path\n");
  	setup_fw(fw_path);
-

Why did you remove this line?

Will remove this change.

Quoted 4 lines

tools/testing/selftests/firmware/fw_namespace.c int main(int argc, char **argv) · line 133

Quoted 2 lines
tools/testing/selftests/firmware/fw_namespace.c +1 -0
  	setvbuf(stdout, NULL, _IONBF, 0);
+

Why is this line added

This too.

Thanks,
Harshal

maintainer
#3 lore raw
Quoted 9 lines · Harshal Wadhwa
Quoted 6 lines · Shuah Khan
Quoted 1 line · Harshal

Specify details in logs of failed cases

How about changing the above to:

Improve error messages adding details on failuires

Will change this in next patch

Quoted 7 lines
Quoted 6 lines

tools/testing/selftests/firmware/fw_namespace.c static void trigger_fw(const char *fw_name, const char *sys_path) · line 41

Quoted 4 lines
   	fd = open(sys_path, O_WRONLY);
   	if (fd < 0)
tools/testing/selftests/firmware/fw_namespace.c +1 -1
-		die("open failed: %s\n",
+		die("open of sys_path failed: %s\n",

Why not just use sys_path as a input parameter to die()?

Sure, that's great. Is there a way to test these changes ?

The same way you tested your v2 patch? How did you test this patch?

thanks,
-- Shuah