1 /* 2 * Copyright (c) International Business Machines Corp., 2001 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12 * the GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. 16 */ 17 18 /* 19 * DESCRIPTION 20 * create a message queue, write a message to it and 21 * read it back. 22 */ 23 24 #include <errno.h> 25 #include <string.h> 26 #include <sys/types.h> 27 #include <sys/ipc.h> 28 #include <sys/msg.h> 29 30 #include "tst_test.h" 31 #include "tst_safe_sysv_ipc.h" 32 #include "libnewipc.h" 33 34 static int queue_id = -1; 35 static key_t msgkey; 36 37 static struct buf { 38 long type; 39 char text[MSGSIZE]; 40 } rcv_buf, snd_buf = {MSGTYPE, "hello, world"}; 41 42 static void verify_msgget(void) 43 { 44 TEST(msgget(msgkey, IPC_CREAT | MSG_RW)); 45 if (TEST_RETURN == -1) { 46 tst_res(TFAIL | TTERRNO, "msgget() failed"); 47 return; 48 } 49 50 queue_id = TEST_RETURN; 51 52 SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0); 53 54 SAFE_MSGRCV(queue_id, &rcv_buf, MSGSIZE, MSGTYPE, IPC_NOWAIT); 55 56 if (strcmp(snd_buf.text, rcv_buf.text) == 0) 57 tst_res(TPASS, "message received = message sent"); 58 else 59 tst_res(TFAIL, "message received != message sent"); 60 } 61 62 static void setup(void) 63 { 64 msgkey = GETIPCKEY(); 65 } 66 67 static void cleanup(void) 68 { 69 if (queue_id != -1) 70 SAFE_MSGCTL(queue_id, IPC_RMID, NULL); 71 } 72 73 static struct tst_test test = { 74 .setup = setup, 75 .cleanup = cleanup, 76 .test_all = verify_msgget, 77 .needs_tmpdir = 1 78 }; 79