Skip to contentSkip to conversation

getrlimit/getrlimit03: fix breakage with Aarch32

PATCH New Steve Muckle 3 participants 6 messages Dec 27, 2018 – Jan 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 getrlimit/getrlimit03: fix breakage with Aarch32

A 64-bit ARM kernel running an Aarch32 user binary has the ugetrlimit and prlimit64 syscalls, but not the getrlimit syscall. This test currently assumes getrlimit is always available.

Modify the test so that it does not fail in this configuration.

---
 testcases/kernel/syscalls/getrlimit/getrlimit03.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/getrlimit/getrlimit03.c +8 -3
index 376ef7241..53a1e2c5d 100644
@@ -158,10 +158,15 @@ static void run(unsigned int resource)
 			      "rlim_max"))
 		return;
 
+	tst_res(TPASS, "__NR_prlimit64(%d) and %s(%d) gave consistent results",
+		resource, __NR_getrlimit_ulong_str, resource);
+
 #if SIGNED_GETRLIMIT
 	errno = 0;
 	ret_l = getrlimit_long(resource, &rlim_l);
 	errno_l = errno;
+	if (errno_l == ENOSYS)
+		return;
 
 	if (compare_retval(resource, ret_u64, errno_u64, ret_l, errno_l,
 			   "__NR_getrlimit") ||
@@ -170,10 +175,10 @@ static void run(unsigned int resource)
 	    compare_u64_long(resource, rlim_u64.rlim_max, rlim_l.rlim_max,
 			     "rlim_max"))
 		return;
-#endif
 
