• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2014 Fujitsu Ltd.
3  * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.
15  */
16 /*
17  * DESCRIPTION
18  *	msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT.
19  */
20 
21 #define _GNU_SOURCE
22 #include <sys/types.h>
23 #include <sys/ipc.h>
24 #include <sys/msg.h>
25 #include <errno.h>
26 
27 #include "test.h"
28 #include "ipcmsg.h"
29 
30 static int msg_q;
31 static int index_q;
32 static struct msginfo msginfo_buf;
33 static struct msqid_ds msgqid_buf;
34 
35 static struct test_case_t {
36 	int *queue_id;
37 	int ipc_cmd;
38 	char *name;
39 	void *buf;
40 } test_cases[] = {
41 	{&msg_q, IPC_INFO, "IPC_INFO", &msginfo_buf},
42 	{&msg_q, MSG_INFO, "MSG_INFO", &msginfo_buf},
43 	{&index_q, MSG_STAT, "MSG_STAT", &msgqid_buf},
44 };
45 
46 char *TCID = "msgctl12";
47 int TST_TOTAL = ARRAY_SIZE(test_cases);
48 
main(int argc,char * argv[])49 int main(int argc, char *argv[])
50 {
51 	int lc;
52 	int i;
53 
54 	tst_parse_opts(argc, argv, NULL, NULL);
55 
56 	setup();
57 
58 	for (lc = 0; TEST_LOOPING(lc); lc++) {
59 
60 		tst_count = 0;
61 
62 		for (i = 0; i < TST_TOTAL; i++) {
63 
64 			TEST(msgctl(*test_cases[i].queue_id,
65 				    test_cases[i].ipc_cmd, test_cases[i].buf));
66 
67 			if (TEST_RETURN == -1) {
68 				tst_resm(TFAIL,
69 					 "msgctl() test %s failed with errno: "
70 					 "%d", test_cases[i].name, TEST_ERRNO);
71 			} else {
72 				tst_resm(TPASS, "msgctl() test %s succeeded",
73 					 test_cases[i].name);
74 			}
75 		}
76 	}
77 
78 	cleanup();
79 	tst_exit();
80 }
81 
setup(void)82 void setup(void)
83 {
84 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
85 
86 	TEST_PAUSE;
87 
88 	msg_q = msgget(IPC_PRIVATE, MSG_RW);
89 	if (msg_q < 0)
90 		tst_brkm(TBROK, cleanup, "Can't create message queue");
91 
92 	index_q = msgctl(msg_q, IPC_INFO, (struct msqid_ds *)&msginfo_buf);
93 	if (index_q < 0)
94 		tst_brkm(TBROK, cleanup, "Can't create message queue");
95 }
96 
cleanup(void)97 void cleanup(void)
98 {
99 	rm_queue(msg_q);
100 }
101