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