• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 <android-base/properties.h>
18 #include <fs_mgr.h>
19 #include <fstab/fstab.h>
20 #include <gtest/gtest.h>
21 #include <liblp/liblp.h>
22 #include <liblp/metadata_format.h>
23 #include <liblp/partition_opener.h>
24 #include <liblp/property_fetcher.h>
25 
26 #include "liblp_test.h"
27 
28 using namespace android::fs_mgr;
29 using namespace android::fs_mgr::testing;
30 using ::testing::Return;
31 
32 // Compliance test on the actual device with dynamic partitions.
33 class DeviceTest : public LiblpTest {
34   public:
SetUp()35     void SetUp() override {
36         // Read real properties.
37         IPropertyFetcher::OverrideForTesting(std::make_unique<PropertyFetcher>());
38         if (!IPropertyFetcher::GetInstance()->GetBoolProperty("ro.boot.dynamic_partitions",
39                                                               false)) {
40             GTEST_SKIP() << "Device doesn't have dynamic partitions enabled, skipping";
41         }
42     }
43 };
44 
TEST_F(DeviceTest,BlockDeviceInfo)45 TEST_F(DeviceTest, BlockDeviceInfo) {
46     PartitionOpener opener;
47     BlockDeviceInfo device_info;
48     ASSERT_TRUE(opener.GetInfo(fs_mgr_get_super_partition_name(), &device_info));
49 
50     // Sanity check that the device doesn't give us some weird inefficient
51     // alignment.
52     EXPECT_EQ(device_info.alignment % LP_SECTOR_SIZE, 0);
53     EXPECT_EQ(device_info.alignment_offset % LP_SECTOR_SIZE, 0);
54     EXPECT_LE(device_info.alignment_offset, INT_MAX);
55     EXPECT_EQ(device_info.logical_block_size % LP_SECTOR_SIZE, 0);
56 
57     // Having an alignment offset > alignment doesn't really make sense.
58     EXPECT_LT(device_info.alignment_offset, device_info.alignment);
59 }
60 
TEST_F(DeviceTest,ReadSuperPartitionCurrentSlot)61 TEST_F(DeviceTest, ReadSuperPartitionCurrentSlot) {
62     auto slot_suffix = fs_mgr_get_slot_suffix();
63     auto slot_number = SlotNumberForSlotSuffix(slot_suffix);
64     auto super_name = fs_mgr_get_super_partition_name(slot_number);
65     auto metadata = ReadMetadata(super_name, slot_number);
66     EXPECT_NE(metadata, nullptr);
67 }
68 
TEST_F(DeviceTest,ReadSuperPartitionOtherSlot)69 TEST_F(DeviceTest, ReadSuperPartitionOtherSlot) {
70     auto other_slot_suffix = fs_mgr_get_other_slot_suffix();
71     if (other_slot_suffix.empty()) {
72         GTEST_SKIP() << "No other slot, skipping";
73     }
74     if (IPropertyFetcher::GetInstance()->GetBoolProperty("ro.boot.dynamic_partitions_retrofit",
75                                                          false)) {
76         GTEST_SKIP() << "Device with retrofit dynamic partition may not have metadata at other "
77                      << "slot, skipping";
78     }
79 
80     auto other_slot_number = SlotNumberForSlotSuffix(other_slot_suffix);
81     auto other_super_name = fs_mgr_get_super_partition_name(other_slot_number);
82     auto other_metadata = ReadMetadata(other_super_name, other_slot_number);
83     EXPECT_NE(other_metadata, nullptr);
84 }
85