Skip to content

Commit 4efc934

Browse files
xuyang0410metan-ucw
authored andcommitted
syscalls/msgstress: Add common file for msgstress
Copy old libmsgctl.c three functions(doreader,dowriter, fill_buffer, verify) into this common file. The reason for not putting it into lib directory because only msgstress cases use these functions. So raising them into lib level makes no sense. Signed-off-by: Yang Xu <[email protected]>
1 parent c07be3c commit 4efc934

File tree

3 files changed

+122
-1
lines changed

3 files changed

+122
-1
lines changed

testcases/kernel/syscalls/ipc/msgstress/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ top_srcdir ?= ../../../../..
66
LTPLIBS = ltpipc
77

88
include $(top_srcdir)/include/mk/testcases.mk
9-
9+
FILTER_OUT_MAKE_TARGETS := msgstress_common
1010
LTPLDLIBS += -lltpipc
1111

1212
include $(top_srcdir)/include/mk/generic_leaf_target.mk
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) International Business Machines Corp., 2002
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
5+
* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved。
6+
*/
7+
8+
#define TST_NO_DEFAULT_MAIN
9+
#include "msgstress_common.h"
10+
11+
int verify(char *buf, char val, int size, int child)
12+
{
13+
while (size-- > 0) {
14+
if (*buf++ != val) {
15+
tst_res(TFAIL, "Verify error in child %d, *buf = %x, "
16+
"val = %x, size = %d\n", child, *buf, val,
17+
size);
18+
return 1;
19+
}
20+
}
21+
return 0;
22+
}
23+
24+
void do_reader(long key, int tid, long type, int child, int nreps)
25+
{
26+
int i, size;
27+
int id;
28+
struct mbuffer buffer;
29+
30+
id = SAFE_MSGGET(key, 0);
31+
if (id != tid) {
32+
tst_res(TFAIL,
33+
"Message queue mismatch in the reader of child group"
34+
" %d for message queue id %d\n", child, id);
35+
return;
36+
}
37+
for (i = 0; i < nreps; i++) {
38+
memset(&buffer, 0, sizeof(buffer));
39+
40+
size = SAFE_MSGRCV(id, &buffer, 100, type, 0);
41+
if (buffer.type != type) {
42+
tst_res(TFAIL, "Type mismatch in child %d, read #%d, "
43+
"for message got %ld, exected %ld",
44+
child, (i + 1), buffer.type, type);
45+
return;
46+
}
47+
if (buffer.data.len + 1 != size) {
48+
tst_res(TFAIL, "Size mismatch in child %d, read #%d, "
49+
"for message got %d, expected %d",
50+
child, (i + 1), buffer.data.len + 1, size);
51+
return;
52+
}
53+
if (verify(buffer.data.pbytes, (key % 255), size - 1, child)) {
54+
tst_res(TFAIL, "Verify failed in child %d read # = %d, "
55+
"key = %lx\n", child, (i + 1), key);
56+
return;
57+
}
58+
key++;
59+
}
60+
}
61+
62+
void fill_buffer(char *buf, char val, int size)
63+
{
64+
int i;
65+
66+
for (i = 0; i < size; i++)
67+
buf[i] = val;
68+
}
69+
70+
void do_writer(long key, int tid, long type, int child, int nreps)
71+
{
72+
int i, size;
73+
int id;
74+
struct mbuffer buffer;
75+
76+
id = SAFE_MSGGET(key, 0);
77+
if (id != tid) {
78+
tst_res(TFAIL, "Message queue mismatch in the reader of child"
79+
" group %d for message queue id %d\n", child, id);
80+
return;
81+
}
82+
83+
for (i = 0; i < nreps; i++) {
84+
memset(&buffer, 0, sizeof(buffer));
85+
86+
do {
87+
size = (lrand48() % 99);
88+
} while (size == 0);
89+
fill_buffer(buffer.data.pbytes, (key % 255), size);
90+
buffer.data.len = size;
91+
buffer.type = type;
92+
SAFE_MSGSND(id, &buffer, size + 1, 0);
93+
key++;
94+
}
95+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
4+
* Author: Yang Xu <[email protected]>
5+
*/
6+
7+
#ifndef MSGSTRESS_COMMON_H
8+
#define MSGSTRESS_COMMON_H
9+
10+
#include <stdlib.h>
11+
#include "tst_safe_sysv_ipc.h"
12+
#include "tst_test.h"
13+
14+
struct mbuffer {
15+
long type;
16+
struct {
17+
char len;
18+
char pbytes[99];
19+
} data;
20+
};
21+
22+
void do_reader(long key, int tid, long type, int child, int nreps);
23+
void do_writer(long key, int tid, long type, int child, int nreps);
24+
25+
#endif
26+

0 commit comments

Comments
 (0)