Skip to contentSkip to conversation

Rewrite msgstress testing suite

PATCH In review Andrea Cervesato 3 participants 4 messages May 3, 2024 – May 7, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Rewrite msgstress testing suite

From: Andrea Cervesato <[email protected]>

msgstress testing suite has been rewritten, taking in consideration that old code was not working most of the times. The new algorithm simply generates new SysV IPC messages, spawning a sender and a receiver which will validate data.

With the new algorithm we also reduce the amount of children which we spawn, since we only have 2: sender and receiver. This permits to increase the number of messages to send and to do not be depedent from system overload.

---
Remove KEY_VAL0 and use IPC_PRIVATE
Rename *failure with *stop
Wait for all children to stop before checking *stop reader() now uses pos variable
*stop as "volatile int"

 runtest/syscalls                              |   6 +-
 runtest/syscalls-ipc                          |   6 +-
 .../kernel/syscalls/ipc/msgstress/.gitignore  |   3 -
 .../kernel/syscalls/ipc/msgstress/Makefile    |   5 -
 .../syscalls/ipc/msgstress/msgstress01.c      | 450 ++++++++----------
 .../syscalls/ipc/msgstress/msgstress02.c      | 408 ----------------
 .../syscalls/ipc/msgstress/msgstress03.c      | 299 ------------
 .../syscalls/ipc/msgstress/msgstress04.c      | 444 -----------------
 8 files changed, 207 insertions(+), 1414 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/ipc/msgstress/msgstress02.c
 delete mode 100644 testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
 delete mode 100644 testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
runtest/syscalls +2 -4
index b9dd9fec6..fabb196be 100644
@@ -864,12 +864,10 @@ msgctl03 msgctl03
 msgctl04 msgctl04
 msgctl05 msgctl05
 msgctl06 msgctl06
-msgstress01 msgstress01
-msgstress02 msgstress02
-msgstress03 msgstress03
-msgstress04 msgstress04
 msgctl12 msgctl12
 
+msgstress01 msgstress01
+
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
runtest/syscalls-ipc +2 -4
index 9860394de..8960c487c 100644
@@ -4,12 +4,10 @@ msgctl03 msgctl03
 msgctl04 msgctl04
 msgctl05 msgctl05
 msgctl06 msgctl06
-msgstress01 msgstress01
-msgstress02 msgstress02
-msgstress03 msgstress03
-msgstress04 msgstress04
 msgctl12 msgctl12
 
+msgstress01 msgstress01
+
 msgget01 msgget01
 msgget02 msgget02
 msgget03 msgget03
testcases/kernel/syscalls/ipc/msgstress/.gitignore +0 -3
index a8f675399..fe9780693 100644
@@ -1,4 +1 @@
 /msgstress01
-/msgstress02
-/msgstress03
-/msgstress04
testcases/kernel/syscalls/ipc/msgstress/Makefile +0 -5
index b821bda01..442eb87d5 100644
@@ -3,10 +3,5 @@
 
 top_srcdir              ?= ../../../../..
 
-LTPLIBS = ltpipc
-
 include $(top_srcdir)/include/mk/testcases.mk
-
-LTPLDLIBS  += -lltpipc
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/msgstress/msgstress01.c +203 -247

504 lines not on this page · raw message

testcases/kernel/syscalls/ipc/msgstress/msgstress02.c deleted +0 -408

408 lines not on this page · raw message

testcases/kernel/syscalls/ipc/msgstress/msgstress03.c deleted +0 -299

299 lines not on this page · raw message

testcases/kernel/syscalls/ipc/msgstress/msgstress04.c deleted +0 -444

