Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 563145789
  • Loading branch information
gvisor-bot committed Sep 6, 2023
1 parent 2319f95 commit c7442a3
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 34 deletions.
1 change: 1 addition & 0 deletions test/syscalls/linux/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,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
10 changes: 6 additions & 4 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 Expand Up @@ -1423,7 +1424,8 @@ TEST(PIDsCgroup, RaceFSDestructionChargeUncharge) {

// Intentionally bad syscall that will cause the calling thread to be
// aborted with a SIGSEGV.
rename(0, 0);
char* null_ptr = nullptr;
rename(null_ptr, null_ptr);
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion test/syscalls/linux/inotify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,8 @@ TEST(Inotify, AddWatchOnInvalidPathFails) {
SyscallFailsWithErrno(ENOENT));

// Garbage path pointer.
EXPECT_THAT(inotify_add_watch(fd.get(), nullptr, IN_CREATE),
char* name = nullptr;
EXPECT_THAT(inotify_add_watch(fd.get(), name, IN_CREATE),
SyscallFailsWithErrno(EFAULT));
}

Expand Down
4 changes: 3 additions & 1 deletion test/syscalls/linux/madvise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ TEST(MadviseDontforkTest, AddressLength) {

// Length must not roll over after rounding up.
size_t badlen = std::numeric_limits<std::size_t>::max() - (kPageSize / 2);
EXPECT_THAT(madvise(0, badlen, MADV_DONTFORK), SyscallFailsWithErrno(EINVAL));
void* null_addr = nullptr;
EXPECT_THAT(madvise(null_addr, badlen, MADV_DONTFORK),
SyscallFailsWithErrno(EINVAL));

// Length need not be page aligned - it is implicitly rounded up.
EXPECT_THAT(madvise(addr, 1, MADV_DONTFORK), SyscallSucceeds());
Expand Down
8 changes: 6 additions & 2 deletions test/syscalls/linux/mincore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ TEST(MincoreTest, UnalignedLengthSucceedsAndIsRoundedUp) {
}

TEST(MincoreTest, ZeroLengthSucceedsAndAllowsAnyVecBelowTaskSize) {
EXPECT_THAT(mincore(nullptr, 0, nullptr), SyscallSucceeds());
void* start = nullptr;
unsigned char* vec = nullptr;
EXPECT_THAT(mincore(start, 0, vec), SyscallSucceeds());
}

TEST(MincoreTest, InvalidLengthFails) {
EXPECT_THAT(mincore(nullptr, -1, nullptr), SyscallFailsWithErrno(ENOMEM));
void* start = nullptr;
unsigned char* vec = nullptr;
EXPECT_THAT(mincore(start, -1, vec), SyscallFailsWithErrno(ENOMEM));
}

} // namespace
Expand Down
8 changes: 6 additions & 2 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 Expand Up @@ -83,11 +85,13 @@ PosixErrorOr<Mapping> NoMappings() {
using MsyncNoMappingTest = MsyncParameterizedTest;

TEST_P(MsyncNoMappingTest, UnmappedAddressWithZeroLengthSucceeds) {
EXPECT_THAT(msync(nullptr, 0, msync_flags()), SyscallSucceeds());
void* null_addr = nullptr;
EXPECT_THAT(msync(null_addr, 0, msync_flags()), SyscallSucceeds());
}

TEST_P(MsyncNoMappingTest, UnmappedAddressWithNonzeroLengthFails) {
EXPECT_THAT(msync(nullptr, kPageSize, msync_flags()),
void* null_addr = nullptr;
EXPECT_THAT(msync(null_addr, kPageSize, msync_flags()),
SyscallFailsWithErrno(ENOMEM));
}

Expand Down
4 changes: 2 additions & 2 deletions test/syscalls/linux/packet_socket_dgram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ TEST_P(CookedPacketTest, ReceiveOutbound) {

// Bind with invalid address.
TEST_P(CookedPacketTest, BindFail) {
// Null address.
sockaddr* null_addr = nullptr;
ASSERT_THAT(
bind(socket_, nullptr, sizeof(struct sockaddr)),
bind(socket_, null_addr, sizeof(struct sockaddr)),
AnyOf(SyscallFailsWithErrno(EFAULT), SyscallFailsWithErrno(EINVAL)));

// Address of size 1.
Expand Down
3 changes: 2 additions & 1 deletion test/syscalls/linux/sched.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ TEST(SchedGetparamTest, ImpossiblePIDReturnsESRCH) {
}

TEST(SchedGetparamTest, NullParamReturnsEINVAL) {
EXPECT_THAT(sched_getparam(0, nullptr), SyscallFailsWithErrno(EINVAL));
sched_param* param = nullptr;
EXPECT_THAT(sched_getparam(0, param), SyscallFailsWithErrno(EINVAL));
}

TEST(SchedGetschedulerTest, ReturnsSchedOther) {
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
3 changes: 2 additions & 1 deletion test/syscalls/linux/socket_ip_unbound.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ TEST_P(IPUnboundSocketTest, NullTOS) {
EXPECT_THAT(getsockopt(socket->get(), t.level, t.option, nullptr, &get_sz),
SyscallFailsWithErrno(EFAULT));
int get = -1;
EXPECT_THAT(getsockopt(socket->get(), t.level, t.option, &get, nullptr),
socklen_t* socklen_ptr = nullptr;
EXPECT_THAT(getsockopt(socket->get(), t.level, t.option, &get, socklen_ptr),
SyscallFailsWithErrno(EFAULT));
}

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
11 changes: 6 additions & 5 deletions test/syscalls/linux/xattr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ TEST_F(XattrTest, XattrNonexistentFile) {
TEST_F(XattrTest, XattrNullName) {
const char* path = test_file_name_.c_str();

EXPECT_THAT(setxattr(path, nullptr, nullptr, 0, /*flags=*/0),
SyscallFailsWithErrno(EFAULT));
EXPECT_THAT(getxattr(path, nullptr, nullptr, 0),
char* name = nullptr;
EXPECT_THAT(setxattr(path, name, nullptr, 0, /*flags=*/0),
SyscallFailsWithErrno(EFAULT));
EXPECT_THAT(removexattr(path, nullptr), SyscallFailsWithErrno(EFAULT));
EXPECT_THAT(getxattr(path, name, nullptr, 0), SyscallFailsWithErrno(EFAULT));
EXPECT_THAT(removexattr(path, name), SyscallFailsWithErrno(EFAULT));
}

TEST_F(XattrTest, XattrEmptyName) {
Expand Down Expand Up @@ -384,7 +384,8 @@ TEST_F(XattrTest, SetXattrReplaceFlag) {
TEST_F(XattrTest, SetXattrInvalidFlags) {
const char* path = test_file_name_.c_str();
int invalid_flags = 0xff;
EXPECT_THAT(setxattr(path, nullptr, nullptr, 0, invalid_flags),
char* null_name = nullptr;
EXPECT_THAT(setxattr(path, null_name, nullptr, 0, invalid_flags),
SyscallFailsWithErrno(EINVAL));
}

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

0 comments on commit c7442a3

Please sign in to comment.