summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorZyad A. Ali <zyad.ali.me@gmail.com>2021-06-21 13:53:48 +0200
committerZyad A. Ali <zyad.ali.me@gmail.com>2021-08-03 18:13:24 +0200
commit6ef2f177fbaff7ff29f46a97e2e3dc9199a42d0d (patch)
tree58db0c9c9a6e89aa59b7f0e76d6b41714a4d3ab2 /test/syscalls/linux
parenteb638ee583ba29a879202451692fadfed7c3fdd0 (diff)
Implement MSG_COPY option for msgrcv(2).
Implement Queue.Copy and add more tests for it. Updates #135
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/msgqueue.cc38
1 files changed, 32 insertions, 6 deletions
diff --git a/test/syscalls/linux/msgqueue.cc b/test/syscalls/linux/msgqueue.cc
index 28dbd6056..837e913d9 100644
--- a/test/syscalls/linux/msgqueue.cc
+++ b/test/syscalls/linux/msgqueue.cc
@@ -345,7 +345,7 @@ bool MsgCopySupported() {
errno == ENOSYS);
}
-// Test usage of MSG_COPY for msgrcv.
+// Test msgrcv using MSG_COPY.
TEST(MsgqueueTest, MsgCopy) {
SKIP_IF(!MsgCopySupported());
@@ -372,11 +372,6 @@ TEST(MsgqueueTest, MsgCopy) {
EXPECT_TRUE(buf == rcv);
}
- // Invalid index.
- msgbuf rcv;
- EXPECT_THAT(msgrcv(queue.get(), &rcv, 1, 5, MSG_COPY | IPC_NOWAIT),
- SyscallFailsWithErrno(ENOMSG));
-
// Re-receive the messages normally.
for (auto& buf : bufs) {
msgbuf rcv;
@@ -386,6 +381,37 @@ TEST(MsgqueueTest, MsgCopy) {
}
}
+// Test msgrcv using MSG_COPY with invalid arguments.
+TEST(MsgqueueTest, MsgCopyInvalidArgs) {
+ SKIP_IF(!MsgCopySupported());
+
+ Queue queue(msgget(IPC_PRIVATE, 0600));
+ ASSERT_THAT(queue.get(), SyscallSucceeds());
+
+ msgbuf rcv;
+ EXPECT_THAT(msgrcv(queue.get(), &rcv, msgSize, 1, MSG_COPY),
+ SyscallFailsWithErrno(EINVAL));
+
+ EXPECT_THAT(
+ msgrcv(queue.get(), &rcv, msgSize, 5, MSG_COPY | MSG_EXCEPT | IPC_NOWAIT),
+ SyscallFailsWithErrno(EINVAL));
+}
+
+// Test msgrcv using MSG_COPY with invalid indices.
+TEST(MsgqueueTest, MsgCopyInvalidIndex) {
+ SKIP_IF(!MsgCopySupported());
+
+ Queue queue(msgget(IPC_PRIVATE, 0600));
+ ASSERT_THAT(queue.get(), SyscallSucceeds());
+
+ msgbuf rcv;
+ EXPECT_THAT(msgrcv(queue.get(), &rcv, msgSize, -3, MSG_COPY | IPC_NOWAIT),
+ SyscallFailsWithErrno(ENOMSG));
+
+ EXPECT_THAT(msgrcv(queue.get(), &rcv, msgSize, 5, MSG_COPY | IPC_NOWAIT),
+ SyscallFailsWithErrno(ENOMSG));
+}
+
// Test msgrcv (most probably) blocking on an empty queue.
TEST(MsgqueueTest, MsgRcvBlocking) {
Queue queue(msgget(IPC_PRIVATE, 0600));