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/unique_fd.h>
18 #include <android/hardware/weaver/1.0/IWeaver.h>
19 #include <ext4_utils/ext4_utils.h>
20 #include <fstab/fstab.h>
21 #include <gtest/gtest.h>
22
23 using namespace android::fs_mgr;
24
25 using android::base::unique_fd;
26 using android::hardware::weaver::V1_0::IWeaver;
27 using android::hardware::weaver::V1_0::WeaverConfig;
28 using android::hardware::weaver::V1_0::WeaverStatus;
29
TEST(MetadataPartition,FirstStageMount)30 TEST(MetadataPartition, FirstStageMount) {
31 Fstab fstab;
32 if (ReadFstabFromDt(&fstab)) {
33 auto entry = GetEntryForMountPoint(&fstab, "/metadata");
34 ASSERT_NE(entry, nullptr);
35 } else {
36 ASSERT_TRUE(ReadDefaultFstab(&fstab));
37 auto entry = GetEntryForMountPoint(&fstab, "/metadata");
38 ASSERT_NE(entry, nullptr);
39 EXPECT_TRUE(entry->fs_mgr_flags.first_stage_mount);
40 }
41 }
42
TEST(MetadataPartition,MinimumSize)43 TEST(MetadataPartition, MinimumSize) {
44 Fstab fstab;
45 ASSERT_TRUE(ReadDefaultFstab(&fstab));
46
47 auto entry = GetEntryForMountPoint(&fstab, "/metadata");
48 ASSERT_NE(entry, nullptr);
49
50 unique_fd fd(open(entry->blk_device.c_str(), O_RDONLY | O_CLOEXEC));
51 ASSERT_GE(fd, 0);
52
53 uint64_t size = get_block_device_size(fd);
54 EXPECT_GE(size, 16777216);
55 }
56
TEST(Weaver,MinimumSlots)57 TEST(Weaver, MinimumSlots) {
58 auto weaver = IWeaver::getService();
59 if (!weaver) {
60 return;
61 }
62
63 WeaverStatus hw_status;
64 WeaverConfig hw_config;
65
66 auto res = weaver->getConfig([&](WeaverStatus status, const WeaverConfig& config) {
67 hw_status = status;
68 hw_config = config;
69 });
70 ASSERT_TRUE(res.isOk());
71 ASSERT_EQ(hw_status, WeaverStatus::OK);
72 EXPECT_GE(hw_config.slots, 16);
73 }
74