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 "DeviceMatrixTest.h"
18 
19 #include <android-base/parseint.h>
20 #include <android-base/properties.h>
21 #include <android/api-level.h>
22 #include <vintf/VintfObject.h>
23 
24 using android::base::GetProperty;
25 
26 namespace android {
27 namespace vintf {
28 namespace testing {
29 
30 const string kVndkVersionProp{"ro.vndk.version"};
31 
SetUp()32 void DeviceMatrixTest::SetUp() {
33   VtsTrebleVintfTestBase::SetUp();
34 
35   vendor_matrix_ = VintfObject::GetDeviceCompatibilityMatrix();
36   ASSERT_NE(nullptr, vendor_matrix_)
37       << "Failed to get device compatibility matrix." << endl;
38 }
39 
40 // @VsrTest = VSR-3.2-014
TEST_F(DeviceMatrixTest,VndkVersion)41 TEST_F(DeviceMatrixTest, VndkVersion) {
42   if (GetBoardApiLevel() < __ANDROID_API_P__) {
43     GTEST_SKIP()
44         << "VNDK version doesn't need to be set on devices before Android P";
45   }
46 
47   std::string syspropVndkVersion = GetProperty(kVndkVersionProp, "");
48 
49   // Device with ro.board.api_level 202404 or later should not set VNDK version.
50   uint64_t board_api_level =
51       android::base::GetUintProperty<uint64_t>("ro.board.api_level", 0);
52   if (board_api_level >= 202404) {
53     GTEST_SKIP() << "VNDK version doesn't need to be set on devices built "
54                     "with Android V or later";
55   }
56 
57   uint64_t syspropVndkVersionNumber;
58   if (!android::base::ParseUint(syspropVndkVersion,
59                                 &syspropVndkVersionNumber)) {
60     syspropVndkVersionNumber = 0;
61   }
62 
63   if (syspropVndkVersionNumber == __ANDROID_API_V__) {
64     GTEST_SKIP() << "Android based on 24Q1 release with VNDK version V should "
65                     "be skipped from check";
66   }
67 
68   ASSERT_LT(syspropVndkVersionNumber, __ANDROID_API_V__)
69       << kVndkVersionProp << " must be less than " << __ANDROID_API_V__;
70 
71   ASSERT_NE("", syspropVndkVersion)
72       << kVndkVersionProp << " must not be empty.";
73 
74   std::string vintfVndkVersion = vendor_matrix_->getVendorNdkVersion();
75   ASSERT_NE("", vintfVndkVersion)
76       << "Device compatibility matrix does not declare proper VNDK version.";
77 
78   EXPECT_EQ(syspropVndkVersion, vintfVndkVersion)
79       << "VNDK version does not match: " << kVndkVersionProp << "="
80       << syspropVndkVersion << ", device compatibility matrix requires "
81       << vintfVndkVersion << ".";
82 }
83 
84 }  // namespace testing
85 }  // namespace vintf
86 }  // namespace android
87