• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  *
4  * This program is free software;  you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  * the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.
16  */
17 
18 /*
19  * DESCRIPTION
20  * test that msgsnd() enqueues a message correctly.
21  */
22 
23 #include <errno.h>
24 #include <sys/types.h>
25 #include <sys/ipc.h>
26 #include <sys/msg.h>
27 
28 #include "tst_test.h"
29 #include "tst_safe_sysv_ipc.h"
30 #include "libnewipc.h"
31 
32 static key_t msgkey;
33 static int queue_id = -1;
34 static struct buf {
35 	long type;
36 	char text[MSGSIZE];
37 } rcv_buf, snd_buf = {MSGTYPE, "hello"};
38 
verify_msgsnd(void)39 static void verify_msgsnd(void)
40 {
41 	struct msqid_ds qs_buf;
42 
43 	TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
44 	if (TEST_RETURN == -1) {
45 		tst_res(TFAIL | TTERRNO, "msgsnd() failed");
46 		return;
47 	}
48 
49 	SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
50 
51 	if (qs_buf.msg_cbytes == MSGSIZE && qs_buf.msg_qnum == 1)
52 		tst_res(TPASS, "queue bytes and number of queues matched");
53 	else
54 		tst_res(TFAIL, "queue bytes or number of queues mismatched");
55 
56 	SAFE_MSGRCV(queue_id, &rcv_buf, MSGSIZE, 1, 0);
57 }
58 
setup(void)59 static void setup(void)
60 {
61 	msgkey = GETIPCKEY();
62 
63 	queue_id = SAFE_MSGGET(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW);
64 }
65 
cleanup(void)66 static void cleanup(void)
67 {
68 	if (queue_id != -1)
69 		SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
70 }
71 
72 static struct tst_test test = {
73 	.tid = "msgsnd01",
74 	.setup = setup,
75 	.cleanup = cleanup,
76 	.test_all = verify_msgsnd,
77 	.needs_tmpdir = 1
78 };
79