From abeee9f2cb6948ab95cc3645d613cc498ac3ff70 Mon Sep 17 00:00:00 2001 From: Kai Liu Date: Wed, 5 Mar 2014 14:28:47 -0800 Subject: [PATCH] Make sure GetUniqueID releated tests run on "regular" storage Summary: With the use of tmpfs or ramfs, unit tests related to GetUniqueID() failed because of the failure from ioctl, which doesn't work with these fancy file systems at all. I fixed this issue and make sure all related tests run on the "regular" storage (disk or flash). Test Plan: TEST_TMPDIR=/dev/shm make check -j32 Reviewers: igor, dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D16593 --- util/env_test.cc | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/util/env_test.cc b/util/env_test.cc index 828b49a0b..eb2829303 100644 --- a/util/env_test.cc +++ b/util/env_test.cc @@ -7,6 +7,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. See the AUTHORS file for names of contributors. +#include #include #include @@ -191,6 +192,15 @@ bool IsSingleVarint(const std::string& s) { } #ifdef OS_LINUX +// To make sure the Env::GetUniqueId() related tests work correctly, The files +// should be stored in regular storage like "hard disk" or "flash device". +// Otherwise we cannot get the correct id. +// +// The following function act as the replacement of test::TmpDir() that may be +// customized by user to be on a storage that doesn't work with GetUniqueId(). +// +// TODO(kailiu) This function still assumes /tmp/ reside in regular +// storage system. bool IsUniqueIDValid(const std::string& s) { return !s.empty() && !IsSingleVarint(s); } @@ -198,11 +208,21 @@ bool IsUniqueIDValid(const std::string& s) { const size_t MAX_ID_SIZE = 100; char temp_id[MAX_ID_SIZE]; +std::string GetOnDiskTestDir() { + char base[100]; + snprintf(base, sizeof(base), "/tmp/rocksdbtest-%d", + static_cast(geteuid())); + // Directory may already exist + Env::Default()->CreateDirIfMissing(base); + + return base; +} + // Only works in linux platforms TEST(EnvPosixTest, RandomAccessUniqueID) { // Create file. const EnvOptions soptions; - std::string fname = test::TmpDir() + "/" + "testfile"; + std::string fname = GetOnDiskTestDir() + "/" + "testfile"; unique_ptr wfile; ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); @@ -261,7 +281,7 @@ TEST(EnvPosixTest, RandomAccessUniqueIDConcurrent) { // Create the files std::vector fnames; for (int i = 0; i < 1000; ++i) { - fnames.push_back(test::TmpDir() + "/" + "testfile" + std::to_string(i)); + fnames.push_back(GetOnDiskTestDir() + "/" + "testfile" + std::to_string(i)); // Create file. unique_ptr wfile; @@ -294,7 +314,8 @@ TEST(EnvPosixTest, RandomAccessUniqueIDConcurrent) { // Only works in linux platforms TEST(EnvPosixTest, RandomAccessUniqueIDDeletes) { const EnvOptions soptions; - std::string fname = test::TmpDir() + "/" + "testfile"; + + std::string fname = GetOnDiskTestDir() + "/" + "testfile"; // Check that after file is deleted we don't get same ID again in a new file. std::unordered_set ids; -- GitLab