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 #include "DeviceManifestTest.h"
18
19 #include <android-base/properties.h>
20 #include <vintf/VintfObject.h>
21 #include "SingleManifestTest.h"
22
23 namespace android {
24 namespace vintf {
25 namespace testing {
26
SetUp()27 void DeviceManifestTest::SetUp() {
28 VtsTrebleVintfTestBase::SetUp();
29
30 vendor_manifest_ = VintfObject::GetDeviceHalManifest();
31 ASSERT_NE(vendor_manifest_, nullptr)
32 << "Failed to get vendor HAL manifest." << endl;
33 }
34
35 // Tests that Shipping FCM Version in the device manifest is at least the
36 // minimum Shipping FCM Version as required by Shipping API level.
TEST_F(DeviceManifestTest,ShippingFcmVersion)37 TEST_F(DeviceManifestTest, ShippingFcmVersion) {
38 uint64_t shipping_api_level = GetShippingApiLevel();
39 ASSERT_NE(shipping_api_level, 0u)
40 << "Device's shipping API level cannot be determined.";
41
42 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
43 if (shipping_fcm_version == Level::UNSPECIFIED) {
44 // O / O-MR1 vendor image doesn't have shipping FCM version declared and
45 // shipping FCM version is inferred from Shipping API level, hence it always
46 // meets the requirement.
47 return;
48 }
49
50 ASSERT_GE(shipping_api_level, kFcm2ApiLevelMap.begin()->first /* 25 */)
51 << "Pre-N devices should not run this test.";
52
53 auto it = kFcm2ApiLevelMap.find(shipping_api_level);
54 ASSERT_TRUE(it != kFcm2ApiLevelMap.end())
55 << "No launch requirement is set yet for Shipping API level "
56 << shipping_api_level << ". Please update the test.";
57
58 Level required_fcm_version = it->second;
59
60 ASSERT_GE(shipping_fcm_version, required_fcm_version)
61 << "Shipping API level == " << shipping_api_level
62 << " requires Shipping FCM Version >= " << required_fcm_version
63 << " (but is " << shipping_fcm_version << ")";
64 }
65
TEST_F(DeviceManifestTest,KernelFcmVersion)66 TEST_F(DeviceManifestTest, KernelFcmVersion) {
67 Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
68 Level kernel_fcm_version = VintfObject::GetRuntimeInfo()->kernelLevel();
69
70 if (shipping_fcm_version == Level::UNSPECIFIED ||
71 shipping_fcm_version < Level::R) {
72 GTEST_SKIP() << "Kernel FCM version not enforced on target FCM version "
73 << shipping_fcm_version;
74 }
75 ASSERT_NE(Level::UNSPECIFIED, kernel_fcm_version)
76 << "Kernel FCM version must be specified for target FCM version "
77 << shipping_fcm_version;
78 ASSERT_GE(kernel_fcm_version, shipping_fcm_version)
79 << "Kernel FCM version " << kernel_fcm_version
80 << " must be greater or equal to target FCM version "
81 << shipping_fcm_version;
82 }
83
84 // Tests that deprecated HALs are not in the manifest, unless a higher,
85 // non-deprecated minor version is in the manifest.
TEST_F(DeviceManifestTest,NoDeprecatedHalsOnManifest)86 TEST_F(DeviceManifestTest, NoDeprecatedHalsOnManifest) {
87 string error;
88 EXPECT_EQ(android::vintf::NO_DEPRECATED_HALS,
89 VintfObject::GetInstance()->checkDeprecation(
90 HidlInterfaceMetadata::all(), &error))
91 << error;
92 }
93
94 // Tests that devices launching R support mapper@4.0. Go devices are exempt
95 // from this requirement, so we use this test to enforce instead of the
96 // compatibility matrix.
TEST_F(DeviceManifestTest,GrallocHalVersionCompatibility)97 TEST_F(DeviceManifestTest, GrallocHalVersionCompatibility) {
98 Level shipping_fcm_version = vendor_manifest_->level();
99 bool is_go_device =
100 android::base::GetBoolProperty("ro.config.low_ram", false);
101 if (shipping_fcm_version == Level::UNSPECIFIED ||
102 shipping_fcm_version < Level::R || is_go_device) {
103 GTEST_SKIP() << "Gralloc4 is only required on launching R devices";
104 }
105
106 ASSERT_TRUE(vendor_manifest_->hasHidlInstance(
107 "android.hardware.graphics.mapper", {4, 0}, "IMapper", "default"));
108 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
109 "android.hardware.graphics.mapper", {2, 0}, "IMapper", "default"));
110 ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
111 "android.hardware.graphics.mapper", {2, 1}, "IMapper", "default"));
112 }
113
GetTestManifests()114 static std::vector<HalManifestPtr> GetTestManifests() {
115 return {
116 VintfObject::GetDeviceHalManifest(),
117 };
118 }
119
120 INSTANTIATE_TEST_CASE_P(DeviceManifest, SingleManifestTest,
121 ::testing::ValuesIn(GetTestManifests()));
122
123 } // namespace testing
124 } // namespace vintf
125 } // namespace android
126