selftests/sched_ext: Fix unused-result warning for read()
Subsystems (2)
cover selftests/sched_ext: Fix unused-result warning for read()
The build fails under -Werror because read() ignores its return value, triggering a warn_unused_result compiler error:
init_enable_count.c: In function ‘run_test’:
init_enable_count.c:60:25: error: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
60 | read(pipe_fds[0], &buf, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as error
Check the return value of read() to satisfy the compiler and catch unexpected pipe failures.
Thanks,
cheng-yang
---
Cheng-Yang Chou (1):
selftests/sched_ext: Fix unused-result warning for read()
tools/testing/selftests/sched_ext/init_enable_count.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.48.1
PATCH 1/1 selftests/sched_ext: Fix unused-result warning for read()
The read() call in run_test() triggers a warn_unused_result compiler warning, which breaks the build under -Werror.
Check the return value of read() and exit the child process upon failure to satisfy the compiler and prevent unexpected pipe errors.
--- tools/testing/selftests/sched_ext/init_enable_count.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/sched_ext/init_enable_count.c +2 -1
@@ -57,7 +57,8 @@ static enum scx_test_status run_test(bool global)char buf;close (pipe_fds[1 ]); -read (pipe_fds[0 ], &buf,1 ); +if (read (pipe_fds[0 ], &buf,1 ) <0 ) +exit (1 );close (pipe_fds[0 ]);exit (0 ); }
Signature · 1 line
2.48.1
Quoted 5 lines · Cheng-Yang Chou
The
read()call inrun_test()triggers awarn_unused_resultcompiler warning, which breaks the build under -Werror.Check the return value of
read()and exit the child process upon failure to satisfy the compiler and prevent unexpected pipe errors.
To be really picky I'd rephrase this part as:
Check the return value of read() and exit the child process on failure to satisfy the compiler and handle pipe read errors.
"Prevent" suggests avoiding the error, which isn't what the patch does. But it also looks good as it is.
Thanks,
-Andrea
Quoted 23 lines
Signed-off-by Cheng-Yang Chou <[email protected]>--- tools/testing/selftests/sched_ext/init_enable_count.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/testing/selftests/sched_ext/init_enable_count.c +2
-1@@ -57,7 +57,8 @@ static enum scx_test_status run_test(bool global)char buf;close (pipe_fds[1 ]); -read (pipe_fds[0 ], &buf,1 ); +if (read (pipe_fds[0 ], &buf,1 ) <0 ) +exit (1 );close (pipe_fds[0 ]);exit (0 ); }Signature · 1 line
2.48.1
PATCH 1/1 selftests/sched_ext: Fix unused-result warning for read()
The read() call in run_test() triggers a warn_unused_result compiler warning, which breaks the build under -Werror.
Check the return value of read() and exit the child process on failure to satisfy the compiler and handle pipe read errors.
---
v2: - Clarify error handling in commit message (Andrea Righi)
tools/testing/selftests/sched_ext/init_enable_count.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/sched_ext/init_enable_count.c +2 -1
@@ -57,7 +57,8 @@ static enum scx_test_status run_test(bool global)char buf;close (pipe_fds[1 ]); -read (pipe_fds[0 ], &buf,1 ); +if (read (pipe_fds[0 ], &buf,1 ) <0 ) +exit (1 );close (pipe_fds[0 ]);exit (0 ); }
Signature · 1 line
2.48.1
Quoted 2 lines
Cheng-Yang Chou (1):
selftests/sched_ext: Fix unused-result warning forread()
Applied to sched_ext/for-7.0-fixes.
Thanks.
--
tejun