-	tst_res(TPASS, "getrlimit(%u) was consistent during all syscalls",
-		resource);
+	tst_res(TPASS, "__NR_prlimit64(%d) and __NR_getrlimit(%d) gave "
+		"consistent results", resource, resource);
+#endif
 }
 
 static struct tst_test test = {
Signature · 1 line
2.20.1.415.g653613c723-goog
#1 lore raw

PATCH 2/3 syscalls/sched_setaffinity: move cpu set macros to include/lapi

The compatibility macros for cpu sets can be used elsewhere in LTP.

---
 .../sched_setaffinity.h => include/lapi/cpuset.h            | 6 +++---
 .../kernel/syscalls/sched_setaffinity/sched_setaffinity01.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
 rename testcases/kernel/syscalls/sched_setaffinity/sched_setaffinity.h => include/lapi/cpuset.h (94%)
include/lapi/cpuset.h renamed from testcases/kernel/syscalls/sched_setaffinity/sched_setaffinity.h +3 -3
similarity index 94%
rename from testcases/kernel/syscalls/sched_setaffinity/sched_setaffinity.h
rename to include/lapi/cpuset.h
index 906864a2c..5dc3fcc05 100644
@@ -29,8 +29,8 @@
 #define _GNU_SOURCE
 #include <sched.h>
 
-#ifndef LTP_SCHED_SETAFFINITY_H
-#define LTP_SCHED_SETAFFINITY_H
+#ifndef LTP_CPUSET_H
+#define LTP_CPUSET_H
 
 #ifndef CPU_ALLOC
 #define CPU_ALLOC(ncpus) malloc(sizeof(cpu_set_t)); \
@@ -56,4 +56,4 @@ if (ncpus > CPU_SETSIZE) { \
 #define CPU_SET_S(cpu, size, mask) CPU_SET(cpu, mask)
 #endif
 
-#endif /* LTP_SCHED_SETAFFINITY_H */
+#endif /* LTP_CPUSET_H */
testcases/kernel/syscalls/sched_setaffinity/sched_setaffinity01.c +1 -1
index 43f8efc9f..e9367d603 100644
@@ -40,7 +40,7 @@
 #include <sys/wait.h>
 #include "test.h"
 #include "safe_macros.h"
-#include "sched_setaffinity.h"
+#include "lapi/cpuset.h"
 #include "lapi/syscalls.h"
 
 char *TCID = "sched_setaffinity01";
Signature · 1 line
2.20.1.415.g653613c723-goog
#2 lore raw

PATCH 3/3 syscalls/getcpu01: convert to new lib, cleanups, enable on Android

In reply to Steve Muckle

Convert getcpu01 test to new library. Also do various cleanups and enable for Android.

---
 include/lapi/cpuset.h                       |   4 +
 testcases/kernel/syscalls/getcpu/getcpu01.c | 314 ++++++--------------
 2 files changed, 102 insertions(+), 216 deletions(-)
include/lapi/cpuset.h +4 -0
index 5dc3fcc05..b94665022 100644
@@ -56,4 +56,8 @@ if (ncpus > CPU_SETSIZE) { \
 #define CPU_SET_S(cpu, size, mask) CPU_SET(cpu, mask)
 #endif
 
+#ifndef CPU_ISSET_S
+#define CPU_ISSET_S(cpu, size, mask) CPU_ISSET(cpu, mask)
+#endif
+
 #endif /* LTP_CPUSET_H */
testcases/kernel/syscalls/getcpu/getcpu01.c +98 -216

387 lines not on this page · raw message

Signature · 1 line
2.20.1.415.g653613c723-goog
#3 lore raw

PATCH 3/3 syscalls/getcpu01: convert to new lib, cleanups, enable on Android

Hi!
I've simplified the test a bit more and pushed, thanks.

The reason why the test was checking for glibc version was because the CPU_ALLOC() and friends macros were not present on old glibc, with the fallback definitions in place we can drop these ifdefs now, see patch below that I applied over your changes.

Also it seems that getcpu syscall is not specific to i386 and many architectures also have vdso implementation.

So we should probably change the test to call both getcpu syscall and sched_getcpu() library function and assert that both are correct.

testcases/kernel/syscalls/getcpu/getcpu01.c +9 -33
index b5380dbb2..eb6ded8ab 100644
@@ -15,32 +15,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
+#include "lapi/syscalls.h"
 #include "lapi/cpuset.h"
 #include "tst_test.h"
 
-#ifdef ANDROID
-	#define TEST_SUPPORTED 1
-#elif defined(__i386__) || defined(__x86_64__)
-	#if __GLIBC_PREREQ(2,6)
-		#if defined(__x86_64__)
-			#include <utmpx.h>
-		#endif
-		#define TEST_SUPPORTED 1
-	#elif defined(__i386__)
-		#define TEST_SUPPORTED 1
-	#else
-		#define TEST_SUPPORTED 0
-	#endif
-#else
-	#define TEST_SUPPORTED 0
-#endif
-
 static inline int get_cpu(unsigned *cpu_id,
 			  unsigned *node_id LTP_ATTRIBUTE_UNUSED,
 			  void *cache_struct LTP_ATTRIBUTE_UNUSED)
 {
 #if defined(__i386__)
-	return syscall(318, cpu_id, node_id, cache_struct);
+	return syscall(__NR_getcpu, cpu_id, node_id, cache_struct);
 #else
 	*cpu_id = sched_getcpu();
 #endif
@@ -66,34 +50,28 @@ static unsigned int set_cpu_affinity(void)
 	cpu_set_t *set;
 	size_t size;
 	int nrcpus = 1024;
+
 realloc:
 	set = CPU_ALLOC(nrcpus);
-	if (set == NULL) {
-		tst_brk(TBROK, "CPU_ALLOC:errno:%d", errno);
-	}
+	if (!set)
+		tst_brk(TBROK | TERRNO, "CPU_ALLOC()");
+
 	size = CPU_ALLOC_SIZE(nrcpus);
 	CPU_ZERO_S(size, set);
 	if (sched_getaffinity(0, size, set) < 0) {
 		CPU_FREE(set);
-#if __GLIBC_PREREQ(2, 7) || defined(ANDROID)
 		if (errno == EINVAL && nrcpus < (1024 << 8)) {
 			nrcpus = nrcpus << 2;
 			goto realloc;
 		}
-#else
-		if (errno == EINVAL)
-			tst_brk(TBROK,
-				"NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)");
-		else
-#endif
-			tst_brk(TBROK, "sched_getaffinity:errno:%d", errno);
+		tst_brk(TBROK | TERRNO, "sched_getaffinity()");
 	}
 	cpu_max = max_cpuid(size, set);
 	CPU_ZERO_S(size, set);
 	CPU_SET_S(cpu_max, size, set);
 	if (sched_setaffinity(0, size, set) < 0) {
 		CPU_FREE(set);
-		tst_brk(TBROK, "sched_setaffinity:errno:%d", errno);
+		tst_brk(TBROK | TERRNO, "sched_setaffinity()");
 	}
 	CPU_FREE(set);
 	return cpu_max;
@@ -104,7 +82,7 @@ static unsigned int get_nodeid(unsigned int cpu_id)
 {
 	DIR *directory_parent, *directory_node;
 	struct dirent *de, *dn;
-	char directory_path[255];
+	char directory_path[PATH_MAX];
 	unsigned int cpu;
 	int node_id = 0;
 
@@ -181,8 +159,6 @@ static void setup(void)
 {
 	if (tst_kvercmp(2, 6, 20) < 0)
 		tst_brk(TCONF, "kernel >= 2.6.20 required");
-	if (!TEST_SUPPORTED)
-		tst_brk(TCONF, "insufficient C library support");
 }
 
 static struct tst_test test = {
Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH 1/3 getrlimit/getrlimit03: fix breakage with Aarch32

In reply to Steve Muckle
Quoted 4 lines · Steve Muckle

A 64-bit ARM kernel running an Aarch32 user binary has the ugetrlimit and prlimit64 syscalls, but not the getrlimit syscall. This test currently assumes getrlimit is always available.

This patch is similar with another:
http://lists.linux.it/pipermail/ltp/2018-December/010249.html

From the structure, I think maybe this one is a tiny bit more clear than previous, but that'd be better if this can print some TCONF message for the ENOSYS.

Quoted 14 lines

Modify the test so that it does not fail in this configuration.

---
 testcases/kernel/syscalls/getrlimit/getrlimit03.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/getrlimit/getrlimit03.c +0 -0
index 376ef7241..53a1e2c5d 100644
@@ -158,10 +158,15 @@ static void run(unsigned int resource)
                              "rlim_max"))

testcases/kernel/syscalls/getrlimit/getrlimit03.c static void run(unsigned int resource) · line 168

Quoted 10 lines
testcases/kernel/syscalls/getrlimit/getrlimit03.c +4 -0
                return;
 
+       tst_res(TPASS, "__NR_prlimit64(%d) and %s(%d) gave consistent results",
+               resource, __NR_getrlimit_ulong_str, resource);
+
 #if SIGNED_GETRLIMIT
        errno = 0;
        ret_l = getrlimit_long(resource, &rlim_l);
        errno_l = errno;
+       if (errno_l == ENOSYS)

Adding tst_res(TCONF, ...) here?

Quoted 22 lines
testcases/kernel/syscalls/getrlimit/getrlimit03.c +4 -4
+               return;
 
        if (compare_retval(resource, ret_u64, errno_u64, ret_l, errno_l,
                           "__NR_getrlimit") ||
@@ -170,10 +175,10 @@ static void run(unsigned int resource)
            compare_u64_long(resource, rlim_u64.rlim_max, rlim_l.rlim_max,
                             "rlim_max"))
                return;
-#endif
 
-       tst_res(TPASS, "getrlimit(%u) was consistent during all syscalls",
-               resource);
+       tst_res(TPASS, "__NR_prlimit64(%d) and __NR_getrlimit(%d) gave "
+               "consistent results", resource, resource);
+#endif
 }
 
 static struct tst_test test = {
--

2.20.1.415.g653613c723-goog

Quoted 2 lines

--
Mailing list info: https://lists.linux.it/listinfo/ltp

--
Regards,
Li Wang

#5 lore raw

PATCH 1/3 getrlimit/getrlimit03: fix breakage with Aarch32

In reply to Steve Muckle

Hi!
As Li pointed out there was patch from Ritchie trying to fix the same issue. In the end I've taken your patch and added the TCONF message and updated the commit message with info from the other patch.

And pushed with these modifications, thanks!

Signature · 2 lines
Cyril Hrubis
[email protected]