Clean up how we skip tests when a syscall isn't in the kernel.
The close_range() test in particular has been confusing a lot of
partners. I think the sys_epoll_test.cpp idiom is the clearest of the
ones in use, so let's use that everywhere. (I haven't actually touched
the SysV IPC tests, because if we do touch them, _deleting_ them --
since all those syscalls are not allowed on Android -- is probably the
change to be made!)
I'm on the fence about factoring this idiom out into a macro. There
should never be too many of these, and we should probably be removing
them? Is anyone still running the current bionic tests on 4.3 kernels
without membarrier(2), and if they are --- why?!
For now though, I haven't removed any of our existing tests; I've just
moved them over to the sys_epoll_test.cpp style.
Test: treehugger
Change-Id: Ie69a0bb8f416c79957188e187610ff8a3c4d1e8f
diff --git a/tests/pidfd_test.cpp b/tests/pidfd_test.cpp
index e2e2046..c01b93f 100644
--- a/tests/pidfd_test.cpp
+++ b/tests/pidfd_test.cpp
@@ -45,10 +45,8 @@
}
unique_fd pidfd(pidfd_open(child, 0));
- if (pidfd.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (pidfd.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, pidfd.get()) << strerror(errno);
siginfo_t siginfo;
int rc = waitid(P_PIDFD, pidfd.get(), &siginfo, WEXITED);
@@ -66,16 +64,12 @@
unique_fd r, w;
ASSERT_TRUE(android::base::Pipe(&r, &w));
unique_fd self(pidfd_open(getpid(), 0));
- if (self.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (self.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, self.get()) << strerror(errno);
unique_fd dup(pidfd_getfd(self.get(), r.get(), 0));
- if (dup.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_getfd not available";
- }
+ if (dup.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_getfd() in this kernel";
+ ASSERT_NE(-1, dup.get()) << strerror(errno);
ASSERT_NE(r.get(), dup.get());
ASSERT_EQ(3, write(w.get(), "foo", 3));
@@ -88,15 +82,12 @@
TEST_F(pidfd_DeathTest, pidfd_send_signal) {
#if defined(__BIONIC__)
unique_fd self(pidfd_open(getpid(), 0));
- if (self.get() == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_open not available";
- }
+ if (self.get() == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_open() in this kernel";
+ ASSERT_NE(-1, self.get()) << strerror(errno);
- if (pidfd_send_signal(self.get(), 0, nullptr, 0) == -1) {
- ASSERT_ERRNO(ENOSYS);
- GTEST_SKIP() << "pidfd_send_signal not available";
- }
+ int rc = pidfd_send_signal(self.get(), 0, nullptr, 0);
+ if (rc == -1 && errno == ENOSYS) GTEST_SKIP() << "no pidfd_send_signal() in this kernel";
+ ASSERT_EQ(0, rc) << strerror(errno);
ASSERT_EXIT(({
// gtest will fork a child off for ASSERT_EXIT: `self` refers to the parent.