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 <unistd.h>
22 
23 #include <gtest/gtest.h>
24 
25 #ifdef HAS_KCMP
kcmp(pid_t pid1,pid_t pid2,int type,unsigned long idx1,unsigned long idx2)26 int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
27   return syscall(SYS_kcmp, pid1, pid2, type, 0, idx1, idx2);
28 }
29 #endif
30 
TEST(kernel_config,NOT_CONFIG_SYSVIPC)31 TEST(kernel_config, NOT_CONFIG_SYSVIPC) {
32 #ifdef HAS_KCMP
33   pid_t pid = getpid();
34   int ret = kcmp(pid, pid, KCMP_SYSVSEM, 0, 0);
35   int error = (ret == -1) ? (errno == ENOSYS) ? EOPNOTSUPP : errno : 0;
36   EXPECT_EQ(-1, kcmp(pid, pid, KCMP_SYSVSEM, 0, 0));
37   EXPECT_EQ(EOPNOTSUPP, error);
38 #endif
39   EXPECT_EQ(-1, access("/proc/sysvipc", F_OK));
40   EXPECT_EQ(-1, access("/proc/sysvipc/msg", F_OK));
41   EXPECT_EQ(-1, access("/proc/sysvipc/sem", F_OK));
42   EXPECT_EQ(-1, access("/proc/sysvipc/shm", F_OK));
43 }
44 
45