blob: c141710293b24904645229802f35b61ab88355f6 [file] [log] [blame]
Zeng Linggang04004682014-02-06 20:02:49 +08001/*
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"
Zeng Linggang04004682014-02-06 20:02:49 +080028#include "ipcmsg.h"
29
30static int msg_q;
31static int index_q;
32static struct msginfo msginfo_buf;
33static struct msqid_ds msgqid_buf;
34
35static 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
46char *TCID = "msgctl12";
47int TST_TOTAL = ARRAY_SIZE(test_cases);
48
49int main(int argc, char *argv[])
50{
51 int lc;
Cyril Hrubis74225622014-06-02 17:54:38 +020052 const char *msg;
Zeng Linggang04004682014-02-06 20:02:49 +080053 int i;
54
55 msg = parse_opts(argc, argv, NULL, NULL);
56 if (msg != NULL)
57 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
58
59 setup();
60
61 for (lc = 0; TEST_LOOPING(lc); lc++) {
62
63 tst_count = 0;
64
65 for (i = 0; i < TST_TOTAL; i++) {
66
67 TEST(msgctl(*test_cases[i].queue_id,
68 test_cases[i].ipc_cmd, test_cases[i].buf));
69
70 if (TEST_RETURN == -1) {
71 tst_resm(TFAIL,
72 "msgctl() test %s failed with errno: "
73 "%d", test_cases[i].name, TEST_ERRNO);
74 } else {
75 tst_resm(TPASS, "msgctl() test %s succeeded",
76 test_cases[i].name);
77 }
78 }
79 }
80
81 cleanup();
82 tst_exit();
83}
84
85void setup(void)
86{
87 tst_sig(NOFORK, DEF_HANDLER, cleanup);
88
89 TEST_PAUSE;
90
91 msg_q = msgget(IPC_PRIVATE, MSG_RW);
92 if (msg_q < 0)
93 tst_brkm(TBROK, cleanup, "Can't create message queue");
94
95 index_q = msgctl(msg_q, IPC_INFO, (struct msqid_ds *)&msginfo_buf);
96 if (index_q < 0)
97 tst_brkm(TBROK, cleanup, "Can't create message queue");
98}
99
100void cleanup(void)
101{
102 rm_queue(msg_q);
Zeng Linggang04004682014-02-06 20:02:49 +0800103}