payload_generation_config_unittest.cc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/payload_generator/payload_generation_config.h"
  17. #include <utility>
  18. #include <gtest/gtest.h>
  19. namespace chromeos_update_engine {
  20. class PayloadGenerationConfigTest : public ::testing::Test {};
  21. TEST_F(PayloadGenerationConfigTest, SimpleLoadPostInstallConfigTest) {
  22. ImageConfig image_config;
  23. image_config.partitions.emplace_back("root");
  24. brillo::KeyValueStore store;
  25. EXPECT_TRUE(
  26. store.LoadFromString("RUN_POSTINSTALL_root=true\n"
  27. "POSTINSTALL_PATH_root=postinstall\n"
  28. "FILESYSTEM_TYPE_root=ext4\n"
  29. "POSTINSTALL_OPTIONAL_root=true"));
  30. EXPECT_TRUE(image_config.LoadPostInstallConfig(store));
  31. EXPECT_FALSE(image_config.partitions[0].postinstall.IsEmpty());
  32. EXPECT_EQ(true, image_config.partitions[0].postinstall.run);
  33. EXPECT_EQ("postinstall", image_config.partitions[0].postinstall.path);
  34. EXPECT_EQ("ext4", image_config.partitions[0].postinstall.filesystem_type);
  35. EXPECT_TRUE(image_config.partitions[0].postinstall.optional);
  36. }
  37. TEST_F(PayloadGenerationConfigTest, LoadPostInstallConfigNameMismatchTest) {
  38. ImageConfig image_config;
  39. image_config.partitions.emplace_back("system");
  40. brillo::KeyValueStore store;
  41. EXPECT_TRUE(
  42. store.LoadFromString("RUN_POSTINSTALL_root=true\n"
  43. "POSTINSTALL_PATH_root=postinstall\n"
  44. "FILESYSTEM_TYPE_root=ext4"));
  45. EXPECT_FALSE(image_config.LoadPostInstallConfig(store));
  46. EXPECT_TRUE(image_config.partitions[0].postinstall.IsEmpty());
  47. }
  48. TEST_F(PayloadGenerationConfigTest, LoadDynamicPartitionMetadataTest) {
  49. ImageConfig image_config;
  50. brillo::KeyValueStore store;
  51. ASSERT_TRUE(
  52. store.LoadFromString("super_partition_groups=group_a group_b\n"
  53. "group_a_size=3221225472\n"
  54. "group_a_partition_list=system product_services\n"
  55. "group_b_size=2147483648\n"
  56. "group_b_partition_list=vendor\n"));
  57. EXPECT_TRUE(image_config.LoadDynamicPartitionMetadata(store));
  58. ASSERT_NE(nullptr, image_config.dynamic_partition_metadata);
  59. ASSERT_EQ(2, image_config.dynamic_partition_metadata->groups_size());
  60. const auto& group_a = image_config.dynamic_partition_metadata->groups(0);
  61. EXPECT_EQ("group_a", group_a.name());
  62. EXPECT_EQ(3221225472u, group_a.size());
  63. ASSERT_EQ(2, group_a.partition_names_size());
  64. EXPECT_EQ("system", group_a.partition_names(0));
  65. EXPECT_EQ("product_services", group_a.partition_names(1));
  66. const auto& group_b = image_config.dynamic_partition_metadata->groups(1);
  67. EXPECT_EQ("group_b", group_b.name());
  68. EXPECT_EQ(2147483648u, group_b.size());
  69. ASSERT_EQ(1, group_b.partition_names_size());
  70. EXPECT_EQ("vendor", group_b.partition_names(0));
  71. }
  72. TEST_F(PayloadGenerationConfigTest,
  73. LoadDynamicPartitionMetadataMissingSizeTest) {
  74. ImageConfig image_config;
  75. brillo::KeyValueStore store;
  76. ASSERT_TRUE(
  77. store.LoadFromString("super_partition_groups=foo\n"
  78. "foo_partition_list=baz\n"));
  79. EXPECT_FALSE(image_config.LoadDynamicPartitionMetadata(store));
  80. EXPECT_EQ(nullptr, image_config.dynamic_partition_metadata);
  81. }
  82. TEST_F(PayloadGenerationConfigTest, LoadDynamicPartitionMetadataBadSizeTest) {
  83. ImageConfig image_config;
  84. brillo::KeyValueStore store;
  85. ASSERT_TRUE(
  86. store.LoadFromString("super_partition_groups=foo\n"
  87. "foo_size=bar\n"
  88. "foo_partition_list=baz\n"));
  89. EXPECT_FALSE(image_config.LoadDynamicPartitionMetadata(store));
  90. EXPECT_EQ(nullptr, image_config.dynamic_partition_metadata);
  91. }
  92. TEST_F(PayloadGenerationConfigTest, ValidateDynamicPartitionMetadata) {
  93. ImageConfig image_config;
  94. PartitionConfig system("system");
  95. system.size = 2147483648u;
  96. PartitionConfig product_services("product_services");
  97. product_services.size = 1073741824u;
  98. image_config.partitions.push_back(std::move(system));
  99. image_config.partitions.push_back(std::move(product_services));
  100. brillo::KeyValueStore store;
  101. ASSERT_TRUE(
  102. store.LoadFromString("super_partition_groups=foo\n"
  103. "foo_size=3221225472\n"
  104. "foo_partition_list=system product_services\n"));
  105. EXPECT_TRUE(image_config.LoadDynamicPartitionMetadata(store));
  106. EXPECT_NE(nullptr, image_config.dynamic_partition_metadata);
  107. EXPECT_TRUE(image_config.ValidateDynamicPartitionMetadata());
  108. }
  109. TEST_F(PayloadGenerationConfigTest, ValidateDynamicPartitionMetadataTooBig) {
  110. ImageConfig image_config;
  111. PartitionConfig system("system");
  112. system.size = 4294967296u;
  113. image_config.partitions.push_back(std::move(system));
  114. brillo::KeyValueStore store;
  115. ASSERT_TRUE(
  116. store.LoadFromString("super_partition_groups=foo\n"
  117. "foo_size=3221225472\n"
  118. "foo_partition_list=system\n"));
  119. EXPECT_TRUE(image_config.LoadDynamicPartitionMetadata(store));
  120. EXPECT_NE(nullptr, image_config.dynamic_partition_metadata);
  121. EXPECT_FALSE(image_config.ValidateDynamicPartitionMetadata());
  122. }
  123. } // namespace chromeos_update_engine