1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2014 Fujitsu Ltd. 4 * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com> 5 * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz> 6 */ 7/* 8 * msgctl12 - test for IPC_INFO MSG_INFO and MSG_STAT. 9 */ 10 11#define _GNU_SOURCE 12#include <errno.h> 13 14#include "tst_test.h" 15#include "tst_safe_sysv_ipc.h" 16#include "libnewipc.h" 17 18static int msg_q = -1; 19static int index_q; 20static struct msginfo msginfo_buf; 21static struct msqid_ds msgqid_buf; 22 23static struct tcase { 24 int *msg_id; 25 int cmd; 26 char *name; 27 void *buf; 28} tc[] = { 29 {&msg_q, IPC_INFO, "IPC_INFO", &msginfo_buf}, 30 {&msg_q, MSG_INFO, "MSG_INFO", &msginfo_buf}, 31 {&index_q, MSG_STAT, "MSG_STAT", &msgqid_buf}, 32}; 33 34static void verify_msgctl(unsigned int i) 35{ 36 TEST(msgctl(*tc[i].msg_id, tc[i].cmd, tc[i].buf)); 37 38 if (TST_RET == -1) { 39 tst_res(TFAIL, 40 "msgctl() test %s failed with errno: " 41 "%d", tc[i].name, TST_ERR); 42 } 43 44 tst_res(TPASS, "msgctl() test %s succeeded", tc[i].name); 45} 46 47static void setup(void) 48{ 49 msg_q = SAFE_MSGGET(IPC_PRIVATE, MSG_RW); 50 index_q = SAFE_MSGCTL(msg_q, IPC_INFO, (struct msqid_ds*)&msginfo_buf); 51} 52 53static void cleanup(void) 54{ 55 if (msg_q >= 0) 56 SAFE_MSGCTL(msg_q, IPC_RMID, NULL); 57} 58 59static struct tst_test test = { 60 .setup = setup, 61 .cleanup = cleanup, 62 .test = verify_msgctl, 63 .tcnt = ARRAY_SIZE(tc), 64}; 65