mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix suggestions from clang.
PiperOrigin-RevId: 255679603
This commit is contained in:
committed by
gVisor bot
parent
295078fa7a
commit
cf51e77d6d
@@ -140,7 +140,8 @@ TEST(ChmodTest, FchmodatFile) {
|
||||
SyscallSucceeds());
|
||||
|
||||
ASSERT_THAT(
|
||||
fchmodat(parent_fd, std::string(Basename(temp_file.path())).c_str(), 0444, 0),
|
||||
fchmodat(parent_fd, std::string(Basename(temp_file.path())).c_str(), 0444,
|
||||
0),
|
||||
SyscallSucceeds());
|
||||
EXPECT_THAT(close(parent_fd), SyscallSucceeds());
|
||||
|
||||
@@ -165,8 +166,9 @@ TEST(ChmodTest, FchmodatDir) {
|
||||
SyscallSucceeds());
|
||||
EXPECT_THAT(close(fd), SyscallSucceeds());
|
||||
|
||||
ASSERT_THAT(fchmodat(parent_fd, std::string(Basename(dir.path())).c_str(), 0, 0),
|
||||
SyscallSucceeds());
|
||||
ASSERT_THAT(
|
||||
fchmodat(parent_fd, std::string(Basename(dir.path())).c_str(), 0, 0),
|
||||
SyscallSucceeds());
|
||||
EXPECT_THAT(close(parent_fd), SyscallSucceeds());
|
||||
|
||||
EXPECT_THAT(open(dir.path().c_str(), O_RDONLY | O_DIRECTORY),
|
||||
|
||||
@@ -186,10 +186,10 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
return errorFromReturn("fchownat-fd", rc);
|
||||
},
|
||||
[](const std::string& path, uid_t owner, gid_t group) -> PosixError {
|
||||
ASSIGN_OR_RETURN_ERRNO(
|
||||
auto dirfd, Open(std::string(Dirname(path)), O_DIRECTORY | O_RDONLY));
|
||||
int rc = fchownat(dirfd.get(), std::string(Basename(path)).c_str(), owner,
|
||||
group, 0);
|
||||
ASSIGN_OR_RETURN_ERRNO(auto dirfd, Open(std::string(Dirname(path)),
|
||||
O_DIRECTORY | O_RDONLY));
|
||||
int rc = fchownat(dirfd.get(), std::string(Basename(path)).c_str(),
|
||||
owner, group, 0);
|
||||
MaybeSave();
|
||||
return errorFromReturn("fchownat-dirfd", rc);
|
||||
}));
|
||||
|
||||
@@ -273,7 +273,8 @@ TEST(ChrootTest, ProcMemSelfMapsNoEscapeProcOpen) {
|
||||
ASSERT_GT(bytes_read, 0);
|
||||
|
||||
// Finally we want to make sure the maps don't contain the chroot path
|
||||
ASSERT_EQ(std::string(buf, bytes_read).find(temp_dir.path()), std::string::npos);
|
||||
ASSERT_EQ(std::string(buf, bytes_read).find(temp_dir.path()),
|
||||
std::string::npos);
|
||||
}
|
||||
|
||||
// Test that mounts outside the chroot will not appear in /proc/self/mounts or
|
||||
|
||||
@@ -255,7 +255,8 @@ TEST(ExecDeathTest, InterpreterScriptArgNUL) {
|
||||
|
||||
TempPath script = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileWith(
|
||||
GetAbsoluteTestTmpdir(),
|
||||
absl::StrCat("#!", link.path(), " foo", std::string(1, '\0'), "bar"), 0755));
|
||||
absl::StrCat("#!", link.path(), " foo", std::string(1, '\0'), "bar"),
|
||||
0755));
|
||||
|
||||
CheckOutput(script.path(), {script.path()}, {}, ArgEnvExitStatus(2, 0),
|
||||
absl::StrCat(link.path(), "\nfoo\n", script.path(), "\n"));
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
#include "test/util/posix_error.h"
|
||||
|
||||
int main(int argc, char** argv, char** envp) {
|
||||
std::string exe = gvisor::testing::ProcessExePath(getpid()).ValueOrDie();
|
||||
std::string exe =
|
||||
gvisor::testing::ProcessExePath(getpid()).ValueOrDie();
|
||||
if (exe[0] != '/') {
|
||||
std::cerr << "relative path: " << exe << std::endl;
|
||||
exit(1);
|
||||
|
||||
@@ -160,7 +160,7 @@ class SocketTest : public ::testing::Test {
|
||||
|
||||
// MatchesStringLength checks that a tuple argument of (struct iovec *, int)
|
||||
// corresponding to an iovec array and its length, contains data that matches
|
||||
// the std::string length strlen.
|
||||
// the string length strlen.
|
||||
MATCHER_P(MatchesStringLength, strlen, "") {
|
||||
struct iovec* iovs = arg.first;
|
||||
int niov = arg.second;
|
||||
@@ -177,7 +177,7 @@ MATCHER_P(MatchesStringLength, strlen, "") {
|
||||
|
||||
// MatchesStringValue checks that a tuple argument of (struct iovec *, int)
|
||||
// corresponding to an iovec array and its length, contains data that matches
|
||||
// the std::string value str.
|
||||
// the string value str.
|
||||
MATCHER_P(MatchesStringValue, str, "") {
|
||||
struct iovec* iovs = arg.first;
|
||||
int len = strlen(str);
|
||||
|
||||
@@ -122,8 +122,8 @@ std::string DumpEvents(const std::vector<Event>& events, int indent_level) {
|
||||
(events.size() > 1) ? "s" : "");
|
||||
int i = 0;
|
||||
for (const Event& ev : events) {
|
||||
ss << StreamFormat("%sevents[%d]: %s\n", std::string(indent_level, '\t'), i++,
|
||||
DumpEvent(ev));
|
||||
ss << StreamFormat("%sevents[%d]: %s\n", std::string(indent_level, '\t'),
|
||||
i++, DumpEvent(ev));
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
@@ -295,10 +295,10 @@ PosixErrorOr<std::vector<Event>> DrainEvents(int fd) {
|
||||
if (event.len > 0) {
|
||||
TEST_CHECK(static_cast<int>(sizeof(struct inotify_event) + event.len) <=
|
||||
readlen);
|
||||
ev.name =
|
||||
std::string(cursor + offsetof(struct inotify_event, name)); // NOLINT
|
||||
ev.name = std::string(cursor +
|
||||
offsetof(struct inotify_event, name)); // NOLINT
|
||||
// Name field should always be smaller than event.len, otherwise we have
|
||||
// a buffer overflow. The two sizes aren't equal because the std::string
|
||||
// a buffer overflow. The two sizes aren't equal because the string
|
||||
// constructor will stop at the first null byte, while event.name may be
|
||||
// padded up to event.len using multiple null bytes.
|
||||
TEST_CHECK(ev.name.size() <= event.len);
|
||||
@@ -319,7 +319,8 @@ PosixErrorOr<FileDescriptor> InotifyInit1(int flags) {
|
||||
return FileDescriptor(fd);
|
||||
}
|
||||
|
||||
PosixErrorOr<int> InotifyAddWatch(int fd, const std::string& path, uint32_t mask) {
|
||||
PosixErrorOr<int> InotifyAddWatch(int fd, const std::string& path,
|
||||
uint32_t mask) {
|
||||
int wd;
|
||||
EXPECT_THAT(wd = inotify_add_watch(fd, path.c_str(), mask),
|
||||
SyscallSucceeds());
|
||||
@@ -980,8 +981,8 @@ TEST(Inotify, WatchOnRelativePath) {
|
||||
EXPECT_THAT(chdir(root.path().c_str()), SyscallSucceeds());
|
||||
|
||||
// Add a watch on file1 with a relative path.
|
||||
const int wd = ASSERT_NO_ERRNO_AND_VALUE(
|
||||
InotifyAddWatch(fd.get(), std::string(Basename(file1.path())), IN_ALL_EVENTS));
|
||||
const int wd = ASSERT_NO_ERRNO_AND_VALUE(InotifyAddWatch(
|
||||
fd.get(), std::string(Basename(file1.path())), IN_ALL_EVENTS));
|
||||
|
||||
// Perform a read on file1, this should generate an IN_ACCESS event.
|
||||
char c;
|
||||
|
||||
@@ -162,7 +162,8 @@ TEST(MadviseDontforkTest, DontforkShared) {
|
||||
// Mmap two shared file-backed pages and MADV_DONTFORK the second page.
|
||||
TempPath f = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileWith(
|
||||
/* parent = */ GetAbsoluteTestTmpdir(),
|
||||
/* content = */ std::string(kPageSize * 2, 2), TempPath::kDefaultFileMode));
|
||||
/* content = */ std::string(kPageSize * 2, 2),
|
||||
TempPath::kDefaultFileMode));
|
||||
FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(Open(f.path(), O_RDWR));
|
||||
|
||||
Mapping m = ASSERT_NO_ERRNO_AND_VALUE(Mmap(
|
||||
|
||||
@@ -60,7 +60,8 @@ int memfd_create(const std::string& name, unsigned int flags) {
|
||||
return syscall(__NR_memfd_create, name.c_str(), flags);
|
||||
}
|
||||
|
||||
PosixErrorOr<FileDescriptor> MemfdCreate(const std::string& name, uint32_t flags) {
|
||||
PosixErrorOr<FileDescriptor> MemfdCreate(const std::string& name,
|
||||
uint32_t flags) {
|
||||
int fd = memfd_create(name, flags);
|
||||
if (fd < 0) {
|
||||
return PosixError(
|
||||
|
||||
@@ -90,7 +90,7 @@ TEST(MknodTest, Fifo) {
|
||||
ASSERT_THAT(stat(fifo.c_str(), &st), SyscallSucceeds());
|
||||
EXPECT_TRUE(S_ISFIFO(st.st_mode));
|
||||
|
||||
std::string msg = "some string";
|
||||
std::string msg = "some std::string";
|
||||
std::vector<char> buf(512);
|
||||
|
||||
// Read-end of the pipe.
|
||||
@@ -116,7 +116,7 @@ TEST(MknodTest, FifoOtrunc) {
|
||||
ASSERT_THAT(stat(fifo.c_str(), &st), SyscallSucceeds());
|
||||
EXPECT_TRUE(S_ISFIFO(st.st_mode));
|
||||
|
||||
std::string msg = "some string";
|
||||
std::string msg = "some std::string";
|
||||
std::vector<char> buf(512);
|
||||
// Read-end of the pipe.
|
||||
ScopedThread t([&fifo, &buf, &msg]() {
|
||||
@@ -144,7 +144,7 @@ TEST(MknodTest, FifoTruncNoOp) {
|
||||
ASSERT_THAT(stat(fifo.c_str(), &st), SyscallSucceeds());
|
||||
EXPECT_TRUE(S_ISFIFO(st.st_mode));
|
||||
|
||||
std::string msg = "some string";
|
||||
std::string msg = "some std::string";
|
||||
std::vector<char> buf(512);
|
||||
// Read-end of the pipe.
|
||||
ScopedThread t([&fifo, &buf, &msg]() {
|
||||
|
||||
@@ -113,7 +113,7 @@ class MMapTest : public ::testing::Test {
|
||||
size_t length_ = 0;
|
||||
};
|
||||
|
||||
// Matches if arg contains the same contents as std::string str.
|
||||
// Matches if arg contains the same contents as string str.
|
||||
MATCHER_P(EqualsMemory, str, "") {
|
||||
if (0 == memcmp(arg, str.c_str(), str.size())) {
|
||||
return true;
|
||||
@@ -1086,8 +1086,8 @@ TEST_F(MMapFileTest, WriteShared) {
|
||||
ASSERT_THAT(Read(buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(buf.size()));
|
||||
// Cast to void* to avoid EXPECT_THAT assuming buf.data() is a
|
||||
// NUL-terminated C std::string. EXPECT_THAT will try to print a char* as a C
|
||||
// std::string, possibly overruning the buffer.
|
||||
// NUL-terminated C string. EXPECT_THAT will try to print a char* as a C
|
||||
// string, possibly overruning the buffer.
|
||||
EXPECT_THAT(reinterpret_cast<void*>(buf.data()),
|
||||
EqualsMemory(std::string(kFileContents)));
|
||||
}
|
||||
@@ -1122,6 +1122,7 @@ TEST_F(MMapFileTest, WriteSharedBeyondEnd) {
|
||||
ASSERT_THAT(Read(buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(first.size()));
|
||||
// Cast to void* to avoid EXPECT_THAT assuming buf.data() is a
|
||||
// NUL-terminated C string. EXPECT_THAT will try to print a char* as a C
|
||||
// NUL-terminated C std::string. EXPECT_THAT will try to print a char* as a C
|
||||
// std::string, possibly overruning the buffer.
|
||||
EXPECT_THAT(reinterpret_cast<void*>(buf.data()), EqualsMemory(first));
|
||||
@@ -1159,8 +1160,8 @@ TEST_F(MMapFileTest, WriteSharedTruncateUp) {
|
||||
ASSERT_THAT(Read(buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(buf.size()));
|
||||
// Cast to void* to avoid EXPECT_THAT assuming buf.data() is a
|
||||
// NUL-terminated C std::string. EXPECT_THAT will try to print a char* as a C
|
||||
// std::string, possibly overruning the buffer.
|
||||
// NUL-terminated C string. EXPECT_THAT will try to print a char* as a C
|
||||
// string, possibly overruning the buffer.
|
||||
EXPECT_THAT(reinterpret_cast<void*>(buf.data()), EqualsMemory(first));
|
||||
EXPECT_THAT(reinterpret_cast<void*>(buf.data() + kPageSize / 2),
|
||||
EqualsMemory(second));
|
||||
@@ -1234,8 +1235,8 @@ TEST_F(MMapFileTest, WriteSharedTruncateDownThenUp) {
|
||||
ASSERT_THAT(Read(buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(buf.size()));
|
||||
// Cast to void* to avoid EXPECT_THAT assuming buf.data() is a
|
||||
// NUL-terminated C std::string. EXPECT_THAT will try to print a char* as a C
|
||||
// std::string, possibly overruning the buffer.
|
||||
// NUL-terminated C string. EXPECT_THAT will try to print a char* as a C
|
||||
// string, possibly overruning the buffer.
|
||||
EXPECT_THAT(reinterpret_cast<void*>(buf.data()), EqualsMemory(zeroed));
|
||||
}
|
||||
|
||||
@@ -1363,8 +1364,8 @@ TEST_F(MMapFileTest, WritePrivate) {
|
||||
ASSERT_THAT(Read(buf.data(), buf.size()),
|
||||
SyscallSucceedsWithValue(buf.size()));
|
||||
// Cast to void* to avoid EXPECT_THAT assuming buf.data() is a
|
||||
// NUL-terminated C std::string. EXPECT_THAT will try to print a char* as a C
|
||||
// std::string, possibly overruning the buffer.
|
||||
// NUL-terminated C string. EXPECT_THAT will try to print a char* as a C
|
||||
// string, possibly overruning the buffer.
|
||||
EXPECT_THAT(reinterpret_cast<void*>(buf.data()),
|
||||
EqualsMemory(std::string(len, '\0')));
|
||||
}
|
||||
|
||||
+31
-20
@@ -206,8 +206,8 @@ PosixError WithSubprocess(SubprocessCallback const& running,
|
||||
}
|
||||
|
||||
// Access the file returned by name when a subprocess is running.
|
||||
PosixError AccessWhileRunning(std::function<std::string(int pid)> name, int flags,
|
||||
std::function<void(int fd)> access) {
|
||||
PosixError AccessWhileRunning(std::function<std::string(int pid)> name,
|
||||
int flags, std::function<void(int fd)> access) {
|
||||
FileDescriptor fd;
|
||||
return WithSubprocess(
|
||||
[&](int pid) -> PosixError {
|
||||
@@ -221,8 +221,8 @@ PosixError AccessWhileRunning(std::function<std::string(int pid)> name, int flag
|
||||
}
|
||||
|
||||
// Access the file returned by name when the a subprocess is zombied.
|
||||
PosixError AccessWhileZombied(std::function<std::string(int pid)> name, int flags,
|
||||
std::function<void(int fd)> access) {
|
||||
PosixError AccessWhileZombied(std::function<std::string(int pid)> name,
|
||||
int flags, std::function<void(int fd)> access) {
|
||||
FileDescriptor fd;
|
||||
return WithSubprocess(
|
||||
[&](int pid) -> PosixError {
|
||||
@@ -239,8 +239,8 @@ PosixError AccessWhileZombied(std::function<std::string(int pid)> name, int flag
|
||||
}
|
||||
|
||||
// Access the file returned by name when the a subprocess is exited.
|
||||
PosixError AccessWhileExited(std::function<std::string(int pid)> name, int flags,
|
||||
std::function<void(int fd)> access) {
|
||||
PosixError AccessWhileExited(std::function<std::string(int pid)> name,
|
||||
int flags, std::function<void(int fd)> access) {
|
||||
FileDescriptor fd;
|
||||
return WithSubprocess(
|
||||
[&](int pid) -> PosixError {
|
||||
@@ -704,7 +704,8 @@ TEST(ProcSelfExe, Absolute) {
|
||||
|
||||
// Sanity check for /proc/cpuinfo fields that must be present.
|
||||
TEST(ProcCpuinfo, RequiredFieldsArePresent) {
|
||||
std::string proc_cpuinfo = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/cpuinfo"));
|
||||
std::string proc_cpuinfo =
|
||||
ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/cpuinfo"));
|
||||
ASSERT_FALSE(proc_cpuinfo.empty());
|
||||
std::vector<std::string> cpuinfo_fields = absl::StrSplit(proc_cpuinfo, '\n');
|
||||
|
||||
@@ -743,7 +744,8 @@ TEST(ProcCpuinfo, DeniesWrite) {
|
||||
|
||||
// Sanity checks that uptime is present.
|
||||
TEST(ProcUptime, IsPresent) {
|
||||
std::string proc_uptime = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/uptime"));
|
||||
std::string proc_uptime =
|
||||
ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/uptime"));
|
||||
ASSERT_FALSE(proc_uptime.empty());
|
||||
std::vector<std::string> uptime_parts = absl::StrSplit(proc_uptime, ' ');
|
||||
|
||||
@@ -775,7 +777,8 @@ TEST(ProcUptime, IsPresent) {
|
||||
}
|
||||
|
||||
TEST(ProcMeminfo, ContainsBasicFields) {
|
||||
std::string proc_meminfo = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/meminfo"));
|
||||
std::string proc_meminfo =
|
||||
ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/meminfo"));
|
||||
EXPECT_THAT(proc_meminfo, AllOf(ContainsRegex(R"(MemTotal:\s+[0-9]+ kB)"),
|
||||
ContainsRegex(R"(MemFree:\s+[0-9]+ kB)")));
|
||||
}
|
||||
@@ -853,12 +856,14 @@ TEST(ProcStat, Fields) {
|
||||
}
|
||||
|
||||
TEST(ProcLoadavg, EndsWithNewline) {
|
||||
std::string proc_loadvg = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/loadavg"));
|
||||
std::string proc_loadvg =
|
||||
ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/loadavg"));
|
||||
EXPECT_EQ(proc_loadvg.back(), '\n');
|
||||
}
|
||||
|
||||
TEST(ProcLoadavg, Fields) {
|
||||
std::string proc_loadvg = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/loadavg"));
|
||||
std::string proc_loadvg =
|
||||
ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/loadavg"));
|
||||
std::vector<std::string> lines = absl::StrSplit(proc_loadvg, '\n');
|
||||
|
||||
// Single line.
|
||||
@@ -1238,10 +1243,12 @@ TEST(ProcPidStatTest, VmStats) {
|
||||
EXPECT_NE('0', data_str[0]);
|
||||
}
|
||||
|
||||
// Parse an array of NUL-terminated char* arrays, returning a vector of strings.
|
||||
// Parse an array of NUL-terminated char* arrays, returning a vector of
|
||||
// strings.
|
||||
std::vector<std::string> ParseNulTerminatedStrings(std::string contents) {
|
||||
EXPECT_EQ('\0', contents.back());
|
||||
// The split will leave an empty std::string if the NUL-byte remains, so pop it.
|
||||
// The split will leave an empty string if the NUL-byte remains, so pop
|
||||
// it.
|
||||
contents.pop_back();
|
||||
|
||||
return absl::StrSplit(contents, '\0');
|
||||
@@ -1491,7 +1498,8 @@ TEST(ProcPidFile, SubprocessExited) {
|
||||
}
|
||||
|
||||
PosixError DirContainsImpl(absl::string_view path,
|
||||
const std::vector<std::string>& targets, bool strict) {
|
||||
const std::vector<std::string>& targets,
|
||||
bool strict) {
|
||||
ASSIGN_OR_RETURN_ERRNO(auto listing, ListDir(path, false));
|
||||
bool success = true;
|
||||
|
||||
@@ -1530,8 +1538,8 @@ PosixError DirContainsExactly(absl::string_view path,
|
||||
return DirContainsImpl(path, targets, true);
|
||||
}
|
||||
|
||||
PosixError EventuallyDirContainsExactly(absl::string_view path,
|
||||
const std::vector<std::string>& targets) {
|
||||
PosixError EventuallyDirContainsExactly(
|
||||
absl::string_view path, const std::vector<std::string>& targets) {
|
||||
constexpr int kRetryCount = 100;
|
||||
const absl::Duration kRetryDelay = absl::Milliseconds(100);
|
||||
|
||||
@@ -1553,11 +1561,13 @@ TEST(ProcTask, Basic) {
|
||||
DirContains("/proc/self/task", {".", "..", absl::StrCat(getpid())}));
|
||||
}
|
||||
|
||||
std::vector<std::string> TaskFiles(const std::vector<std::string>& initial_contents,
|
||||
const std::vector<pid_t>& pids) {
|
||||
std::vector<std::string> TaskFiles(
|
||||
const std::vector<std::string>& initial_contents,
|
||||
const std::vector<pid_t>& pids) {
|
||||
return VecCat<std::string>(
|
||||
initial_contents,
|
||||
ApplyVec<std::string>([](const pid_t p) { return absl::StrCat(p); }, pids));
|
||||
ApplyVec<std::string>([](const pid_t p) { return absl::StrCat(p); },
|
||||
pids));
|
||||
}
|
||||
|
||||
std::vector<std::string> TaskFiles(const std::vector<pid_t>& pids) {
|
||||
@@ -1894,7 +1904,8 @@ void CheckDuplicatesRecursively(std::string path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT_EQ(children.find(std::string(dp->d_name)), children.end()) << dp->d_name;
|
||||
ASSERT_EQ(children.find(std::string(dp->d_name)), children.end())
|
||||
<< dp->d_name;
|
||||
children.insert(std::string(dp->d_name));
|
||||
|
||||
ASSERT_NE(dp->d_type, DT_UNKNOWN);
|
||||
|
||||
@@ -67,7 +67,7 @@ std::string ExtractPath(const struct sockaddr* addr) {
|
||||
// Abstract socket paths are null padded to the end of the struct
|
||||
// sockaddr. However, these null bytes may or may not show up in
|
||||
// /proc/net/unix depending on the kernel version. Truncate after the first
|
||||
// null byte (by treating path as a c-std::string).
|
||||
// null byte (by treating path as a c-string).
|
||||
return StrCat("@", &path[1]);
|
||||
}
|
||||
return std::string(path);
|
||||
@@ -80,7 +80,7 @@ PosixErrorOr<std::vector<UnixEntry>> ProcNetUnixEntries() {
|
||||
|
||||
bool skipped_header = false;
|
||||
std::vector<UnixEntry> entries;
|
||||
std::vector<std::string> lines = absl::StrSplit(content, absl::ByAnyChar("\n"));
|
||||
std::vector<std::string> lines = absl::StrSplit(content, '\n');
|
||||
std::cerr << "<contents of /proc/net/unix>" << std::endl;
|
||||
for (std::string line : lines) {
|
||||
// Emit the proc entry to the test output to provide context for the test
|
||||
@@ -123,7 +123,8 @@ PosixErrorOr<std::vector<UnixEntry>> ProcNetUnixEntries() {
|
||||
UnixEntry entry;
|
||||
|
||||
// Process the first 6 fields, up to but not including "Inode".
|
||||
std::vector<std::string> fields = absl::StrSplit(line, absl::MaxSplits(' ', 6));
|
||||
std::vector<std::string> fields =
|
||||
absl::StrSplit(line, absl::MaxSplits(' ', 6));
|
||||
|
||||
if (fields.size() < 7) {
|
||||
return PosixError(EINVAL, StrFormat("Invalid entry: '%s'\n", line));
|
||||
|
||||
@@ -105,7 +105,7 @@ struct Field {
|
||||
uint64_t value;
|
||||
};
|
||||
|
||||
// ParseFields returns a std::string representation of value, using the names in
|
||||
// ParseFields returns a string representation of value, using the names in
|
||||
// fields.
|
||||
std::string ParseFields(const Field* fields, size_t len, uint64_t value) {
|
||||
bool first = true;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
namespace gvisor {
|
||||
namespace testing {
|
||||
|
||||
// A NUL-terminated std::string containing the data used by tests using the following
|
||||
// A NUL-terminated string containing the data used by tests using the following
|
||||
// test helpers.
|
||||
extern const char kReadvTestData[];
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ TEST(SendFileTest, SendTriviallyWithBothFilesReadWrite) {
|
||||
|
||||
TEST(SendFileTest, SendAndUpdateFileOffset) {
|
||||
// Create temp files.
|
||||
// Test input std::string length must be > 2 AND even.
|
||||
// Test input string length must be > 2 AND even.
|
||||
constexpr char kData[] = "The slings and arrows of outrageous fortune,";
|
||||
constexpr int kDataSize = sizeof(kData) - 1;
|
||||
constexpr int kHalfDataSize = kDataSize / 2;
|
||||
@@ -180,7 +180,7 @@ TEST(SendFileTest, SendAndUpdateFileOffset) {
|
||||
|
||||
TEST(SendFileTest, SendAndUpdateFileOffsetFromNonzeroStartingPoint) {
|
||||
// Create temp files.
|
||||
// Test input std::string length must be > 2 AND divisible by 4.
|
||||
// Test input string length must be > 2 AND divisible by 4.
|
||||
constexpr char kData[] = "The slings and arrows of outrageous fortune,";
|
||||
constexpr int kDataSize = sizeof(kData) - 1;
|
||||
constexpr int kHalfDataSize = kDataSize / 2;
|
||||
@@ -233,7 +233,7 @@ TEST(SendFileTest, SendAndUpdateFileOffsetFromNonzeroStartingPoint) {
|
||||
|
||||
TEST(SendFileTest, SendAndUpdateGivenOffset) {
|
||||
// Create temp files.
|
||||
// Test input std::string length must be >= 4 AND divisible by 4.
|
||||
// Test input string length must be >= 4 AND divisible by 4.
|
||||
constexpr char kData[] = "Or to take Arms against a Sea of troubles,";
|
||||
constexpr int kDataSize = sizeof(kData) + 1;
|
||||
constexpr int kHalfDataSize = kDataSize / 2;
|
||||
|
||||
@@ -151,8 +151,8 @@ TEST(NetlinkRouteTest, GetPeerName) {
|
||||
// the value is considered ok.
|
||||
// 2: A description of what the sockopt value is expected to be. Should complete
|
||||
// the sentence "<value> was unexpected, expected <description>"
|
||||
using SockOptTest =
|
||||
::testing::TestWithParam<std::tuple<int, std::function<bool(int)>, std::string>>;
|
||||
using SockOptTest = ::testing::TestWithParam<
|
||||
std::tuple<int, std::function<bool(int)>, std::string>>;
|
||||
|
||||
TEST_P(SockOptTest, GetSockOpt) {
|
||||
int sockopt = std::get<0>(GetParam());
|
||||
|
||||
@@ -53,7 +53,7 @@ SocketPairKind UnixDomainSocketPair(int type) {
|
||||
|
||||
SocketPairKind FilesystemBoundUnixDomainSocketPair(int type) {
|
||||
std::string description = absl::StrCat(DescribeUnixDomainSocketType(type),
|
||||
" created with filesystem binding");
|
||||
" created with filesystem binding");
|
||||
if ((type & SOCK_DGRAM) == SOCK_DGRAM) {
|
||||
return SocketPairKind{
|
||||
description, AF_UNIX, type, 0,
|
||||
@@ -65,8 +65,9 @@ SocketPairKind FilesystemBoundUnixDomainSocketPair(int type) {
|
||||
}
|
||||
|
||||
SocketPairKind AbstractBoundUnixDomainSocketPair(int type) {
|
||||
std::string description = absl::StrCat(DescribeUnixDomainSocketType(type),
|
||||
" created with abstract namespace binding");
|
||||
std::string description =
|
||||
absl::StrCat(DescribeUnixDomainSocketType(type),
|
||||
" created with abstract namespace binding");
|
||||
if ((type & SOCK_DGRAM) == SOCK_DGRAM) {
|
||||
return SocketPairKind{
|
||||
description, AF_UNIX, type, 0,
|
||||
@@ -78,7 +79,7 @@ SocketPairKind AbstractBoundUnixDomainSocketPair(int type) {
|
||||
|
||||
SocketPairKind SocketpairGoferUnixDomainSocketPair(int type) {
|
||||
std::string description = absl::StrCat(DescribeUnixDomainSocketType(type),
|
||||
" created with the socketpair gofer");
|
||||
" created with the socketpair gofer");
|
||||
return SocketPairKind{description, AF_UNIX, type, 0,
|
||||
SocketpairGoferSocketPairCreator(AF_UNIX, type, 0)};
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
namespace gvisor {
|
||||
namespace testing {
|
||||
|
||||
// DescribeUnixDomainSocketType returns a human-readable std::string explaining the
|
||||
// DescribeUnixDomainSocketType returns a human-readable string explaining the
|
||||
// given Unix domain socket type.
|
||||
std::string DescribeUnixDomainSocketType(int type);
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ PosixError WalkTree(
|
||||
}
|
||||
|
||||
PosixErrorOr<std::vector<std::string>> ListDir(absl::string_view abspath,
|
||||
bool skipdots) {
|
||||
bool skipdots) {
|
||||
std::vector<std::string> files;
|
||||
|
||||
DIR* dir = opendir(std::string(abspath).c_str());
|
||||
@@ -381,7 +381,7 @@ PosixError RecursivelyCreateDir(absl::string_view path) {
|
||||
// Makes a path absolute with respect to an optional base. If no base is
|
||||
// provided it will use the current working directory.
|
||||
PosixErrorOr<std::string> MakeAbsolute(absl::string_view filename,
|
||||
absl::string_view base) {
|
||||
absl::string_view base) {
|
||||
if (filename.empty()) {
|
||||
return PosixError(EINVAL, "filename cannot be empty.");
|
||||
}
|
||||
@@ -494,7 +494,7 @@ std::string CleanPath(const absl::string_view unclean_path) {
|
||||
}
|
||||
|
||||
PosixErrorOr<std::string> GetRelativePath(absl::string_view source,
|
||||
absl::string_view dest) {
|
||||
absl::string_view dest) {
|
||||
if (!absl::StartsWith(source, "/") || !absl::StartsWith(dest, "/")) {
|
||||
// At least one of the inputs is not an absolute path.
|
||||
return PosixError(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user