• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
TEST_F(SystemVendorTest,KernelCompatibility)86 TEST_F(SystemVendorTest, KernelCompatibility) {
87   auto fwk_matrix = VintfObject::GetFrameworkCompatibilityMatrix();
88   ASSERT_NE(fwk_matrix, nullptr)
89       << "Failed to get framework compatibility matrix.";
90   auto runtime_info = VintfObject::GetRuntimeInfo();
91   ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
92 
93   string error;
94   EXPECT_TRUE(runtime_info->checkCompatibility(
95       *fwk_matrix, &error,
96       ::android::vintf::CheckFlags::DISABLE_ALL_CHECKS.enableKernel()))
97       << error;
98 }
99 
TEST_F(SystemVendorTest,NoMainlineKernel)100 TEST_F(SystemVendorTest, NoMainlineKernel) {
101   auto runtime_info = VintfObject::GetRuntimeInfo();
102   ASSERT_NE(nullptr, runtime_info) << "Failed to get runtime info.";
103 
104   const bool is_release =
105       base::GetProperty("ro.build.version.codename", "") == "REL";
106 
107   if (runtime_info->isMainlineKernel()) {
108     if (is_release) {
109       ADD_FAILURE() << "uname returns \"" << runtime_info->osRelease()
110                     << "\". Mainline kernel is not allowed.";
111     } else {
112       GTEST_LOG_(ERROR)
113           << "uname returns \"" << runtime_info->osRelease()
114           << "\". Mainline kernel will not be allowed upon release.";
115     }
116   }
117 }
118 
119 // Tests that vendor and framework are compatible.
120 // If any of the other tests in SystemVendorTest fails, this test will fail as
121 // well. This is a double check in case the sub-tests do not cover some
122 // checks.
123 // AVB version is not a compliance requirement.
TEST_F(SystemVendorTest,VendorFrameworkCompatibility)124 TEST_F(SystemVendorTest, VendorFrameworkCompatibility) {
125   string error;
126   EXPECT_EQ(
127       android::vintf::COMPATIBLE,
128       VintfObject::GetInstance()->checkCompatibility(
129           &error, ::android::vintf::CheckFlags::ENABLE_ALL_CHECKS.disableAvb()))
130       << error;
131 }
132 
133 template <typename D, typename S>
insert(D * d,const S & s)134 static void insert(D *d, const S &s) {
135   d->insert(s.begin(), s.end());
136 }
137 
138 std::set<std::string>
139     SystemVendorSingleHwbinderHalTest::manifest_hwbinder_hals_;
SetUpTestSuite()140 void SystemVendorSingleHwbinderHalTest::SetUpTestSuite() {
141   auto device_manifest = VintfObject::GetDeviceHalManifest();
142   ASSERT_NE(device_manifest, nullptr) << "Failed to get device HAL manifest.";
143   auto fwk_manifest = VintfObject::GetFrameworkHalManifest();
144   ASSERT_NE(fwk_manifest, nullptr) << "Failed to get framework HAL manifest.";
145 
146   insert(&manifest_hwbinder_hals_,
147          GetDeclaredHidlHalsOfTransport(fwk_manifest, Transport::HWBINDER));
148   insert(&manifest_hwbinder_hals_,
149          GetDeclaredHidlHalsOfTransport(device_manifest, Transport::HWBINDER));
150 }
151 
GetTestCaseSuffix(const::testing::TestParamInfo<ParamType> & info)152 std::string SystemVendorSingleHwbinderHalTest::GetTestCaseSuffix(
153     const ::testing::TestParamInfo<ParamType> &info) {
154   return SanitizeTestCaseName(info.param) + "_" +
155          std::to_string(info.index);
156 }
157 
158 // This needs to be tested besides
159 // SingleManifestTest.ServedHwbinderHalIsInManifest because some HALs may
160 // refuse to provide its PID, and the partition cannot be inferred.
TEST_P(SystemVendorSingleHwbinderHalTest,ServedHwbinderHalIsInManifests)161 TEST_P(SystemVendorSingleHwbinderHalTest, ServedHwbinderHalIsInManifests) {
162   const auto &fq_instance_name = GetParam();
163   if (fq_instance_name.find(IBase::descriptor) == 0) {
164     GTEST_SKIP() << "Skipping for IBase: " << fq_instance_name;
165   }
166 
167   EXPECT_THAT(manifest_hwbinder_hals_, Contains(fq_instance_name))
168       << fq_instance_name << " is being served, but it is not in a manifest.";
169 }
170 
171 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(
172     SystemVendorSingleHwbinderHalTest);
173 INSTANTIATE_TEST_CASE_P(
174     SystemVendorTest, SystemVendorSingleHwbinderHalTest,
175     ValuesIn(SingleHwbinderHalTest::ListRegisteredHwbinderHals()),
176     &SystemVendorSingleHwbinderHalTest::GetTestCaseSuffix);
177 
178 // Test framework manifest only
179 
180 INSTANTIATE_TEST_CASE_P(
181     FrameworkManifest, SingleHidlTest,
182     Combine(ValuesIn(VtsTrebleVintfTestBase::GetHidlInstances(
183                 VintfObject::GetFrameworkHalManifest())),
184             Values(VintfObject::GetFrameworkHalManifest())),
185     &GetTestCaseSuffix<SingleHidlTest>);
186 
187 INSTANTIATE_TEST_CASE_P(
188     FrameworkManifest, SingleHwbinderHalTest,
189     Combine(ValuesIn(SingleHwbinderHalTest::ListRegisteredHwbinderHals()),
190             Values(VintfObject::GetFrameworkHalManifest())),
191     &SingleHwbinderHalTest::GetTestCaseSuffix);
192 
193 INSTANTIATE_TEST_CASE_P(
194     FrameworkManifest, SingleAidlTest,
195     Combine(ValuesIn(VtsTrebleVintfTestBase::GetAidlInstances(
196                 VintfObject::GetFrameworkHalManifest())),
197             Values(VintfObject::GetFrameworkHalManifest())),
198     &GetTestCaseSuffix<SingleAidlTest>);
199 
200 }  // namespace testing
201 }  // namespace vintf
202 }  // namespace android
203