* [LTP] [PATCH] syscalls/msgsnd01: Add check for msg_lspid and msg_stime
@ 2020-07-20 2:16 Yang Xu
2020-08-13 12:30 ` Cyril Hrubis
0 siblings, 1 reply; 2+ messages in thread
From: Yang Xu @ 2020-07-20 2:16 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
.../kernel/syscalls/ipc/msgsnd/msgsnd01.c | 20 +++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index fca7c6789..6368690de 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -18,7 +18,8 @@
#include "libnewipc.h"
static key_t msgkey;
-static int queue_id = -1;
+static time_t creat_time, last_snd_time;
+static int queue_id = -1, pid;
static struct buf {
long type;
char text[MSGSIZE];
@@ -40,15 +41,30 @@ static void verify_msgsnd(void)
tst_res(TPASS, "queue bytes and number of queues matched");
else
tst_res(TFAIL, "queue bytes or number of queues mismatched");
+ if (qs_buf.msg_lspid == pid)
+ tst_res(TPASS, "PID of last msgsnd(2) matched");
+ else
+ tst_res(TFAIL, "PID of last msgsnd(2) mismatched");
+
+ if (qs_buf.msg_stime >= creat_time && qs_buf.msg_stime >= last_snd_time)
+ tst_res(TPASS, "create time = %lu, last_snd_time = %lu, msg_stime = %lu",
+ (unsigned long)creat_time, (unsigned long)last_snd_time,
+ (unsigned long)qs_buf.msg_stime);
+ else
+ tst_res(TFAIL, "create time = %lu, last_snd_time = %lu, msg_stime = %lu",
+ (unsigned long)creat_time, (unsigned long)last_snd_time,
+ (unsigned long)qs_buf.msg_stime);
SAFE_MSGRCV(queue_id, &rcv_buf, MSGSIZE, 1, 0);
+ last_snd_time = qs_buf.msg_stime;
}
static void setup(void)
{
msgkey = GETIPCKEY();
-
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
+ pid = getpid();
+ time(&creat_time);
}
static void cleanup(void)
--
2.23.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [LTP] [PATCH] syscalls/msgsnd01: Add check for msg_lspid and msg_stime
2020-07-20 2:16 [LTP] [PATCH] syscalls/msgsnd01: Add check for msg_lspid and msg_stime Yang Xu
@ 2020-08-13 12:30 ` Cyril Hrubis
0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2020-08-13 12:30 UTC (permalink / raw)
To: ltp
Hi!
I've changed how we do the timestamp check and pushed, thanks.
The timestamp check now takes time before the call and after the call
and checks that the timestamp is between these two, which in 99.9999% of
cases would be the same numbers so this is much stronger assertion than
you had there before.
See diff:
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 6368690de..5f5da52d2 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -18,7 +18,6 @@
#include "libnewipc.h"
static key_t msgkey;
-static time_t creat_time, last_snd_time;
static int queue_id = -1, pid;
static struct buf {
long type;
@@ -28,12 +27,15 @@ static struct buf {
static void verify_msgsnd(void)
{
struct msqid_ds qs_buf;
+ time_t before_snd, after_snd;
+ time(&before_snd);
TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
if (TST_RET == -1) {
tst_res(TFAIL | TTERRNO, "msgsnd() failed");
return;
}
+ time(&after_snd);
SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
@@ -41,22 +43,23 @@ static void verify_msgsnd(void)
tst_res(TPASS, "queue bytes and number of queues matched");
else
tst_res(TFAIL, "queue bytes or number of queues mismatched");
+
if (qs_buf.msg_lspid == pid)
tst_res(TPASS, "PID of last msgsnd(2) matched");
else
tst_res(TFAIL, "PID of last msgsnd(2) mismatched");
- if (qs_buf.msg_stime >= creat_time && qs_buf.msg_stime >= last_snd_time)
- tst_res(TPASS, "create time = %lu, last_snd_time = %lu, msg_stime = %lu",
- (unsigned long)creat_time, (unsigned long)last_snd_time,
- (unsigned long)qs_buf.msg_stime);
- else
- tst_res(TFAIL, "create time = %lu, last_snd_time = %lu, msg_stime = %lu",
- (unsigned long)creat_time, (unsigned long)last_snd_time,
- (unsigned long)qs_buf.msg_stime);
+ if (qs_buf.msg_stime >= before_snd && qs_buf.msg_stime <= after_snd) {
+ tst_res(TPASS, "msg_stime = %lu in [%lu, %lu]",
+ (unsigned long)qs_buf.msg_stime,
+ (unsigned long)before_snd, (unsigned long)after_snd);
+ } else {
+ tst_res(TFAIL, "msg_stime = %lu out of [%lu, %lu]",
+ (unsigned long)qs_buf.msg_stime,
+ (unsigned long)before_snd, (unsigned long)after_snd);
+ }
SAFE_MSGRCV(queue_id, &rcv_buf, MSGSIZE, 1, 0);
- last_snd_time = qs_buf.msg_stime;
}
static void setup(void)
@@ -64,7 +67,6 @@ static void setup(void)
msgkey = GETIPCKEY();
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
pid = getpid();
- time(&creat_time);
}
static void cleanup(void)
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-13 12:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-20 2:16 [LTP] [PATCH] syscalls/msgsnd01: Add check for msg_lspid and msg_stime Yang Xu
2020-08-13 12:30 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox