Use GetAbsoluteTestTmpdir() rather than hard-code "/tmp"

This change makes these tests easier to run on systems that have their temp
directory in another location.

PiperOrigin-RevId: 388601202
This commit is contained in:
Adam Barth
2021-08-03 19:54:35 -07:00
committed by gVisor bot
parent 8caf231cb1
commit 681e541904
4 changed files with 7 additions and 5 deletions
+2 -1
View File
@@ -121,7 +121,8 @@ TEST(LseekTest, InvalidFD) {
}
TEST(LseekTest, DirCurEnd) {
const FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(Open("/tmp", O_RDONLY));
const FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(
Open(GetAbsoluteTestTmpdir().c_str(), O_RDONLY));
ASSERT_THAT(lseek(fd.get(), 0, SEEK_CUR), SyscallSucceedsWithValue(0));
}
+3 -2
View File
@@ -445,9 +445,10 @@ TEST(MemfdTest, SealsAreInodeLevelProperties) {
// Tmpfs files also support seals, but are created with F_SEAL_SEAL.
TEST(MemfdTest, TmpfsFilesHaveSealSeal) {
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(IsTmpfs("/tmp")));
std::string tmpdir = GetAbsoluteTestTmpdir();
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(IsTmpfs(tmpdir.c_str())));
const TempPath tmpfs_file =
ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileIn("/tmp"));
ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileIn(tmpdir.c_str()));
const FileDescriptor fd =
ASSERT_NO_ERRNO_AND_VALUE(Open(tmpfs_file.path(), O_RDWR, 0644));
EXPECT_THAT(fcntl(fd.get(), F_GET_SEALS),
+1 -1
View File
@@ -765,7 +765,7 @@ TEST_F(StatTest, StatxSymlink) {
SKIP_IF(!IsRunningOnGvisor() && statx(-1, nullptr, 0, 0, nullptr) < 0 &&
errno == ENOSYS);
std::string parent_dir = "/tmp";
std::string parent_dir = GetAbsoluteTestTmpdir();
TempPath link = ASSERT_NO_ERRNO_AND_VALUE(
TempPath::CreateSymlinkTo(parent_dir, test_file_name_));
std::string p = link.path();
+1 -1
View File
@@ -28,7 +28,7 @@ namespace testing {
namespace {
TEST(StatfsTest, CannotStatBadPath) {
auto temp_file = NewTempAbsPathInDir("/tmp");
auto temp_file = NewTempAbsPath();
struct statfs st;
EXPECT_THAT(statfs(temp_file.c_str(), &st), SyscallFailsWithErrno(ENOENT));