1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <errno.h>
17 #ifdef HAS_KCMP
18 #include <linux/kcmp.h>
19 #include <sys/syscall.h>
20 #endif
21 #include <sys/ipc.h>
22 #include <sys/msg.h>
23 #include <sys/sem.h>
24 #include <sys/shm.h>
25 #include <unistd.h>
26
27 #include <gtest/gtest.h>
28
29 #ifdef HAS_KCMP
kcmp(pid_t pid1,pid_t pid2,int type,unsigned long idx1,unsigned long idx2)30 int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
31 return syscall(SYS_kcmp, pid1, pid2, type, 0, idx1, idx2);
32 }
33 #endif
34
TEST(kernel_config,NOT_CONFIG_SYSVIPC)35 TEST(kernel_config, NOT_CONFIG_SYSVIPC) {
36 #ifdef HAS_KCMP
37 pid_t pid = getpid();
38 int ret = kcmp(pid, pid, KCMP_SYSVSEM, 0, 0);
39 int error = (ret == -1) ? (errno == ENOSYS) ? EOPNOTSUPP : errno : 0;
40 EXPECT_EQ(-1, kcmp(pid, pid, KCMP_SYSVSEM, 0, 0));
41 EXPECT_EQ(EOPNOTSUPP, error);
42 #endif
43
44 EXPECT_EQ(-1, access("/proc/sysvipc", R_OK));
45
46 EXPECT_EQ(-1, access("/proc/sysvipc/msg", F_OK));
47 EXPECT_EQ(-1, msgctl(-1, IPC_STAT, nullptr));
48 EXPECT_EQ(ENOSYS, errno);
49
50 EXPECT_EQ(-1, access("/proc/sysvipc/sem", F_OK));
51 EXPECT_EQ(-1, semctl(-1, 0, IPC_STAT, nullptr));
52 EXPECT_EQ(ENOSYS, errno);
53
54 EXPECT_EQ(-1, access("/proc/sysvipc/shm", F_OK));
55 EXPECT_EQ(-1, shmctl(-1, IPC_STAT, nullptr));
56 EXPECT_EQ(ENOSYS, errno);
57 }
58
59