summaryrefslogtreecommitdiff
path: root/treble/vintf/DeviceMatrixTest.cpp
blob: fa4c2d233407007459acca913d6a7b249a20f73f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "DeviceMatrixTest.h"

#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android/api-level.h>
#include <vintf/VintfObject.h>

using android::base::GetProperty;

namespace android {
namespace vintf {
namespace testing {

const string kVndkVersionProp{"ro.vndk.version"};

void DeviceMatrixTest::SetUp() {
  VtsTrebleVintfTestBase::SetUp();

  vendor_matrix_ = VintfObject::GetDeviceCompatibilityMatrix();
  ASSERT_NE(nullptr, vendor_matrix_)
      << "Failed to get device compatibility matrix." << endl;
}

// @VsrTest = VSR-3.2-014
TEST_F(DeviceMatrixTest, VndkVersion) {
  if (GetBoardApiLevel() < __ANDROID_API_P__) {
    GTEST_SKIP()
        << "VNDK version doesn't need to be set on devices before Android P";
  }

  std::string syspropVndkVersion = GetProperty(kVndkVersionProp, "");

  // TODO(b/306081093) As of VNDK deprecation, there is no good property to
  // check which platform version is used to build vendor. For now, let's assume
  // that any device running board api level Android R or above can be a
  // candidate of Android V, and skip test for those devices. This should be
  // revisited once we have a new property to check platform version used to
  // build vendor.
  if (GetBoardApiLevel() >= __ANDROID_API_R__) {
    // TODO(b/306081093) When vendor's target platform is greater or equal than
    // V, check if vendor VNDK version (both sysprop and VINTF) is empty and
    // fail if not.
    if (syspropVndkVersion.empty()) {
      GTEST_SKIP() << "VNDK version doesn't need to be set on devices built "
                      "with Android V";
    }

    uint64_t syspropVndkVersionNumber;
    if (!android::base::ParseUint(syspropVndkVersion, &syspropVndkVersionNumber)) {
      syspropVndkVersionNumber = 0;
    }

    ASSERT_LE(syspropVndkVersionNumber, __ANDROID_API_V__)
        << kVndkVersionProp << " must be less or equal than "
        << __ANDROID_API_V__;

    if (syspropVndkVersionNumber == __ANDROID_API_V__) {
      GTEST_SKIP()
          << "VNDK version 35 may not have matching VINTF VNDK version.";
    }
  }

  ASSERT_NE("", syspropVndkVersion)
      << kVndkVersionProp << " must not be empty.";

  std::string vintfVndkVersion = vendor_matrix_->getVendorNdkVersion();
  ASSERT_NE("", vintfVndkVersion)
      << "Device compatibility matrix does not declare proper VNDK version.";

  EXPECT_EQ(syspropVndkVersion, vintfVndkVersion)
      << "VNDK version does not match: " << kVndkVersionProp << "="
      << syspropVndkVersion << ", device compatibility matrix requires "
      << vintfVndkVersion << ".";
}

}  // namespace testing
}  // namespace vintf
}  // namespace android