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 <android-base/result.h>
21 #include <libvts_vintf_test_common/common.h>
22 #include <vintf/VintfObject.h>
23 
24 #include "SingleManifestTest.h"
25 
26 namespace android {
27 namespace vintf {
28 namespace testing {
29 
SetUp()30 void DeviceManifestTest::SetUp() {
31   VtsTrebleVintfTestBase::SetUp();
32 
33   vendor_manifest_ = VintfObject::GetDeviceHalManifest();
34   ASSERT_NE(vendor_manifest_, nullptr)
35       << "Failed to get vendor HAL manifest." << endl;
36 }
37 
38 // Tests that Shipping FCM Version in the device manifest is at least the
39 // minimum Shipping FCM Version as required by Board API level.
TEST_F(DeviceManifestTest,ShippingFcmVersion)40 TEST_F(DeviceManifestTest, ShippingFcmVersion) {
41   uint64_t board_api_level = GetBoardApiLevel();
42   Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
43   auto res = TestTargetFcmVersion(shipping_fcm_version, board_api_level);
44   ASSERT_RESULT_OK(res);
45 }
46 
TEST_F(DeviceManifestTest,KernelFcmVersion)47 TEST_F(DeviceManifestTest, KernelFcmVersion) {
48   Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
49 
50   if (shipping_fcm_version == Level::UNSPECIFIED ||
51       shipping_fcm_version < Level::R) {
52     GTEST_SKIP() << "Kernel FCM version not enforced on target FCM version "
53                  << shipping_fcm_version;
54   }
55   std::string error;
56   Level kernel_fcm_version = VintfObject::GetInstance()->getKernelLevel(&error);
57   ASSERT_NE(Level::UNSPECIFIED, kernel_fcm_version)
58       << "Kernel FCM version must be specified for target FCM version '"
59       << shipping_fcm_version << "': " << error;
60   ASSERT_GE(kernel_fcm_version, shipping_fcm_version)
61       << "Kernel FCM version " << kernel_fcm_version
62       << " must be greater or equal to target FCM version "
63       << shipping_fcm_version;
64 }
65 
66 // Tests that deprecated HALs are not in the manifest, unless a higher,
67 // non-deprecated minor version is in the manifest.
TEST_F(DeviceManifestTest,NoDeprecatedHalsOnManifest)68 TEST_F(DeviceManifestTest, NoDeprecatedHalsOnManifest) {
69   string error;
70   EXPECT_EQ(android::vintf::NO_DEPRECATED_HALS,
71             VintfObject::GetInstance()->checkDeprecation(
72                 HidlInterfaceMetadata::all(), &error))
73       << error;
74 }
75 
76 // Tests that devices launching R support mapper@4.0.  Go devices are exempt
77 // from this requirement, so we use this test to enforce instead of the
78 // compatibility matrix.
TEST_F(DeviceManifestTest,GrallocHalVersionCompatibility)79 TEST_F(DeviceManifestTest, GrallocHalVersionCompatibility) {
80   Level shipping_fcm_version = VintfObject::GetDeviceHalManifest()->level();
81   bool is_go_device =
82       android::base::GetBoolProperty("ro.config.low_ram", false);
83   if (shipping_fcm_version == Level::UNSPECIFIED ||
84       shipping_fcm_version < Level::R || is_go_device) {
85     GTEST_SKIP() << "Gralloc4 is only required on launching R devices";
86   }
87 
88   ASSERT_TRUE(vendor_manifest_->hasHidlInstance(
89       "android.hardware.graphics.mapper", {4, 0}, "IMapper", "default"));
90   ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
91       "android.hardware.graphics.mapper", {2, 0}, "IMapper", "default"));
92   ASSERT_FALSE(vendor_manifest_->hasHidlInstance(
93       "android.hardware.graphics.mapper", {2, 1}, "IMapper", "default"));
94 }
95 
GetTestManifests()96 static std::vector<HalManifestPtr> GetTestManifests() {
97   return {
98       VintfObject::GetDeviceHalManifest(),
99   };
100 }
101 
102 INSTANTIATE_TEST_CASE_P(DeviceManifest, SingleManifestTest,
103                         ::testing::ValuesIn(GetTestManifests()));
104 
105 }  // namespace testing
106 }  // namespace vintf
107 }  // namespace android
108