diff options
| -rw-r--r-- | compiler/utils/assembler_test.h | 11 | ||||
| -rw-r--r-- | runtime/base/unix_file/fd_file_test.cc | 3 | ||||
| -rw-r--r-- | runtime/base/unix_file/mapped_file_test.cc | 8 | ||||
| -rw-r--r-- | runtime/base/unix_file/random_access_file_test.h | 6 | ||||
| -rw-r--r-- | runtime/common_runtime_test.cc | 20 | ||||
| -rw-r--r-- | runtime/common_runtime_test.h | 8 |
6 files changed, 46 insertions, 10 deletions
diff --git a/compiler/utils/assembler_test.h b/compiler/utils/assembler_test.h index 754496b332..05ac70ed74 100644 --- a/compiler/utils/assembler_test.h +++ b/compiler/utils/assembler_test.h @@ -208,12 +208,17 @@ class AssemblerTest : public testing::Test { assembler_.reset(new Ass()); // Fake a runtime test for ScratchFile - std::string android_data; - CommonRuntimeTest::SetEnvironmentVariables(android_data); + CommonRuntimeTest::SetUpAndroidData(android_data_); SetUpHelpers(); } + void TearDown() OVERRIDE { + // We leave temporaries in case this failed so we can debug issues. + CommonRuntimeTest::TearDownAndroidData(android_data_, false); + tmpnam_ = ""; + } + // Override this to set up any architecture-specific things, e.g., register vectors. virtual void SetUpHelpers() {} @@ -687,6 +692,8 @@ class AssemblerTest : public testing::Test { std::string resolved_objdump_cmd_; std::string resolved_disassemble_cmd_; + std::string android_data_; + static constexpr size_t OBJDUMP_SECTION_LINE_MIN_TOKENS = 6; }; diff --git a/runtime/base/unix_file/fd_file_test.cc b/runtime/base/unix_file/fd_file_test.cc index 33b3d3e186..3481f2ff9f 100644 --- a/runtime/base/unix_file/fd_file_test.cc +++ b/runtime/base/unix_file/fd_file_test.cc @@ -59,6 +59,9 @@ TEST_F(FdFileTest, OpenClose) { EXPECT_TRUE(file.Open(good_path, O_RDONLY)); EXPECT_GE(file.Fd(), 0); EXPECT_TRUE(file.IsOpened()); + + file.Close(); + ASSERT_EQ(unlink(good_path.c_str()), 0); } TEST_F(FdFileTest, ReadFullyEmptyFile) { diff --git a/runtime/base/unix_file/mapped_file_test.cc b/runtime/base/unix_file/mapped_file_test.cc index 7e45321d48..59334d45ad 100644 --- a/runtime/base/unix_file/mapped_file_test.cc +++ b/runtime/base/unix_file/mapped_file_test.cc @@ -30,7 +30,7 @@ class MappedFileTest : public RandomAccessFileTest { } void SetUp() { - art::CommonRuntimeTest::SetEnvironmentVariables(android_data_); + RandomAccessFileTest::SetUp(); good_path_ = GetTmpPath("some-file.txt"); int fd = TEMP_FAILURE_RETRY(open(good_path_.c_str(), O_CREAT|O_RDWR, 0666)); @@ -42,6 +42,12 @@ class MappedFileTest : public RandomAccessFileTest { ASSERT_TRUE(CopyFile(src, &dst)); } + void TearDown() { + ASSERT_EQ(unlink(good_path_.c_str()), 0); + + RandomAccessFileTest::TearDown(); + } + virtual RandomAccessFile* MakeTestFile() { TEMP_FAILURE_RETRY(truncate(good_path_.c_str(), 0)); MappedFile* f = new MappedFile; diff --git a/runtime/base/unix_file/random_access_file_test.h b/runtime/base/unix_file/random_access_file_test.h index 1d0b866960..0002433628 100644 --- a/runtime/base/unix_file/random_access_file_test.h +++ b/runtime/base/unix_file/random_access_file_test.h @@ -35,7 +35,11 @@ class RandomAccessFileTest : public testing::Test { virtual RandomAccessFile* MakeTestFile() = 0; virtual void SetUp() { - art::CommonRuntimeTest::SetEnvironmentVariables(android_data_); + art::CommonRuntimeTest::SetUpAndroidData(android_data_); + } + + virtual void TearDown() { + art::CommonRuntimeTest::TearDownAndroidData(android_data_, true); } std::string GetTmpPath(const std::string& name) { diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index 997236200c..6f3b3a33d5 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -95,7 +95,7 @@ void ScratchFile::Unlink() { CommonRuntimeTest::CommonRuntimeTest() {} CommonRuntimeTest::~CommonRuntimeTest() {} -void CommonRuntimeTest::SetEnvironmentVariables(std::string& android_data) { +void CommonRuntimeTest::SetUpAndroidRoot() { if (IsHost()) { // $ANDROID_ROOT is set on the device, but not necessarily on the host. // But it needs to be set so that icu4c can find its locale data. @@ -135,7 +135,9 @@ void CommonRuntimeTest::SetEnvironmentVariables(std::string& android_data) { setenv("ANDROID_HOST_OUT", getenv("ANDROID_ROOT"), 1); } } +} +void CommonRuntimeTest::SetUpAndroidData(std::string& android_data) { // On target, Cannot use /mnt/sdcard because it is mounted noexec, so use subdir of dalvik-cache if (IsHost()) { const char* tmpdir = getenv("TMPDIR"); @@ -154,6 +156,15 @@ void CommonRuntimeTest::SetEnvironmentVariables(std::string& android_data) { setenv("ANDROID_DATA", android_data.c_str(), 1); } +void CommonRuntimeTest::TearDownAndroidData(const std::string& android_data, bool fail_on_error) { + if (fail_on_error) { + ASSERT_EQ(rmdir(android_data.c_str()), 0); + } else { + rmdir(android_data.c_str()); + } +} + + const DexFile* CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) { std::vector<const DexFile*> dex_files; std::string error_msg; @@ -167,7 +178,8 @@ const DexFile* CommonRuntimeTest::LoadExpectSingleDexFile(const char* location) } void CommonRuntimeTest::SetUp() { - SetEnvironmentVariables(android_data_); + SetUpAndroidRoot(); + SetUpAndroidData(android_data_); dalvik_cache_.append(android_data_.c_str()); dalvik_cache_.append("/dalvik-cache"); int mkdir_result = mkdir(dalvik_cache_.c_str(), 0700); @@ -211,7 +223,6 @@ void CommonRuntimeTest::SetUp() { runtime_->GetHeap()->VerifyHeap(); // Check for heap corruption before the test } - void CommonRuntimeTest::ClearDirectory(const char* dirpath) { ASSERT_TRUE(dirpath != nullptr); DIR* dir = opendir(dirpath); @@ -245,8 +256,7 @@ void CommonRuntimeTest::TearDown() { ClearDirectory(dalvik_cache_.c_str()); int rmdir_cache_result = rmdir(dalvik_cache_.c_str()); ASSERT_EQ(0, rmdir_cache_result); - int rmdir_data_result = rmdir(android_data_.c_str()); - ASSERT_EQ(0, rmdir_data_result); + TearDownAndroidData(android_data_, true); // icu4c has a fixed 10-element array "gCommonICUDataArray". // If we run > 10 tests, we fill that array and u_setCommonData fails. diff --git a/runtime/common_runtime_test.h b/runtime/common_runtime_test.h index 363d8daaf8..0fefc210bd 100644 --- a/runtime/common_runtime_test.h +++ b/runtime/common_runtime_test.h @@ -64,7 +64,13 @@ class ScratchFile { class CommonRuntimeTest : public testing::Test { public: - static void SetEnvironmentVariables(std::string& android_data); + static void SetUpAndroidRoot(); + + // Note: setting up ANDROID_DATA may create a temporary directory. If this is used in a + // non-derived class, be sure to also call the corresponding tear-down below. + static void SetUpAndroidData(std::string& android_data); + + static void TearDownAndroidData(const std::string& android_data, bool fail_on_error); CommonRuntimeTest(); ~CommonRuntimeTest(); |