Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 567370524
  • Loading branch information
gvisor-bot committed Sep 21, 2023
1 parent f744f44 commit ae1294b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions test/syscalls/linux/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions test/syscalls/linux/alarm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions test/syscalls/linux/cgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
Expand All @@ -874,7 +875,7 @@ PosixError WriteAndVerifyControlValue(const Cgroup& c, std::string_view path,
PosixErrorOr<std::vector<bool>> ParseBitmap(std::string s) {
std::vector<bool> bitmap;
bitmap.reserve(64);
for (const std::string_view& t : absl::StrSplit(s, ',')) {
for (const absl::string_view& t : absl::StrSplit(s, ',')) {
std::vector<std::string> parts = absl::StrSplit(t, absl::MaxSplits('-', 2));
if (parts.size() == 2) {
ASSIGN_OR_RETURN_ERRNO(uint64_t start, Atoi<uint64_t>(parts[0]));
Expand Down
2 changes: 2 additions & 0 deletions test/syscalls/linux/msync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <utility>
#include <vector>

#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"
Expand Down
5 changes: 5 additions & 0 deletions test/syscalls/linux/shm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
15 changes: 7 additions & 8 deletions test/syscalls/linux/socket_inet_loopback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const sockaddr_in6*>(addr_in)
->sin6_addr.s6_addr32)) {
EXPECT_TRUE(IN6_IS_ADDR_V4MAPPED(sock_addr_in6->sin6_addr.s6_addr32))
&(reinterpret_cast<const sockaddr_in6*>(addr_in)
->sin6_addr))) {
EXPECT_TRUE(IN6_IS_ADDR_V4MAPPED(&sock_addr_in6->sin6_addr))
<< OperationToString(operation)
<< " getsocknam=" << GetAddrStr(AsSockAddr(&sock_addr));
}
Expand All @@ -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<const sockaddr_in6*>(addr_in)
->sin6_addr.s6_addr32)) {
IN6_IS_ADDR_V4MAPPED(
&(reinterpret_cast<const sockaddr_in6*>(addr_in)->sin6_addr))) {
EXPECT_TRUE(IN6_IS_ADDR_V4MAPPED(
reinterpret_cast<const sockaddr_in6*>(&peer_addr)
->sin6_addr.s6_addr32))
&(reinterpret_cast<const sockaddr_in6*>(&peer_addr)->sin6_addr)))
<< OperationToString(operation)
<< " getpeername=" << GetAddrStr(AsSockAddr(&peer_addr));
}
Expand Down
7 changes: 4 additions & 3 deletions test/syscalls/linux/socket_ip_tcp_generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/syscalls/linux/udp_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/util/cgroup_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Cgroup {
}

// Creates a child cgroup under this cgroup with the given name.
PosixErrorOr<Cgroup> CreateChild(std::string_view name) const;
PosixErrorOr<Cgroup> CreateChild(absl::string_view name) const;

std::string Relpath(absl::string_view leaf) const {
return JoinPath(cgroup_path_, leaf);
Expand Down Expand Up @@ -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<absl::flat_hash_set<pid_t>> ParsePIDList(
absl::string_view data) const;
Expand Down
3 changes: 2 additions & 1 deletion test/util/mount_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ MountOptionals() {
}

PosixError ParseOptionalTag(std::string_view tag, MountOptional* opt) {
std::vector<std::string_view> key_value = absl::StrSplit(tag, ':');
std::vector<absl::string_view> 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))
Expand Down
7 changes: 7 additions & 0 deletions test/util/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit ae1294b

Please sign in to comment.