1 /* Basic tests for SYSV message queue functions.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
23 #include <sys/types.h>
27 #include <support/support.h>
28 #include <support/check.h>
29 #include <support/temp_file.h>
35 __syscall_slong_t type
;
42 #define MSGTYPE 0x01020304
43 #define MSGDATA "0123456789"
45 /* These are for the temporary file we generate. */
52 /* Enforce message queue removal in case of early test failure.
53 Ignore error since the msgq may already have being removed. */
54 msgctl (msqid
, IPC_RMID
, NULL
);
58 do_prepare (int argc
, char *argv
[])
60 int fd
= create_temp_file ("tst-sysvmsg.", &name
);
62 FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno
);
65 #define PREPARE do_prepare
67 /* It is not an extensive test, but rather a functional one aimed to check
68 correct parameter passing on kernel. */
70 #define MSGQ_MODE 0644
77 key_t key
= ftok (name
, 'G');
79 FAIL_EXIT1 ("ftok failed");
81 msqid
= msgget (key
, MSGQ_MODE
| IPC_CREAT
);
85 FAIL_UNSUPPORTED ("msgget not supported");
86 FAIL_EXIT1 ("msgget failed (errno=%d)", errno
);
89 /* Get message queue kernel information and do some sanity checks. */
90 struct msqid_ds msginfo
;
91 if (msgctl (msqid
, IPC_STAT
, &msginfo
) == -1)
92 FAIL_EXIT1 ("msgctl with IPC_STAT failed (errno=%d)", errno
);
94 if (msginfo
.msg_perm
.__key
!= key
)
95 FAIL_EXIT1 ("msgid_ds::msg_perm::key (%d) != %d",
96 (int) msginfo
.msg_perm
.__key
, (int) key
);
97 if (msginfo
.msg_perm
.mode
!= MSGQ_MODE
)
98 FAIL_EXIT1 ("msgid_ds::msg_perm::mode (%o) != %o",
99 msginfo
.msg_perm
.mode
, MSGQ_MODE
);
100 if (msginfo
.msg_qnum
!= 0)
101 FAIL_EXIT1 ("msgid_ds::msg_qnum (%lu) != 0",
102 (long unsigned) msginfo
.msg_qnum
);
104 /* Check if last argument (IPC_NOWAIT) is correctly handled. */
105 struct msgbuf_t msg2rcv
= { 0 };
106 if (msgrcv (msqid
, &msg2rcv
, sizeof (msg2rcv
.buf
), MSGTYPE
,
109 FAIL_EXIT1 ("msgrcv failed (errno=%d)", errno
);
111 struct msgbuf_t msg2snd
= { MSGTYPE
, MSGDATA
};
112 if (msgsnd (msqid
, &msg2snd
, sizeof (msg2snd
.buf
), 0) == -1)
113 FAIL_EXIT1 ("msgsnd failed (errno=%d)", errno
);
115 if (msgrcv (msqid
, &msg2rcv
, sizeof (msg2rcv
.buf
), MSGTYPE
, 0) == -1)
116 FAIL_EXIT1 ("msgrcv failed (errno=%d)", errno
);
119 if (strncmp (msg2snd
.buf
, msg2rcv
.buf
, TEXTSIZE
) != 0)
122 if (msgctl (msqid
, IPC_RMID
, NULL
) == -1)
123 FAIL_EXIT1 ("msgctl failed");
128 #include <support/test-driver.c>