linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] selftests: firmware: Add details in error logging
@ 2025-07-14 21:26 Harshal
  2025-07-14 21:39 ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Harshal @ 2025-07-14 21:26 UTC (permalink / raw)
  To: shuah, skhan; +Cc: Harshal, linux-kselftest, linux-kernel

Specify details in logs of failed cases

Signed-off-by: Harshal <embedkari167@gmail.com>
---
v2:
- revert back to exit() instead of die() to avoid modifying system behaviour

v1: https://lore.kernel.org/all/c7c071ed-6a4e-4a9c-ba9d-c745fd42c22f@linuxfoundation.org/
 tools/testing/selftests/firmware/fw_namespace.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/firmware/fw_namespace.c b/tools/testing/selftests/firmware/fw_namespace.c
index 04757dc7e546..5b0032498ede 100644
--- a/tools/testing/selftests/firmware/fw_namespace.c
+++ b/tools/testing/selftests/firmware/fw_namespace.c
@@ -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))
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] selftests: firmware: Add details in error logging
  2025-07-14 21:26 [PATCH v2] selftests: firmware: Add details in error logging Harshal
@ 2025-07-14 21:39 ` Shuah Khan
  2025-07-20 18:21   ` Harshal Wadhwa
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2025-07-14 21:39 UTC (permalink / raw)
  To: Harshal, shuah; +Cc: linux-kselftest, linux-kernel, Shuah Khan

On 7/14/25 15:26, Harshal wrote:
> Specify details in logs of failed cases

How about changing the above to:

Improve error messages adding details on failuires

> 
> Signed-off-by: Harshal <embedkari167@gmail.com>
> ---
> v2:
> - revert back to exit() instead of die() to avoid modifying system behaviour
> 
> v1: https://lore.kernel.org/all/c7c071ed-6a4e-4a9c-ba9d-c745fd42c22f@linuxfoundation.org/
>   tools/testing/selftests/firmware/fw_namespace.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/firmware/fw_namespace.c b/tools/testing/selftests/firmware/fw_namespace.c
> index 04757dc7e546..5b0032498ede 100644
> --- a/tools/testing/selftests/firmware/fw_namespace.c
> +++ b/tools/testing/selftests/firmware/fw_namespace.c
> @@ -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()?

>   		    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()?

>   		    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

>   		    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);
> -

Why did you remove this line?

>   	setvbuf(stdout, NULL, _IONBF, 0);
> +

Why is this line added

>   	/* 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] selftests: firmware: Add details in error logging
  2025-07-14 21:39 ` Shuah Khan
@ 2025-07-20 18:21   ` Harshal Wadhwa
  2025-07-24 20:29     ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Harshal Wadhwa @ 2025-07-20 18:21 UTC (permalink / raw)
  To: Shuah Khan; +Cc: shuah, linux-kselftest, linux-kernel

On Mon, Jul 14, 2025 at 03:39:47PM -0600, Shuah Khan wrote:
> On 7/14/25 15:26, Harshal wrote:
> > 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

> >   	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()?
Sure, that's great. Is there a way to test these changes ?

> > @@ -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.
> >   	setvbuf(stdout, NULL, _IONBF, 0);
> > +
> 
> Why is this line added
This too.

Thanks,
Harshal

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] selftests: firmware: Add details in error logging
  2025-07-20 18:21   ` Harshal Wadhwa
@ 2025-07-24 20:29     ` Shuah Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2025-07-24 20:29 UTC (permalink / raw)
  To: Harshal Wadhwa; +Cc: shuah, linux-kselftest, linux-kernel, Shuah Khan

On 7/20/25 12:21, Harshal Wadhwa wrote:
> On Mon, Jul 14, 2025 at 03:39:47PM -0600, Shuah Khan wrote:
>> On 7/14/25 15:26, Harshal wrote:
>>> 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
> 
>>>    	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()?
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-24 20:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-14 21:26 [PATCH v2] selftests: firmware: Add details in error logging Harshal
2025-07-14 21:39 ` Shuah Khan
2025-07-20 18:21   ` Harshal Wadhwa
2025-07-24 20:29     ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).