Commit 1e1837a8 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

zdtm: Add futex-rl test

To test futex robust list C/R.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 57032aff
...@@ -21,6 +21,7 @@ static/vdso00 ...@@ -21,6 +21,7 @@ static/vdso00
static/file_shared static/file_shared
static/timers static/timers
static/futex static/futex
static/futex-rl
static/xids00 static/xids00
streaming/pipe_loop00 streaming/pipe_loop00
streaming/pipe_shared00 streaming/pipe_shared00
......
...@@ -12,6 +12,7 @@ TST_NOFILE = \ ...@@ -12,6 +12,7 @@ TST_NOFILE = \
zombie00 \ zombie00 \
fpu00 \ fpu00 \
futex \ futex \
futex-rl \
mmx00 \ mmx00 \
sse00 \ sse00 \
sse20 \ sse20 \
...@@ -169,6 +170,8 @@ $(TST): $(LIB) ...@@ -169,6 +170,8 @@ $(TST): $(LIB)
futex.o: override CFLAGS += -pthread futex.o: override CFLAGS += -pthread
futex: override LDFLAGS += -pthread futex: override LDFLAGS += -pthread
futex-rl.o: override CFLAGS += -pthread
futex-rl: override LDFLAGS += -pthread
jobctl00: override LDLIBS += -lutil jobctl00: override LDLIBS += -lutil
socket_listen: override LDLIBS += -lrt socket_listen: override LDLIBS += -lrt
socket_aio: override LDLIBS += -lrt socket_aio: override LDLIBS += -lrt
......
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include "zdtmtst.h"
const char *test_doc = "Check the futex robust list c/r";
const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org>";
struct args {
task_waiter_t waiter;
int result;
};
static pid_t __gettid(void)
{
return syscall(__NR_gettid);
}
void *thread_fn(void *arg)
{
struct robust_list_head *head_orig = NULL, *head_new = NULL;
size_t len_orig = 0, len_new = 0;
struct args *args = arg;
test_msg("Obtaining old RL\n");
if (syscall(__NR_get_robust_list, __gettid(), &head_orig, &len_orig)) {
args->result = -1;
fail("__NR_get_robust_list failed");
}
test_msg("Complete\n");
task_waiter_complete(&args->waiter, 1);
if (args->result == -1)
goto out;
task_waiter_wait4(&args->waiter, 2);
test_msg("Obtaining new RL\n");
if (syscall(__NR_get_robust_list, __gettid(), &head_new, &len_new)) {
args->result = -1;
fail("__NR_get_robust_list failed");
}
if (args->result == -1)
goto out;
if (head_orig != head_new || len_orig != len_new) {
args->result = -1;
fail("comparision failed");
}
args->result = 0;
out:
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread;
struct args *args;
test_init(argc, argv);
args = (struct args *)mmap(NULL, sizeof(*args), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
if ((void *)args == MAP_FAILED) {
fail("mmap failed\n");
exit(1);
}
task_waiter_init(&args->waiter);
args->result = 0;
test_msg("Createing thread\n");
if (pthread_create(&thread, NULL, thread_fn, (void *)args)) {
fail("Can't create thread\n");
exit(1);
}
test_msg("Wait for thread work\n");
task_waiter_wait4(&args->waiter, 1);
if (args->result == -1) {
fail("thread failed\n");
exit(1);
}
test_msg("C/R cycle\n");
test_daemon();
test_waitsig();
task_waiter_complete(&args->waiter, 2);
pthread_join(thread, NULL);
if (args->result)
fail();
else
pass();
munmap((void *)args, sizeof(*args));
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment