riscv: selftests: Fix warnings pointer masking test
PATCH v5 1/1 riscv: selftests: Fix warnings pointer masking test
When compiling the pointer masking tests with -Wall this warning is present:
pointer_masking.c: In function ‘test_tagged_addr_abi_sysctl’:
pointer_masking.c:203:9: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
203 | pwrite(fd, &value, 1, 0); |
^~~~~~~~~~~~~~~~~~~~~~~~ pointer_masking.c:208:9: warning:
ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
208 | pwrite(fd, &value, 1, 0);
I came across this on riscv64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04).
Fix this by checking that the number of bytes written equal the expected number of bytes written.
---
Changes in v5:
- No longer skip second pwrite if first one fails
- Use wrapper function instead of goto (Drew)
- Link to v4: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v4-1-0c77eb725486@rivosinc.com
Changes in v4:
- Skip sysctl_enabled test if first pwrite failed
- Link to v3: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v3-1-5c28b0f9640d@rivosinc.com
Changes in v3:
- Fix sysctl enabled test case (Drew/Alex)
- Move pwrite err condition into goto (Drew)
- Link to v2: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v2-1-1bf0c5095f58@rivosinc.com
Changes in v2:
- I had ret != 2 for testing, I changed it to be ret != 1.
- Link to v1: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v1-1-ea1e9665ce7a@rivosinc.com
--- .../testing/selftests/riscv/abi/pointer_masking.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
tools/testing/selftests/riscv/abi/pointer_masking.c +16 -6
@@ -185,8 +185,20 @@ static void test_fork_exec(void) } } +static bool pwrite_wrapper (int fd,void *buf,size_t count,const char *msg) +{ +int ret =pwrite (fd, buf, count,0 ); + +if (ret != count) { +ksft_perror (msg); +return false; + } +return true; +} +static void test_tagged_addr_abi_sysctl (void ) { +char *err_pwrite_msg ="failed to write to /proc/sys/abi/tagged_addr_disabled\n" ;char value;int fd;
@@ -200,14 +212,12 @@ static void test_tagged_addr_abi_sysctl(void) } value ='1' ; -pwrite (fd, &value,1 ,0 ); -ksft_test_result (set_tagged_addr_ctrl (min_pmlen, true) == -EINVAL , -"sysctl disabled\n" ); +if (!pwrite_wrapper (fd, &value,1 ,"write '1'" )) +ksft_test_result_fail (err_pwrite_msg); value ='0' ; -pwrite (fd, &value,1 ,0 ); -ksft_test_result (set_tagged_addr_ctrl (min_pmlen, true) ==0 , -"sysctl enabled\n" ); +if (!pwrite_wrapper (fd, &value,1 ,"write '0'" )) +ksft_test_result_fail (err_pwrite_msg);set_tagged_addr_ctrl (0 , false);
---
base-commit: 40384c840ea1944d7c5a392e8975ed088ecf0b37
change-id: 20241204-fix_warnings_pointer_masking_tests-3860e4f35429
Signature · 1 line
- Charlie
Quoted 88 lines · Charlie Jenkins
When compiling the pointer masking tests with -Wall this warning is present:
pointer_masking.c: In function ‘test_tagged_addr_abi_sysctl’:
pointer_masking.c:203:9: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
203 |pwrite(fd, &value, 1, 0); |^~~~~~~~~~~~~~~~~~~~~~~~ pointer_masking.c:208:9: warning:ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
208 |pwrite(fd, &value, 1, 0);I came across this on riscv64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04).
Fix this by checking that the number of bytes written equal the expected number of bytes written.
Fixes 7470b5afd150 ("riscv: selftests: Add a pointer masking test")Signed-off-by Charlie Jenkins <[email protected]>---
Changes in v5:
- No longer skip second pwrite if first one fails
- Use wrapper function instead of goto (Drew)
- Link to v4: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v4-1-0c77eb725486@rivosinc.comChanges in v4:
- Skipsysctl_enabledtest if first pwrite failed
- Link to v3: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v3-1-5c28b0f9640d@rivosinc.comChanges in v3:
- Fix sysctl enabled test case (Drew/Alex)
- Move pwrite err condition into goto (Drew)
- Link to v2: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v2-1-1bf0c5095f58@rivosinc.comChanges in v2:
- I had ret != 2 for testing, I changed it to be ret != 1.
- Link to v1: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v1-1-ea1e9665ce7a@rivosinc.com--- .../testing/selftests/riscv/abi/pointer_masking.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)tools/testing/selftests/riscv/abi/pointer_masking.c +16
-7@@ -185,8 +185,20 @@ static void test_fork_exec(void) } } +static bool pwrite_wrapper (int fd,void *buf,size_t count,const char *msg) +{ +int ret =pwrite (fd, buf, count,0 ); + +if (ret != count) { +ksft_perror (msg); +return false; + } +return true; +} +static void test_tagged_addr_abi_sysctl (void ) { +char *err_pwrite_msg ="failed to write to /proc/sys/abi/tagged_addr_disabled\n" ;char value;int fd;@@ -200,14 +212,12 @@ static void test_tagged_addr_abi_sysctl(void) } value ='1' ; -pwrite (fd, &value,1 ,0 ); -ksft_test_result (set_tagged_addr_ctrl (min_pmlen, true) == -EINVAL , -"sysctl disabled\n" ); +if (!pwrite_wrapper (fd, &value,1 ,"write '1'" )) +ksft_test_result_fail (err_pwrite_msg); value ='0' ; -pwrite (fd, &value,1 ,0 ); -ksft_test_result (set_tagged_addr_ctrl (min_pmlen, true) ==0 , -"sysctl enabled\n" ); +if (!pwrite_wrapper (fd, &value,1 ,"write '0'" )) +ksft_test_result_fail (err_pwrite_msg);set_tagged_addr_ctrl (0 , false); ---
Quoted 5 lines
base-commit:
40384c840ea1944d7c5a392e8975ed088ecf0b37
change-id: 20241204-fix_warnings_pointer_masking_tests-3860e4f35429Signature · 1 line
- Charlie
Thanks,
drew
Hi Charlie,
Quoted 73 lines · Charlie Jenkins
When compiling the pointer masking tests with -Wall this warning is present:
pointer_masking.c: In function ‘test_tagged_addr_abi_sysctl’:
pointer_masking.c:203:9: warning: ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
203 |pwrite(fd, &value, 1, 0); |^~~~~~~~~~~~~~~~~~~~~~~~ pointer_masking.c:208:9: warning:ignoring return value of ‘pwrite’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
208 |pwrite(fd, &value, 1, 0);I came across this on riscv64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04).
Fix this by checking that the number of bytes written equal the expected number of bytes written.
Fixes 7470b5afd150 ("riscv: selftests: Add a pointer masking test")Signed-off-by Charlie Jenkins <[email protected]>---
Changes in v5:
- No longer skip second pwrite if first one fails
- Use wrapper function instead of goto (Drew)
- Link to v4: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v4-1-0c77eb725486@rivosinc.comChanges in v4:
- Skipsysctl_enabledtest if first pwrite failed
- Link to v3: https://lore.kernel.org/r/20241205-fix_warnings_pointer_masking_tests-v3-1-5c28b0f9640d@rivosinc.comChanges in v3:
- Fix sysctl enabled test case (Drew/Alex)
- Move pwrite err condition into goto (Drew)
- Link to v2: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v2-1-1bf0c5095f58@rivosinc.comChanges in v2:
- I had ret != 2 for testing, I changed it to be ret != 1.
- Link to v1: https://lore.kernel.org/r/20241204-fix_warnings_pointer_masking_tests-v1-1-ea1e9665ce7a@rivosinc.com--- .../testing/selftests/riscv/abi/pointer_masking.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)tools/testing/selftests/riscv/abi/pointer_masking.c +12
-2@@ -185,8 +185,20 @@ static void test_fork_exec(void) } } +static bool pwrite_wrapper (int fd,void *buf,size_t count,const char *msg) +{ +int ret =pwrite (fd, buf, count,0 ); + +if (ret != count) { +ksft_perror (msg); +return false; + } +return true; +} +static void test_tagged_addr_abi_sysctl (void ) { +char *err_pwrite_msg ="failed to write to /proc/sys/abi/tagged_addr_disabled\n" ;char value;int fd;@@ -200,14 +212,12 @@ static void test_tagged_addr_abi_sysctl(void) } value ='1' ; -pwrite (fd, &value,1 ,0 ); - ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL,
tools/testing/selftests/riscv/abi/pointer_masking.c static void test_tagged_addr_abi_sysctl(void) · line 220
Quoted 10 lines
tools/testing/selftests/riscv/abi/pointer_masking.c +4
-4- "sysctl disabled\n"); +if (!pwrite_wrapper (fd, &value,1 ,"write '1'" )) +ksft_test_result_fail (err_pwrite_msg); value ='0' ; -pwrite (fd, &value,1 ,0 ); -ksft_test_result (set_tagged_addr_ctrl (min_pmlen, true) ==0 , -"sysctl enabled\n" ); +if (!pwrite_wrapper (fd, &value,1 ,"write '0'" )) +ksft_test_result_fail (err_pwrite_msg);
You've removed the ksft_test_result() calls, which contain the actual behavioral tests (set_tagged_addr_ctrl()), so the test no longer does anything but toggle the sysctl:
# Testing fork/exec behavior
ok 55 dereference after fork
ok 56 dereference after fork+exec
# Testing tagged address ABI sysctl
# Testing tagged address ABI
ok 57 PMLEN=0 tagged address ABI
ok 58 PMLEN=7 tagged address ABI
ok 59 PMLEN=16 tagged address ABI
# Planned tests != run tests (61 != 59)
# Totals: pass:59 fail:0 xfail:0 xpass:0 skip:0 error:0
It does do the right thing if I mount --bind /dev/full /proc/sys/abi/tagged_addr_disabled:
# Testing fork/exec behavior
ok 55 dereference after fork
ok 56 dereference after fork+exec
# Testing tagged address ABI sysctl
# write '1': No space left on device (28) not ok 57 failed to write to /proc/sys/abi/tagged_addr_disabled # write '0': No space left on device (28) not ok 58 failed to write to /proc/sys/abi/tagged_addr_disabled # Testing tagged address ABI ok 59 PMLEN=0 tagged address ABI ok 60 PMLEN=7 tagged address ABI ok 61 PMLEN=16 tagged address ABI # Totals: pass:59 fail:2 xfail:0 xpass:0 skip:0 error:0
So I guess the "ksft_test_result(set_tagged_addr_ctrl..." needs to go in the else case of the pwrite_wrapper() call.
Regards,
Samuel
Quoted 7 lines
tools/testing/selftests/riscv/abi/pointer_masking.c +0
-1set_tagged_addr_ctrl (0 , false); ---base-commit:
40384c840ea1944d7c5a392e8975ed088ecf0b37
change-id: 20241204-fix_warnings_pointer_masking_tests-3860e4f35429