AU/unittest: use unique files in BzipExtentWriterTest.ChunkedTest
Stop using constant file names, which cause conflicts (and hence test
failures) when run in parallel. Also removed whitespaces at end of
lines.
BUG=chromium:236465
TEST=Test uses uniquely named temporary files
Change-Id: Ia75b94ac9b36c8c256bdfc06e9b761dbcab5482c
Reviewed-on: https://gerrit.chromium.org/gerrit/60645
Commit-Queue: Gilad Arnold <[email protected]>
Reviewed-by: Gilad Arnold <[email protected]>
Tested-by: Gilad Arnold <[email protected]>
diff --git a/bzip_extent_writer_unittest.cc b/bzip_extent_writer_unittest.cc
index 38ba117..185c201 100644
--- a/bzip_extent_writer_unittest.cc
+++ b/bzip_extent_writer_unittest.cc
@@ -33,7 +33,6 @@
}
virtual void TearDown() {
close(fd_);
- LOG(INFO) << "unlink: " << path_;
unlink(path_);
}
int fd() { return fd_; }
@@ -58,15 +57,15 @@
0x42, 0x5a, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26, 0x53, 0x59, 0xcc, 0xc3,
0x71, 0xd4, 0x00, 0x00, 0x02, 0x41, 0x80, 0x00, 0x10, 0x02, 0x00, 0x0c,
0x00, 0x20, 0x00, 0x21, 0x9a, 0x68, 0x33, 0x4d, 0x19, 0x97, 0x8b, 0xb9,
- 0x22, 0x9c, 0x28, 0x48, 0x66, 0x61, 0xb8, 0xea, 0x00,
+ 0x22, 0x9c, 0x28, 0x48, 0x66, 0x61, 0xb8, 0xea, 0x00,
};
-
+
DirectExtentWriter direct_writer;
BzipExtentWriter bzip_writer(&direct_writer);
EXPECT_TRUE(bzip_writer.Init(fd(), extents, kBlockSize));
EXPECT_TRUE(bzip_writer.Write(test, sizeof(test)));
EXPECT_TRUE(bzip_writer.End());
-
+
char buf[sizeof(test_uncompressed) + 1];
memset(buf, 0, sizeof(buf));
ssize_t bytes_read = pread(fd(), buf, sizeof(buf) - 1, 0);
@@ -76,10 +75,14 @@
TEST_F(BzipExtentWriterTest, ChunkedTest) {
const vector<char>::size_type kDecompressedLength = 2048 * 1024; // 2 MiB
- const string kDecompressedPath = "BzipExtentWriterTest-file-decompressed";
- const string kCompressedPath = "BzipExtentWriterTest-file-compressed";
+ string decompressed_path;
+ ASSERT_TRUE(utils::MakeTempFile("BzipExtentWriterTest-decompressed-XXXXXX",
+ &decompressed_path, NULL));
+ string compressed_path;
+ ASSERT_TRUE(utils::MakeTempFile("BzipExtentWriterTest-compressed-XXXXXX",
+ &compressed_path, NULL));
const size_t kChunkSize = 3;
-
+
vector<Extent> extents;
Extent extent;
extent.set_start_block(0);
@@ -88,15 +91,15 @@
vector<char> decompressed_data(kDecompressedLength);
FillWithData(&decompressed_data);
-
- EXPECT_TRUE(WriteFileVector(kDecompressedPath, decompressed_data));
-
- EXPECT_EQ(0, System(string("cat ") + kDecompressedPath + "|bzip2>" +
- kCompressedPath));
+
+ EXPECT_TRUE(WriteFileVector(decompressed_path, decompressed_data));
+
+ EXPECT_EQ(0, System(string("cat ") + decompressed_path + "|bzip2>" +
+ compressed_path));
vector<char> compressed_data;
- EXPECT_TRUE(utils::ReadFile(kCompressedPath, &compressed_data));
-
+ EXPECT_TRUE(utils::ReadFile(compressed_path, &compressed_data));
+
DirectExtentWriter direct_writer;
BzipExtentWriter bzip_writer(&direct_writer);
EXPECT_TRUE(bzip_writer.Init(fd(), extents, kBlockSize));
@@ -111,15 +114,15 @@
// Check that the const input has not been clobbered.
ExpectVectorsEq(original_compressed_data, compressed_data);
-
+
vector<char> output(kDecompressedLength + 1);
ssize_t bytes_read = pread(fd(), &output[0], output.size(), 0);
EXPECT_EQ(kDecompressedLength, bytes_read);
output.resize(kDecompressedLength);
ExpectVectorsEq(decompressed_data, output);
-
- unlink(kDecompressedPath.c_str());
- unlink(kCompressedPath.c_str());
+
+ unlink(decompressed_path.c_str());
+ unlink(compressed_path.c_str());
}
} // namespace chromeos_update_engine