1 /* 2 * Copyright (c) 2014 Fujitsu Ltd. 3 * Author: Zeng Linggang <zenglg.jy (at) cn.fujitsu.com> 4 * Copyright (c) 2018 Cyril Hrubis <chrubis (at) suse.cz> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of version 2 of the GNU General Public License as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it would be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program. 16 */ 17 /* 18 * msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT. 19 */ 20 21 #define _GNU_SOURCE 22 #include <errno.h> 23 24 #include "tst_test.h" 25 #include "tst_safe_sysv_ipc.h" 26 #include "libnewipc.h" 27 28 static int msg_q = -1; 29 static int index_q; 30 static struct msginfo msginfo_buf; 31 static struct msqid_ds msgqid_buf; 32 33 static struct tcase { 34 int *msg_id; 35 int cmd; 36 char *name; 37 void *buf; 38 } tc[] = { 39 {&msg_q, IPC_INFO, "IPC_INFO", &msginfo_buf}, 40 {&msg_q, MSG_INFO, "MSG_INFO", &msginfo_buf}, 41 {&index_q, MSG_STAT, "MSG_STAT", &msgqid_buf}, 42 }; 43 44 static void verify_msgctl(unsigned int i) 45 { 46 TEST(msgctl(*tc[i].msg_id, tc[i].cmd, tc[i].buf)); 47 48 if (TST_RET == -1) { 49 tst_res(TFAIL, 50 "msgctl() test %s failed with errno: " 51 "%d", tc[i].name, TST_ERR); 52 } 53 54 tst_res(TPASS, "msgctl() test %s succeeded", tc[i].name); 55 } 56 57 static void setup(void) 58 { 59 msg_q = SAFE_MSGGET(IPC_PRIVATE, MSG_RW); 60 index_q = SAFE_MSGCTL(msg_q, IPC_INFO, (struct msqid_ds*)&msginfo_buf); 61 } 62 63 static void cleanup(void) 64 { 65 if (msg_q >= 0) 66 SAFE_MSGCTL(msg_q, IPC_RMID, NULL); 67 } 68 69 static struct tst_test test = { 70 .setup = setup, 71 .cleanup = cleanup, 72 .test = verify_msgctl, 73 .tcnt = ARRAY_SIZE(tc), 74 }; 75