1 /*
2 * Copyright (C) 2018 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 // SystemVendorTest test cases that runs on P+ vendor.
18
19 #include "SystemVendorTest.h"
20
21 #include <android-base/logging.h>
22 #include <android-base/strings.h>
23 #include <vintf/VintfObject.h>
24 #include <iostream>
25
26 #include "SingleManifestTest.h"
27
28 namespace android {
29 namespace vintf {
30 namespace testing {
31
32 using std::endl;
33
34 // Tests that device manifest and framework compatibility matrix are compatible.
TEST_F(SystemVendorTest,DeviceManifestFrameworkMatrixCompatibility)35 TEST_F(SystemVendorTest, DeviceManifestFrameworkMatrixCompatibility) {
36 auto device_manifest = VintfObject::GetDeviceHalManifest();
37 ASSERT_NE(device_manifest, nullptr) << "Failed to get device HAL manifest.";
38 auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
39 ASSERT_NE(fwk_matrix, nullptr)
40 << "Failed to get framework compatibility matrix.";
41
42 string error;
43 EXPECT_TRUE(device_manifest->checkCompatibility(*fwk_matrix, &error))
44 << error;
45 }
46
47 // Tests that framework manifest and device compatibility matrix are compatible.
TEST_F(SystemVendorTest,FrameworkManifestDeviceMatrixCompatibility)48 TEST_F(SystemVendorTest, FrameworkManifestDeviceMatrixCompatibility) {
49 auto fwk_manifest = VintfObject::GetFrameworkHalManifest();
50 ASSERT_NE(fwk_manifest, nullptr) << "Failed to get framework HAL manifest.";
51 auto device_matrix = VintfObject::GetDeviceCompatibilityMatrix();
52 ASSERT_NE(device_matrix, nullptr)
53 << "Failed to get device compatibility matrix.";
54
55 string error;
56 EXPECT_TRUE(fwk_manifest->checkCompatibility(*device_matrix, &error))
57 << error;
58 }
59
60 // Tests that framework compatibility matrix and runtime info are compatible.
61 // AVB version is not a compliance requirement.
TEST_F(SystemVendorTest,FrameworkMatrixDeviceRuntimeCompatibility)62 TEST_F(SystemVendorTest, FrameworkMatrixDeviceRuntimeCompatibility) {
63 auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
64 ASSERT_NE(fwk_matrix, nullptr)
65 << "Failed to get framework compatibility matrix.";
66 auto runtime_info = VintfObject::GetRuntimeInfo();
67 ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
68
69 string error;
70 EXPECT_TRUE(runtime_info->checkCompatibility(
71 *fwk_matrix, &error,
72 ::android::vintf::CheckFlags::ENABLE_ALL_CHECKS.disableAvb()
73 .disableKernel()))
74 << error;
75 }
76
77 // Tests that runtime kernel matches requirements in compatibility matrix.
78 // This includes testing kernel version and kernel configurations.
TEST_F(SystemVendorTest,KernelCompatibility)79 TEST_F(SystemVendorTest, KernelCompatibility) {
80 auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
81 ASSERT_NE(fwk_matrix, nullptr)
82 << "Failed to get framework compatibility matrix.";
83 auto runtime_info = VintfObject::GetRuntimeInfo();
84 ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
85
86 string error;
87 EXPECT_TRUE(runtime_info->checkCompatibility(
88 *fwk_matrix, &error,
89 ::android::vintf::CheckFlags::DISABLE_ALL_CHECKS.enableKernel()))
90 << error;
91 }
92
93 // Tests that vendor and framework are compatible.
94 // If any of the other tests in SystemVendorTest fails, this test will fail as
95 // well. This is a sanity check in case the sub-tests do not cover some
96 // checks.
97 // AVB version is not a compliance requirement.
TEST_F(SystemVendorTest,VendorFrameworkCompatibility)98 TEST_F(SystemVendorTest, VendorFrameworkCompatibility) {
99 string error;
100 EXPECT_EQ(android::vintf::COMPATIBLE,
101 VintfObject::CheckCompatibility(
102 {}, &error,
103 ::android::vintf::CheckFlags::ENABLE_ALL_CHECKS.disableAvb()))
104 << error;
105 }
106
107 template <typename D, typename S>
insert(D * d,const S & s)108 static void insert(D *d, const S &s) {
109 d->insert(s.begin(), s.end());
110 }
111
112 // This needs to be tested besides
113 // SingleManifestTest.ServedHwbinderHalsAreInManifest because some HALs may
114 // refuse to provide its PID, and the partition cannot be inferred.
TEST_F(SystemVendorTest,ServedHwbinderHalsAreInManifest)115 TEST_F(SystemVendorTest, ServedHwbinderHalsAreInManifest) {
116 auto device_manifest = VintfObject::GetDeviceHalManifest();
117 ASSERT_NE(device_manifest, nullptr) << "Failed to get device HAL manifest.";
118 auto fwk_manifest = VintfObject::GetFrameworkHalManifest();
119 ASSERT_NE(fwk_manifest, nullptr) << "Failed to get framework HAL manifest.";
120
121 std::set<std::string> manifest_hwbinder_hals;
122
123 insert(&manifest_hwbinder_hals, GetHwbinderHals(fwk_manifest));
124 insert(&manifest_hwbinder_hals, GetHwbinderHals(device_manifest));
125
126 Return<void> ret = default_manager_->list([&](const auto &list) {
127 for (const auto &name : list) {
128 // TODO(b/73774955): use standardized parsing code for fqinstancename
129 if (std::string(name).find(IBase::descriptor) == 0) continue;
130
131 EXPECT_NE(manifest_hwbinder_hals.find(name), manifest_hwbinder_hals.end())
132 << name << " is being served, but it is not in a manifest.";
133 }
134 });
135 EXPECT_TRUE(ret.isOk());
136 }
137
GetTestManifests()138 static std::vector<HalManifestPtr> GetTestManifests() {
139 return {
140 VintfObject::GetFrameworkHalManifest(),
141 };
142 }
143
144 INSTANTIATE_TEST_CASE_P(FrameworkManifest, SingleManifestTest,
145 ::testing::ValuesIn(GetTestManifests()));
146
147 } // namespace testing
148 } // namespace vintf
149 } // namespace android
150