Skip to content

Commit dac76a8

Browse files
metan-ucwpevik
authored andcommitted
syscalls/msgstress01: Fix timeouts
Make the test exit if runtime has been exhausted before we finished the requested amount of iterations. For that to happen we let the main test process to loop while checking the runtime and set the stop flag if runtime was exhausted. We also need to separate the stop and fail flag and add counter for finished children. Also if we exhaust our runtime during the initial fork phase we print a warning, since we hardly did a meaningful testing in that case. The changes can be tested with -I parameter, e.g. -I 5 should trigger the TWARN message and you should be able to get the test to stop in the message sending phase with larger -I value. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Martin Doucha <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent 8a2dca1 commit dac76a8

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

testcases/kernel/syscalls/ipc/msgstress/msgstress01.c

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static char *str_num_iterations;
5050
static int num_messages = 1000;
5151
static int num_iterations = MAXNREPS;
5252
static volatile int *stop;
53+
static volatile int *fail;
54+
static int *finished;
55+
static int *flags;
5356

5457
static int get_used_sysvipc(void)
5558
{
@@ -77,6 +80,10 @@ static void reset_messages(void)
7780

7881
for (int i = 0; i < num_messages; i++)
7982
ipc_data[i].id = -1;
83+
84+
*stop = 0;
85+
*fail = 0;
86+
*finished = 0;
8087
}
8188

8289
static int create_message(const int id)
@@ -113,6 +120,8 @@ static void writer(const int id, const int pos)
113120
tst_brk(TBROK | TERRNO, "msgsnd() failed");
114121
}
115122
}
123+
124+
tst_atomic_inc(finished);
116125
}
117126

118127
static void reader(const int id, const int pos)
@@ -139,13 +148,15 @@ static void reader(const int id, const int pos)
139148
tst_res(TFAIL, "Received the wrong message type");
140149

141150
*stop = 1;
151+
*fail = 1;
142152
return;
143153
}
144154

145155
if (msg_recv.data.len != buff->msg.data.len) {
146156
tst_res(TFAIL, "Received the wrong message data length");
147157

148158
*stop = 1;
159+
*fail = 1;
149160
return;
150161
}
151162

@@ -156,6 +167,7 @@ static void reader(const int id, const int pos)
156167
buff->msg.data.pbytes[i]);
157168

158169
*stop = 1;
170+
*fail = 1;
159171
return;
160172
}
161173
}
@@ -164,6 +176,8 @@ static void reader(const int id, const int pos)
164176
tst_res(TDEBUG, "msg_recv.type = %ld", msg_recv.type);
165177
tst_res(TDEBUG, "msg_recv.data.len = %d", msg_recv.data.len);
166178
}
179+
180+
tst_atomic_inc(finished);
167181
}
168182

169183
static void remove_queues(void)
@@ -198,12 +212,37 @@ static void run(void)
198212

199213
if (*stop)
200214
break;
215+
216+
if (!tst_remaining_runtime()) {
217+
tst_res(TWARN, "Out of runtime during forking...");
218+
*stop = 1;
219+
break;
220+
}
221+
}
222+
223+
if (!(*stop))
224+
tst_res(TINFO, "All processes running");
225+
226+
for (;;) {
227+
if (tst_atomic_load(finished) == 2 * num_messages)
228+
break;
229+
230+
if (*stop)
231+
break;
232+
233+
if (!tst_remaining_runtime()) {
234+
tst_res(TINFO, "Out of runtime, stopping processes...");
235+
*stop = 1;
236+
break;
237+
}
238+
239+
sleep(1);
201240
}
202241

203242
tst_reap_children();
204243
remove_queues();
205244

206-
if (!(*stop))
245+
if (!(*fail))
207246
tst_res(TPASS, "Test passed. All messages have been received");
208247
}
209248

@@ -244,14 +283,16 @@ static void setup(void)
244283
MAP_SHARED | MAP_ANONYMOUS,
245284
-1, 0);
246285

247-
stop = SAFE_MMAP(
286+
flags = SAFE_MMAP(
248287
NULL,
249-
sizeof(int),
288+
sizeof(int) * 3,
250289
PROT_READ | PROT_WRITE,
251290
MAP_SHARED | MAP_ANONYMOUS,
252291
-1, 0);
253292

254-
reset_messages();
293+
stop = &flags[0];
294+
fail = &flags[1];
295+
finished = &flags[2];
255296
}
256297

257298
static void cleanup(void)
@@ -262,7 +303,7 @@ static void cleanup(void)
262303
remove_queues();
263304

264305
SAFE_MUNMAP(ipc_data, sizeof(struct sysv_data) * num_messages);
265-
SAFE_MUNMAP((void *)stop, sizeof(int));
306+
SAFE_MUNMAP(flags, sizeof(int) * 3);
266307
}
267308

268309
static struct tst_test test = {
@@ -273,7 +314,8 @@ static struct tst_test test = {
273314
.max_runtime = 180,
274315
.options = (struct tst_option[]) {
275316
{"n:", &str_num_messages, "Number of messages to send (default: 1000)"},
276-
{"l:", &str_num_iterations, "Number iterations per message (default: 10000)"},
317+
{"l:", &str_num_iterations, "Number iterations per message (default: "
318+
TST_TO_STR(MAXNREPS) ")"},
277319
{},
278320
},
279321
};

0 commit comments

Comments
 (0)