boot_control_chromeos_unittest.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "update_engine/boot_control_chromeos.h"
  17. #include <gtest/gtest.h>
  18. namespace chromeos_update_engine {
  19. class BootControlChromeOSTest : public ::testing::Test {
  20. protected:
  21. void SetUp() override {
  22. // We don't run Init() for bootctl_, we set its internal values instead.
  23. bootctl_.num_slots_ = 2;
  24. bootctl_.current_slot_ = 0;
  25. bootctl_.boot_disk_name_ = "/dev/null";
  26. }
  27. BootControlChromeOS bootctl_; // BootControlChromeOS under test.
  28. };
  29. TEST_F(BootControlChromeOSTest, SysfsBlockDeviceTest) {
  30. EXPECT_EQ("/sys/block/sda", bootctl_.SysfsBlockDevice("/dev/sda"));
  31. EXPECT_EQ("", bootctl_.SysfsBlockDevice("/foo/sda"));
  32. EXPECT_EQ("", bootctl_.SysfsBlockDevice("/dev/foo/bar"));
  33. EXPECT_EQ("", bootctl_.SysfsBlockDevice("/"));
  34. EXPECT_EQ("", bootctl_.SysfsBlockDevice("./"));
  35. EXPECT_EQ("", bootctl_.SysfsBlockDevice(""));
  36. }
  37. TEST_F(BootControlChromeOSTest, GetPartitionNumberTest) {
  38. // The partition name should not be case-sensitive.
  39. EXPECT_EQ(2, bootctl_.GetPartitionNumber("kernel", 0));
  40. EXPECT_EQ(2, bootctl_.GetPartitionNumber("boot", 0));
  41. EXPECT_EQ(2, bootctl_.GetPartitionNumber("KERNEL", 0));
  42. EXPECT_EQ(2, bootctl_.GetPartitionNumber("BOOT", 0));
  43. EXPECT_EQ(3, bootctl_.GetPartitionNumber("ROOT", 0));
  44. EXPECT_EQ(3, bootctl_.GetPartitionNumber("system", 0));
  45. EXPECT_EQ(3, bootctl_.GetPartitionNumber("ROOT", 0));
  46. EXPECT_EQ(3, bootctl_.GetPartitionNumber("system", 0));
  47. // Slot B.
  48. EXPECT_EQ(4, bootctl_.GetPartitionNumber("KERNEL", 1));
  49. EXPECT_EQ(5, bootctl_.GetPartitionNumber("ROOT", 1));
  50. // Slot C doesn't exists.
  51. EXPECT_EQ(-1, bootctl_.GetPartitionNumber("KERNEL", 2));
  52. EXPECT_EQ(-1, bootctl_.GetPartitionNumber("ROOT", 2));
  53. // Non A/B partitions are ignored.
  54. EXPECT_EQ(-1, bootctl_.GetPartitionNumber("OEM", 0));
  55. EXPECT_EQ(-1, bootctl_.GetPartitionNumber("A little panda", 0));
  56. }
  57. } // namespace chromeos_update_engine