From 73eccab91ec58aafd1ffdf038993b78a812ba30f Mon Sep 17 00:00:00 2001 From: Jing Chen Date: Fri, 11 Dec 2020 04:19:58 -0800 Subject: Make semctl IPC_INFO cmd return the index of highest used entry. PiperOrigin-RevId: 346973338 --- test/syscalls/linux/semaphore.cc | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'test/syscalls/linux/semaphore.cc') diff --git a/test/syscalls/linux/semaphore.cc b/test/syscalls/linux/semaphore.cc index 1c1bf6a57..fb4695e72 100644 --- a/test/syscalls/linux/semaphore.cc +++ b/test/syscalls/linux/semaphore.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -774,8 +775,32 @@ TEST(SemaphoreTest, SemopGetncntOnSignal_NoRandomSave) { } TEST(SemaphoreTest, IpcInfo) { + std::stack sem_ids; + std::stack max_used_indexes; struct seminfo info; - ASSERT_THAT(semctl(0, 0, IPC_INFO, &info), SyscallSucceeds()); + for (int i = 0; i < 3; i++) { + int sem_id = 0; + ASSERT_THAT(sem_id = semget(IPC_PRIVATE, 1, 0600 | IPC_CREAT), + SyscallSucceeds()); + sem_ids.push(sem_id); + int max_used_index = 0; + EXPECT_THAT(max_used_index = semctl(0, 0, IPC_INFO, &info), + SyscallSucceeds()); + if (!max_used_indexes.empty()) { + EXPECT_GT(max_used_index, max_used_indexes.top()); + } + max_used_indexes.push(max_used_index); + } + while (!sem_ids.empty()) { + int sem_id = sem_ids.top(); + sem_ids.pop(); + ASSERT_THAT(semctl(sem_id, 0, IPC_RMID), SyscallSucceeds()); + int max_index = max_used_indexes.top(); + EXPECT_THAT(max_index = semctl(0, 0, IPC_INFO, &info), SyscallSucceeds()); + EXPECT_GE(max_used_indexes.top(), max_index); + max_used_indexes.pop(); + } + ASSERT_THAT(semctl(0, 0, IPC_INFO, &info), SyscallSucceedsWithValue(0)); EXPECT_EQ(info.semmap, 1024000000); EXPECT_EQ(info.semmni, 32000); -- cgit v1.2.3