Musl and glibc syscall wrappers handles the null mq name in different
ways and report different errors. Glibc reports error if the mq_name
is not preceded by "/" character but musl does not treat this as an error.
Avoid the syscall wrapper by calling the syscall directly. This needs
skipping the leading "/" character in mq_name as expected by the kernel.
Signed-off-by: Amit Daniel Kachhap <amit.kachhap(a)arm.com>
---
Changes in v3:
* Updated commit messages for musl and glibc as pointed by Beata.
testcases/kernel/syscalls/mq_open/mq_open01.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/mq_open/mq_open01.c b/testcases/kernel/syscalls/mq_open/mq_open01.c
index cd2a229d8..06858991e 100644
--- a/testcases/kernel/syscalls/mq_open/mq_open01.c
+++ b/testcases/kernel/syscalls/mq_open/mq_open01.c
@@ -14,6 +14,7 @@
#include "tst_test.h"
#include "tst_safe_file_ops.h"
#include "tst_safe_posix_ipc.h"
+#include "lapi/syscalls.h"
#define QUEUE_NAME "/test_mqueue"
#define QUEUE_INIT "/init_mqueue"
@@ -95,7 +96,7 @@ static struct test_case tcase[] = {
.qname = "",
.oflag = O_CREAT,
.ret = -1,
- .err = EINVAL,
+ .err = ENOENT,
},
{
.desc = "NORMAL",
@@ -228,7 +229,10 @@ static void do_test(unsigned int i)
if (tc->setup)
tc->setup();
- TEST(fd = mq_open(qname, tc->oflag, S_IRWXU, tc->rq));
+ if (*qname == '/')
+ TEST(fd = tst_syscall(__NR_mq_open, qname + 1, tc->oflag, S_IRWXU, tc->rq));
+ else
+ TEST(fd = tst_syscall(__NR_mq_open, qname, tc->oflag, S_IRWXU, tc->rq));
if (fd > 0 && tc->rq) {
if (mq_getattr(fd, &oldattr) < 0) {
--
2.25.1
This fixes two tests that were failing in our debian distribution because
of a PID limit imposed by systemd which was not properly detected.
This was fixed by adding another file to read the max_pid from that should
be available everywhere.
This worked for msgstress04, but doing some testing msgstress03 still hit
the limit. Printing the number of PIDs in use, it seems like msgstress03
had some accounting issues, the real number of PIDs in use always being
5-10% greater than what it thought it was.
Not finding where this accounting error was, I reduced the number of
free PIDs by 10% which proved to do the trick.
I'm not too sure about these solutions and would be happy to receive some
feedback, hence the RFC state.
(It might make sense to split the patch as well, but it would be two very
small diffs.)
Thanks in advance !
Teo Couprie Diaz (1):
lib/tst_pid: Add a new file to get pid_max
lib/tst_pid.c | 4 ++++
testcases/kernel/syscalls/ipc/msgstress/msgstress03.c | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
--
2.25.1
In order to get an unmapped memory area, the test case msync03 uses sbrk
with an offset to make sure it is beyond the program break.
This causes issues in purecap, where brk is disabled, and in plain aarch64
due to a buggy sbrk implemention in Musl (ver. 1.5).
Instead, don't rely on sbrk at all and use an mmaped page, unmap it and use
this pointer in order to get an unmapped area of memory. This guarantees
an ENOMEM in both compat and purecap.
Signed-off-by: Teo Couprie Diaz <teo.coupriediaz(a)arm.com>
---
testcases/kernel/syscalls/msync/msync03.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/msync/msync03.c b/testcases/kernel/syscalls/msync/msync03.c
index 8fa62e57a..3231bac1e 100644
--- a/testcases/kernel/syscalls/msync/msync03.c
+++ b/testcases/kernel/syscalls/msync/msync03.c
@@ -120,7 +120,8 @@ static void setup(void)
nwrite += BUF_SIZE;
}
- addr1 = SAFE_MMAP(cleanup, 0, page_sz, PROT_READ | PROT_WRITE,
+ /* addr4 will point to the second page which will be unmapped. */
+ addr1 = SAFE_MMAP(cleanup, 0, page_sz*2, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_LOCKED, fd, 0);
/* addr2 is not a multiple of PAGESIZE */
@@ -130,8 +131,9 @@ static void setup(void)
SAFE_GETRLIMIT(NULL, RLIMIT_DATA, &rl);
addr3 = (char *)(uintptr_t)rl.rlim_max;
- /* memory pointed to by addr4 was not mapped */
- addr4 = sbrk(0) + (4 * page_sz);
+ /* memory pointed to by addr4 is not mapped */
+ addr4 = addr1 + page_sz;
+ SAFE_MUNMAP(cleanup, addr4, page_sz);
}
static void msync_verify(struct test_case_t *tc)
--
2.25.1
Simplify semctl03 testcases by dropping the variadicness from test
wrappers which might spin out of control if not handled correctly.
Also, it seems that the level of indirection for the valid union semun
argument went slightly too far, resulting in passing over an address of
the above mentioned union instead it's value, so fix that one as well.
Signed-off-by: Beata Michalska <beata.michalska(a)arm.com>
---
v2:
- restore test wrappers but drop variadicness from those
.../kernel/syscalls/ipc/semctl/semctl03.c | 23 +++++--------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl03.c b/testcases/kernel/syscalls/ipc/semctl/semctl03.c
index f9f335e4a..dacd929b6 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl03.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl03.c
@@ -21,28 +21,16 @@ static int sem_id = -1;
static int bad_id = -1;
static struct semid_ds sem_ds;
-static union semun sem_un = {.buf = &sem_ds};
-static void *semds_ptr = &sem_un;
+static void *semds_ptr = &sem_ds;
static void *bad_ptr;
-static union semun arg = {0};
-static int libc_semctl(int semid, int semnum, int cmd, ...)
+static int libc_semctl(int semid, int semnum, int cmd, union semun arg)
{
- va_list ap;
-
- va_start(ap, cmd);
- arg = va_arg(ap, union semun);
- va_end(ap);
return semctl(semid, semnum, cmd, arg);
}
-static int sys_semctl(int semid, int semnum, int cmd, ...)
+static int sys_semctl(int semid, int semnum, int cmd, union semun arg)
{
- va_list ap;
-
- va_start(ap, cmd);
- arg = va_arg(ap, union semun);
- va_end(ap);
return tst_syscall(__NR_semctl, semid, semnum, cmd, arg);
}
@@ -61,7 +49,7 @@ static struct tcases {
static struct test_variants
{
- int (*semctl)(int semid, int semnum, int cmd, ...);
+ int (*semctl)(int semid, int semnum, int cmd, union semun arg);
char *desc;
} variants[] = {
{ .semctl = libc_semctl, .desc = "libc semctl()"},
@@ -74,13 +62,14 @@ static void verify_semctl(unsigned int n)
{
struct tcases *tc = &tests[n];
struct test_variants *tv = &variants[tst_variant];
+ union semun arg = {.buf = *(tc->buf)};
if (tc->error == EFAULT && tv->semctl == libc_semctl) {
tst_res(TCONF, "EFAULT is skipped for libc variant");
return;
}
- TST_EXP_FAIL(tv->semctl(*(tc->sem_id), 0, tc->ipc_cmd, *(tc->buf)),
+ TST_EXP_FAIL(tv->semctl(*(tc->sem_id), 0, tc->ipc_cmd, arg),
tc->error, "semctl() with %s", tc->message);
}
--
2.25.1
In msync03, sbrk(0) was used and offset to get a pointer to an unmapped
area.
This caused issues in purecap because sbrk is now disabled, and
in compat with the 1.5 verrsion of musl because of a bug in the
sbrk implementation.
Instead, don't rely on sbrk at all and mmap a page, unmap it and use
this pointer in order to get an unmapped area of memory, generating an
ENOMEM in compat and purecap.
Signed-off-by: Teo Couprie Diaz <teo.coupriediaz(a)arm.com>
---
testcases/kernel/syscalls/msync/msync03.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/msync/msync03.c b/testcases/kernel/syscalls/msync/msync03.c
index 8fa62e57a..6d59c9d26 100644
--- a/testcases/kernel/syscalls/msync/msync03.c
+++ b/testcases/kernel/syscalls/msync/msync03.c
@@ -130,8 +130,17 @@ static void setup(void)
SAFE_GETRLIMIT(NULL, RLIMIT_DATA, &rl);
addr3 = (char *)(uintptr_t)rl.rlim_max;
- /* memory pointed to by addr4 was not mapped */
- addr4 = sbrk(0) + (4 * page_sz);
+ /* memory pointed to by addr4 is not mapped */
+ addr4 = mmap(NULL, page_sz, PROT_NONE, MAP_PRIVATE, 0, 0);
+ if (addr4 == MAP_FAILED) {
+ addr4 = NULL;
+ } else {
+ if (!munmap(addr4, page_sz))
+ tst_resm(TFAIL, "Could not setup test, munmap failed :\n%s",
+ strerror(errno));
+ }
+
+ tst_resm(TINFO, "addr4 : %p", addr4);
}
static void msync_verify(struct test_case_t *tc)
--
2.25.1