Skip to content

Commit c2dcdc8

Browse files
xuyang0410metan-ucw
authored andcommitted
ipc/msgrcv0*: cleanup && convert to new API
1) The msgrcv03,04 was merged into msgrcv02 2) take use of IPC related macros 3) msgrcv08 is a valid test on 64bit enable it as well Signed-off-by: Yang Xu <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent db9b5af commit c2dcdc8

File tree

12 files changed

+348
-1326
lines changed

12 files changed

+348
-1326
lines changed

runtest/syscalls

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,6 @@ msgget03 msgget03
811811

812812
msgrcv01 msgrcv01
813813
msgrcv02 msgrcv02
814-
msgrcv03 msgrcv03
815-
msgrcv04 msgrcv04
816814
msgrcv05 msgrcv05
817815
msgrcv06 msgrcv06
818816
msgrcv07 msgrcv07

runtest/syscalls-ipc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ msgget03 msgget03
1515

1616
msgrcv01 msgrcv01
1717
msgrcv02 msgrcv02
18-
msgrcv03 msgrcv03
19-
msgrcv04 msgrcv04
2018
msgrcv05 msgrcv05
2119
msgrcv06 msgrcv06
2220
msgrcv07 msgrcv07

testcases/kernel/syscalls/ipc/msgrcv/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/msgrcv01
22
/msgrcv02
3-
/msgrcv03
4-
/msgrcv04
53
/msgrcv05
64
/msgrcv06
75
/msgrcv07

testcases/kernel/syscalls/ipc/msgrcv/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
top_srcdir ?= ../../../../..
55

6-
LTPLIBS = ltpipc
6+
LTPLIBS = ltpnewipc
77

88
include $(top_srcdir)/include/mk/testcases.mk
99

10-
LTPLDLIBS = -lltpipc
10+
LTPLDLIBS = -lltpnewipc
1111

1212
include $(top_srcdir)/include/mk/generic_leaf_target.mk
Lines changed: 38 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,55 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
12
/*
3+
* Copyright (c) International Business Machines Corp., 2001
24
*
3-
* Copyright (c) International Business Machines Corp., 2001
4-
*
5-
* This program is free software; you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation; either version 2 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13-
* the GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
19-
20-
/*
21-
* NAME
22-
* msgrcv01.c
23-
*
24-
* DESCRIPTION
25-
* msgrcv01 - test that msgrcv() receives the expected message
26-
*
27-
* ALGORITHM
28-
* create a message queue
29-
* initialize a message buffer with a known message and type
30-
* loop if that option was specified
31-
* fork a child to receive the message
32-
* parent enqueues the message then exits
33-
* check the return code
34-
* if failure, issue a FAIL message.
35-
* otherwise,
36-
* if doing functionality testing
37-
* build a new message and compare it to the one received
38-
* if they are the same,
39-
* issue a PASS message
40-
* otherwise
41-
* issue a FAIL message
42-
* call cleanup
43-
*
44-
* USAGE: <for command-line>
45-
* msgrcv01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
46-
* where, -c n : Run n copies concurrently.
47-
* -f : Turn off functionality Testing.
48-
* -i n : Execute test n times.
49-
* -I x : Execute test for x seconds.
50-
* -P x : Pause for x seconds between iterations.
51-
* -t : Turn on syscall timing.
52-
*
53-
* HISTORY
54-
* 03/2001 - Written by Wayne Boyer
55-
*
56-
* RESTRICTIONS
57-
* none
5+
* msgrcv01 - test that msgrcv() receives the expected message
586
*/
597

