selftests/futex: Create test for robust list
André Almeida
reviewerv3 cover selftests/futex: Create test for robust list
This patchset creates a selftest for the robust list interface, to track regressions and assure that the interface keeps working as expected.
In this version I removed the kselftest_harness include, but I expanded the current futex selftest API a little bit with basic ASSERT_ macros to make the test easier to write and read. In the future, hopefully we can move all futex selftests to the kselftest_harness API anyway.
Changes from v2:
- Create ASSERT_ macros for futex selftests
- Dropped kselftest_harness include, using just futex test API
- This is the expected output:
TAP version 13
1..6
ok 1 test_robustness
ok 2 test_set_robust_list_invalid_size
ok 3 test_get_robust_list_self
ok 4 test_get_robust_list_child
ok 5 test_set_list_op_pending
ok 6 test_robust_list_multiple_elements
# Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
https://lore.kernel.org/lkml/[email protected]
André Almeida (2):
selftests/futex: Add ASSERT_ macros
selftests/futex: Create test for robust list
.../selftests/futex/functional/.gitignore | 1 + .../selftests/futex/functional/Makefile | 3 +- .../selftests/futex/functional/robust_list.c | 512 ++++++++++++++++++ .../testing/selftests/futex/include/logging.h | 28 + 4 files changed, 543 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/futex/functional/robust_list.c
Signature · 1 line
2.46.0
André Almeida
reviewerPATCH v3 1/2 selftests/futex: Add ASSERT_ macros
Create ASSERT_{EQ, NE, TRUE, FALSE} macros to make test creation easier.
--- .../testing/selftests/futex/include/logging.h | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)
tools/testing/selftests/futex/include/logging.h +28 -0
@@ -23,6 +23,34 @@#include <linux/futex.h> #include "kselftest.h" +#define ASSERT_EQ (var, value) \ + if (var != value) { \ + ksft_test_result_fail("%s: expected %ld, but %s has %ld\n", \ + __func__, (long int) value, #var, (long int) var); \ + return; \ + } + +#define ASSERT_NE (var, value) \ + if (var == value) { \ + ksft_test_result_fail("%s: expected not %ld, but %s has %ld\n", \ + __func__, (long int) value, #var, (long int) var); \ + return; \ + } + +#define ASSERT_TRUE (var) \ + if ((var) == 0) { \ + ksft_test_result_fail("%s: expected %s to be true\n", \ + __func__, #var); \ + return; \ + } + +#define ASSERT_FALSE (var) \ + if (var) { \ + ksft_test_result_fail("%s: expected %s to be false\n", \ + __func__, #var); \ + return; \ + } +/* * Define PASS, ERROR, and FAIL strings with and without color escape * sequences, default to no color.
Signature · 1 line
2.46.0
André Almeida
reviewerPATCH v3 2/2 selftests/futex: Create test for robust list
In reply to André AlmeidaCreate a test for the robust list mechanism. Test the following uAPI operations:
- Creating a robust mutex where the lock waiter is wake by the kernel when the lock owner died
- Setting a robust list to the current task
- Getting a robust list from the current task
- Getting a robust list from another task
- Using the list_op_pending field from robust_list_head struct to test robustness when the lock owner dies before completing the locking
- Setting a invalid size for syscall argument len
---
Changes from v2:
- Dropped kselftest_harness include, using just futex test API
- This is the expected output:
TAP version 13
1..6
ok 1 test_robustness
ok 2 test_set_robust_list_invalid_size
ok 3 test_get_robust_list_self
ok 4 test_get_robust_list_child
ok 5 test_set_list_op_pending
ok 6 test_robust_list_multiple_elements
# Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
Changes from v1:
- Change futex type from int to _Atomic(unsigned int)
- Use old futex(FUTEX_WAIT) instead of the new sys_futex_wait()
--- .../selftests/futex/functional/.gitignore | 1 + .../selftests/futex/functional/Makefile | 3 +- .../selftests/futex/functional/robust_list.c | 512 ++++++++++++++++++ 3 files changed, 515 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/futex/functional/robust_list.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
@@ -9,3 +9,4 @@ futex_wait_wouldblock futex_wait futex_requeue futex_waitv +robust_list
tools/testing/selftests/futex/functional/Makefile +2 -1
@@ -17,7 +17,8 @@ TEST_GEN_PROGS := \ futex_wait_private_mapped_file \ futex_wait \ futex_requeue \ - futex_waitv + futex_waitv \ + robust_list TEST_PROGS := run.sh
tools/testing/selftests/futex/functional/robust_list.c new file +512 -0
512 lines not on this page · raw message
Signature · 1 line
2.46.0
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi André,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tip/locking/core]
[also build test WARNING on linus/master v6.12-rc2 next-20241011] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andr-Almeida/selftests-futex-Add-ASSERT_-macros/20241010-091311 base: tip/locking/core patch link: https://lore.kernel.org/r/20241010011142.905297-3-andrealmeid%40igalia.com patch subject: [PATCH v3 2/2] selftests/futex: Create test for robust list
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241012/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/
All warnings (new ones prefixed by >>):
>> robust_list.c:121:44: warning: passing 'int *' to parameter of type 'unsigned int *' converts between pointers to integer types with different sign [-Wpointer-sign]
121 | if (atomic_compare_exchange_strong(futex, &zero, tid)) {
| ^~~~~ /opt/cross/clang-3b5b5c1ec4/lib/clang/18/include/stdatomic.h:144:112: note: expanded from macro 'atomic_compare_exchange_strong'
144 | #define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
| ^~~~~~~~
1 warning generated.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki