syscalls/mq_timedreceive: Add check data returned from mq_timedreceive
PATCH v2 1/4 syscalls/mq_timedreceive: Add check data returned from mq_timedreceive
This is a regression from
commit 5c266719126b0e770102b787a904cf90ece922ec
Author: Petr Vorel <[email protected]> Date: Wed Mar 8 15:21:52 2017 +0100
syscalls/mq_timedreceive: convert to new API
--- .../syscalls/mq_timedreceive/mq_timedreceive01.c | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-)
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +20 -12
@@ -28,6 +28,10 @@#include "tst_sig_proc.h" #include "tst_safe_posix_ipc.h" +#define MAX_MSGSIZE 8192 +#define QUEUE_NAME "/test_mqueue" + +static char smsg[MAX_MSGSIZE ];static struct sigaction act;static pid_t pid;static int fd, fd_root;
@@ -35,7 +39,7 @@ static struct timespec timeout_ts;static struct timespec eintr_ts;struct test_case { -int len; +unsigned int len;unsigned prio;struct timespec *rq;int fd;
@@ -47,10 +51,6 @@ struct test_case {void (*cleanup)(void ); }; -#define MAX_MSGSIZE 8192 - -#define QUEUE_NAME "/test_mqueue" -static void create_queue (void );static void create_queue_nonblock (void );static void create_queue_sig (void );
@@ -175,10 +175,15 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)static void setup (void ) { +unsigned int i; + act.sa_handler = sighandler;sigaction (SIGINT , &act,NULL ); fd_root =SAFE_OPEN ("/" ,O_RDONLY ); + +for (i =0 ; i <MAX_MSGSIZE ; i++) + smsg[i] = i; }static void cleanup (void )
@@ -227,12 +232,6 @@ static void open_fd(void)static void send_msg (int fd,int len,int prio) { -char smsg[MAX_MSGSIZE ]; -int i; - -for (i =0 ; i < len; i++) - smsg[i] = i; -if (mq_timedsend (fd, smsg, len, prio, &((struct timespec ){0 })) <0 )tst_brk (TBROK |TERRNO ,"mq_timedsend failed" );
@@ -256,9 +255,10 @@ static void unlink_queue_sig(void)static void do_test (unsigned int i) { +unsigned int j;const struct test_case *tc = &tcase[i];char rmsg[MAX_MSGSIZE ]; -unsigned prio; +unsigned int prio;size_t msg_len =MAX_MSGSIZE ;/*
@@ -308,6 +308,14 @@ static void do_test(unsigned int i)return ; } +for (j =0 ; j < tc->len; j++) { +if (rmsg[j] != smsg[j]) { +tst_res (TFAIL |TTERRNO ,"mq_timedreceive wrong data in loop %d returned %d, expected %d" , + i, rmsg[j], smsg[j]); +return ; + } + } +tst_res (TPASS ,"mq_timedreceive returned %ld prio %u" ,TEST_RETURN , prio); }
Signature · 1 line
2.12.2
PATCH v2 2/4 syscalls/{mq_timedsend, mq_timedreceive}: Convert to new API + cleanup
* Convert syscalls/mq_timedsend to new API.
* Create queues in the test setup and reuse them. This requires to delete all messages at the end of each test (cleanup queue).
* Added headers mq.h (general usage for posix messages tests) and mq_timed.h (specific to mq_timedsend and mq_timedreceive) to reuse common code.
* Cleanup and unify syscalls/mq_timedsend and syscalls/mq_timedreceive.
---
This is IMHO the best balance between reducing code duplicity and not loosing readability (I know, there still a lot of common code in syscalls/mq_timedsend and syscalls/mq_timedreceive).
I tried to avoid using static variables in headers where possible.
--- testcases/kernel/syscalls/mq_timedreceive/Makefile | 1 + .../syscalls/mq_timedreceive/mq_timedreceive01.c | 249 ++------ testcases/kernel/syscalls/mq_timedsend/Makefile | 1 + .../kernel/syscalls/mq_timedsend/mq_timedsend01.c | 654 +++++++-------------- testcases/kernel/syscalls/utils/mq.h | 88 +++ testcases/kernel/syscalls/utils/mq_timed.h | 68 +++ 6 files changed, 421 insertions(+), 640 deletions(-) create mode 100644 testcases/kernel/syscalls/utils/mq.h create mode 100644 testcases/kernel/syscalls/utils/mq_timed.h
testcases/kernel/syscalls/mq_timedreceive/Makefile +1 -0
@@ -21,6 +21,7 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk CPPFLAGS ?= -D_POSIX_C_SOURCE=$(shell getconf _POSIX_MESSAGE_PASSING)L +CPPFLAGS += -I$(abs_srcdir)/../utils LDLIBS += -lpthread -lrt include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +62 -187
384 lines not on this page · raw message
testcases/kernel/syscalls/mq_timedsend/Makefile +1 -0
@@ -20,6 +20,7 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk +CPPFLAGS += -I$(abs_srcdir)/../utils LDLIBS += -lpthread -lrt include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c +201 -453
681 lines not on this page · raw message
testcases/kernel/syscalls/utils/mq.h new file +88 -0
88 lines not on this page · raw message
testcases/kernel/syscalls/utils/mq_timed.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.12.2
PATCH v2 2/4 syscalls/{mq_timedsend, mq_timedreceive}: Convert to new API + cleanup
Hi!
Quoted 5 lines
testcases/kernel/syscalls/utils/mq_timed.h new file +5
-0+static pid_t set_sig (void ) +{ +clock_gettime (CLOCK_REALTIME , &eintr_ts); + eintr_ts.tv_sec +=3 ; +
testcases/kernel/syscalls/utils/mq_timed.h line 53
Quoted 10 lines
testcases/kernel/syscalls/utils/mq_timed.h new file +10
-0+return create_sig_proc (SIGINT ,40 ,200000 ); +} + +static void set_timeout (void ) +{ +clock_gettime (CLOCK_REALTIME , &timeout_ts); + timeout_ts.tv_nsec +=50000000 ; + timeout_ts.tv_sec += timeout_ts.tv_nsec /1000000000 ; + timeout_ts.tv_nsec %=1000000000 ; +}
I went ahead and changed these two functions to get the timespec as a parameter, which eliminated need for the two global timespec variables, which made the code flow a bit easier to understand.
And pushed the patchset, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 3/4 syscalls/mq_notify: Cleanup + use mq.h header
In reply to Petr Vorel--- testcases/kernel/syscalls/mq_notify/Makefile | 1 + testcases/kernel/syscalls/mq_notify/mq_notify01.c | 222 ++++++++++------------ 2 files changed, 98 insertions(+), 125 deletions(-)
testcases/kernel/syscalls/mq_notify/Makefile +1 -0
@@ -21,6 +21,7 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk CPPFLAGS ?= -D_POSIX_C_SOURCE=$(shell getconf _POSIX_MESSAGE_PASSING)L +CPPFLAGS += -I$(abs_srcdir)/../utils LDLIBS += -lpthread -lrt include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mq_notify/mq_notify01.c +97 -125
320 lines not on this page · raw message
Signature · 1 line
2.12.2
PATCH v2 4/4 syscalls/mq_*: Cleanup unused _POSIX_C_SOURCE macro
In reply to Petr Vorel--- testcases/kernel/syscalls/mq_notify/Makefile | 1 - testcases/kernel/syscalls/mq_timedreceive/Makefile | 1 - testcases/kernel/syscalls/mq_unlink/Makefile | 1 - 3 files changed, 3 deletions(-)
testcases/kernel/syscalls/mq_notify/Makefile +0 -1
@@ -20,7 +20,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -CPPFLAGS ?= -D_POSIX_C_SOURCE=$(shell getconf _POSIX_MESSAGE_PASSING)L CPPFLAGS += -I$(abs_srcdir)/../utils LDLIBS += -lpthread -lrt
testcases/kernel/syscalls/mq_timedreceive/Makefile +0 -1
@@ -20,7 +20,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -CPPFLAGS ?= -D_POSIX_C_SOURCE=$(shell getconf _POSIX_MESSAGE_PASSING)L CPPFLAGS += -I$(abs_srcdir)/../utils LDLIBS += -lpthread -lrt
testcases/kernel/syscalls/mq_unlink/Makefile +0 -1
@@ -20,7 +20,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -CPPFLAGS ?= -D_POSIX_C_SOURCE=$(shell getconf _POSIX_MESSAGE_PASSING)L LDLIBS += -lpthread -lrt include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signature · 1 line
2.12.2
PATCH v2 1/4 syscalls/mq_timedreceive: Add check data returned from mq_timedreceive
In reply to Petr VorelHi!
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c static void do_test(unsigned int i) · line 313
Quoted 3 lines
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +3
-0+for (j =0 ; j < tc->len; j++) { +if (rmsg[j] != smsg[j]) { + tst_res(TFAIL | TTERRNO, "mq_timedreceive wrong data in loop %d returned %d, expected %d",
^
I've removed the TTERRNO here and from the previous message as well, since that will always print SUCCESS here anyway and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]