diff --git a/test/syscalls/linux/BUILD b/test/syscalls/linux/BUILD index 294be7380..be82c3d80 100644 --- a/test/syscalls/linux/BUILD +++ b/test/syscalls/linux/BUILD @@ -1446,6 +1446,7 @@ cc_binary( srcs = ["msync.cc"], linkstatic = 1, deps = [ + gtest, "//test/util:file_descriptor", "//test/util:memory_util", "//test/util:posix_error", diff --git a/test/syscalls/linux/alarm.cc b/test/syscalls/linux/alarm.cc index cd0704334..9a3c70d3b 100644 --- a/test/syscalls/linux/alarm.cc +++ b/test/syscalls/linux/alarm.cc @@ -132,6 +132,10 @@ TEST(AlarmTest, SaSiginfo) { ASSERT_THAT(pause(), SyscallFailsWithErrno(EINTR)); } +#ifndef SA_INTERRUPT +#define SA_INTERRUPT 0x20000000 +#endif // SA_INTERRUPT + // No random save as the test relies on alarm timing. Cooperative save tests // already cover the save between alarm and pause. TEST(AlarmTest, SaInterrupt) { diff --git a/test/syscalls/linux/cgroup.cc b/test/syscalls/linux/cgroup.cc index 4fca07c7e..985a1eaef 100644 --- a/test/syscalls/linux/cgroup.cc +++ b/test/syscalls/linux/cgroup.cc @@ -28,10 +28,11 @@ #include "absl/container/flat_hash_set.h" #include "absl/strings/str_split.h" #include "absl/synchronization/notification.h" -#include "test/util/capability_util.h" #include "test/util/cgroup_util.h" #include "test/util/cleanup.h" +#include "test/util/linux_capability_util.h" #include "test/util/mount_util.h" +#include "test/util/posix_error.h" #include "test/util/temp_path.h" #include "test/util/test_util.h" #include "test/util/thread_util.h" @@ -857,7 +858,7 @@ TEST(CPUAcctCgroup, NoDoubleAccounting) { // WriteAndVerifyControlValue attempts to write val to a cgroup file at path, // and verify the value by reading it afterwards. -PosixError WriteAndVerifyControlValue(const Cgroup& c, std::string_view path, +PosixError WriteAndVerifyControlValue(const Cgroup& c, absl::string_view path, int64_t val) { RETURN_IF_ERRNO(c.WriteIntegerControlFile(path, val)); ASSIGN_OR_RETURN_ERRNO(int64_t newval, c.ReadIntegerControlFile(path)); @@ -874,7 +875,7 @@ PosixError WriteAndVerifyControlValue(const Cgroup& c, std::string_view path, PosixErrorOr> ParseBitmap(std::string s) { std::vector bitmap; bitmap.reserve(64); - for (const std::string_view& t : absl::StrSplit(s, ',')) { + for (const absl::string_view& t : absl::StrSplit(s, ',')) { std::vector parts = absl::StrSplit(t, absl::MaxSplits('-', 2)); if (parts.size() == 2) { ASSIGN_OR_RETURN_ERRNO(uint64_t start, Atoi(parts[0])); diff --git a/test/syscalls/linux/msync.cc b/test/syscalls/linux/msync.cc index 2b2b6aef9..1e1a2b440 100644 --- a/test/syscalls/linux/msync.cc +++ b/test/syscalls/linux/msync.cc @@ -20,6 +20,8 @@ #include #include +#include "gmock/gmock.h" +#include "gtest/gtest.h" #include "test/util/file_descriptor.h" #include "test/util/memory_util.h" #include "test/util/posix_error.h" diff --git a/test/syscalls/linux/shm.cc b/test/syscalls/linux/shm.cc index baf794152..799c5d77e 100644 --- a/test/syscalls/linux/shm.cc +++ b/test/syscalls/linux/shm.cc @@ -300,6 +300,11 @@ TEST(ShmTest, ShmCtlSet) { ASSERT_NO_ERRNO(Shmdt(addr)); } +#ifndef SHM_DEST +// Not defined in bionic +#define SHM_DEST 0x200 +#endif + TEST(ShmTest, RemovedSegmentsAreMarkedDeleted) { ShmSegment shm = ASSERT_NO_ERRNO_AND_VALUE( Shmget(IPC_PRIVATE, kAllocSize, IPC_CREAT | 0777)); diff --git a/test/syscalls/linux/socket_inet_loopback.cc b/test/syscalls/linux/socket_inet_loopback.cc index 84b3460fb..8dde3eeea 100644 --- a/test/syscalls/linux/socket_inet_loopback.cc +++ b/test/syscalls/linux/socket_inet_loopback.cc @@ -161,15 +161,15 @@ TEST_P(DualStackSocketTest, AddressOperations) { if (operation == Operation::SendTo) { EXPECT_EQ(sock_addr_in6->sin6_family, AF_INET6); - EXPECT_TRUE(IN6_IS_ADDR_UNSPECIFIED(sock_addr_in6->sin6_addr.s6_addr32)) + EXPECT_TRUE(IN6_IS_ADDR_UNSPECIFIED(&sock_addr_in6->sin6_addr)) << OperationToString(operation) << " getsocknam=" << GetAddrStr(AsSockAddr(&sock_addr)); EXPECT_NE(sock_addr_in6->sin6_port, 0); } else if (IN6_IS_ADDR_V4MAPPED( - reinterpret_cast(addr_in) - ->sin6_addr.s6_addr32)) { - EXPECT_TRUE(IN6_IS_ADDR_V4MAPPED(sock_addr_in6->sin6_addr.s6_addr32)) + &(reinterpret_cast(addr_in) + ->sin6_addr))) { + EXPECT_TRUE(IN6_IS_ADDR_V4MAPPED(&sock_addr_in6->sin6_addr)) << OperationToString(operation) << " getsocknam=" << GetAddrStr(AsSockAddr(&sock_addr)); } @@ -183,11 +183,10 @@ TEST_P(DualStackSocketTest, AddressOperations) { ASSERT_EQ(addrlen, sizeof(struct sockaddr_in6)); if (addr.family() == AF_INET || - IN6_IS_ADDR_V4MAPPED(reinterpret_cast(addr_in) - ->sin6_addr.s6_addr32)) { + IN6_IS_ADDR_V4MAPPED( + &(reinterpret_cast(addr_in)->sin6_addr))) { EXPECT_TRUE(IN6_IS_ADDR_V4MAPPED( - reinterpret_cast(&peer_addr) - ->sin6_addr.s6_addr32)) + &(reinterpret_cast(&peer_addr)->sin6_addr))) << OperationToString(operation) << " getpeername=" << GetAddrStr(AsSockAddr(&peer_addr)); } diff --git a/test/syscalls/linux/socket_ip_tcp_generic.cc b/test/syscalls/linux/socket_ip_tcp_generic.cc index 87c0105c4..cfee6b08f 100644 --- a/test/syscalls/linux/socket_ip_tcp_generic.cc +++ b/test/syscalls/linux/socket_ip_tcp_generic.cc @@ -143,9 +143,10 @@ TEST_P(TCPSocketPairTest, RSTCausesPollHUP) { // Confirm we at least have one unread byte. int bytes_available = 0; - ASSERT_THAT( - RetryEINTR(ioctl)(sockets->second_fd(), FIONREAD, &bytes_available), - SyscallSucceeds()); + ASSERT_THAT(RetryEINTR([&]() { + return ioctl(sockets->second_fd(), FIONREAD, &bytes_available); + })(), + SyscallSucceeds()); EXPECT_GT(bytes_available, 0); // Now close the connected socket without reading the data from the second, diff --git a/test/syscalls/linux/udp_socket.cc b/test/syscalls/linux/udp_socket.cc index be30807e0..1c48e0d9e 100644 --- a/test/syscalls/linux/udp_socket.cc +++ b/test/syscalls/linux/udp_socket.cc @@ -2475,7 +2475,7 @@ TEST(UdpInet6SocketTest, ConnectInet4Sockaddr) { ASSERT_NE(addr = inet_ntop(sockname.ss_family, &sockname, addr_buf, sizeof(addr_buf)), nullptr); - ASSERT_TRUE(IN6_IS_ADDR_V4MAPPED(sin6->sin6_addr.s6_addr)) << addr; + ASSERT_TRUE(IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) << addr; } } // namespace diff --git a/test/util/cgroup_util.h b/test/util/cgroup_util.h index a13f1772d..97c02874a 100644 --- a/test/util/cgroup_util.h +++ b/test/util/cgroup_util.h @@ -53,7 +53,7 @@ class Cgroup { } // Creates a child cgroup under this cgroup with the given name. - PosixErrorOr CreateChild(std::string_view name) const; + PosixErrorOr CreateChild(absl::string_view name) const; std::string Relpath(absl::string_view leaf) const { return JoinPath(cgroup_path_, leaf); @@ -104,7 +104,7 @@ class Cgroup { PosixError EnterThread(pid_t pid) const; private: - Cgroup(std::string_view path, std::string_view mountpoint); + Cgroup(absl::string_view path, absl::string_view mountpoint); PosixErrorOr> ParsePIDList( absl::string_view data) const; diff --git a/test/util/mount_util.cc b/test/util/mount_util.cc index 63e8684b9..a545b039f 100644 --- a/test/util/mount_util.cc +++ b/test/util/mount_util.cc @@ -209,7 +209,8 @@ MountOptionals() { } PosixError ParseOptionalTag(std::string_view tag, MountOptional* opt) { - std::vector key_value = absl::StrSplit(tag, ':'); + std::vector key_value = + absl::StrSplit(absl::string_view(tag.data(), tag.size()), ':'); if (key_value.size() != 2) return PosixError(0); if (key_value[0] == "shared") { if (!absl::SimpleAtoi(key_value[1], &opt->shared)) diff --git a/test/util/test_util.h b/test/util/test_util.h index 41aa2fcd9..65c2cee3f 100644 --- a/test/util/test_util.h +++ b/test/util/test_util.h @@ -193,6 +193,13 @@ #include "test/util/posix_error.h" #include "test/util/save_util.h" +// Android's libc, Bionic, specifies that many syscall arguments are _Nonnull, +// causing tests that specifically test for syscall behavior on null arguments +// to fail to build. +#if defined(__BIONIC__) && defined(__clang__) +#pragma clang diagnostic ignored "-Wnonnull" +#endif + namespace gvisor { namespace testing {