444 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 71 lines
(quoted diff) +30 -35
+static void reader(const int id, const int pos)
+{
+	int size;
+	int iter = num_iterations;
+	struct sysv_msg msg_recv;
+	struct sysv_data *buff = &ipc_data[pos];
+
+	while (--iter >= 0 && !(*stop)) {
+		memset(&msg_recv, 0, sizeof(struct sysv_msg));
+
+		size = SAFE_MSGRCV(id, &msg_recv, 100, MSGTYPE, 0);
+
+		if (msg_recv.type != buff->msg.type) {
+			tst_res(TFAIL, "Received the wrong message type");
 
-	for (i = 0; i < nprocs; i++) {
-		fflush(stdout);
-		if ((pid = FORK_OR_VFORK()) < 0) {
-			tst_brkm(TFAIL,
-				 NULL,
-				 "\tFork failed (may be OK if under stress)");
+			*stop = 1;
+			return;
 		}
-		/* Child does this */
-		if (pid == 0) {
-			procstat = 1;
-			exit(dotest(keyarray[i], i));
+
+		if (msg_recv.data.len != buff->msg.data.len) {
+			tst_res(TFAIL, "Received the wrong message data length");
+
+			*stop = 1;
+			return;
 		}
-		pidarray[i] = pid;
-	}
 
-	count = 0;
-	while (1) {
-		if ((wait(&status)) > 0) {
-			if (status >> 8 != 0) {
-				tst_brkm(TFAIL, NULL,
-					 "Child exit status = %d",
-					 status >> 8);
-			}
-			count++;
-		} else {
-			if (errno != EINTR) {
-				break;
+		for (int i = 0; i < size; i++) {
+			if (msg_recv.data.pbytes[i] != buff->msg.data.pbytes[i]) {
+				tst_res(TFAIL, "Received wrong data at index %d: %x != %x", i,
+					msg_recv.data.pbytes[i],
+					buff->msg.data.pbytes[i]);
+
+				*stop = 1;
+				return;
 			}
-#ifdef DEBUG
-			tst_resm(TINFO, "Signal detected during wait");
-#endif
 		}
-	}
-	/* Make sure proper number of children exited */
-	if (count != nprocs) {
-		tst_brkm(TFAIL,
-			 NULL,
-			 "Wrong number of children exited, Saw %d, Expected %d",
-			 count, nprocs);
-	}

Review

Quoted 10 lines
(quoted diff) +5 -3
 
-	tst_resm(TPASS, "Test ran successfully!");
+		tst_res(TDEBUG, "Received correct data");
+		tst_res(TDEBUG, "msg_recv.type = %ld", msg_recv.type);
+		tst_res(TDEBUG, "msg_recv.data.len = %d", msg_recv.data.len);
+	}
 
-	cleanup();
-	tst_exit();
+	buff->id = -1;

You can't reset the buff->id to -1 here since that will cause the test to leak the message queues because the cleanup will not remove anything.

Quoted 5 lines

}

(quoted diff) +1 -1
-static int dotest(key_t key, int child_process)
+static void run(void)
 {

Review

Quoted 10 lines
(quoted diff) +2 -7
-	int id, pid;
-	int ret, status;
+	int id, pos;
 
-	sighold(SIGTERM);
-	TEST(msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR));
-	if (TEST_RETURN < 0) {
-		printf("msgget() error in child %d: %s\n",
-			child_process, strerror(TEST_ERRNO));
+	reset_messages();

And this is even a bigger problem, with that we forget the IDs on each iteration with -i so we will leak even more message queues, just check ipcs output after running this test.

I can push the patch with a following diff, if you agree:

testcases/kernel/syscalls/ipc/msgstress/msgstress01.c +11 -8
index 5851938dd..5c84957b3 100644
@@ -6,7 +6,7 @@
  * Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
  */
 
-/*
+/*\
  * [Description]
  *
  * Stress test for SysV IPC. We send multiple messages at the same time,
@@ -146,8 +146,15 @@ static void reader(const int id, const int pos)
                tst_res(TDEBUG, "msg_recv.type = %ld", msg_recv.type);
                tst_res(TDEBUG, "msg_recv.data.len = %d", msg_recv.data.len);
        }
+}
 
-       buff->id = -1;
+static void remove_queues(void)
+{
+       for (int pos = 0; pos < num_messages; pos++) {
+               struct sysv_data *buff = &ipc_data[pos];
+               if (buff->id != -1)
+                       SAFE_MSGCTL(buff->id, IPC_RMID, NULL);
+       }
 }
 
 static void run(void)
@@ -175,6 +182,7 @@ static void run(void)
        }
 
        tst_reap_children();
+       remove_queues();
 
        if (!(*stop))
                tst_res(TPASS, "Test passed. All messages have been received");
@@ -232,12 +240,7 @@ static void cleanup(void)
        if (!ipc_data)
                return;
 
-       for (int pos = 0; pos < num_messages; pos++) {
-               struct sysv_data *buff = &ipc_data[pos];
-
-               if (buff->id != -1)
-                       SAFE_MSGCTL(buff->id, IPC_RMID, NULL);
-       }
+       remove_queues();
 
        SAFE_MUNMAP(ipc_data, sizeof(struct sysv_data) * num_messages);
        SAFE_MUNMAP((void *)stop, sizeof(int));
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi!

Thanks for catching it. Yes, feel free to add it and send the patch.

Andrea

Quoted 162 lines · Cyril Hrubis

Hi!

Quoted 71 lines
(quoted diff) +30 -35
+static void reader(const int id, const int pos)
+{
+	int size;
+	int iter = num_iterations;
+	struct sysv_msg msg_recv;
+	struct sysv_data *buff = &ipc_data[pos];
+
+	while (--iter >= 0 && !(*stop)) {
+		memset(&msg_recv, 0, sizeof(struct sysv_msg));
+
+		size = SAFE_MSGRCV(id, &msg_recv, 100, MSGTYPE, 0);
+
+		if (msg_recv.type != buff->msg.type) {
+			tst_res(TFAIL, "Received the wrong message type");
 
-	for (i = 0; i < nprocs; i++) {
-		fflush(stdout);
-		if ((pid = FORK_OR_VFORK()) < 0) {
-			tst_brkm(TFAIL,
-				 NULL,
-				 "\tFork failed (may be OK if under stress)");
+			*stop = 1;
+			return;
  		}
-		/* Child does this */
-		if (pid == 0) {
-			procstat = 1;
-			exit(dotest(keyarray[i], i));
+
+		if (msg_recv.data.len != buff->msg.data.len) {
+			tst_res(TFAIL, "Received the wrong message data length");
+
+			*stop = 1;
+			return;
  		}
-		pidarray[i] = pid;
-	}
 
-	count = 0;
-	while (1) {
-		if ((wait(&status)) > 0) {
-			if (status >> 8 != 0) {
-				tst_brkm(TFAIL, NULL,
-					 "Child exit status = %d",
-					 status >> 8);
-			}
-			count++;
-		} else {
-			if (errno != EINTR) {
-				break;
+		for (int i = 0; i < size; i++) {
+			if (msg_recv.data.pbytes[i] != buff->msg.data.pbytes[i]) {
+				tst_res(TFAIL, "Received wrong data at index %d: %x != %x", i,
+					msg_recv.data.pbytes[i],
+					buff->msg.data.pbytes[i]);
+
+				*stop = 1;
+				return;
  			}
-#ifdef DEBUG
-			tst_resm(TINFO, "Signal detected during wait");
-#endif
  		}
-	}
-	/* Make sure proper number of children exited */
-	if (count != nprocs) {
-		tst_brkm(TFAIL,
-			 NULL,
-			 "Wrong number of children exited, Saw %d, Expected %d",
-			 count, nprocs);
-	}

Review

Quoted 10 lines
(quoted diff) +5 -3
 
-	tst_resm(TPASS, "Test ran successfully!");
+		tst_res(TDEBUG, "Received correct data");
+		tst_res(TDEBUG, "msg_recv.type = %ld", msg_recv.type);
+		tst_res(TDEBUG, "msg_recv.data.len = %d", msg_recv.data.len);
+	}
 
-	cleanup();
-	tst_exit();
+	buff->id = -1;

You can't reset the buff->id to -1 here since that will cause the test to leak the message queues because the cleanup will not remove anything.

Quoted 5 lines
  }
(quoted diff) +1 -1
-static int dotest(key_t key, int child_process)
+static void run(void)
  {

Review

Quoted 10 lines
(quoted diff) +2 -7
-	int id, pid;
-	int ret, status;
+	int id, pos;
 
-	sighold(SIGTERM);
-	TEST(msgget(key, IPC_CREAT | S_IRUSR | S_IWUSR));
-	if (TEST_RETURN < 0) {
-		printf("msgget() error in child %d: %s\n",
-			child_process, strerror(TEST_ERRNO));
+	reset_messages();

And this is even a bigger problem, with that we forget the IDs on each iteration with -i so we will leak even more message queues, just check ipcs output after running this test.

I can push the patch with a following diff, if you agree:

testcases/kernel/syscalls/ipc/msgstress/msgstress01.c +11 -8
index 5851938dd..5c84957b3 100644
@@ -6,7 +6,7 @@
   * Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
   */
 
-/*
+/*\
   * [Description]
   *
   * Stress test for SysV IPC. We send multiple messages at the same time,
@@ -146,8 +146,15 @@ static void reader(const int id, const int pos)
                 tst_res(TDEBUG, "msg_recv.type = %ld", msg_recv.type);
                 tst_res(TDEBUG, "msg_recv.data.len = %d", msg_recv.data.len);
         }
+}
 
-       buff->id = -1;
+static void remove_queues(void)
+{
+       for (int pos = 0; pos < num_messages; pos++) {
+               struct sysv_data *buff = &ipc_data[pos];
+               if (buff->id != -1)
+                       SAFE_MSGCTL(buff->id, IPC_RMID, NULL);
+       }
  }
 
  static void run(void)
@@ -175,6 +182,7 @@ static void run(void)
         }
 
         tst_reap_children();
+       remove_queues();
 
         if (!(*stop))
                 tst_res(TPASS, "Test passed. All messages have been received");
@@ -232,12 +240,7 @@ static void cleanup(void)
         if (!ipc_data)
                 return;
 
-       for (int pos = 0; pos < num_messages; pos++) {
-               struct sysv_data *buff = &ipc_data[pos];
-
-               if (buff->id != -1)
-                       SAFE_MSGCTL(buff->id, IPC_RMID, NULL);
-       }
+       remove_queues();
 
         SAFE_MUNMAP(ipc_data, sizeof(struct sysv_data) * num_messages);
         SAFE_MUNMAP((void *)stop, sizeof(int));
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 1 line

Thanks for catching it. Yes, feel free to add it and send the patch.

Pushed with the proposed changed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp