Added support for generic loopback partition name parsing
Changed SplitPartitionName/MakePartitionName functions to
support generic device partition names where partition number
is separated from the disk name with 'p'. This used to be the
case only for MMC devices (/dev/mmcblk). But now, as long
as the disk name ends with a digit, then the following partition
name is assumed to be separated by 'p'.
Also added special case for NAND devices (/dev/ubiblock) to
be split and merged too, in order to make it possible to
use the split/merge functions with KernelDeviceOfBootDevice().
Updated KernelDeviceOfBootDevice() and GetInstallDev() to use
the SplitPartitionName/MakePartitionName functions.
Finally, updated the unit tests for ubiblock devices and added
unit tests for MakePartitionName function.
BUG=chromium:354494
TEST=Added/updated unit tests. All unit tests pass.
Change-Id: I8a813e13b315d118027bd84f179a0e569d0d4014
Reviewed-on: https://chromium-review.googlesource.com/191785
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/utils_unittest.cc b/utils_unittest.cc
index 7105d3a..5e9d098 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -45,6 +45,7 @@
TEST(UtilsTest, KernelDeviceOfBootDevice) {
+ EXPECT_EQ("", utils::KernelDeviceOfBootDevice(""));
EXPECT_EQ("", utils::KernelDeviceOfBootDevice("foo"));
EXPECT_EQ("", utils::KernelDeviceOfBootDevice("/dev/sda0"));
EXPECT_EQ("", utils::KernelDeviceOfBootDevice("/dev/sda1"));
@@ -207,11 +208,11 @@
TEST(UtilsTest, GetDiskNameTest) {
EXPECT_EQ("/dev/sda", utils::GetDiskName("/dev/sda3"));
- EXPECT_EQ("/dev/sda", utils::GetDiskName("/dev/sda1234"));
+ EXPECT_EQ("/dev/sdp", utils::GetDiskName("/dev/sdp1234"));
EXPECT_EQ("/dev/mmcblk0", utils::GetDiskName("/dev/mmcblk0p3"));
EXPECT_EQ("", utils::GetDiskName("/dev/mmcblk0p"));
EXPECT_EQ("", utils::GetDiskName("/dev/sda"));
- EXPECT_EQ("", utils::GetDiskName("/dev/ubiblock3_2"));
+ EXPECT_EQ("/dev/ubiblock", utils::GetDiskName("/dev/ubiblock3_2"));
EXPECT_EQ("", utils::GetDiskName("/dev/foo/bar"));
EXPECT_EQ("", utils::GetDiskName("/"));
EXPECT_EQ("", utils::GetDiskName(""));
@@ -233,16 +234,32 @@
TEST(UtilsTest, GetPartitionNumberTest) {
EXPECT_EQ(3, utils::GetPartitionNumber("/dev/sda3"));
+ EXPECT_EQ(3, utils::GetPartitionNumber("/dev/sdz3"));
EXPECT_EQ(123, utils::GetPartitionNumber("/dev/sda123"));
EXPECT_EQ(2, utils::GetPartitionNumber("/dev/mmcblk0p2"));
EXPECT_EQ(0, utils::GetPartitionNumber("/dev/mmcblk0p"));
- EXPECT_EQ(0, utils::GetPartitionNumber("/dev/ubiblock3_2"));
+ EXPECT_EQ(3, utils::GetPartitionNumber("/dev/ubiblock3_2"));
EXPECT_EQ(0, utils::GetPartitionNumber(""));
EXPECT_EQ(0, utils::GetPartitionNumber("/"));
EXPECT_EQ(0, utils::GetPartitionNumber("/dev/"));
EXPECT_EQ(0, utils::GetPartitionNumber("/dev/sda"));
+ EXPECT_EQ(10, utils::GetPartitionNumber("/dev/loop10"));
+ EXPECT_EQ(11, utils::GetPartitionNumber("/dev/loop28p11"));
+ EXPECT_EQ(10, utils::GetPartitionNumber("/dev/loop10_0"));
+ EXPECT_EQ(11, utils::GetPartitionNumber("/dev/loop28p11_0"));
}
+TEST(UtilsTest, MakePartitionNameTest) {
+ EXPECT_EQ("/dev/sda4", utils::MakePartitionName("/dev/sda", 4));
+ EXPECT_EQ("/dev/sda123", utils::MakePartitionName("/dev/sda", 123));
+ EXPECT_EQ("/dev/mmcblk2", utils::MakePartitionName("/dev/mmcblk", 2));
+ EXPECT_EQ("/dev/mmcblk0p2", utils::MakePartitionName("/dev/mmcblk0", 2));
+ EXPECT_EQ("/dev/loop8", utils::MakePartitionName("/dev/loop", 8));
+ EXPECT_EQ("/dev/loop12p2", utils::MakePartitionName("/dev/loop12", 2));
+ EXPECT_EQ("/dev/ubiblock3_0", utils::MakePartitionName("/dev/ubiblock", 3));
+}
+
+
TEST(UtilsTest, CompareCpuSharesTest) {
EXPECT_LT(utils::CompareCpuShares(utils::kCpuSharesLow,
utils::kCpuSharesNormal), 0);