| 1 |
/* COVERAGE: msgget msgsnd msgrcv msgctl */ |
| 2 |
#include <stdio.h> |
| 3 |
#include <string.h> |
| 4 |
#include <time.h> |
| 5 |
#include <sys/ipc.h> |
| 6 |
#include <sys/msg.h> |
| 7 |
#include <sys/wait.h> |
| 8 |
#include <sys/mman.h> |
| 9 |
|
| 10 |
#define MSGTXTLEN 128 // msg text length |
| 11 |
|
| 12 |
struct msg_buf { |
| 13 |
long mtype; |
| 14 |
char mtext[MSGTXTLEN]; |
| 15 |
} msg; |
| 16 |
|
| 17 |
int |
| 18 |
main(int argc, char **argv) |
| 19 |
{ |
| 20 |
int msgqid; |
| 21 |
|
| 22 |
mlockall(MCL_CURRENT); |
| 23 |
|
| 24 |
// Test basic operation. |
| 25 |
|
| 26 |
// create a message queue. |
| 27 |
msgqid = msgget(IPC_PRIVATE, IPC_CREAT|IPC_EXCL|0600); |
| 28 |
//staptest// msgget (IPC_PRIVATE, IPC_CREAT|IPC_EXCL|0600) = NNNN |
| 29 |
|
| 30 |
// create a message to send |
| 31 |
msg.mtype = 1; |
| 32 |
strcpy(msg.mtext, "a text msg...\n"); |
| 33 |
|
| 34 |
// send the message to queue |
| 35 |
msgsnd(msgqid, &msg, sizeof(msg), IPC_NOWAIT); |
| 36 |
//staptest// msgsnd (NNNN, XXXX, NNNN, IPC_NOWAIT) = NNNN |
| 37 |
|
| 38 |
// read the message from queue |
| 39 |
msgrcv(msgqid, &msg, sizeof(msg), 0, 0); |
| 40 |
//staptest// msgrcv (NNNN, XXXX, NNNN, 0, 0x0) = NNNN |
| 41 |
|
| 42 |
// remove the queue |
| 43 |
msgctl(msgqid, IPC_RMID, NULL); |
| 44 |
//staptest// msgctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = 0 |
| 45 |
|
| 46 |
// Range checking. |
| 47 |
|
| 48 |
msgqid = msgget((key_t)-1, IPC_CREAT|IPC_EXCL|0600); |
| 49 |
//staptest// msgget (-1, IPC_CREAT|IPC_EXCL|0600) = NNNN |
| 50 |
|
| 51 |
msgsnd(-1, &msg, sizeof(msg), 0); |
| 52 |
//staptest// msgsnd (-1, XXXX, NNNN, 0x0) = NNNN |
| 53 |
|
| 54 |
msgsnd(msgqid, (void *)-1, sizeof(msg), 0); |
| 55 |
#ifdef __s390__ |
| 56 |
//staptest// msgsnd (NNNN, 0x[7]?[f]+, NNNN, 0x0) = NNNN |
| 57 |
#else |
| 58 |
//staptest// msgsnd (NNNN, 0x[f]+, NNNN, 0x0) = NNNN |
| 59 |
#endif |
| 60 |
|
| 61 |
msgsnd(msgqid, &msg, (size_t)-1, 0); |
| 62 |
#if __WORDSIZE == 64 |
| 63 |
//staptest// msgsnd (NNNN, XXXX, 18446744073709551615, 0x0) = NNNN |
| 64 |
#else |
| 65 |
//staptest// msgsnd (NNNN, XXXX, 4294967295, 0x0) = NNNN |
| 66 |
#endif |
| 67 |
|
| 68 |
msgsnd(msgqid, &msg, sizeof(msg), -1); |
| 69 |
//staptest// msgsnd (NNNN, XXXX, NNNN, [[[[MSG!!!!IPC]]]]_[^ ]+|XXXX) = NNNN |
| 70 |
|
| 71 |
msgrcv(-1, &msg, sizeof(msg), 0, 0); |
| 72 |
//staptest// msgrcv (-1, XXXX, NNNN, 0, 0x0) = NNNN |
| 73 |
|
| 74 |
msgrcv(msgqid, (void *)-1, sizeof(msg), 0, 0); |
| 75 |
#ifdef __s390__ |
| 76 |
//staptest// msgrcv (NNNN, 0x[7]?[f]+, NNNN, 0, 0x0) = NNNN |
| 77 |
#else |
| 78 |
//staptest// msgrcv (NNNN, 0x[f]+, NNNN, 0, 0x0) = NNNN |
| 79 |
#endif |
| 80 |
|
| 81 |
msgrcv(msgqid, &msg, (size_t)-1, 0, 0); |
| 82 |
#if __WORDSIZE == 64 |
| 83 |
//staptest// msgrcv (NNNN, XXXX, 18446744073709551615, 0, 0x0) = NNNN |
| 84 |
#else |
| 85 |
//staptest// msgrcv (NNNN, XXXX, 4294967295, 0, 0x0) = NNNN |
| 86 |
#endif |
| 87 |
|
| 88 |
msgrcv(msgqid, &msg, sizeof(msg), -1, IPC_NOWAIT); |
| 89 |
//staptest// msgrcv (NNNN, XXXX, NNNN, -1, IPC_NOWAIT) = NNNN |
| 90 |
|
| 91 |
msgrcv(msgqid, &msg, sizeof(msg), 0, -1); |
| 92 |
//staptest// msgrcv (NNNN, XXXX, NNNN, 0, [[[[MSG!!!!IPC]]]]_[^ ]+|XXXX) = NNNN |
| 93 |
|
| 94 |
msgctl(msgqid, IPC_RMID, NULL); |
| 95 |
//staptest// msgctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = NNNN |
| 96 |
|
| 97 |
msgqid = msgget(IPC_PRIVATE, -1); |
| 98 |
//staptest// msgget (IPC_PRIVATE, IPC_[^ ]+|XXXX|0777) = NNNN |
| 99 |
|
| 100 |
msgctl(msgqid, IPC_RMID, NULL); |
| 101 |
//staptest// msgctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x0) = NNNN |
| 102 |
|
| 103 |
msgctl(msgqid, -1, NULL); |
| 104 |
//staptest// msgctl (NNNN, [[[[IPC_64|]]]]?XXXX, 0x0) = NNNN |
| 105 |
|
| 106 |
// The following SEGVs if compiled as a 32-on-64 bit binary on x86_64 in msqid_to_msqid64() |
| 107 |
#if __WORDSIZE == 64 |
| 108 |
msgctl(msgqid, IPC_RMID, (struct msqid_ds *)-1); |
| 109 |
#ifdef __s390__ |
| 110 |
//staptest// msgctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x[7]?[f]+) = NNNN |
| 111 |
#else |
| 112 |
//staptest// msgctl (NNNN, [[[[IPC_64|]]]]?IPC_RMID, 0x[f]+) = NNNN |
| 113 |
#endif |
| 114 |
#endif |
| 115 |
|
| 116 |
return 0; |
| 117 |
} |