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 (GetVendorApiLevel() < __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 } else if (board_api_level <= __ANDROID_API_U__ &&
67 board_api_level >= __ANDROID_API_R__ &&
68 syspropVndkVersion.empty()) {
69 GTEST_SKIP() << kVndkVersionProp
70 << " is empty, but this is allowed when the "
71 "ro.board.api_level is set to "
72 << board_api_level;
73 }
74
75 ASSERT_LT(syspropVndkVersionNumber, __ANDROID_API_V__)
76 << kVndkVersionProp << " must be less than " << __ANDROID_API_V__;
77
78 ASSERT_NE("", syspropVndkVersion)
79 << kVndkVersionProp << " must not be empty.";
80
81 std::string vintfVndkVersion = vendor_matrix_->getVendorNdkVersion();
82 ASSERT_NE("", vintfVndkVersion)
83 << "Device compatibility matrix does not declare proper VNDK version.";
84
85 EXPECT_EQ(syspropVndkVersion, vintfVndkVersion)
86 << "VNDK version does not match: " << kVndkVersionProp << "="
87 << syspropVndkVersion << ", device compatibility matrix requires "
88 << vintfVndkVersion << ".";
89 }
90
91 } // namespace testing
92 } // namespace vintf
93 } // namespace android
94