• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "update_engine/boot_control_chromeos.h"
18 
19 #include <gtest/gtest.h>
20 
21 namespace chromeos_update_engine {
22 
23 class BootControlChromeOSTest : public ::testing::Test {
24  protected:
SetUp()25   void SetUp() override {
26     // We don't run Init() for bootctl_, we set its internal values instead.
27     bootctl_.num_slots_ = 2;
28     bootctl_.current_slot_ = 0;
29     bootctl_.boot_disk_name_ = "/dev/null";
30   }
31 
32   BootControlChromeOS bootctl_;  // BootControlChromeOS under test.
33 };
34 
TEST_F(BootControlChromeOSTest,SysfsBlockDeviceTest)35 TEST_F(BootControlChromeOSTest, SysfsBlockDeviceTest) {
36   EXPECT_EQ("/sys/block/sda", bootctl_.SysfsBlockDevice("/dev/sda"));
37   EXPECT_EQ("", bootctl_.SysfsBlockDevice("/foo/sda"));
38   EXPECT_EQ("", bootctl_.SysfsBlockDevice("/dev/foo/bar"));
39   EXPECT_EQ("", bootctl_.SysfsBlockDevice("/"));
40   EXPECT_EQ("", bootctl_.SysfsBlockDevice("./"));
41   EXPECT_EQ("", bootctl_.SysfsBlockDevice(""));
42 }
43 
TEST_F(BootControlChromeOSTest,GetPartitionNumberTest)44 TEST_F(BootControlChromeOSTest, GetPartitionNumberTest) {
45   // The partition name should not be case-sensitive.
46   EXPECT_EQ(2, bootctl_.GetPartitionNumber("kernel", 0));
47   EXPECT_EQ(2, bootctl_.GetPartitionNumber("boot", 0));
48   EXPECT_EQ(2, bootctl_.GetPartitionNumber("KERNEL", 0));
49   EXPECT_EQ(2, bootctl_.GetPartitionNumber("BOOT", 0));
50 
51   EXPECT_EQ(3, bootctl_.GetPartitionNumber("ROOT", 0));
52   EXPECT_EQ(3, bootctl_.GetPartitionNumber("system", 0));
53 
54   EXPECT_EQ(3, bootctl_.GetPartitionNumber("ROOT", 0));
55   EXPECT_EQ(3, bootctl_.GetPartitionNumber("system", 0));
56 
57   // Slot B.
58   EXPECT_EQ(4, bootctl_.GetPartitionNumber("KERNEL", 1));
59   EXPECT_EQ(5, bootctl_.GetPartitionNumber("ROOT", 1));
60 
61   // Slot C doesn't exists.
62   EXPECT_EQ(-1, bootctl_.GetPartitionNumber("KERNEL", 2));
63   EXPECT_EQ(-1, bootctl_.GetPartitionNumber("ROOT", 2));
64 
65   // Non A/B partitions are ignored.
66   EXPECT_EQ(-1, bootctl_.GetPartitionNumber("OEM", 0));
67   EXPECT_EQ(-1, bootctl_.GetPartitionNumber("A little panda", 0));
68 }
69 
70 }  // namespace chromeos_update_engine
71