OSDN Git Service

Make the NOT_CONFIG_SYSVIPC test also exercise the syscalls
authorLuis Hector Chavez <lhchavez@google.com>
Tue, 24 Apr 2018 15:40:10 +0000 (08:40 -0700)
committerLuis Hector Chavez <lhchavez@google.com>
Thu, 26 Apr 2018 15:38:32 +0000 (08:38 -0700)
This change augments the NOT_CONFIG_SYSVIPC test, such that in addition
to being evidence-based (by inspecting some paths in /proc), it also
tries to invoke the syscalls.  This is done because in some platforms
like Chrome OS, the SYSVIPC kernel config is enabled (because some parts
of the system require that to boot), but when Android is running, all
SYSVIPC syscalls are blocked by an LSM in the kernel.

It also changes the /proc/sysvipc path check from using access(2) and
F_OK to R_OK, since the paths itself is present and visible.

Bug: 77490033
Test: CtsKernelConfigTestCases
Change-Id: I79df1816e0e5d3618da2a0e242c3d685352b7220
Merged-In: I79df1816e0e5d3618da2a0e242c3d685352b7220
(cherry picked from commit 687cd48d8bce5548c7bf1dcbbfd3fd770e452362)

tests/kernel.config/sysvipc_test.cpp

index 49952f0..015991d 100644 (file)
 #include <linux/kcmp.h>
 #include <sys/syscall.h>
 #endif
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/sem.h>
+#include <sys/shm.h>
 #include <unistd.h>
 
 #include <gtest/gtest.h>
@@ -36,9 +40,19 @@ TEST(kernel_config, NOT_CONFIG_SYSVIPC) {
   EXPECT_EQ(-1, kcmp(pid, pid, KCMP_SYSVSEM, 0, 0));
   EXPECT_EQ(EOPNOTSUPP, error);
 #endif
-  EXPECT_EQ(-1, access("/proc/sysvipc", F_OK));
+
+  EXPECT_EQ(-1, access("/proc/sysvipc", R_OK));
+
   EXPECT_EQ(-1, access("/proc/sysvipc/msg", F_OK));
+  EXPECT_EQ(-1, msgctl(-1, IPC_STAT, nullptr));
+  EXPECT_EQ(ENOSYS, errno);
+
   EXPECT_EQ(-1, access("/proc/sysvipc/sem", F_OK));
+  EXPECT_EQ(-1, semctl(-1, 0, IPC_STAT, nullptr));
+  EXPECT_EQ(ENOSYS, errno);
+
   EXPECT_EQ(-1, access("/proc/sysvipc/shm", F_OK));
+  EXPECT_EQ(-1, shmctl(-1, IPC_STAT, nullptr));
+  EXPECT_EQ(ENOSYS, errno);
 }