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/properties.h>
23 #include <android-base/strings.h>
24 #include <gmock/gmock.h>
25 #include <vintf/VintfObject.h>
26
27 #include <iostream>
28
29 #include "SingleManifestTest.h"
30
31 namespace android {
32 namespace vintf {
33 namespace testing {
34
35 using std::endl;
36 using ::testing::Combine;
37 using ::testing::Contains;
38 using ::testing::Values;
39 using ::testing::ValuesIn;
40
41 // Tests that device manifest and framework compatibility matrix are compatible.
TEST_F(SystemVendorTest,DeviceManifestFrameworkMatrixCompatibility)42 TEST_F(SystemVendorTest, DeviceManifestFrameworkMatrixCompatibility) {
43 auto device_manifest = VintfObject::GetDeviceHalManifest();
44 ASSERT_NE(device_manifest, nullptr) << "Failed to get device HAL manifest.";
45 auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
46 ASSERT_NE(fwk_matrix, nullptr)
47 << "Failed to get framework compatibility matrix.";
48
49 string error;
50 EXPECT_TRUE(device_manifest->checkCompatibility(*fwk_matrix, &error))
51 << error;
52 }
53
54 // Tests that framework manifest and device compatibility matrix are compatible.
TEST_F(SystemVendorTest,FrameworkManifestDeviceMatrixCompatibility)55 TEST_F(SystemVendorTest, FrameworkManifestDeviceMatrixCompatibility) {
56 auto fwk_manifest = VintfObject::GetFrameworkHalManifest();
57 ASSERT_NE(fwk_manifest, nullptr) << "Failed to get framework HAL manifest.";
58 auto device_matrix = VintfObject::GetDeviceCompatibilityMatrix();
59 ASSERT_NE(device_matrix, nullptr)
60 << "Failed to get device compatibility matrix.";
61
62 string error;
63 EXPECT_TRUE(fwk_manifest->checkCompatibility(*device_matrix, &error))
64 << error;
65 }
66
67 // Tests that framework compatibility matrix and runtime info are compatible.
68 // AVB version is not a compliance requirement.
TEST_F(SystemVendorTest,FrameworkMatrixDeviceRuntimeCompatibility)69 TEST_F(SystemVendorTest, FrameworkMatrixDeviceRuntimeCompatibility) {
70 auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
71 ASSERT_NE(fwk_matrix, nullptr)
72 << "Failed to get framework compatibility matrix.";
73 auto runtime_info = VintfObject::GetRuntimeInfo();
74 ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
75
76 string error;
77 EXPECT_TRUE(runtime_info->checkCompatibility(
78 *fwk_matrix, &error,
79 ::android::vintf::CheckFlags::ENABLE_ALL_CHECKS.disableAvb()
80 .disableKernel()))
81 << error;
82 }
83
84 // Tests that runtime kernel matches requirements in compatibility matrix.
85 // This includes testing kernel version and kernel configurations.
86 //
87 // Requirements:
88 //
89 // VSR-3.4.6-001: CONFIG_RANDOMIZE_BASE
90 // VSR-3.4.6-002: CONFIG_SHADOW_CALL_STACK
91 // VSR-3.4.6-002|VSR-3.4.6-003: CONFIG_CFI_CLANG
92 //
93 // @VsrTest = VSR-3.4.6-001|VSR-3.4.6-002|VSR-3.4.6-003
TEST_F(SystemVendorTest,KernelCompatibility)94 TEST_F(SystemVendorTest, KernelCompatibility) {
95 auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
96 ASSERT_NE(fwk_matrix, nullptr)
97 << "Failed to get framework compatibility matrix.";
98 auto runtime_info = VintfObject::GetRuntimeInfo();
99 ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
100
101 string error;
102 EXPECT_TRUE(runtime_info->checkCompatibility(
103 *fwk_matrix, &error,
104 ::android::vintf::CheckFlags::DISABLE_ALL_CHECKS.enableKernel()))
105 << error;
106 }
107
TEST_F(SystemVendorTest,NoMainlineKernel)108 TEST_F(SystemVendorTest, NoMainlineKernel) {
109 auto runtime_info = VintfObject::GetRuntimeInfo();
110 ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
111
112 const bool is_release =
113 base::GetProperty("ro.build.version.codename", "") == "REL";
114
115 if (runtime_info->isMainlineKernel()) {
116 if (is_release) {
117 ADD_FAILURE() << "uname returns \"" << runtime_info->osRelease()
118 << "\". Mainline kernel is not allowed.";
119 } else {
120 GTEST_LOG_(ERROR)
121 << "uname returns \"" << runtime_info->osRelease()
122 << "\". Mainline kernel will not be allowed upon release.";
123 }
124 }
125 }
126
127 // Tests that vendor and framework are compatible.
128 // If any of the other tests in SystemVendorTest fails, this test will fail as
129 // well. This is a double check in case the sub-tests do not cover some
130 // checks.
131 // AVB version is not a compliance requirement.
TEST_F(SystemVendorTest,VendorFrameworkCompatibility)132 TEST_F(SystemVendorTest, VendorFrameworkCompatibility) {
133 string error;
134 EXPECT_EQ(
135 android::vintf::COMPATIBLE,
136 VintfObject::GetInstance()->checkCompatibility(
137 &error, ::android::vintf::CheckFlags::ENABLE_ALL_CHECKS.disableAvb()))
138 << error;
139 }
140
141 template <typename D, typename S>
insert(D * d,const S & s)142 static void insert(D *d, const S &s) {
143 d->insert(s.begin(), s.end());
144 }
145
146 std::set<std::string>
147 SystemVendorSingleHwbinderHalTest::manifest_hwbinder_hals_;
SetUpTestSuite()148 void SystemVendorSingleHwbinderHalTest::SetUpTestSuite() {
149 auto device_manifest = VintfObject::GetDeviceHalManifest();
150 ASSERT_NE(device_manifest, nullptr) << "Failed to get device HAL manifest.";
151 auto fwk_manifest = VintfObject::GetFrameworkHalManifest();
152 ASSERT_NE(fwk_manifest, nullptr) << "Failed to get framework HAL manifest.";
153
154 insert(&manifest_hwbinder_hals_,
155 GetDeclaredHidlHalsOfTransport(fwk_manifest, Transport::HWBINDER));
156 insert(&manifest_hwbinder_hals_,
157 GetDeclaredHidlHalsOfTransport(device_manifest, Transport::HWBINDER));
158 }
159
GetTestCaseSuffix(const::testing::TestParamInfo<ParamType> & info)160 std::string SystemVendorSingleHwbinderHalTest::GetTestCaseSuffix(
161 const ::testing::TestParamInfo<ParamType> &info) {
162 return SanitizeTestCaseName(info.param) + "_" +
163 std::to_string(info.index);
164 }
165
166 // This needs to be tested besides
167 // SingleManifestTest.ServedHwbinderHalIsInManifest because some HALs may
168 // refuse to provide its PID, and the partition cannot be inferred.
TEST_P(SystemVendorSingleHwbinderHalTest,ServedHwbinderHalIsInManifests)169 TEST_P(SystemVendorSingleHwbinderHalTest, ServedHwbinderHalIsInManifests) {
170 const auto &fq_instance_name = GetParam();
171 if (fq_instance_name.find(IBase::descriptor) == 0) {
172 GTEST_SKIP() << "Skipping for IBase: " << fq_instance_name;
173 }
174
175 EXPECT_THAT(manifest_hwbinder_hals_, Contains(fq_instance_name))
176 << fq_instance_name << " is being served, but it is not in a manifest.";
177 }
178
179 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(
180 SystemVendorSingleHwbinderHalTest);
181 INSTANTIATE_TEST_CASE_P(
182 SystemVendorTest, SystemVendorSingleHwbinderHalTest,
183 ValuesIn(SingleHwbinderHalTest::ListRegisteredHwbinderHals()),
184 &SystemVendorSingleHwbinderHalTest::GetTestCaseSuffix);
185
186 // Test framework manifest only
187
188 INSTANTIATE_TEST_CASE_P(
189 FrameworkManifest, SingleHidlTest,
190 Combine(ValuesIn(VtsTrebleVintfTestBase::GetHidlInstances(
191 VintfObject::GetFrameworkHalManifest())),
192 Values(VintfObject::GetFrameworkHalManifest())),
193 &GetTestCaseSuffix<SingleHidlTest>);
194
195 INSTANTIATE_TEST_CASE_P(
196 FrameworkManifest, SingleHwbinderHalTest,
197 Combine(ValuesIn(SingleHwbinderHalTest::ListRegisteredHwbinderHals()),
198 Values(VintfObject::GetFrameworkHalManifest())),
199 &SingleHwbinderHalTest::GetTestCaseSuffix);
200
201 INSTANTIATE_TEST_CASE_P(
202 FrameworkManifest, SingleAidlTest,
203 Combine(ValuesIn(VtsTrebleVintfTestBase::GetAidlInstances(
204 VintfObject::GetFrameworkHalManifest())),
205 Values(VintfObject::GetFrameworkHalManifest())),
206 &GetTestCaseSuffix<SingleAidlTest>);
207
208 } // namespace testing
209 } // namespace vintf
210 } // namespace android
211