diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-02-07 11:40:45 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-02-07 11:41:44 -0800 |
commit | 9ef3427ac14a84002497f3c8bac346486cb36f2b (patch) | |
tree | 186a4377900f481b56cbb28c2389f4f3f0b7f65a /test/syscalls/linux | |
parent | 3c71e025e83f1684eec9517f64d0d8a7a0608191 (diff) |
Implement semctl(2) SETALL and GETALL
PiperOrigin-RevId: 232914984
Change-Id: Id2643d7ad8e986ca9be76d860788a71db2674cda
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r-- | test/syscalls/linux/semaphore.cc | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/test/syscalls/linux/semaphore.cc b/test/syscalls/linux/semaphore.cc index 12e33732d..da3d2c6fe 100644 --- a/test/syscalls/linux/semaphore.cc +++ b/test/syscalls/linux/semaphore.cc @@ -223,7 +223,7 @@ TEST(SemaphoreTest, SemOpRemoveWithWaiter_NoRandomSave) { }); // This must happen before IPC_RMID runs above. Otherwise it fails with EINVAL - // instead because the semaphire has already been removed. + // instead because the semaphore has already been removed. struct sembuf buf = {}; buf.sem_op = -1; ASSERT_THAT(RetryEINTR(semop)(sem.get(), &buf, 1), @@ -408,6 +408,29 @@ TEST(SemaphoreTest, SemCtlVal) { thZero.Join(); } +TEST(SemaphoreTest, SemCtlValAll) { + AutoSem sem(semget(IPC_PRIVATE, 3, 0600 | IPC_CREAT)); + ASSERT_THAT(sem.get(), SyscallSucceeds()); + + // Semaphores must start with 0. + uint16_t get[3] = {10, 10, 10}; + EXPECT_THAT(semctl(sem.get(), 1, GETALL, get), SyscallSucceedsWithValue(0)); + for (auto v : get) { + EXPECT_EQ(v, 0); + } + + // SetAll and check that they were set. + uint16_t vals[3] = {0, 10, 20}; + EXPECT_THAT(semctl(sem.get(), 1, SETALL, vals), SyscallSucceedsWithValue(0)); + EXPECT_THAT(semctl(sem.get(), 1, GETALL, get), SyscallSucceedsWithValue(0)); + for (size_t i = 0; i < ABSL_ARRAYSIZE(vals); ++i) { + EXPECT_EQ(get[i], vals[i]); + } + + EXPECT_THAT(semctl(sem.get(), 1, SETALL, nullptr), + SyscallFailsWithErrno(EFAULT)); +} + TEST(SemaphoreTest, SemIpcSet) { // Drop CAP_IPC_OWNER which allows us to bypass semaphore permissions. ASSERT_NO_ERRNO(SetCapability(CAP_IPC_OWNER, false)); |