From e49d055b5d66bfccc19372cc908aad62dc8f63b3 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 14 Apr 2017 16:25:05 +0000 Subject: [PATCH] tests: make mq test executable reenterable * tests/mq.c (NAME): Remove. (main): Replace the fixed message queue name with a dynamically made name containing the pid of process. * tests/gen_tests.in (mq): Update -a option. --- tests/gen_tests.in | 2 +- tests/mq.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 9f91fddd..6936dd8d 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -170,7 +170,7 @@ mmsg_name -a25 -e trace=sendmmsg,recvmmsg mmsg_name-v -v -a25 -e trace=sendmmsg,recvmmsg mount move_pages -s3 -mq -a28 -e trace=mq_getsetattr,mq_open,mq_unlink +mq -a32 -e trace=mq_getsetattr,mq_open,mq_unlink mq_sendrecv -a14 -e trace=mq_open,mq_notify,mq_timedsend,mq_timedreceive,mq_unlink mq_sendrecv-read -eread=0 -a14 -e trace=mq_open,mq_notify,mq_timedsend,mq_timedreceive,mq_unlink mq_sendrecv-write -ewrite=0 -a14 -e trace=mq_open,mq_notify,mq_timedsend,mq_timedreceive,mq_unlink diff --git a/tests/mq.c b/tests/mq.c index 9c2ffc8e..12539453 100644 --- a/tests/mq.c +++ b/tests/mq.c @@ -37,17 +37,19 @@ # include # include -# define NAME "strace-mq.test" - int main (void) { struct mq_attr attr; (void) close(0); - if (mq_open("/" NAME, O_CREAT, 0700, NULL)) + char *name; + if (asprintf(&name, "/strace-mq-%u.sample", getpid()) < 0) + perror_msg_and_fail("asprintf"); + + if (mq_open(name, O_CREAT, 0700, NULL)) perror_msg_and_skip("mq_open"); - printf("mq_open(\"%s\", O_RDONLY|O_CREAT, 0700, NULL) = 0\n", NAME); + printf("mq_open(\"%s\", O_RDONLY|O_CREAT, 0700, NULL) = 0\n", name + 1); if (mq_getattr(0, &attr)) perror_msg_and_skip("mq_getattr"); @@ -63,9 +65,9 @@ main (void) (long long) attr.mq_maxmsg, (long long) attr.mq_msgsize); - if (mq_unlink("/" NAME)) + if (mq_unlink(name)) perror_msg_and_skip("mq_unlink"); - printf("mq_unlink(\"%s\") = 0\n", NAME); + printf("mq_unlink(\"%s\") = 0\n", name + 1); puts("+++ exited with 0 +++"); return 0; -- 2.50.1