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

Unified Diff: utils_unittest.cc

Issue 3706006: AU: Add a utility routine to get the filesystem size from a device. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: review comments Created 10 years, 2 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 | « utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils_unittest.cc
diff --git a/utils_unittest.cc b/utils_unittest.cc
index a5550d38db58033afb0d82aa39449d4e8f6666aa..4f1730596c52ca0f12239d1b15697aebb377b552 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -10,7 +10,10 @@
#include <string>
#include <vector>
-#include "gtest/gtest.h"
+#include <base/string_util.h>
+#include <gtest/gtest.h>
+
+#include "update_engine/test_utils.h"
#include "update_engine/utils.h"
using std::map;
@@ -205,4 +208,21 @@ TEST(UtilsTest, ApplyMapTest) {
}
}
+TEST(UtilsTest, RunAsRootGetFilesystemSizeTest) {
+ string img;
+ EXPECT_TRUE(utils::MakeTempFile("/tmp/img.XXXXXX", &img, NULL));
+ ScopedPathUnlinker img_unlinker(img);
+ CreateExtImageAtPath(img, NULL);
+ // Extend the "partition" holding the file system from 10MiB to 20MiB.
+ EXPECT_EQ(0, System(base::StringPrintf(
+ "dd if=/dev/zero of=%s seek=20971519 bs=1 count=1",
+ img.c_str())));
+ EXPECT_EQ(20 * 1024 * 1024, utils::FileSize(img));
+ int block_count = 0;
+ int block_size = 0;
+ EXPECT_TRUE(utils::GetFilesystemSize(img, &block_count, &block_size));
+ EXPECT_EQ(4096, block_size);
+ EXPECT_EQ(10 * 1024 * 1024 / 4096, block_count);
+}
+
} // namespace chromeos_update_engine
« no previous file with comments | « utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698