Skip to contentSkip to conversation

syscalls/msgsnd01: Add check for msg_lspid and msg_stime

PATCH New Yang Xu 2 participants 2 messages Jul 20, 2020 – Aug 13, 2020

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH 1/1 syscalls/msgsnd01: Add check for msg_lspid and msg_stime

---
 .../kernel/syscalls/ipc/msgsnd/msgsnd01.c     | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c +18 -2
index fca7c6789..6368690de 100644
@@ -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)
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 syscalls/msgsnd01: Add check for msg_lspid and msg_stime

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:

testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c +13 -11
index 6368690de..5f5da52d2 100644
@@ -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)
Signature · 2 lines
Cyril Hrubis
[email protected]