608
#include <string.h>
619
#include <sys/wait.h>
62-
63-
#include "test.h"
64-
65-
#include "ipcmsg.h"
66-
67-
void cleanup(void);
68-
void setup(void);
69-
void do_child(void);
70-
71-
char *TCID = "msgrcv01";
72-
int TST_TOTAL = 1;
73-
74-
int msg_q_1;
75-
MSGBUF snd_buf, rcv_buf, cmp_buf;
76-
77-
pid_t c_pid;
78-
79-
int main(int ac, char **av)
10+
#include "tst_test.h"
11+
#include "tst_safe_sysv_ipc.h"
12+
#include "libnewipc.h"
13+
14+
static key_t msgkey;
15+
static int queue_id = -1;
16+
static struct buf {
17+
long type;
18+
char mtext[MSGSIZE];
19+
} rcv_buf, snd_buf = {MSGTYPE, "hello"};
20+
21+
static void verify_msgrcv(void)
8022
{
81-
int lc;
82-
void check_functionality(void);
83-
int status, e_code;
84-
85-
tst_parse_opts(ac, av, NULL, NULL);
86-
87-
#ifdef UCLINUX
88-
maybe_run_child(&do_child, "d", &msg_q_1);
89-
#endif
90-
91-
setup(); /* global setup */
92-
93-
/* The following loop checks looping state if -i option given */
94-
95-
for (lc = 0; TEST_LOOPING(lc); lc++) {
96-
/* reset tst_count in case we are looping */
97-
tst_count = 0;
98-
99-
/*
100-
* fork a child to read from the queue while the parent
101-
* enqueues the message to be read.
102-
*/
103-
if ((c_pid = FORK_OR_VFORK()) == -1) {
104-
tst_brkm(TBROK, cleanup, "could not fork");
105-
}
106-
107-
if (c_pid == 0) { /* child */
108-
#ifdef UCLINUX
109-
if (self_exec(av[0], "d", msg_q_1) < 0) {
110-
tst_brkm(TBROK, cleanup, "could not self_exec");
111-
}
112-
#else
113-
do_child();
114-
#endif
115-
} else { /* parent */
116-
/* put the message on the queue */
117-
if (msgsnd(msg_q_1, &snd_buf, MSGSIZE, 0) == -1) {
118-
tst_brkm(TBROK, cleanup,
119-
"Couldn't enqueue" " message");
120-
}
121-
/* wait for the child to finish */
122-
wait(&status);
123-
/* make sure the child returned a good exit status */
124-
e_code = status >> 8;
125-
if (e_code != 0) {
126-
tst_resm(TFAIL, "Failures reported above");
127-
}
23+
SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
12824

129-
}
25+
TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
26+
if (TST_RET == -1) {
27+
tst_res(TFAIL | TTERRNO, "msgrcv failed");
28+
return;
13029
}
131-
132-
cleanup();
133-
tst_exit();
134-
135-
/** NOT REACHED **/
136-
30+
if (strcmp(rcv_buf.mtext, snd_buf.mtext) == 0)
31+
tst_res(TPASS, "message received(%s) = message sent(%s)",
32+
rcv_buf.mtext, snd_buf.mtext);
33+
else
34+
tst_res(TFAIL, "message received(%s) != message sent(%s)",
35+
rcv_buf.mtext, snd_buf.mtext);
13736
}
13837

139-
/*
140-
* do_child()
141-
*/
142-
void do_child(void)
38+
static void setup(void)
14339
{
144-
int retval = 0;
145-
146-
TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));
147-
148-
if (TEST_RETURN == -1) {
149-
retval = 1;
150-
tst_resm(TFAIL, "%s call failed - errno = %d : %s",
151-
TCID, TEST_ERRNO, strerror(TEST_ERRNO));
152-
} else {
153-
/*
154-
* Build a new message and compare it
155-
* with the one received.
156-
*/
157-
init_buf(&cmp_buf, MSGTYPE, MSGSIZE);
158-
159-
if (strcmp(rcv_buf.mtext, cmp_buf.mtext) == 0) {
160-
tst_resm(TPASS,
161-
"message received = " "message sent");
162-
} else {
163-
retval = 1;
164-
tst_resm(TFAIL,
165-
"message received != " "message sent");
166-
}
167-
}
168-
exit(retval);
40+
msgkey = GETIPCKEY();
41+
queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
16942
}
17043

171-
/*
172-
* setup() - performs all the ONE TIME setup for this test.
173-
*/
174-
void setup(void)
44+
static void cleanup(void)
17545
{
176-
177-
tst_sig(FORK, DEF_HANDLER, cleanup);
178-
179-
TEST_PAUSE;
180-
181-
/*
182-
* Create a temporary directory and cd into it.
183-
* This helps to ensure that a unique msgkey is created.
184-
* See libs/libltpipc/libipc.c for more information.
185-
*/
186-
tst_tmpdir();
187-
188-
msgkey = getipckey();
189-
190-
/* create a message queue with read/write permission */
191-
if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) {
192-
tst_brkm(TBROK, cleanup, "Can't create message queue");
193-
}
194-
195-
/* initialize the message buffer */
196-
init_buf(&snd_buf, MSGTYPE, MSGSIZE);
46+
if (queue_id != -1)
47+
SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
19748
}
19849

199-
/*
200-
* cleanup() - performs all the ONE TIME cleanup for this test at completion
201-
* or premature exit.
202-
*/
203-
void cleanup(void)
204-
{
205-
/* if it exists, remove the message queue that was created */
206-
rm_queue(msg_q_1);
207-
208-
tst_rmdir();
209-
210-
}
50+
static struct tst_test test = {
51+
.setup = setup,
52+
.cleanup = cleanup,
53+
.test_all = verify_msgrcv,
54+
.needs_tmpdir = 1,
55+
};

0 commit comments

Comments
 (0)