diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-06-10 02:39:40 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-06-10 02:39:40 -0700 |
commit | c867c5526d4b25e8f01e0d6a6e81974676957c97 (patch) | |
tree | 010e99c7d1c98538b84b38ab797b4191e29c14f6 /test/syscalls/linux | |
parent | a51fcf22ebe522c028e99692bbedf04daf0436cc (diff) | |
parent | 69e3476ad5247a11f4b93e29607bb7c1513d3cc4 (diff) |
Merge pull request #6103 from sudo-sturbia:semaphore-err
PiperOrigin-RevId: 378607458
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r-- | test/syscalls/linux/semaphore.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/syscalls/linux/semaphore.cc b/test/syscalls/linux/semaphore.cc index 2ce8f836c..f72957f89 100644 --- a/test/syscalls/linux/semaphore.cc +++ b/test/syscalls/linux/semaphore.cc @@ -49,6 +49,9 @@ constexpr int kSemAem = 32767; class AutoSem { public: + // Creates a new private semaphore. + AutoSem() : id_(semget(IPC_PRIVATE, 1, 0)) {} + explicit AutoSem(int id) : id_(id) {} ~AutoSem() { if (id_ >= 0) { @@ -101,6 +104,20 @@ TEST(SemaphoreTest, SemGet) { EXPECT_NE(sem3.get(), sem2.get()); } +// Tests system-wide limits for semget. +TEST(SemaphoreTest, SemGetSystemLimits) { + // Disable save so that we don't trigger save/restore too many times. + const DisableSave ds; + + // Exceed number of semaphores per set. + EXPECT_THAT(semget(IPC_PRIVATE, kSemMsl + 1, 0), + SyscallFailsWithErrno(EINVAL)); + + // Exceed system-wide limit for semaphore sets by 1. + AutoSem sems[kSemMni]; + EXPECT_THAT(semget(IPC_PRIVATE, 1, 0), SyscallFailsWithErrno(ENOSPC)); +} + // Tests simple operations that shouldn't block in a single-thread. TEST(SemaphoreTest, SemOpSingleNoBlock) { AutoSem sem(semget(IPC_PRIVATE, 1, 0600 | IPC_CREAT)); |