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 *	msgctl13 - test for IPC_RMID
19 */
20
21#include <sys/types.h>
22#include <sys/ipc.h>
23#include <sys/msg.h>
24#include <errno.h>
25
26#include "test.h"
27#include "ipcmsg.h"
28
29char *TCID = "msgctl13";
30int TST_TOTAL = 1;
31static struct msqid_ds buf;
32
33static void msgctl_verify(void);
34
35int main(int argc, char *argv[])
36{
37	int lc;
38
39	tst_parse_opts(argc, argv, NULL, NULL);
40
41	setup();
42
43	for (lc = 0; TEST_LOOPING(lc); lc++) {
44
45		tst_count = 0;
46
47		msgctl_verify();
48	}
49
50	cleanup();
51	tst_exit();
52}
53
54void setup(void)
55{
56	tst_sig(NOFORK, DEF_HANDLER, cleanup);
57
58	TEST_PAUSE;
59}
60
61static void msgctl_verify(void)
62{
63	int msg_q;
64
65	msg_q = msgget(IPC_PRIVATE, MSG_RW);
66	if (msg_q == -1)
67		tst_brkm(TBROK, cleanup, "Can't create message queue");
68
69	TEST(msgctl(msg_q, IPC_RMID, NULL));
70
71	if (TEST_RETURN != 0) {
72		tst_resm(TFAIL, "msgctl() test IPC_RMID failed with errno: %d",
73			 TEST_ERRNO);
74		return;
75	}
76
77	TEST(msgctl(msg_q, IPC_STAT, &buf));
78	if (TEST_ERRNO == EINVAL)
79		tst_resm(TPASS, "msgctl() test IPC_RMID succeeded");
80	else
81		tst_resm(TFAIL, "msgctl() test IPC_RMID failed unexpectedly");
82}
83
84void cleanup(void)
85{
86}
87