From: Dmitry V. Levin Date: Tue, 2 Aug 2016 16:47:34 +0000 (+0000) Subject: tests: simplify attach-f-p.test X-Git-Tag: v4.14~229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c416ff5ffa63dd502e525b36c4614a5e4b7b05f0;p=strace tests: simplify attach-f-p.test * tests/attach-f-p.c Simplify communications between threads by replacing per-thread timers with pipes. * tests/attach-f-p.test: Do not ignore signals. --- diff --git a/tests/attach-f-p.c b/tests/attach-f-p.c index 8e0f2058..8a733d05 100644 --- a/tests/attach-f-p.c +++ b/tests/attach-f-p.c @@ -31,10 +31,8 @@ #include #include #include -#include #include #include -#include #include #include @@ -45,38 +43,24 @@ typedef union { pid_t pid; } retval_t; -typedef struct { - sigset_t set; - unsigned int no; -} thread_arg_t; - static const char text_parent[] = "attach-f-p.test parent"; static const char *child[N] = { "attach-f-p.test child 0", "attach-f-p.test child 1", "attach-f-p.test child 2" }; -static const int sigs[N] = { SIGALRM, SIGUSR1, SIGUSR2 }; -static const struct itimerspec its[N] = { - { .it_value.tv_sec = 1 }, - { .it_value.tv_sec = 2 }, - { .it_value.tv_sec = 3 } -}; -static thread_arg_t args[N] = { - { .no = 0 }, - { .no = 1 }, - { .no = 2 } -}; +typedef int pipefd[2]; +static pipefd pipes[N]; static void * thread(void *a) { - thread_arg_t *arg = a; - int signo; - errno = sigwait(&arg->set, &signo); - if (errno) - perror_msg_and_fail("sigwait"); - assert(chdir(child[arg->no]) == -1); + unsigned int no = (long) a; + int i; + + if (read(pipes[no][0], &i, sizeof(i)) != (int) sizeof(i)) + perror_msg_and_fail("read[%u]", no); + assert(chdir(child[no]) == -1); retval_t retval = { .pid = syscall(__NR_gettid) }; return retval.ptr; } @@ -84,31 +68,17 @@ thread(void *a) int main(void) { - static timer_t timerid[N]; pthread_t t[N]; unsigned int i; - for (i = 0; i < N; ++i) { - sigemptyset(&args[i].set); - sigaddset(&args[i].set, sigs[i]); - - errno = pthread_sigmask(SIG_BLOCK, &args[i].set, NULL); - if (errno) - perror_msg_and_fail("pthread_sigmask"); - } + if (write(3, "", 0) != 0) + perror_msg_and_fail("write"); for (i = 0; i < N; ++i) { - struct sigevent sev = { - .sigev_notify = SIGEV_SIGNAL, - .sigev_signo = sigs[i] - }; - if (timer_create(CLOCK_MONOTONIC, &sev, &timerid[i])) - perror_msg_and_skip("timer_create"); - - if (timer_settime(timerid[i], 0, &its[i], NULL)) - perror_msg_and_fail("timer_settime"); + if (pipe(pipes[i])) + perror_msg_and_fail("pipe"); - errno = pthread_create(&t[i], NULL, thread, (void *) &args[i]); + errno = pthread_create(&t[i], NULL, thread, (void *) (long) i); if (errno) perror_msg_and_fail("pthread_create"); } @@ -117,6 +87,10 @@ main(void) perror_msg_and_fail("write"); for (i = 0; i < N; ++i) { + /* sleep a bit to let the tracer catch up */ + sleep(1); + if (write(pipes[i][1], &i, sizeof(i)) != (int) sizeof(i)) + perror_msg_and_fail("write[%u]", i); retval_t retval; errno = pthread_join(t[i], &retval.ptr); if (errno) @@ -128,12 +102,7 @@ main(void) } /* sleep a bit more to let the tracer catch up */ - if (timer_settime(timerid[0], 0, &its[0], NULL)) - perror_msg_and_fail("timer_settime"); - int signo; - errno = sigwait(&args[0].set, &signo); - if (errno) - perror_msg_and_fail("sigwait"); + sleep(1); pid_t pid = getpid(); assert(chdir(text_parent) == -1); diff --git a/tests/attach-f-p.test b/tests/attach-f-p.test index 02230a07..030659a2 100755 --- a/tests/attach-f-p.test +++ b/tests/attach-f-p.test @@ -44,6 +44,6 @@ while ! [ -s "$OUT" ]; do fail_ 'set_ptracer_any sleep failed' done -run_strace -a32 -f -echdir -esignal=none -p $tracee_pid +run_strace -a32 -f -echdir -p $tracee_pid match_diff "$LOG" "$EXP" rm -f "$EXP" "$OUT"