AU/unittest: eliminate use of kMountPath
This change should allow multiple tests to be run in parallel, including
a whole set of DeltaPerformerTest cases, a case of
FilesystemIteratorTest, a case of FilesystemCopierActionTest, and a case
of UtilsTest.
BUG=chromium:236465
TEST=Tests successful
Change-Id: I47a2afccbece5b0a9e637b3d80af1bf7bbf3623e
Reviewed-on: https://gerrit.chromium.org/gerrit/62952
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/filesystem_iterator_unittest.cc b/filesystem_iterator_unittest.cc
index fddde01..2ea3728 100644
--- a/filesystem_iterator_unittest.cc
+++ b/filesystem_iterator_unittest.cc
@@ -44,30 +44,42 @@
TEST_F(FilesystemIteratorTest, RunAsRootSuccessTest) {
ASSERT_EQ(0, getuid());
- string first_image;
+
+ // Create uniquely named main/sub images.
+ string main_image;
ASSERT_TRUE(utils::MakeTempFile("FilesystemIteratorTest.image1-XXXXXX",
- &first_image, NULL));
+ &main_image, NULL));
+ ScopedPathUnlinker main_image_unlinker(main_image);
+
string sub_image;
ASSERT_TRUE(utils::MakeTempFile("FilesystemIteratorTest.image2-XXXXXX",
&sub_image, NULL));
+ ScopedPathUnlinker sub_image_unlinker(sub_image);
+
+ // Create uniqely named main/sub mount points.
+ string main_image_mount_point;
+ ASSERT_TRUE(utils::MakeTempDirectory(
+ "/tmp/FilesystemIteratorTest.mount-XXXXXX",
+ &main_image_mount_point));
+ ScopedPathUnlinker main_image_mount_point_unlinker(main_image_mount_point);
+ const string sub_image_mount_point = main_image_mount_point + "/some_dir/mnt";
vector<string> expected_paths_vector;
- CreateExtImageAtPath(first_image, &expected_paths_vector);
+ CreateExtImageAtPath(main_image, &expected_paths_vector);
CreateExtImageAtPath(sub_image, NULL);
- ASSERT_EQ(0, System(string("mount -o loop ") + first_image + " " +
- kMountPath));
+ ASSERT_EQ(0, System(string("mount -o loop ") + main_image + " " +
+ main_image_mount_point));
ASSERT_EQ(0, System(string("mount -o loop ") + sub_image + " " +
- kMountPath + "/some_dir/mnt"));
+ sub_image_mount_point));
for (vector<string>::iterator it = expected_paths_vector.begin();
it != expected_paths_vector.end(); ++it)
- *it = kMountPath + *it;
+ *it = main_image_mount_point + *it;
set<string> expected_paths(expected_paths_vector.begin(),
expected_paths_vector.end());
- VerifyAllPaths(kMountPath, expected_paths);
+ VerifyAllPaths(main_image_mount_point, expected_paths);
- EXPECT_TRUE(utils::UnmountFilesystem(kMountPath + string("/some_dir/mnt")));
- EXPECT_TRUE(utils::UnmountFilesystem(kMountPath));
- EXPECT_EQ(0, System(string("rm -f ") + first_image + " " + sub_image));
+ EXPECT_TRUE(utils::UnmountFilesystem(sub_image_mount_point));
+ EXPECT_TRUE(utils::UnmountFilesystem(main_image_mount_point));
}
TEST_F(FilesystemIteratorTest, NegativeTest) {
diff --git a/test_utils.cc b/test_utils.cc
index 5379979..b489cf1 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -28,6 +28,8 @@
namespace chromeos_update_engine {
+const char* const kMountPathTemplate = "/tmp/UpdateEngineTests_mnt-XXXXXX";
+
bool WriteFileVector(const std::string& path, const std::vector<char>& data) {
return utils::WriteFile(path.c_str(), &data[0], data.size());
}
@@ -193,31 +195,41 @@
}
void CreateExtImageAtPath(const string& path, vector<string>* out_paths) {
- // create 10MiB sparse file
+ // create 10MiB sparse file, mounted at a unique location.
+ string mount_path;
+ CHECK(utils::MakeTempDirectory(kMountPathTemplate, &mount_path));
+ ScopedPathUnlinker mount_path_unlinker(mount_path);
+
EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s"
" seek=10485759 bs=1 count=1",
path.c_str())));
EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -b 4096 -F %s", path.c_str())));
- EXPECT_EQ(0, System(StringPrintf("mkdir -p %s", kMountPath)));
EXPECT_EQ(0, System(StringPrintf("mount -o loop %s %s", path.c_str(),
- kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("echo hi > %s/hi", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("echo hello > %s/hello", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/empty_dir", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/mnt", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("echo T > %s/some_dir/test", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("mkfifo %s/some_dir/fifo", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("mknod %s/cdev c 2 3", kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("ln -s /some/target %s/sym", kMountPath)));
+ mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("echo hi > %s/hi", mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("echo hello > %s/hello",
+ mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir", mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/empty_dir",
+ mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/mnt",
+ mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("echo T > %s/some_dir/test",
+ mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("mkfifo %s/some_dir/fifo",
+ mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("mknod %s/cdev c 2 3", mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("ln -s /some/target %s/sym",
+ mount_path.c_str())));
EXPECT_EQ(0, System(StringPrintf("ln %s/some_dir/test %s/testlink",
- kMountPath, kMountPath)));
- EXPECT_EQ(0, System(StringPrintf("echo T > %s/srchardlink0", kMountPath)));
+ mount_path.c_str(), mount_path.c_str())));
+ EXPECT_EQ(0, System(StringPrintf("echo T > %s/srchardlink0",
+ mount_path.c_str())));
EXPECT_EQ(0, System(StringPrintf("ln %s/srchardlink0 %s/srchardlink1",
- kMountPath, kMountPath)));
+ mount_path.c_str(), mount_path.c_str())));
EXPECT_EQ(0, System(StringPrintf("ln -s bogus %s/boguslink",
- kMountPath)));
- EXPECT_TRUE(utils::UnmountFilesystem(kMountPath));
+ mount_path.c_str())));
+ EXPECT_TRUE(utils::UnmountFilesystem(mount_path.c_str()));
if (out_paths) {
out_paths->clear();
diff --git a/test_utils.h b/test_utils.h
index 6d3c5bd..2b72af1 100644
--- a/test_utils.h
+++ b/test_utils.h
@@ -112,7 +112,6 @@
0xbe, 0x9f, 0xa3, 0x5d
};
-const char* const kMountPath = "/tmp/UpdateEngineTests_mnt";
} // namespace {}
// Creates an empty ext image.