summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJing Chen <chjing@google.com>2020-12-11 04:19:58 -0800
committergVisor bot <gvisor-bot@google.com>2020-12-11 04:22:04 -0800
commit73eccab91ec58aafd1ffdf038993b78a812ba30f (patch)
tree67d1a83d0c35fd264c2e2ce64466bc220959303a /test
parent0eb4acad37c448a298c77090b3475ce6903ecf18 (diff)
Make semctl IPC_INFO cmd return the index of highest used entry.
PiperOrigin-RevId: 346973338
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/semaphore.cc27
1 files changed, 26 insertions, 1 deletions
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 <atomic>
#include <cerrno>
#include <ctime>
+#include <stack>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -774,8 +775,32 @@ TEST(SemaphoreTest, SemopGetncntOnSignal_NoRandomSave) {
}
TEST(SemaphoreTest, IpcInfo) {
+ std::stack<int> sem_ids;
+ std::stack<int> 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);