Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #define LOG_TAG "LibHidlTest" |
| 18 | |
| 19 | #include <vintf/parse_string.h> |
| 20 | #include <vintf/parse_xml.h> |
| 21 | #include <vintf/CompatibilityMatrix.h> |
Yifan Hong | a7201e7 | 2017-02-17 10:09:59 -0800 | [diff] [blame^] | 22 | #include <vintf/RuntimeInfo.h> |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 23 | #include <vintf/VendorManifest.h> |
| 24 | |
| 25 | #include <android-base/logging.h> |
Yifan Hong | 3f5489a | 2017-02-08 11:14:21 -0800 | [diff] [blame] | 26 | #include <android-base/parseint.h> |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 27 | #include <gtest/gtest.h> |
| 28 | |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace vintf { |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 31 | |
Yifan Hong | 4a5eb7b | 2017-02-16 18:19:26 -0800 | [diff] [blame] | 32 | extern const XmlConverter<Version> &gVersionConverter; |
| 33 | extern const XmlConverter<MatrixHal> &gMatrixHalConverter; |
| 34 | extern const XmlConverter<KernelConfigTypedValue> &gKernelConfigTypedValueConverter; |
| 35 | extern const XmlConverter<HalImplementation> &gHalImplementationConverter; |
| 36 | extern const XmlConverter<VendorManifest> &gVendorManifestConverter; |
| 37 | extern const XmlConverter<CompatibilityMatrix> &gCompatibilityMatrixConverter; |
| 38 | |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 39 | struct LibVintfTest : public ::testing::Test { |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 40 | public: |
| 41 | virtual void SetUp() override { |
| 42 | } |
| 43 | virtual void TearDown() override { |
| 44 | } |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 45 | bool add(CompatibilityMatrix &cm, MatrixHal &&hal) { |
| 46 | return cm.add(std::move(hal)); |
| 47 | } |
| 48 | bool add(CompatibilityMatrix &cm, MatrixKernel &&kernel) { |
| 49 | return cm.add(std::move(kernel)); |
| 50 | } |
| 51 | bool add(VendorManifest &vm, ManifestHal &&hal) { |
| 52 | return vm.add(std::move(hal)); |
| 53 | } |
Yifan Hong | 558380a | 2017-02-09 15:37:32 -0800 | [diff] [blame] | 54 | void set(CompatibilityMatrix &cm, Sepolicy &&sepolicy) { |
Yifan Hong | ec34286 | 2017-02-16 17:57:06 -0800 | [diff] [blame] | 55 | cm.mSepolicy = sepolicy; |
Yifan Hong | 558380a | 2017-02-09 15:37:32 -0800 | [diff] [blame] | 56 | } |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 57 | const ManifestHal *getHal(VendorManifest &vm, const std::string &name) { |
| 58 | return vm.getHal(name); |
| 59 | } |
| 60 | ConstMapValueIterable<std::string, ManifestHal> getHals(VendorManifest &vm) { |
| 61 | return vm.getHals(); |
| 62 | } |
| 63 | bool isEqual(const CompatibilityMatrix &cm1, const CompatibilityMatrix &cm2) { |
Yifan Hong | ec34286 | 2017-02-16 17:57:06 -0800 | [diff] [blame] | 64 | return cm1.mHals == cm2.mHals && cm1.mKernels == cm2.mKernels; |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 65 | } |
Yifan Hong | 5a06ef7 | 2017-01-24 19:54:24 -0800 | [diff] [blame] | 66 | bool isValid(const ManifestHal &mh) { |
| 67 | return mh.isValid(); |
| 68 | } |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 69 | VendorManifest testVendorManifest() { |
| 70 | VendorManifest vm; |
| 71 | vm.add(ManifestHal::hal("android.hardware.camera", ImplLevel::SOC, "msm8892", |
| 72 | Version(2,0), Transport::HWBINDER)); |
| 73 | vm.add(ManifestHal::hal("android.hardware.nfc", ImplLevel::GENERIC, "generic", |
| 74 | Version(1,0), Transport::PASSTHROUGH)); |
| 75 | |
| 76 | return vm; |
| 77 | } |
Yifan Hong | a7201e7 | 2017-02-17 10:09:59 -0800 | [diff] [blame^] | 78 | RuntimeInfo testRuntimeInfo() { |
| 79 | RuntimeInfo info; |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 80 | info.mOsName = "Linux"; |
| 81 | info.mNodeName = "localhost"; |
| 82 | info.mOsRelease = "3.18.31-g936f9a479d0f"; |
| 83 | info.mKernelVersion = {3, 18, 31}; |
| 84 | info.mOsVersion = "#4 SMP PREEMPT Wed Feb 1 18:10:52 PST 2017"; |
| 85 | info.mHardwareId = "aarch64"; |
| 86 | info.mKernelSepolicyVersion = 30; |
Yifan Hong | f1af752 | 2017-02-16 18:00:55 -0800 | [diff] [blame] | 87 | info.mKernelConfigs = { |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 88 | {"CONFIG_64BIT", "y"}, |
| 89 | {"CONFIG_ANDROID_BINDER_DEVICES", "\"binder,hwbinder\""}, |
| 90 | {"CONFIG_ARCH_MMAP_RND_BITS", "24"}, |
| 91 | {"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", "\"\""}, |
| 92 | {"CONFIG_ILLEGAL_POINTER_VALUE", "0xdead000000000000"} |
| 93 | }; |
| 94 | return info; |
| 95 | } |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 98 | |
| 99 | TEST_F(LibVintfTest, Stringify) { |
| 100 | VendorManifest vm = testVendorManifest(); |
| 101 | EXPECT_EQ(dump(vm), "hidl/android.hardware.camera/hwbinder/soc/msm8892/2.0:" |
| 102 | "hidl/android.hardware.nfc/passthrough/generic/generic/1.0"); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 103 | |
| 104 | EXPECT_EQ(to_string(HalFormat::HIDL), "hidl"); |
| 105 | EXPECT_EQ(to_string(HalFormat::NATIVE), "native"); |
| 106 | |
| 107 | VersionRange v(1, 2, 3); |
| 108 | EXPECT_EQ(to_string(v), "1.2-3"); |
| 109 | VersionRange v2; |
| 110 | EXPECT_TRUE(parse("1.2-3", &v2)); |
| 111 | EXPECT_EQ(v, v2); |
| 112 | } |
| 113 | |
| 114 | TEST_F(LibVintfTest, VendorManifestConverter) { |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 115 | VendorManifest vm = testVendorManifest(); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 116 | std::string xml = gVendorManifestConverter(vm); |
| 117 | EXPECT_EQ(xml, |
| 118 | "<manifest version=\"1.0\">\n" |
| 119 | " <hal format=\"hidl\">\n" |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 120 | " <name>android.hardware.camera</name>\n" |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 121 | " <transport>hwbinder</transport>\n" |
| 122 | " <impl level=\"soc\">msm8892</impl>\n" |
| 123 | " <version>2.0</version>\n" |
| 124 | " </hal>\n" |
| 125 | " <hal format=\"hidl\">\n" |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 126 | " <name>android.hardware.nfc</name>\n" |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 127 | " <transport>passthrough</transport>\n" |
| 128 | " <impl level=\"generic\">generic</impl>\n" |
| 129 | " <version>1.0</version>\n" |
| 130 | " </hal>\n" |
| 131 | "</manifest>\n"); |
| 132 | } |
| 133 | |
| 134 | TEST_F(LibVintfTest, VersionConverter) { |
| 135 | Version v(3, 6); |
| 136 | std::string xml = gVersionConverter(v); |
| 137 | EXPECT_EQ(xml, "<version>3.6</version>\n"); |
| 138 | Version v2; |
| 139 | EXPECT_TRUE(gVersionConverter(&v2, xml)); |
| 140 | EXPECT_EQ(v, v2); |
| 141 | } |
| 142 | |
| 143 | TEST_F(LibVintfTest, HalImplementationConverter) { |
| 144 | HalImplementation hl{ImplLevel::SOC, "msm8992"}; |
| 145 | std::string xml = gHalImplementationConverter(hl); |
| 146 | EXPECT_EQ(xml, "<impl level=\"soc\">msm8992</impl>\n"); |
| 147 | HalImplementation hl2; |
| 148 | EXPECT_TRUE(gHalImplementationConverter(&hl2, xml)); |
| 149 | EXPECT_EQ(hl.impl, hl2.impl); |
| 150 | EXPECT_EQ(hl.implLevel, hl2.implLevel); |
| 151 | } |
| 152 | |
| 153 | TEST_F(LibVintfTest, MatrixHalConverter) { |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 154 | MatrixHal mh{HalFormat::NATIVE, "android.hardware.camera", |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 155 | {{VersionRange(1,2,3), VersionRange(4,5,6)}}, |
| 156 | false /* optional */}; |
| 157 | std::string xml = gMatrixHalConverter(mh); |
| 158 | EXPECT_EQ(xml, |
| 159 | "<hal format=\"native\" optional=\"false\">\n" |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 160 | " <name>android.hardware.camera</name>\n" |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 161 | " <version>1.2-3</version>\n" |
| 162 | " <version>4.5-6</version>\n" |
| 163 | "</hal>\n"); |
| 164 | MatrixHal mh2; |
| 165 | EXPECT_TRUE(gMatrixHalConverter(&mh2, xml)); |
| 166 | EXPECT_EQ(mh, mh2); |
| 167 | } |
| 168 | |
Yifan Hong | 3f5489a | 2017-02-08 11:14:21 -0800 | [diff] [blame] | 169 | TEST_F(LibVintfTest, KernelConfigTypedValueConverter) { |
| 170 | |
| 171 | KernelConfigTypedValue converted; |
| 172 | |
| 173 | auto testOne = [] (const KernelConfigTypedValue &original, |
| 174 | const std::string &expectXml) { |
| 175 | std::string xml; |
| 176 | KernelConfigTypedValue converted; |
| 177 | xml = gKernelConfigTypedValueConverter(original); |
| 178 | EXPECT_EQ(xml, expectXml); |
| 179 | EXPECT_TRUE(gKernelConfigTypedValueConverter(&converted, xml)); |
| 180 | EXPECT_EQ(original, converted); |
| 181 | }; |
| 182 | |
| 183 | auto testParse = [] (const KernelConfigTypedValue &original, |
| 184 | const std::string &xml) { |
| 185 | KernelConfigTypedValue converted; |
| 186 | EXPECT_TRUE(gKernelConfigTypedValueConverter(&converted, xml)); |
| 187 | EXPECT_EQ(original, converted); |
| 188 | }; |
| 189 | |
| 190 | testOne(KernelConfigTypedValue("stringvalue"), |
| 191 | "<value type=\"string\">stringvalue</value>\n"); |
| 192 | testOne(KernelConfigTypedValue(""), |
| 193 | "<value type=\"string\"></value>\n"); |
| 194 | |
| 195 | testOne(KernelConfigTypedValue(Tristate::YES), |
| 196 | "<value type=\"tristate\">y</value>\n"); |
| 197 | testOne(KernelConfigTypedValue(Tristate::NO), |
| 198 | "<value type=\"tristate\">n</value>\n"); |
| 199 | testOne(KernelConfigTypedValue(Tristate::MODULE), |
| 200 | "<value type=\"tristate\">m</value>\n"); |
| 201 | EXPECT_FALSE(gKernelConfigTypedValueConverter(&converted, |
| 202 | "<value type=\"tristate\">q</value>\n")); |
| 203 | |
| 204 | testOne(KernelConfigTypedValue(KernelConfigRangeValue{4, 20}), |
| 205 | "<value type=\"range\">4-20</value>\n"); |
| 206 | testOne(KernelConfigTypedValue(KernelConfigRangeValue{0, UINT64_MAX}), |
| 207 | "<value type=\"range\">0-18446744073709551615</value>\n"); |
| 208 | testParse(KernelConfigTypedValue(KernelConfigRangeValue{0, UINT64_MAX}), |
| 209 | "<value type=\"range\">0x0-0xffffffffffffffff</value>\n"); |
| 210 | |
| 211 | EXPECT_FALSE(gKernelConfigTypedValueConverter(&converted, |
| 212 | "<value type=\"int\">-18446744073709551616</value>\n")); |
| 213 | |
| 214 | testOne(KernelConfigTypedValue(INT64_MIN), |
| 215 | "<value type=\"int\">-9223372036854775808</value>\n"); |
| 216 | testParse(KernelConfigTypedValue(INT64_MIN), |
| 217 | "<value type=\"int\">0x8000000000000000</value>\n"); |
| 218 | testParse(KernelConfigTypedValue(INT64_MIN), |
| 219 | "<value type=\"int\">-0X8000000000000000</value>\n"); |
| 220 | |
| 221 | testParse(KernelConfigTypedValue(INT64_MIN + 1), |
| 222 | "<value type=\"int\">-0X7FFFFFFFFFFFFFFF</value>\n"); |
| 223 | |
| 224 | testParse(KernelConfigTypedValue(-0x50), |
| 225 | "<value type=\"int\">-0x50</value>\n"); |
| 226 | |
| 227 | testOne(KernelConfigTypedValue(0), |
| 228 | "<value type=\"int\">0</value>\n"); |
| 229 | |
| 230 | // Truncation for underflow. |
| 231 | testParse(KernelConfigTypedValue(1), |
| 232 | "<value type=\"int\">-0xffffffffffffffff</value>\n"); |
| 233 | testParse(KernelConfigTypedValue(1), |
| 234 | "<value type=\"int\">-18446744073709551615</value>\n"); |
| 235 | |
| 236 | testOne(KernelConfigTypedValue(INT64_MAX), |
| 237 | "<value type=\"int\">9223372036854775807</value>\n"); |
| 238 | testParse(KernelConfigTypedValue(INT64_MAX), |
| 239 | "<value type=\"int\">0x7FFFFFFFFFFFFFFF</value>\n"); |
| 240 | // Truncation for underflow. |
| 241 | testParse(KernelConfigTypedValue(INT64_MAX), |
| 242 | "<value type=\"int\">-9223372036854775809</value>\n"); |
| 243 | |
| 244 | testParse(KernelConfigTypedValue(-1), |
| 245 | "<value type=\"int\">18446744073709551615</value>\n"); |
| 246 | testParse(KernelConfigTypedValue(-1), |
| 247 | "<value type=\"int\">0xffffffffffffffff</value>\n"); |
| 248 | |
| 249 | EXPECT_FALSE(gKernelConfigTypedValueConverter(&converted, |
| 250 | "<value type=\"int\">18446744073709551616</value>\n")); |
| 251 | } |
| 252 | |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 253 | TEST_F(LibVintfTest, CompatibilityMatrixCoverter) { |
| 254 | CompatibilityMatrix cm; |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 255 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.camera", |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 256 | {{VersionRange(1,2,3), VersionRange(4,5,6)}}, |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 257 | false /* optional */})); |
| 258 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.nfc", |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 259 | {{VersionRange(4,5,6), VersionRange(10,11,12)}}, |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 260 | true /* optional */})); |
Yifan Hong | 3f5489a | 2017-02-08 11:14:21 -0800 | [diff] [blame] | 261 | EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(3, 18, 22), |
| 262 | {KernelConfig{"CONFIG_FOO", Tristate::YES}, KernelConfig{"CONFIG_BAR", "stringvalue"}}})); |
| 263 | EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(4, 4, 1), |
| 264 | {KernelConfig{"CONFIG_BAZ", 20}, KernelConfig{"CONFIG_BAR", KernelConfigRangeValue{3, 5} }}})); |
Yifan Hong | 558380a | 2017-02-09 15:37:32 -0800 | [diff] [blame] | 265 | set(cm, Sepolicy(30, {1, 3})); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 266 | std::string xml = gCompatibilityMatrixConverter(cm); |
| 267 | EXPECT_EQ(xml, |
Yifan Hong | 3f5489a | 2017-02-08 11:14:21 -0800 | [diff] [blame] | 268 | "<compatibility-matrix version=\"1.0\">\n" |
| 269 | " <hal format=\"native\" optional=\"false\">\n" |
| 270 | " <name>android.hardware.camera</name>\n" |
| 271 | " <version>1.2-3</version>\n" |
| 272 | " <version>4.5-6</version>\n" |
| 273 | " </hal>\n" |
| 274 | " <hal format=\"native\" optional=\"true\">\n" |
| 275 | " <name>android.hardware.nfc</name>\n" |
| 276 | " <version>4.5-6</version>\n" |
| 277 | " <version>10.11-12</version>\n" |
| 278 | " </hal>\n" |
| 279 | " <kernel version=\"3.18\" minlts=\"3.18.22\">\n" |
| 280 | " <config>\n" |
| 281 | " <key>CONFIG_FOO</key>\n" |
| 282 | " <value type=\"tristate\">y</value>\n" |
| 283 | " </config>\n" |
| 284 | " <config>\n" |
| 285 | " <key>CONFIG_BAR</key>\n" |
| 286 | " <value type=\"string\">stringvalue</value>\n" |
| 287 | " </config>\n" |
| 288 | " </kernel>\n" |
| 289 | " <kernel version=\"4.4\" minlts=\"4.4.1\">\n" |
| 290 | " <config>\n" |
| 291 | " <key>CONFIG_BAZ</key>\n" |
| 292 | " <value type=\"int\">20</value>\n" |
| 293 | " </config>\n" |
| 294 | " <config>\n" |
| 295 | " <key>CONFIG_BAR</key>\n" |
| 296 | " <value type=\"range\">3-5</value>\n" |
| 297 | " </config>\n" |
| 298 | " </kernel>\n" |
Yifan Hong | 558380a | 2017-02-09 15:37:32 -0800 | [diff] [blame] | 299 | " <sepolicy>\n" |
| 300 | " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n" |
| 301 | " <sepolicy-version>1-3</sepolicy-version>\n" |
| 302 | " </sepolicy>\n" |
Yifan Hong | 3f5489a | 2017-02-08 11:14:21 -0800 | [diff] [blame] | 303 | "</compatibility-matrix>\n"); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 304 | CompatibilityMatrix cm2; |
| 305 | EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml)); |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 306 | EXPECT_TRUE(isEqual(cm, cm2)); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | TEST_F(LibVintfTest, IsValid) { |
Yifan Hong | 5a06ef7 | 2017-01-24 19:54:24 -0800 | [diff] [blame] | 310 | EXPECT_TRUE(isValid(ManifestHal())); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 311 | |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 312 | ManifestHal invalidHal = ManifestHal::hal("android.hardware.camera", ImplLevel::SOC, "msm8892", |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 313 | {{Version(2,0), Version(2,1)}}, Transport::PASSTHROUGH); |
Yifan Hong | 5a06ef7 | 2017-01-24 19:54:24 -0800 | [diff] [blame] | 314 | EXPECT_FALSE(isValid(invalidHal)); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 315 | VendorManifest vm2; |
Yifan Hong | 5a06ef7 | 2017-01-24 19:54:24 -0800 | [diff] [blame] | 316 | EXPECT_FALSE(add(vm2, std::move(invalidHal))); |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 319 | TEST_F(LibVintfTest, VendorManifestGetHal) { |
| 320 | VendorManifest vm = testVendorManifest(); |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 321 | EXPECT_NE(getHal(vm, "android.hardware.camera"), nullptr); |
| 322 | EXPECT_EQ(getHal(vm, "non-existent"), nullptr); |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 323 | |
| 324 | std::vector<std::string> arr{"android.hardware.camera", "android.hardware.nfc"}; |
| 325 | size_t i = 0; |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 326 | for (const auto &hal : getHals(vm)) { |
Yifan Hong | ef6d4d3 | 2017-01-23 14:12:28 -0800 | [diff] [blame] | 327 | EXPECT_EQ(hal.name, arr[i++]); |
| 328 | } |
| 329 | } |
| 330 | |
Yifan Hong | a7201e7 | 2017-02-17 10:09:59 -0800 | [diff] [blame^] | 331 | TEST_F(LibVintfTest, RuntimeInfo) { |
| 332 | RuntimeInfo ki = testRuntimeInfo(); |
Yifan Hong | c66ad1e | 2017-02-08 20:19:45 -0800 | [diff] [blame] | 333 | using KernelConfigs = std::vector<KernelConfig>; |
| 334 | const KernelConfigs configs { |
| 335 | KernelConfig{"CONFIG_64BIT", Tristate::YES}, |
| 336 | KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", "binder,hwbinder"}, |
| 337 | KernelConfig{"CONFIG_ARCH_MMAP_RND_BITS", 24}, |
| 338 | KernelConfig{"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", ""}, |
| 339 | KernelConfig{"CONFIG_ILLEGAL_POINTER_VALUE", 0xdead000000000000}, |
| 340 | KernelConfig{"CONFIG_NOTEXIST", Tristate::NO}, |
| 341 | }; |
| 342 | |
| 343 | auto testMatrix = [&] (MatrixKernel &&kernel) { |
| 344 | CompatibilityMatrix cm; |
| 345 | add(cm, std::move(kernel)); |
| 346 | set(cm, {30, {1, 3}}); |
| 347 | return cm; |
| 348 | }; |
| 349 | |
| 350 | std::string error; |
| 351 | |
| 352 | { |
| 353 | MatrixKernel kernel(KernelVersion{4, 4, 1}, KernelConfigs(configs)); |
| 354 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 355 | EXPECT_FALSE(ki.checkCompatibility(cm)) << "Kernel version shouldn't match"; |
| 356 | } |
| 357 | |
| 358 | { |
| 359 | MatrixKernel kernel(KernelVersion{3, 18, 22}, KernelConfigs(configs)); |
| 360 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 361 | EXPECT_TRUE(ki.checkCompatibility(cm, &error)) << error; |
| 362 | } |
| 363 | |
| 364 | { |
| 365 | MatrixKernel kernel(KernelVersion{3, 18, 22}, KernelConfigs(configs)); |
| 366 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 367 | set(cm, Sepolicy{22, {1, 3}}); |
| 368 | EXPECT_FALSE(ki.checkCompatibility(cm, &error)) |
| 369 | << "kernel-sepolicy-version shouldn't match"; |
| 370 | set(cm, Sepolicy{40, {1, 3}}); |
| 371 | EXPECT_FALSE(ki.checkCompatibility(cm, &error)) |
| 372 | << "kernel-sepolicy-version shouldn't match"; |
| 373 | } |
| 374 | |
| 375 | { |
| 376 | KernelConfigs newConfigs(configs); |
| 377 | newConfigs[0] = KernelConfig{"CONFIG_64BIT", Tristate::NO}; |
| 378 | MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); |
| 379 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 380 | EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for tristate"; |
| 381 | } |
| 382 | |
| 383 | { |
| 384 | KernelConfigs newConfigs(configs); |
| 385 | newConfigs[0] = KernelConfig{"CONFIG_64BIT", 20}; |
| 386 | MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); |
| 387 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 388 | EXPECT_FALSE(ki.checkCompatibility(cm)) << "Type shouldn't match"; |
| 389 | } |
| 390 | |
| 391 | { |
| 392 | KernelConfigs newConfigs(configs); |
| 393 | newConfigs[1] = KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", "binder"}; |
| 394 | MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); |
| 395 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 396 | EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for string"; |
| 397 | } |
| 398 | |
| 399 | { |
| 400 | KernelConfigs newConfigs(configs); |
| 401 | newConfigs[1] = KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", Tristate::YES}; |
| 402 | MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); |
| 403 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 404 | EXPECT_FALSE(ki.checkCompatibility(cm)) << "Type shouldn't match"; |
| 405 | } |
| 406 | |
| 407 | { |
| 408 | KernelConfigs newConfigs(configs); |
| 409 | newConfigs[2] = KernelConfig{"CONFIG_ARCH_MMAP_RND_BITS", 30}; |
| 410 | MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); |
| 411 | CompatibilityMatrix cm = testMatrix(std::move(kernel)); |
| 412 | EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for integer"; |
| 413 | } |
| 414 | } |
| 415 | |
Yifan Hong | a999357 | 2017-01-24 19:33:15 -0800 | [diff] [blame] | 416 | } // namespace vintf |
| 417 | } // namespace android |
| 418 | |
Yifan Hong | 676447a | 2016-11-15 12:57:23 -0800 | [diff] [blame] | 419 | int main(int argc, char **argv) { |
| 420 | ::testing::InitGoogleTest(&argc, argv); |
| 421 | return RUN_ALL_TESTS(); |
| 422 | } |