Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: src/platform/update_engine/extent_mapper_unittest.cc

Issue 891002: AU: Delta Diff Generator (Closed)
Patch Set: fixes for review Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/update_engine/extent_mapper.cc ('k') | src/platform/update_engine/extent_writer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/update_engine/extent_mapper_unittest.cc
diff --git a/src/platform/update_engine/extent_mapper_unittest.cc b/src/platform/update_engine/extent_mapper_unittest.cc
index 6962004064498882f97e8d69942289d0d987a7ef..dc69437360ddaecebb238599d2006d23b8da78d1 100644
--- a/src/platform/update_engine/extent_mapper_unittest.cc
+++ b/src/platform/update_engine/extent_mapper_unittest.cc
@@ -11,6 +11,7 @@
#include <gtest/gtest.h>
#include "base/basictypes.h"
#include "update_engine/extent_mapper.h"
+#include "update_engine/graph_types.h"
#include "update_engine/utils.h"
using std::set;
@@ -27,8 +28,11 @@ TEST(ExtentMapperTest, RunAsRootSimpleTest) {
// In lieu of this, we do a weak test: make sure the extents of the unittest
// executable are consistent and they match with the size of the file.
const string kFilename = "/proc/self/exe";
- const off_t kBlockSize = 4096;
+ uint32 block_size = 0;
+ EXPECT_TRUE(extent_mapper::GetFilesystemBlockSize(kFilename, &block_size));
+ EXPECT_GT(block_size, 0);
+
vector<Extent> extents;
ASSERT_TRUE(extent_mapper::ExtentsForFileFibmap(kFilename, &extents));
@@ -48,7 +52,41 @@ TEST(ExtentMapperTest, RunAsRootSimpleTest) {
struct stat stbuf;
EXPECT_EQ(0, stat(kFilename.c_str(), &stbuf));
- EXPECT_EQ(blocks.size(), (stbuf.st_size + kBlockSize - 1)/kBlockSize);
+ EXPECT_EQ(blocks.size(), (stbuf.st_size + block_size - 1)/block_size);
+}
+
+TEST(ExtentMapperTest, RunAsRootSparseFileTest) {
+ // Create sparse file with one real block, then two sparse ones, then a real
+ // block at the end.
+ const char tmp_name_template[] =
+ "/tmp/ExtentMapperTest.RunAsRootSparseFileTest.XXXXXX";
+ char buf[sizeof(tmp_name_template)];
+ strncpy(buf, tmp_name_template, sizeof(buf));
+ COMPILE_ASSERT(sizeof(buf) > 8, buf_size_incorrect);
+ ASSERT_EQ('\0', buf[sizeof(buf) - 1]);
+
+ int fd = mkstemp(buf);
+ ASSERT_GE(fd, 0);
+
+ uint32 block_size = 0;
+ EXPECT_TRUE(extent_mapper::GetFilesystemBlockSize(buf, &block_size));
+ EXPECT_GT(block_size, 0);
+
+ EXPECT_EQ(1, pwrite(fd, "x", 1, 0));
+ EXPECT_EQ(1, pwrite(fd, "x", 1, 3 * block_size));
+ close(fd);
+
+ vector<Extent> extents;
+ EXPECT_TRUE(extent_mapper::ExtentsForFileFibmap(buf, &extents));
+ unlink(buf);
+ EXPECT_EQ(3, extents.size());
+ EXPECT_EQ(1, extents[0].num_blocks());
+ EXPECT_EQ(2, extents[1].num_blocks());
+ EXPECT_EQ(1, extents[2].num_blocks());
+ EXPECT_NE(kSparseHole, extents[0].start_block());
+ EXPECT_EQ(kSparseHole, extents[1].start_block());
+ EXPECT_NE(kSparseHole, extents[2].start_block());
+ EXPECT_NE(extents[2].start_block(), extents[0].start_block());
}
} // namespace chromeos_update_engine
« no previous file with comments | « src/platform/update_engine/extent_mapper.cc ('k') | src/platform/update_engine/extent_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698