1From cd15fde3f6ff9bff56b04090c1fde3cc40378453 Mon Sep 17 00:00:00 2001
2From: Edward Liaw <[email protected]>
3Date: Fri, 6 Oct 2023 20:04:21 +0000
4Subject: [PATCH] futex: Skip when futex_waitv/shmget not implemented
5
6getshm and futex_waitv are not implemented in Android.  These rely on
7System V shared memory functions which is disallowed by selinux.
8
9Bug: 234151152
10Test: atest vts_linux_kselftest_arm_64:futex_functional_run.sh_arm_64
11Signed-off-by: Edward Liaw <[email protected]>
12---
13 .../testing/selftests/futex/functional/futex_wait.c |  5 +++++
14 .../selftests/futex/functional/futex_wait_timeout.c | 11 ++++++++---
15 .../futex/functional/futex_wait_wouldblock.c        | 13 +++++++++----
16 tools/testing/selftests/futex/functional/run.sh     |  6 ++----
17 4 files changed, 24 insertions(+), 11 deletions(-)
18
19diff --git a/tools/testing/selftests/futex/functional/futex_wait.c b/tools/testing/selftests/futex/functional/futex_wait.c
20index 685140d9b93d..6267680c3567 100644
21--- a/tools/testing/selftests/futex/functional/futex_wait.c
22+++ b/tools/testing/selftests/futex/functional/futex_wait.c
23@@ -96,6 +96,11 @@ int main(int argc, char *argv[])
24 	/* Testing an anon page shared memory */
25 	shm_id = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666);
26 	if (shm_id < 0) {
27+		if (errno == ENOSYS) {
28+			ksft_test_result_skip("shmget returned: %d %s",
29+					      errno, strerror(errno));
30+			exit(KSFT_SKIP);
31+		}
32 		perror("shmget");
33 		exit(1);
34 	}
35diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c
36index 3651ce17beeb..cff38f9de0ca 100644
37--- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c
38+++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c
39@@ -61,9 +61,14 @@ void *get_pi_lock(void *arg)
40 static void test_timeout(int res, int *ret, char *test_name, int err)
41 {
42 	if (!res || errno != err) {
43-		ksft_test_result_fail("%s returned %d\n", test_name,
44-				      res < 0 ? errno : res);
45-		*ret = RET_FAIL;
46+		if (errno == ENOSYS) {
47+			ksft_test_result_skip("%s returned %d\n", test_name,
48+					      errno);
49+		} else {
50+			ksft_test_result_fail("%s returned %d\n", test_name,
51+					      res < 0 ? errno : res);
52+			*ret = RET_FAIL;
53+		}
54 	} else {
55 		ksft_test_result_pass("%s succeeds\n", test_name);
56 	}
57diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
58index 7d7a6a06cdb7..7606440e01a0 100644
59--- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
60+++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
61@@ -98,10 +98,15 @@ int main(int argc, char *argv[])
62 	info("Calling futex_waitv on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
63 	res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC);
64 	if (!res || errno != EWOULDBLOCK) {
65-		ksft_test_result_pass("futex_waitv returned: %d %s\n",
66-				      res ? errno : res,
67-				      res ? strerror(errno) : "");
68-		ret = RET_FAIL;
69+		if (errno == ENOSYS) {
70+			ksft_test_result_skip("futex_waitv returned %d\n",
71+					      errno);
72+		} else {
73+			ksft_test_result_fail("futex_waitv returned: %d %s\n",
74+					      res ? errno : res,
75+					      res ? strerror(errno) : "");
76+			ret = RET_FAIL;
77+		}
78 	} else {
79 		ksft_test_result_pass("futex_waitv\n");
80 	}
81diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testing/selftests/futex/functional/run.sh
82index f7bd16078707..82ccc3f04d33 100755
83--- a/tools/testing/selftests/futex/functional/run.sh
84+++ b/tools/testing/selftests/futex/functional/run.sh
85@@ -84,10 +84,8 @@ echo
86 run_test ./futex_wait_uninitialized_heap $COLOR
87 run_test ./futex_wait_private_mapped_file $COLOR
88
89-# b/234151152
90-# Disable because system v shared memory not available
91-#echo
92-#run_test ./futex_wait $COLOR
93+echo
94+run_test ./futex_wait $COLOR
95
96 echo
97 run_test ./futex_requeue $COLOR
98--
992.42.0.609.gbb76f46606-goog
100
101