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 "LibVintfTest"
18
19 #include <algorithm>
20 #include <functional>
21
22 #include <android-base/logging.h>
23 #include <android-base/parseint.h>
24 #include <android-base/strings.h>
25 #include <gtest/gtest.h>
26
27 #include <vintf/CompatibilityMatrix.h>
28 #include <vintf/KernelConfigParser.h>
29 #include <vintf/VintfObject.h>
30 #include <vintf/parse_string.h>
31 #include <vintf/parse_xml.h>
32 #include "constants-private.h"
33 #include "test_constants.h"
34
35 namespace android {
36 namespace vintf {
37
38 extern XmlConverter<Version>& gVersionConverter;
39 extern XmlConverter<ManifestHal>& gManifestHalConverter;
40 extern XmlConverter<MatrixHal>& gMatrixHalConverter;
41 extern XmlConverter<KernelConfigTypedValue>& gKernelConfigTypedValueConverter;
42 extern XmlConverter<KernelInfo>& gKernelInfoConverter;
43 extern XmlConverter<HalManifest>& gHalManifestConverter;
44 extern XmlConverter<CompatibilityMatrix>& gCompatibilityMatrixConverter;
45
In(const std::string & sub,const std::string & str)46 static bool In(const std::string& sub, const std::string& str) {
47 return str.find(sub) != std::string::npos;
48 }
49 #define EXPECT_IN(sub, str) EXPECT_TRUE(In((sub), (str))) << (str);
50
51 #ifndef LIBVINTF_TARGET
52 #define EXPECT_CONTAINS(str, sub) EXPECT_IN(sub, str);
53 #endif
54
55 struct LibVintfTest : public ::testing::Test {
56 public:
SetUpandroid::vintf::LibVintfTest57 virtual void SetUp() override {
58 }
TearDownandroid::vintf::LibVintfTest59 virtual void TearDown() override {
60 }
addandroid::vintf::LibVintfTest61 bool add(CompatibilityMatrix &cm, MatrixHal &&hal) {
62 return cm.add(std::move(hal));
63 }
addandroid::vintf::LibVintfTest64 bool add(CompatibilityMatrix &cm, MatrixKernel &&kernel) {
65 std::string error;
66 bool success = cm.addKernel(std::move(kernel), &error);
67 EXPECT_EQ(success, error == "") << "success: " << success << ", error: " << error;
68 return success;
69 }
addandroid::vintf::LibVintfTest70 bool add(HalManifest &vm, ManifestHal &&hal) {
71 return vm.add(std::move(hal));
72 }
addXmlFileandroid::vintf::LibVintfTest73 void addXmlFile(CompatibilityMatrix& cm, std::string name, VersionRange range) {
74 MatrixXmlFile f;
75 f.mName = name;
76 f.mVersionRange = range;
77 f.mFormat = XmlSchemaFormat::DTD;
78 f.mOptional = true;
79 cm.addXmlFile(std::move(f));
80 }
setandroid::vintf::LibVintfTest81 void set(CompatibilityMatrix &cm, Sepolicy &&sepolicy) {
82 cm.framework.mSepolicy = sepolicy;
83 }
setandroid::vintf::LibVintfTest84 void set(CompatibilityMatrix &cm, SchemaType type) {
85 cm.mType = type;
86 }
setandroid::vintf::LibVintfTest87 void set(CompatibilityMatrix &cm, VndkVersionRange &&range, std::set<std::string> &&libs) {
88 cm.device.mVndk.mVersionRange = range;
89 cm.device.mVndk.mLibraries = libs;
90 }
setAvbandroid::vintf::LibVintfTest91 void setAvb(RuntimeInfo &ki, Version vbmeta, Version boot) {
92 ki.mBootVbmetaAvbVersion = vbmeta;
93 ki.mBootAvbVersion = boot;
94 }
setAvbandroid::vintf::LibVintfTest95 void setAvb(CompatibilityMatrix &cm, Version &&avbVersion) {
96 cm.framework.mAvbMetaVersion = avbVersion;
97 }
getAvbandroid::vintf::LibVintfTest98 Version getAvb(CompatibilityMatrix &cm) {
99 return cm.framework.mAvbMetaVersion;
100 }
getAnyHalandroid::vintf::LibVintfTest101 const ManifestHal *getAnyHal(HalManifest &vm, const std::string &name) {
102 return vm.getAnyHal(name);
103 }
getAnyHalandroid::vintf::LibVintfTest104 MatrixHal *getAnyHal(CompatibilityMatrix &cm, const std::string &name) {
105 return cm.getAnyHal(name);
106 }
getHalsandroid::vintf::LibVintfTest107 ConstMultiMapValueIterable<std::string, ManifestHal> getHals(const HalManifest& vm) {
108 return vm.getHals();
109 }
getHalsandroid::vintf::LibVintfTest110 std::vector<const ManifestHal*> getHals(const HalManifest& vm, const std::string& name) {
111 return vm.getHals(name);
112 }
getHalsandroid::vintf::LibVintfTest113 std::vector<const MatrixHal*> getHals(const CompatibilityMatrix& cm, const std::string& name) {
114 return cm.getHals(name);
115 }
isValidandroid::vintf::LibVintfTest116 bool isValid(const ManifestHal &mh) {
117 return mh.isValid();
118 }
getKernelsandroid::vintf::LibVintfTest119 std::vector<MatrixKernel>& getKernels(CompatibilityMatrix& cm) { return cm.framework.mKernels; }
addAllHalsAsOptionalandroid::vintf::LibVintfTest120 bool addAllHalsAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2, std::string* e) {
121 return cm1->addAllHalsAsOptional(cm2, e);
122 }
addAllXmlFilesAsOptionalandroid::vintf::LibVintfTest123 bool addAllXmlFilesAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2,
124 std::string* e) {
125 return cm1->addAllXmlFilesAsOptional(cm2, e);
126 }
checkUnusedHalsandroid::vintf::LibVintfTest127 std::set<std::string> checkUnusedHals(const HalManifest& m, const CompatibilityMatrix& cm) {
128 return m.checkUnusedHals(cm, {});
129 }
130
testHalInterfacesandroid::vintf::LibVintfTest131 std::map<std::string, HalInterface> testHalInterfaces() {
132 HalInterface intf("IFoo", {"default"});
133 std::map<std::string, HalInterface> map;
134 map[intf.name()] = intf;
135 return map;
136 }
137
testDeviceManifestandroid::vintf::LibVintfTest138 HalManifest testDeviceManifest() {
139 HalManifest vm;
140 vm.mType = SchemaType::DEVICE;
141 vm.device.mSepolicyVersion = {25, 0};
142 vm.add(ManifestHal{HalFormat::HIDL,
143 "android.hardware.camera",
144 {Version(2, 0)},
145 {Transport::HWBINDER, Arch::ARCH_EMPTY},
146 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
147 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}});
148 vm.add(ManifestHal{HalFormat::HIDL,
149 "android.hardware.nfc",
150 {Version(1, 0)},
151 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
152 {{"INfc", {"INfc", {"default"}}}}});
153
154 return vm;
155 }
testDeviceManifestWithXmlFileandroid::vintf::LibVintfTest156 HalManifest testDeviceManifestWithXmlFile() {
157 HalManifest vm = testDeviceManifest();
158 ManifestXmlFile xmlFile;
159 xmlFile.mName = "media_profile";
160 xmlFile.mVersion = {1, 0};
161 vm.addXmlFile(std::move(xmlFile));
162 return vm;
163 }
testFrameworkManfiestandroid::vintf::LibVintfTest164 HalManifest testFrameworkManfiest() {
165 HalManifest vm;
166 vm.mType = SchemaType::FRAMEWORK;
167 vm.add(ManifestHal{HalFormat::HIDL,
168 "android.hidl.manager",
169 {Version(1, 0)},
170 {Transport::HWBINDER, Arch::ARCH_EMPTY},
171 {
172 {"IServiceManager", {"IServiceManager", {"default"}}},
173 }});
174 Vndk vndk2505;
175 vndk2505.mVersionRange = {25, 0, 5};
176 vndk2505.mLibraries = { "libjpeg.so", "libbase.so" };
177 Vndk vndk2513;
178 vndk2513.mVersionRange = {25, 1, 3};
179 vndk2513.mLibraries = { "libjpeg.so", "libbase.so", "libtinyxml2.so" };
180 vm.framework.mVndks = { std::move(vndk2505), std::move(vndk2513) };
181
182 return vm;
183 }
testRuntimeInfoandroid::vintf::LibVintfTest184 RuntimeInfo testRuntimeInfo() {
185 RuntimeInfo info;
186 info.mOsName = "Linux";
187 info.mNodeName = "localhost";
188 info.mOsRelease = "3.18.31-g936f9a479d0f";
189 info.mOsVersion = "#4 SMP PREEMPT Wed Feb 1 18:10:52 PST 2017";
190 info.mHardwareId = "aarch64";
191 info.mKernelSepolicyVersion = 30;
192 info.mKernel = testKernelInfo();
193 setAvb(info, {2, 1}, {2, 1});
194 return info;
195 }
testKernelInfoandroid::vintf::LibVintfTest196 KernelInfo testKernelInfo() {
197 KernelInfo info;
198 info.mVersion = {3, 18, 31};
199 info.mConfigs = {{"CONFIG_64BIT", "y"},
200 {"CONFIG_ANDROID_BINDER_DEVICES", "\"binder,hwbinder\""},
201 {"CONFIG_ARCH_MMAP_RND_BITS", "24"},
202 {"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", "\"\""},
203 {"CONFIG_ILLEGAL_POINTER_VALUE", "0xdead000000000000"}};
204 return info;
205 }
206 };
207
208 // clang-format off
209
TEST_F(LibVintfTest,ArchOperatorOr)210 TEST_F(LibVintfTest, ArchOperatorOr) {
211 Arch a = Arch::ARCH_EMPTY;
212 a |= Arch::ARCH_32;
213 EXPECT_EQ(Arch::ARCH_32, a);
214
215 a |= Arch::ARCH_64;
216 EXPECT_EQ(Arch::ARCH_32_64, a);
217
218 a = Arch::ARCH_EMPTY;
219 a |= Arch::ARCH_64;
220 EXPECT_EQ(Arch::ARCH_64, a);
221 }
222
TEST_F(LibVintfTest,Stringify)223 TEST_F(LibVintfTest, Stringify) {
224 HalManifest vm = testDeviceManifest();
225 EXPECT_EQ(dump(vm), "hidl/android.hardware.camera/hwbinder/2.0:"
226 "hidl/android.hardware.nfc/passthrough32+64/1.0");
227
228 EXPECT_EQ(to_string(HalFormat::HIDL), "hidl");
229 EXPECT_EQ(to_string(HalFormat::NATIVE), "native");
230
231 VersionRange v(1, 2, 3);
232 EXPECT_EQ(to_string(v), "1.2-3");
233 VersionRange v2;
234 EXPECT_TRUE(parse("1.2-3", &v2));
235 EXPECT_EQ(v, v2);
236 }
237
TEST_F(LibVintfTest,GetTransport)238 TEST_F(LibVintfTest, GetTransport) {
239 HalManifest vm = testDeviceManifest();
240 EXPECT_EQ(Transport::HWBINDER, vm.getHidlTransport("android.hardware.camera",
241 {2, 0}, "ICamera", "default"));
242 }
243
TEST_F(LibVintfTest,FutureManifestCompatible)244 TEST_F(LibVintfTest, FutureManifestCompatible) {
245 HalManifest expectedManifest;
246 expectedManifest.add(ManifestHal{HalFormat::HIDL,
247 "android.hardware.foo",
248 {Version(1, 0)},
249 {Transport::HWBINDER, Arch::ARCH_EMPTY},
250 {
251 {"IFoo", {"IFoo", {"default"}}},
252 }});
253 std::string manifestXml =
254 "<manifest " + kMetaVersionStr + " type=\"device\" might_add=\"true\">\n"
255 " <hal format=\"hidl\" attribuet_might_be_added=\"value\">\n"
256 " <name>android.hardware.foo</name>\n"
257 " <transport>hwbinder</transport>\n"
258 " <version>1.0</version>\n"
259 " <interface>\n"
260 " <name>IFoo</name>\n"
261 " <instance>default</instance>\n"
262 " </interface>\n"
263 " </hal>\n"
264 " <tag_might_be_added/>\n"
265 "</manifest>\n";
266 HalManifest manifest;
267 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
268 EXPECT_EQ(expectedManifest, manifest);
269 }
270
TEST_F(LibVintfTest,HalManifestConverter)271 TEST_F(LibVintfTest, HalManifestConverter) {
272 HalManifest vm = testDeviceManifest();
273 std::string xml =
274 gHalManifestConverter(vm, SerializeFlags::NO_TAGS.enableHals().enableSepolicy());
275 EXPECT_EQ(xml,
276 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
277 " <hal format=\"hidl\">\n"
278 " <name>android.hardware.camera</name>\n"
279 " <transport>hwbinder</transport>\n"
280 " <version>2.0</version>\n"
281 " <interface>\n"
282 " <name>IBetterCamera</name>\n"
283 " <instance>camera</instance>\n"
284 " </interface>\n"
285 " <interface>\n"
286 " <name>ICamera</name>\n"
287 " <instance>default</instance>\n"
288 " <instance>legacy/0</instance>\n"
289 " </interface>\n"
290 " </hal>\n"
291 " <hal format=\"hidl\">\n"
292 " <name>android.hardware.nfc</name>\n"
293 " <transport arch=\"32+64\">passthrough</transport>\n"
294 " <version>1.0</version>\n"
295 " <interface>\n"
296 " <name>INfc</name>\n"
297 " <instance>default</instance>\n"
298 " </interface>\n"
299 " </hal>\n"
300 " <sepolicy>\n"
301 " <version>25.0</version>\n"
302 " </sepolicy>\n"
303 "</manifest>\n");
304 HalManifest vm2;
305 EXPECT_TRUE(gHalManifestConverter(&vm2, xml));
306 EXPECT_EQ(vm, vm2);
307 }
308
TEST_F(LibVintfTest,HalManifestConverterFramework)309 TEST_F(LibVintfTest, HalManifestConverterFramework) {
310 HalManifest vm = testFrameworkManfiest();
311 std::string xml = gHalManifestConverter(vm, SerializeFlags::NO_TAGS.enableHals().enableVndk());
312 EXPECT_EQ(xml,
313 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
314 " <hal format=\"hidl\">\n"
315 " <name>android.hidl.manager</name>\n"
316 " <transport>hwbinder</transport>\n"
317 " <version>1.0</version>\n"
318 " <interface>\n"
319 " <name>IServiceManager</name>\n"
320 " <instance>default</instance>\n"
321 " </interface>\n"
322 " </hal>\n"
323 " <vndk>\n"
324 " <version>25.0.5</version>\n"
325 " <library>libbase.so</library>\n"
326 " <library>libjpeg.so</library>\n"
327 " </vndk>\n"
328 " <vndk>\n"
329 " <version>25.1.3</version>\n"
330 " <library>libbase.so</library>\n"
331 " <library>libjpeg.so</library>\n"
332 " <library>libtinyxml2.so</library>\n"
333 " </vndk>\n"
334 "</manifest>\n");
335 HalManifest vm2;
336 EXPECT_TRUE(gHalManifestConverter(&vm2, xml));
337 EXPECT_EQ(vm, vm2);
338 }
339
TEST_F(LibVintfTest,HalManifestOptional)340 TEST_F(LibVintfTest, HalManifestOptional) {
341 HalManifest vm;
342 EXPECT_TRUE(gHalManifestConverter(&vm,
343 "<manifest " + kMetaVersionStr + " type=\"device\"></manifest>"));
344 EXPECT_TRUE(gHalManifestConverter(&vm,
345 "<manifest " + kMetaVersionStr + " type=\"device\">"
346 " <hal>"
347 " <name>android.hidl.manager</name>"
348 " <transport>hwbinder</transport>"
349 " <version>1.0</version>"
350 " </hal>"
351 "</manifest>"));
352 EXPECT_FALSE(gHalManifestConverter(&vm,
353 "<manifest " + kMetaVersionStr + " type=\"device\">"
354 " <hal>"
355 " <name>android.hidl.manager</name>"
356 " <version>1.0</version>"
357 " </hal>"
358 "</manifest>"));
359 }
360
TEST_F(LibVintfTest,HalManifestNative)361 TEST_F(LibVintfTest, HalManifestNative) {
362 HalManifest vm;
363 EXPECT_TRUE(gHalManifestConverter(&vm,
364 "<manifest " + kMetaVersionStr + " type=\"device\">"
365 " <hal format=\"native\">"
366 " <name>foo</name>"
367 " <version>1.0</version>"
368 " </hal>"
369 "</manifest>"))
370 << gHalManifestConverter.lastError();
371 EXPECT_FALSE(gHalManifestConverter(&vm,
372 "<manifest " + kMetaVersionStr + " type=\"device\">"
373 " <hal format=\"native\">"
374 " <name>foo</name>"
375 " <version>1.0</version>"
376 " <transport>hwbinder</transport>"
377 " </hal>"
378 "</manifest>"));
379 EXPECT_TRUE(gHalManifestConverter.lastError().find(
380 "Native HAL 'foo' should not have <transport> defined") != std::string::npos);
381 }
382
TEST_F(LibVintfTest,HalManifestDuplicate)383 TEST_F(LibVintfTest, HalManifestDuplicate) {
384 HalManifest vm;
385 EXPECT_FALSE(gHalManifestConverter(&vm,
386 "<manifest " + kMetaVersionStr + " type=\"device\">"
387 " <hal>"
388 " <name>android.hidl.manager</name>"
389 " <transport>hwbinder</transport>"
390 " <version>1.0</version>"
391 " <version>1.1</version>"
392 " </hal>"
393 "</manifest>"))
394 << "Should not allow duplicated major version in <hal>";
395 EXPECT_FALSE(gHalManifestConverter(&vm,
396 "<manifest " + kMetaVersionStr + " type=\"device\">"
397 " <hal>"
398 " <name>android.hidl.manager</name>"
399 " <transport>hwbinder</transport>"
400 " <version>1.0</version>"
401 " </hal>"
402 " <hal>"
403 " <name>android.hidl.manager</name>"
404 " <transport arch=\"32+64\">passthrough</transport>"
405 " <version>1.1</version>"
406 " </hal>"
407 "</manifest>"))
408 << "Should not allow duplicated major version across <hal>";
409 }
410
TEST_F(LibVintfTest,HalManifestGetTransport)411 TEST_F(LibVintfTest, HalManifestGetTransport) {
412 HalManifest vm;
413 EXPECT_TRUE(gHalManifestConverter(&vm,
414 "<manifest " + kMetaVersionStr + " type=\"device\">"
415 " <hal>"
416 " <name>android.hidl.manager</name>"
417 " <transport>hwbinder</transport>"
418 " <version>1.0</version>"
419 " <interface>"
420 " <name>IServiceManager</name>"
421 " <instance>default</instance>"
422 " </interface>"
423 " </hal>"
424 " <hal>"
425 " <name>android.hidl.manager</name>"
426 " <transport arch=\"32+64\">passthrough</transport>"
427 " <version>2.1</version>"
428 " <interface>"
429 " <name>IServiceManager</name>"
430 " <instance>default</instance>"
431 " </interface>"
432 " </hal>"
433 "</manifest>"));
434 EXPECT_EQ(Transport::PASSTHROUGH,
435 vm.getHidlTransport("android.hidl.manager", {2, 1}, "IServiceManager", "default"));
436 EXPECT_EQ(Transport::PASSTHROUGH,
437 vm.getHidlTransport("android.hidl.manager", {2, 0}, "IServiceManager", "default"));
438 EXPECT_EQ(Transport::EMPTY,
439 vm.getHidlTransport("android.hidl.manager", {2, 2}, "IServiceManager", "default"));
440 EXPECT_EQ(Transport::HWBINDER,
441 vm.getHidlTransport("android.hidl.manager", {1, 0}, "IServiceManager", "default"));
442 }
443
TEST_F(LibVintfTest,HalManifestInstances)444 TEST_F(LibVintfTest, HalManifestInstances) {
445 HalManifest vm = testDeviceManifest();
446 EXPECT_EQ(vm.getHidlInstances("android.hardware.camera", {2, 0}, "ICamera"),
447 std::set<std::string>({"default", "legacy/0"}));
448 EXPECT_EQ(vm.getHidlInstances("android.hardware.camera", {2, 0}, "IBetterCamera"),
449 std::set<std::string>({"camera"}));
450 EXPECT_EQ(vm.getHidlInstances("android.hardware.camera", {2, 0}, "INotExist"),
451 std::set<std::string>({}));
452 EXPECT_EQ(vm.getHidlInstances("android.hardware.nfc", {1, 0}, "INfc"),
453 std::set<std::string>({"default"}));
454
455 EXPECT_TRUE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "ICamera", "default"));
456 EXPECT_TRUE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "ICamera", "legacy/0"));
457 EXPECT_TRUE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "IBetterCamera", "camera"));
458 EXPECT_TRUE(vm.hasHidlInstance("android.hardware.nfc", {1, 0}, "INfc", "default"));
459
460 EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "INotExist", "default"));
461 EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "ICamera", "notexist"));
462 EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "IBetterCamera", "default"));
463 EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "INotExist", "notexist"));
464 EXPECT_FALSE(vm.hasHidlInstance("android.hardware.nfc", {1, 0}, "INfc", "notexist"));
465 }
466
TEST_F(LibVintfTest,VersionConverter)467 TEST_F(LibVintfTest, VersionConverter) {
468 Version v(3, 6);
469 std::string xml = gVersionConverter(v);
470 EXPECT_EQ(xml, "<version>3.6</version>\n");
471 Version v2;
472 EXPECT_TRUE(gVersionConverter(&v2, xml));
473 EXPECT_EQ(v, v2);
474 }
475
insert(std::map<std::string,HalInterface> * map,HalInterface && intf)476 static bool insert(std::map<std::string, HalInterface>* map, HalInterface&& intf) {
477 std::string name{intf.name()};
478 return map->emplace(std::move(name), std::move(intf)).second;
479 }
480
TEST_F(LibVintfTest,MatrixHalConverter)481 TEST_F(LibVintfTest, MatrixHalConverter) {
482 MatrixHal mh{HalFormat::NATIVE, "android.hardware.camera",
483 {{VersionRange(1,2,3), VersionRange(4,5,6)}},
484 false /* optional */, {}};
485 EXPECT_TRUE(insert(&mh.interfaces, {"IBetterCamera", {"default", "great"}}));
486 EXPECT_TRUE(insert(&mh.interfaces, {"ICamera", {"default"}}));
487 std::string xml = gMatrixHalConverter(mh);
488 EXPECT_EQ(xml,
489 "<hal format=\"native\" optional=\"false\">\n"
490 " <name>android.hardware.camera</name>\n"
491 " <version>1.2-3</version>\n"
492 " <version>4.5-6</version>\n"
493 " <interface>\n"
494 " <name>IBetterCamera</name>\n"
495 " <instance>default</instance>\n"
496 " <instance>great</instance>\n"
497 " </interface>\n"
498 " <interface>\n"
499 " <name>ICamera</name>\n"
500 " <instance>default</instance>\n"
501 " </interface>\n"
502 "</hal>\n");
503 MatrixHal mh2;
504 EXPECT_TRUE(gMatrixHalConverter(&mh2, xml));
505 EXPECT_EQ(mh, mh2);
506 }
507
TEST_F(LibVintfTest,KernelConfigTypedValueConverter)508 TEST_F(LibVintfTest, KernelConfigTypedValueConverter) {
509
510 KernelConfigTypedValue converted;
511
512 auto testOne = [] (const KernelConfigTypedValue &original,
513 const std::string &expectXml) {
514 std::string xml;
515 KernelConfigTypedValue converted;
516 xml = gKernelConfigTypedValueConverter(original);
517 EXPECT_EQ(xml, expectXml);
518 EXPECT_TRUE(gKernelConfigTypedValueConverter(&converted, xml));
519 EXPECT_EQ(original, converted);
520 };
521
522 auto testParse = [] (const KernelConfigTypedValue &original,
523 const std::string &xml) {
524 KernelConfigTypedValue converted;
525 EXPECT_TRUE(gKernelConfigTypedValueConverter(&converted, xml));
526 EXPECT_EQ(original, converted);
527 };
528
529 testOne(KernelConfigTypedValue("stringvalue"),
530 "<value type=\"string\">stringvalue</value>\n");
531 testOne(KernelConfigTypedValue(""),
532 "<value type=\"string\"></value>\n");
533
534 testOne(KernelConfigTypedValue(Tristate::YES),
535 "<value type=\"tristate\">y</value>\n");
536 testOne(KernelConfigTypedValue(Tristate::NO),
537 "<value type=\"tristate\">n</value>\n");
538 testOne(KernelConfigTypedValue(Tristate::MODULE),
539 "<value type=\"tristate\">m</value>\n");
540 EXPECT_FALSE(gKernelConfigTypedValueConverter(&converted,
541 "<value type=\"tristate\">q</value>\n"));
542
543 testOne(KernelConfigTypedValue(KernelConfigRangeValue{4, 20}),
544 "<value type=\"range\">4-20</value>\n");
545 testOne(KernelConfigTypedValue(KernelConfigRangeValue{0, UINT64_MAX}),
546 "<value type=\"range\">0-18446744073709551615</value>\n");
547 testParse(KernelConfigTypedValue(KernelConfigRangeValue{0, UINT64_MAX}),
548 "<value type=\"range\">0x0-0xffffffffffffffff</value>\n");
549
550 EXPECT_FALSE(gKernelConfigTypedValueConverter(&converted,
551 "<value type=\"int\">-18446744073709551616</value>\n"));
552
553 testOne(KernelConfigTypedValue(INT64_MIN),
554 "<value type=\"int\">-9223372036854775808</value>\n");
555 testParse(KernelConfigTypedValue(INT64_MIN),
556 "<value type=\"int\">0x8000000000000000</value>\n");
557 testParse(KernelConfigTypedValue(INT64_MIN),
558 "<value type=\"int\">-0X8000000000000000</value>\n");
559
560 testParse(KernelConfigTypedValue(INT64_MIN + 1),
561 "<value type=\"int\">-0X7FFFFFFFFFFFFFFF</value>\n");
562
563 testParse(KernelConfigTypedValue(-0x50),
564 "<value type=\"int\">-0x50</value>\n");
565
566 testOne(KernelConfigTypedValue(0),
567 "<value type=\"int\">0</value>\n");
568
569 // Truncation for underflow.
570 testParse(KernelConfigTypedValue(1),
571 "<value type=\"int\">-0xffffffffffffffff</value>\n");
572 testParse(KernelConfigTypedValue(1),
573 "<value type=\"int\">-18446744073709551615</value>\n");
574
575 testOne(KernelConfigTypedValue(INT64_MAX),
576 "<value type=\"int\">9223372036854775807</value>\n");
577 testParse(KernelConfigTypedValue(INT64_MAX),
578 "<value type=\"int\">0x7FFFFFFFFFFFFFFF</value>\n");
579 // Truncation for underflow.
580 testParse(KernelConfigTypedValue(INT64_MAX),
581 "<value type=\"int\">-9223372036854775809</value>\n");
582
583 testParse(KernelConfigTypedValue(-1),
584 "<value type=\"int\">18446744073709551615</value>\n");
585 testParse(KernelConfigTypedValue(-1),
586 "<value type=\"int\">0xffffffffffffffff</value>\n");
587
588 EXPECT_FALSE(gKernelConfigTypedValueConverter(&converted,
589 "<value type=\"int\">18446744073709551616</value>\n"));
590 }
591
TEST_F(LibVintfTest,CompatibilityMatrixConverter)592 TEST_F(LibVintfTest, CompatibilityMatrixConverter) {
593 CompatibilityMatrix cm;
594 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.camera",
595 {{VersionRange(1,2,3), VersionRange(4,5,6)}},
596 false /* optional */, testHalInterfaces()}));
597 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.nfc",
598 {{VersionRange(4,5,6), VersionRange(10,11,12)}},
599 true /* optional */, testHalInterfaces()}));
600 EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(3, 18, 22),
601 {KernelConfig{"CONFIG_FOO", Tristate::YES}, KernelConfig{"CONFIG_BAR", "stringvalue"}}}));
602 EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(4, 4, 1),
603 {KernelConfig{"CONFIG_BAZ", 20}, KernelConfig{"CONFIG_BAR", KernelConfigRangeValue{3, 5} }}}));
604 set(cm, Sepolicy(30, {{25, 0}, {26, 0, 3}}));
605 setAvb(cm, Version{2, 1});
606 std::string xml = gCompatibilityMatrixConverter(cm);
607 EXPECT_EQ(xml,
608 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
609 " <hal format=\"native\" optional=\"false\">\n"
610 " <name>android.hardware.camera</name>\n"
611 " <version>1.2-3</version>\n"
612 " <version>4.5-6</version>\n"
613 " <interface>\n"
614 " <name>IFoo</name>\n"
615 " <instance>default</instance>\n"
616 " </interface>\n"
617 " </hal>\n"
618 " <hal format=\"native\" optional=\"true\">\n"
619 " <name>android.hardware.nfc</name>\n"
620 " <version>4.5-6</version>\n"
621 " <version>10.11-12</version>\n"
622 " <interface>\n"
623 " <name>IFoo</name>\n"
624 " <instance>default</instance>\n"
625 " </interface>\n"
626 " </hal>\n"
627 " <kernel version=\"3.18.22\">\n"
628 " <config>\n"
629 " <key>CONFIG_FOO</key>\n"
630 " <value type=\"tristate\">y</value>\n"
631 " </config>\n"
632 " <config>\n"
633 " <key>CONFIG_BAR</key>\n"
634 " <value type=\"string\">stringvalue</value>\n"
635 " </config>\n"
636 " </kernel>\n"
637 " <kernel version=\"4.4.1\">\n"
638 " <config>\n"
639 " <key>CONFIG_BAZ</key>\n"
640 " <value type=\"int\">20</value>\n"
641 " </config>\n"
642 " <config>\n"
643 " <key>CONFIG_BAR</key>\n"
644 " <value type=\"range\">3-5</value>\n"
645 " </config>\n"
646 " </kernel>\n"
647 " <sepolicy>\n"
648 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
649 " <sepolicy-version>25.0</sepolicy-version>\n"
650 " <sepolicy-version>26.0-3</sepolicy-version>\n"
651 " </sepolicy>\n"
652 " <avb>\n"
653 " <vbmeta-version>2.1</vbmeta-version>\n"
654 " </avb>\n"
655 "</compatibility-matrix>\n");
656 CompatibilityMatrix cm2;
657 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml));
658 EXPECT_EQ(cm, cm2);
659 }
660
TEST_F(LibVintfTest,DeviceCompatibilityMatrixCoverter)661 TEST_F(LibVintfTest, DeviceCompatibilityMatrixCoverter) {
662 CompatibilityMatrix cm;
663 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hidl.manager",
664 {{VersionRange(1,0)}},
665 false /* optional */, testHalInterfaces()}));
666 set(cm, SchemaType::DEVICE);
667 set(cm, VndkVersionRange{25,0,1,5}, {"libjpeg.so", "libbase.so"});
668 std::string xml = gCompatibilityMatrixConverter(cm);
669 EXPECT_EQ(xml,
670 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
671 " <hal format=\"native\" optional=\"false\">\n"
672 " <name>android.hidl.manager</name>\n"
673 " <version>1.0</version>\n"
674 " <interface>\n"
675 " <name>IFoo</name>\n"
676 " <instance>default</instance>\n"
677 " </interface>\n"
678 " </hal>\n"
679 " <vndk>\n"
680 " <version>25.0.1-5</version>\n"
681 " <library>libbase.so</library>\n"
682 " <library>libjpeg.so</library>\n"
683 " </vndk>\n"
684 "</compatibility-matrix>\n");
685 CompatibilityMatrix cm2;
686 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml));
687 EXPECT_EQ(cm, cm2);
688 }
689
TEST_F(LibVintfTest,IsValid)690 TEST_F(LibVintfTest, IsValid) {
691 EXPECT_TRUE(isValid(ManifestHal()));
692
693 ManifestHal invalidHal{HalFormat::HIDL,
694 "android.hardware.camera",
695 {{Version(2, 0), Version(2, 1)}},
696 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
697 {}};
698
699 EXPECT_FALSE(isValid(invalidHal));
700 HalManifest vm2;
701 EXPECT_FALSE(add(vm2, std::move(invalidHal)));
702 }
703
TEST_F(LibVintfTest,HalManifestGetHalNames)704 TEST_F(LibVintfTest, HalManifestGetHalNames) {
705 HalManifest vm = testDeviceManifest();
706 EXPECT_EQ(vm.getHalNames(), std::set<std::string>(
707 {"android.hardware.camera", "android.hardware.nfc"}));
708 }
709
TEST_F(LibVintfTest,HalManifestGetAllHals)710 TEST_F(LibVintfTest, HalManifestGetAllHals) {
711 HalManifest vm = testDeviceManifest();
712 EXPECT_NE(getAnyHal(vm, "android.hardware.camera"), nullptr);
713 EXPECT_EQ(getAnyHal(vm, "non-existent"), nullptr);
714
715 std::vector<std::string> arr{"android.hardware.camera", "android.hardware.nfc"};
716 size_t i = 0;
717 for (const auto &hal : getHals(vm)) {
718 EXPECT_EQ(hal.name, arr[i++]);
719 }
720 }
721
TEST_F(LibVintfTest,HalManifestGetHals)722 TEST_F(LibVintfTest, HalManifestGetHals) {
723 HalManifest vm;
724 EXPECT_TRUE(add(vm, ManifestHal{HalFormat::HIDL,
725 "android.hardware.camera",
726 {Version(1, 2)},
727 {Transport::HWBINDER, Arch::ARCH_EMPTY},
728 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
729 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}));
730 EXPECT_TRUE(add(vm, ManifestHal{HalFormat::HIDL,
731 "android.hardware.camera",
732 {Version(2, 0)},
733 {Transport::HWBINDER, Arch::ARCH_EMPTY},
734 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
735 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}));
736 EXPECT_TRUE(add(vm, ManifestHal{HalFormat::HIDL,
737 "android.hardware.nfc",
738 {Version(1, 0), Version(2, 1)},
739 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
740 {{"INfc", {"INfc", {"default"}}}}}));
741 ManifestHal expectedCameraHalV1_2 =
742 ManifestHal{HalFormat::HIDL,
743 "android.hardware.camera",
744 {Version(1, 2)},
745 {Transport::HWBINDER, Arch::ARCH_EMPTY},
746 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
747 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}};
748 ManifestHal expectedCameraHalV2_0 =
749 ManifestHal{HalFormat::HIDL,
750 "android.hardware.camera",
751 {Version(2, 0)},
752 {Transport::HWBINDER, Arch::ARCH_EMPTY},
753 {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
754 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}};
755 ManifestHal expectedNfcHal = ManifestHal{HalFormat::HIDL,
756 "android.hardware.nfc",
757 {Version(1, 0), Version(2, 1)},
758 {Transport::PASSTHROUGH, Arch::ARCH_32_64},
759 {{"INfc", {"INfc", {"default"}}}}};
760 auto cameraHals = getHals(vm, "android.hardware.camera");
761 EXPECT_EQ((int)cameraHals.size(), 2);
762 EXPECT_EQ(*cameraHals[0], expectedCameraHalV1_2);
763 EXPECT_EQ(*cameraHals[1], expectedCameraHalV2_0);
764 auto nfcHals = getHals(vm, "android.hardware.nfc");
765 EXPECT_EQ((int)nfcHals.size(), 1);
766 EXPECT_EQ(*nfcHals[0], expectedNfcHal);
767 }
768
TEST_F(LibVintfTest,CompatibilityMatrixGetHals)769 TEST_F(LibVintfTest, CompatibilityMatrixGetHals) {
770 CompatibilityMatrix cm;
771 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE,
772 "android.hardware.camera",
773 {{VersionRange(1, 2, 3), VersionRange(4, 5, 6)}},
774 false /* optional */,
775 testHalInterfaces()}));
776 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE,
777 "android.hardware.nfc",
778 {{VersionRange(4, 5, 6), VersionRange(10, 11, 12)}},
779 true /* optional */,
780 testHalInterfaces()}));
781
782 MatrixHal expectedCameraHal = MatrixHal{
783 HalFormat::NATIVE,
784 "android.hardware.camera",
785 {{VersionRange(1, 2, 3), VersionRange(4, 5, 6)}},
786 false /* optional */,
787 testHalInterfaces(),
788 };
789 MatrixHal expectedNfcHal = MatrixHal{HalFormat::NATIVE,
790 "android.hardware.nfc",
791 {{VersionRange(4, 5, 6), VersionRange(10, 11, 12)}},
792 true /* optional */,
793 testHalInterfaces()};
794 auto cameraHals = getHals(cm, "android.hardware.camera");
795 EXPECT_EQ((int)cameraHals.size(), 1);
796 EXPECT_EQ(*cameraHals[0], expectedCameraHal);
797 auto nfcHals = getHals(cm, "android.hardware.nfc");
798 EXPECT_EQ((int)nfcHals.size(), 1);
799 EXPECT_EQ(*nfcHals[0], expectedNfcHal);
800 }
801
TEST_F(LibVintfTest,RuntimeInfo)802 TEST_F(LibVintfTest, RuntimeInfo) {
803 RuntimeInfo ki = testRuntimeInfo();
804 using KernelConfigs = std::vector<KernelConfig>;
805 const KernelConfigs configs {
806 KernelConfig{"CONFIG_64BIT", Tristate::YES},
807 KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", "binder,hwbinder"},
808 KernelConfig{"CONFIG_ARCH_MMAP_RND_BITS", 24},
809 KernelConfig{"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", ""},
810 KernelConfig{"CONFIG_ILLEGAL_POINTER_VALUE", 0xdead000000000000},
811 KernelConfig{"CONFIG_NOTEXIST", Tristate::NO},
812 };
813
814 auto testMatrix = [&] (MatrixKernel &&kernel) {
815 CompatibilityMatrix cm;
816 add(cm, std::move(kernel));
817 set(cm, {30, {{25, 0}}});
818 setAvb(cm, {2, 1});
819 return cm;
820 };
821
822 std::string error;
823
824 {
825 MatrixKernel kernel(KernelVersion{4, 4, 1}, KernelConfigs(configs));
826 CompatibilityMatrix cm = testMatrix(std::move(kernel));
827 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Kernel version shouldn't match";
828 }
829
830 {
831 MatrixKernel kernel(KernelVersion{3, 18, 60}, KernelConfigs(configs));
832 CompatibilityMatrix cm = testMatrix(std::move(kernel));
833 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Kernel version shouldn't match";
834 }
835
836 {
837 MatrixKernel kernel(KernelVersion{3, 18, 22}, KernelConfigs(configs));
838 CompatibilityMatrix cm = testMatrix(std::move(kernel));
839 EXPECT_TRUE(ki.checkCompatibility(cm, &error)) << error;
840 }
841
842 {
843 MatrixKernel kernel(KernelVersion{3, 18, 22}, KernelConfigs(configs));
844 CompatibilityMatrix cm = testMatrix(std::move(kernel));
845 set(cm, Sepolicy{22, {{25, 0}}});
846 EXPECT_TRUE(ki.checkCompatibility(cm, &error)) << error;
847 set(cm, Sepolicy{40, {{25, 0}}});
848 EXPECT_FALSE(ki.checkCompatibility(cm, &error))
849 << "kernel-sepolicy-version shouldn't match";
850 EXPECT_IN("kernelSepolicyVersion = 30 but required >= 40", error);
851 }
852
853 {
854 KernelConfigs newConfigs(configs);
855 newConfigs[0] = KernelConfig{"CONFIG_64BIT", Tristate::NO};
856 MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs));
857 CompatibilityMatrix cm = testMatrix(std::move(kernel));
858 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for tristate";
859 }
860
861 {
862 KernelConfigs newConfigs(configs);
863 newConfigs[0] = KernelConfig{"CONFIG_64BIT", 20};
864 MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs));
865 CompatibilityMatrix cm = testMatrix(std::move(kernel));
866 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Type shouldn't match";
867 }
868
869 {
870 KernelConfigs newConfigs(configs);
871 newConfigs[1] = KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", "binder"};
872 MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs));
873 CompatibilityMatrix cm = testMatrix(std::move(kernel));
874 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for string";
875 }
876
877 {
878 KernelConfigs newConfigs(configs);
879 newConfigs[1] = KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", Tristate::YES};
880 MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs));
881 CompatibilityMatrix cm = testMatrix(std::move(kernel));
882 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Type shouldn't match";
883 }
884
885 {
886 KernelConfigs newConfigs(configs);
887 newConfigs[2] = KernelConfig{"CONFIG_ARCH_MMAP_RND_BITS", 30};
888 MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs));
889 CompatibilityMatrix cm = testMatrix(std::move(kernel));
890 EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for integer";
891 }
892
893 RuntimeInfo badAvb = testRuntimeInfo();
894 CompatibilityMatrix cm = testMatrix(MatrixKernel(KernelVersion{3, 18, 31}, {}));
895 {
896 setAvb(badAvb, {1, 0}, {2, 1});
897 EXPECT_FALSE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS));
898 EXPECT_STREQ(error.c_str(), "Vbmeta version 1.0 does not match framework matrix 2.1");
899 }
900 {
901 setAvb(badAvb, {2, 1}, {3, 0});
902 EXPECT_FALSE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS));
903 }
904 {
905 setAvb(badAvb, {2, 1}, {2, 3});
906 EXPECT_TRUE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS));
907 }
908 {
909 setAvb(badAvb, {2, 3}, {2, 1});
910 EXPECT_TRUE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS));
911 }
912 }
913
TEST_F(LibVintfTest,MissingAvb)914 TEST_F(LibVintfTest, MissingAvb) {
915 std::string xml =
916 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
917 " <kernel version=\"3.18.31\"></kernel>"
918 " <sepolicy>\n"
919 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
920 " <sepolicy-version>25.5</sepolicy-version>\n"
921 " </sepolicy>\n"
922 "</compatibility-matrix>\n";
923 CompatibilityMatrix cm;
924 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml));
925 EXPECT_EQ(getAvb(cm), Version(0, 0));
926 }
927
TEST_F(LibVintfTest,DisableAvb)928 TEST_F(LibVintfTest, DisableAvb) {
929 std::string xml =
930 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
931 " <kernel version=\"3.18.31\"></kernel>"
932 " <sepolicy>\n"
933 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
934 " <sepolicy-version>25.5</sepolicy-version>\n"
935 " </sepolicy>\n"
936 " <avb>\n"
937 " <vbmeta-version>1.0</vbmeta-version>\n"
938 " </avb>\n"
939 "</compatibility-matrix>\n";
940 CompatibilityMatrix cm;
941 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml));
942 RuntimeInfo ki = testRuntimeInfo();
943 std::string error;
944 EXPECT_FALSE(ki.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS));
945 EXPECT_STREQ(error.c_str(), "AVB version 2.1 does not match framework matrix 1.0");
946 EXPECT_TRUE(ki.checkCompatibility(cm, &error, CheckFlags::DISABLE_AVB_CHECK)) << error;
947 }
948
949 // This is the test extracted from VINTF Object doc
TEST_F(LibVintfTest,HalCompat)950 TEST_F(LibVintfTest, HalCompat) {
951 CompatibilityMatrix matrix;
952 std::string error;
953
954 std::string matrixXml =
955 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
956 " <hal format=\"hidl\" optional=\"false\">\n"
957 " <name>android.hardware.foo</name>\n"
958 " <version>1.0</version>\n"
959 " <version>3.1-2</version>\n"
960 " <interface>\n"
961 " <name>IFoo</name>\n"
962 " <instance>default</instance>\n"
963 " <instance>specific</instance>\n"
964 " </interface>\n"
965 " </hal>\n"
966 " <hal format=\"hidl\" optional=\"false\">\n"
967 " <name>android.hardware.foo</name>\n"
968 " <version>2.0</version>\n"
969 " <interface>\n"
970 " <name>IBar</name>\n"
971 " <instance>default</instance>\n"
972 " </interface>\n"
973 " </hal>\n"
974 " <sepolicy>\n"
975 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
976 " <sepolicy-version>25.5</sepolicy-version>\n"
977 " </sepolicy>\n"
978 "</compatibility-matrix>\n";
979 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml))
980 << gCompatibilityMatrixConverter.lastError();
981
982 {
983 std::string manifestXml =
984 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
985 " <hal format=\"hidl\">\n"
986 " <name>android.hardware.foo</name>\n"
987 " <transport>hwbinder</transport>\n"
988 " <version>1.0</version>\n"
989 " <interface>\n"
990 " <name>IFoo</name>\n"
991 " <instance>default</instance>\n"
992 " <instance>specific</instance>\n"
993 " </interface>\n"
994 " </hal>\n"
995 " <hal format=\"hidl\">\n"
996 " <name>android.hardware.foo</name>\n"
997 " <transport>hwbinder</transport>\n"
998 " <version>2.0</version>\n"
999 " <interface>\n"
1000 " <name>IBar</name>\n"
1001 " <instance>default</instance>\n"
1002 " </interface>\n"
1003 " </hal>\n"
1004 " <sepolicy>\n"
1005 " <version>25.5</version>\n"
1006 " </sepolicy>\n"
1007 "</manifest>\n";
1008
1009 HalManifest manifest;
1010 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1011 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1012 }
1013
1014 {
1015 std::string manifestXml =
1016 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1017 " <hal format=\"hidl\">\n"
1018 " <name>android.hardware.foo</name>\n"
1019 " <transport>hwbinder</transport>\n"
1020 " <version>1.0</version>\n"
1021 " <interface>\n"
1022 " <name>IFoo</name>\n"
1023 " <instance>default</instance>\n"
1024 " <instance>specific</instance>\n"
1025 " </interface>\n"
1026 " </hal>\n"
1027 " <sepolicy>\n"
1028 " <version>25.5</version>\n"
1029 " </sepolicy>\n"
1030 "</manifest>\n";
1031 HalManifest manifest;
1032 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1033 EXPECT_FALSE(manifest.checkCompatibility(matrix, &error))
1034 << "should not be compatible because IBar is missing";
1035 }
1036
1037 {
1038 std::string manifestXml =
1039 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1040 " <hal format=\"hidl\">\n"
1041 " <name>android.hardware.foo</name>\n"
1042 " <transport>hwbinder</transport>\n"
1043 " <version>1.0</version>\n"
1044 " <interface>\n"
1045 " <name>IFoo</name>\n"
1046 " <instance>default</instance>\n"
1047 " </interface>\n"
1048 " </hal>\n"
1049 " <hal format=\"hidl\">\n"
1050 " <name>android.hardware.foo</name>\n"
1051 " <transport>hwbinder</transport>\n"
1052 " <version>2.0</version>\n"
1053 " <interface>\n"
1054 " <name>IBar</name>\n"
1055 " <instance>default</instance>\n"
1056 " </interface>\n"
1057 " </hal>\n"
1058 " <sepolicy>\n"
1059 " <version>25.5</version>\n"
1060 " </sepolicy>\n"
1061 "</manifest>\n";
1062 HalManifest manifest;
1063 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1064 EXPECT_FALSE(manifest.checkCompatibility(matrix, &error))
1065 << "should not be compatible because IFoo/specific is missing";
1066 }
1067
1068 {
1069 std::string manifestXml =
1070 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1071 " <hal format=\"hidl\">\n"
1072 " <name>android.hardware.foo</name>\n"
1073 " <transport>hwbinder</transport>\n"
1074 " <version>3.3</version>\n"
1075 " <interface>\n"
1076 " <name>IFoo</name>\n"
1077 " <instance>default</instance>\n"
1078 " <instance>specific</instance>\n"
1079 " </interface>\n"
1080 " </hal>\n"
1081 " <hal format=\"hidl\">\n"
1082 " <name>android.hardware.foo</name>\n"
1083 " <transport>hwbinder</transport>\n"
1084 " <version>2.0</version>\n"
1085 " <interface>\n"
1086 " <name>IBar</name>\n"
1087 " <instance>default</instance>\n"
1088 " </interface>\n"
1089 " </hal>\n"
1090 " <sepolicy>\n"
1091 " <version>25.5</version>\n"
1092 " </sepolicy>\n"
1093 "</manifest>\n";
1094 HalManifest manifest;
1095 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1096 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1097 }
1098
1099 {
1100 std::string manifestXml =
1101 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1102 " <hal format=\"hidl\">\n"
1103 " <name>android.hardware.foo</name>\n"
1104 " <transport>hwbinder</transport>\n"
1105 " <version>1.0</version>\n"
1106 " <interface>\n"
1107 " <name>IFoo</name>\n"
1108 " <instance>default</instance>\n"
1109 " </interface>\n"
1110 " </hal>\n"
1111 " <hal format=\"hidl\">\n"
1112 " <name>android.hardware.foo</name>\n"
1113 " <transport>hwbinder</transport>\n"
1114 " <version>3.2</version>\n"
1115 " <interface>\n"
1116 " <name>IFoo</name>\n"
1117 " <instance>specific</instance>\n"
1118 " </interface>\n"
1119 " </hal>\n"
1120 " <hal format=\"hidl\">\n"
1121 " <name>android.hardware.foo</name>\n"
1122 " <transport>hwbinder</transport>\n"
1123 " <version>2.0</version>\n"
1124 " <interface>\n"
1125 " <name>IBar</name>\n"
1126 " <instance>default</instance>\n"
1127 " </interface>\n"
1128 " </hal>\n"
1129 " <sepolicy>\n"
1130 " <version>25.5</version>\n"
1131 " </sepolicy>\n"
1132 "</manifest>\n";
1133 HalManifest manifest;
1134 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1135 EXPECT_FALSE(manifest.checkCompatibility(matrix, &error))
1136 << "should not be compatible even though @1.0::IFoo/default "
1137 << "and @3.2::IFoo/specific present";
1138 }
1139
1140 {
1141 std::string manifestXml =
1142 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1143 " <hal format=\"hidl\">\n"
1144 " <name>android.hardware.foo</name>\n"
1145 " <transport>hwbinder</transport>\n"
1146 " <version>1.0</version>\n"
1147 " <interface>\n"
1148 " <name>IFoo</name>\n"
1149 " <instance>default</instance>\n"
1150 " <instance>specific</instance>\n"
1151 " </interface>\n"
1152 " </hal>\n"
1153 " <hal format=\"hidl\">\n"
1154 " <name>android.hardware.foo</name>\n"
1155 " <transport>hwbinder</transport>\n"
1156 " <version>2.0</version>\n"
1157 " <interface>\n"
1158 " <name>IBar</name>\n"
1159 " <instance>default</instance>\n"
1160 " </interface>\n"
1161 " </hal>\n"
1162 " <sepolicy>\n"
1163 " <version>25.5</version>\n"
1164 " </sepolicy>\n"
1165 "</manifest>\n";
1166 HalManifest manifest;
1167 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml))
1168 << gHalManifestConverter.lastError();
1169 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1170 }
1171 }
1172
TEST_F(LibVintfTest,Compat)1173 TEST_F(LibVintfTest, Compat) {
1174 std::string manifestXml =
1175 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1176 " <hal format=\"hidl\">\n"
1177 " <name>android.hardware.camera</name>\n"
1178 " <transport>hwbinder</transport>\n"
1179 " <version>3.5</version>\n"
1180 " <interface>\n"
1181 " <name>IBetterCamera</name>\n"
1182 " <instance>camera</instance>\n"
1183 " </interface>\n"
1184 " <interface>\n"
1185 " <name>ICamera</name>\n"
1186 " <instance>default</instance>\n"
1187 " <instance>legacy/0</instance>\n"
1188 " </interface>\n"
1189 " </hal>\n"
1190 " <hal format=\"hidl\">\n"
1191 " <name>android.hardware.nfc</name>\n"
1192 " <transport>hwbinder</transport>\n"
1193 " <version>1.0</version>\n"
1194 " <interface>\n"
1195 " <name>INfc</name>\n"
1196 " <instance>nfc_nci</instance>\n"
1197 " </interface>\n"
1198 " </hal>\n"
1199 " <hal format=\"hidl\">\n"
1200 " <name>android.hardware.nfc</name>\n"
1201 " <transport>hwbinder</transport>\n"
1202 " <version>2.0</version>\n"
1203 " <interface>\n"
1204 " <name>INfc</name>\n"
1205 " <instance>default</instance>\n"
1206 " <instance>nfc_nci</instance>\n"
1207 " </interface>\n"
1208 " </hal>\n"
1209 " <sepolicy>\n"
1210 " <version>25.5</version>\n"
1211 " </sepolicy>\n"
1212 "</manifest>\n";
1213
1214 std::string matrixXml =
1215 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1216 " <hal format=\"hidl\" optional=\"false\">\n"
1217 " <name>android.hardware.camera</name>\n"
1218 " <version>2.0-5</version>\n"
1219 " <version>3.4-16</version>\n"
1220 " <interface>\n"
1221 " <name>IBetterCamera</name>\n"
1222 " <instance>camera</instance>\n"
1223 " </interface>\n"
1224 " <interface>\n"
1225 " <name>ICamera</name>\n"
1226 " <instance>default</instance>\n"
1227 " <instance>legacy/0</instance>\n"
1228 " </interface>\n"
1229 " </hal>\n"
1230 " <hal format=\"hidl\" optional=\"false\">\n"
1231 " <name>android.hardware.nfc</name>\n"
1232 " <version>1.0</version>\n"
1233 " <version>2.0</version>\n"
1234 " <interface>\n"
1235 " <name>INfc</name>\n"
1236 " <instance>nfc_nci</instance>\n"
1237 " </interface>\n"
1238 " </hal>\n"
1239 " <hal format=\"hidl\" optional=\"true\">\n"
1240 " <name>android.hardware.foo</name>\n"
1241 " <version>1.0</version>\n"
1242 " </hal>\n"
1243 " <sepolicy>\n"
1244 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1245 " <sepolicy-version>25.5</sepolicy-version>\n"
1246 " <sepolicy-version>26.0-3</sepolicy-version>\n"
1247 " </sepolicy>\n"
1248 " <avb>\n"
1249 " <vbmeta-version>2.1</vbmeta-version>\n"
1250 " </avb>\n"
1251 "</compatibility-matrix>\n";
1252
1253 HalManifest manifest;
1254 CompatibilityMatrix matrix;
1255 std::string error;
1256 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1257 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1258 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1259
1260 // some smaller test cases
1261 matrixXml =
1262 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1263 " <hal format=\"hidl\" optional=\"false\">\n"
1264 " <name>android.hardware.camera</name>\n"
1265 " <version>3.4</version>\n"
1266 " </hal>\n"
1267 " <sepolicy>\n"
1268 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1269 " <sepolicy-version>25.5</sepolicy-version>\n"
1270 " </sepolicy>\n"
1271 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1272 "</compatibility-matrix>\n";
1273 matrix = {};
1274 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1275 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1276 MatrixHal *camera = getAnyHal(matrix, "android.hardware.camera");
1277 EXPECT_NE(camera, nullptr);
1278 camera->versionRanges[0] = {3, 5};
1279 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1280 camera->versionRanges[0] = {3, 6};
1281 EXPECT_FALSE(manifest.checkCompatibility(matrix));
1282
1283 // reset it
1284 matrix = {};
1285 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1286 set(matrix, Sepolicy{30, {{26, 0}}});
1287 EXPECT_FALSE(manifest.checkCompatibility(matrix));
1288 set(matrix, Sepolicy{30, {{25, 6}}});
1289 EXPECT_FALSE(manifest.checkCompatibility(matrix));
1290 set(matrix, Sepolicy{30, {{25, 4}}});
1291 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
1292 }
1293
1294 /////////////////// xmlfile tests
1295
TEST_F(LibVintfTest,HalManifestConverterXmlFile)1296 TEST_F(LibVintfTest, HalManifestConverterXmlFile) {
1297 HalManifest vm = testDeviceManifestWithXmlFile();
1298 std::string xml = gHalManifestConverter(
1299 vm, SerializeFlags::NO_TAGS.enableHals().enableSepolicy().enableXmlFiles());
1300 EXPECT_EQ(xml,
1301 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
1302 " <hal format=\"hidl\">\n"
1303 " <name>android.hardware.camera</name>\n"
1304 " <transport>hwbinder</transport>\n"
1305 " <version>2.0</version>\n"
1306 " <interface>\n"
1307 " <name>IBetterCamera</name>\n"
1308 " <instance>camera</instance>\n"
1309 " </interface>\n"
1310 " <interface>\n"
1311 " <name>ICamera</name>\n"
1312 " <instance>default</instance>\n"
1313 " <instance>legacy/0</instance>\n"
1314 " </interface>\n"
1315 " </hal>\n"
1316 " <hal format=\"hidl\">\n"
1317 " <name>android.hardware.nfc</name>\n"
1318 " <transport arch=\"32+64\">passthrough</transport>\n"
1319 " <version>1.0</version>\n"
1320 " <interface>\n"
1321 " <name>INfc</name>\n"
1322 " <instance>default</instance>\n"
1323 " </interface>\n"
1324 " </hal>\n"
1325 " <sepolicy>\n"
1326 " <version>25.0</version>\n"
1327 " </sepolicy>\n"
1328 " <xmlfile>\n"
1329 " <name>media_profile</name>\n"
1330 " <version>1.0</version>\n"
1331 " </xmlfile>\n"
1332 "</manifest>\n");
1333 HalManifest vm2;
1334 EXPECT_TRUE(gHalManifestConverter(&vm2, xml));
1335 EXPECT_EQ(vm, vm2);
1336 }
1337
TEST_F(LibVintfTest,CompatibilityMatrixConverterXmlFile)1338 TEST_F(LibVintfTest, CompatibilityMatrixConverterXmlFile) {
1339 CompatibilityMatrix cm;
1340 addXmlFile(cm, "media_profile", {1, 0});
1341 std::string xml = gCompatibilityMatrixConverter(cm, SerializeFlags::XMLFILES_ONLY);
1342 EXPECT_EQ(xml,
1343 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1344 " <xmlfile format=\"dtd\" optional=\"true\">\n"
1345 " <name>media_profile</name>\n"
1346 " <version>1.0</version>\n"
1347 " </xmlfile>\n"
1348 "</compatibility-matrix>\n");
1349 CompatibilityMatrix cm2;
1350 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml));
1351 EXPECT_EQ(cm, cm2);
1352 }
1353
TEST_F(LibVintfTest,CompatibilityMatrixConverterXmlFile2)1354 TEST_F(LibVintfTest, CompatibilityMatrixConverterXmlFile2) {
1355 std::string xml =
1356 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1357 " <xmlfile format=\"dtd\" optional=\"false\">\n"
1358 " <name>media_profile</name>\n"
1359 " <version>1.0</version>\n"
1360 " </xmlfile>\n"
1361 "</compatibility-matrix>\n";
1362 CompatibilityMatrix cm;
1363 EXPECT_FALSE(gCompatibilityMatrixConverter(&cm, xml));
1364 EXPECT_EQ(
1365 "compatibility-matrix.xmlfile entry media_profile has to be optional for "
1366 "compatibility matrix version 1.0",
1367 gCompatibilityMatrixConverter.lastError());
1368 }
1369
TEST_F(LibVintfTest,ManifestXmlFilePathDevice)1370 TEST_F(LibVintfTest, ManifestXmlFilePathDevice) {
1371 std::string manifestXml =
1372 "<manifest " + kMetaVersionStr + " type=\"device\">"
1373 " <xmlfile>"
1374 " <name>media_profile</name>"
1375 " <version>1.0</version>"
1376 " </xmlfile>"
1377 "</manifest>";
1378 HalManifest manifest;
1379 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1380 EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}),
1381 "/vendor/etc/media_profile_V1_0.xml");
1382 }
1383
TEST_F(LibVintfTest,ManifestXmlFilePathFramework)1384 TEST_F(LibVintfTest, ManifestXmlFilePathFramework) {
1385 std::string manifestXml =
1386 "<manifest " + kMetaVersionStr + " type=\"framework\">"
1387 " <xmlfile>"
1388 " <name>media_profile</name>"
1389 " <version>1.0</version>"
1390 " </xmlfile>"
1391 "</manifest>";
1392 HalManifest manifest;
1393 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1394 EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}),
1395 "/system/etc/media_profile_V1_0.xml");
1396 }
1397
TEST_F(LibVintfTest,ManifestXmlFilePathOverride)1398 TEST_F(LibVintfTest, ManifestXmlFilePathOverride) {
1399 std::string manifestXml =
1400 "<manifest " + kMetaVersionStr + " type=\"device\">"
1401 " <xmlfile>"
1402 " <name>media_profile</name>"
1403 " <version>1.0</version>"
1404 " <path>/vendor/etc/foo.xml</path>"
1405 " </xmlfile>"
1406 "</manifest>";
1407 HalManifest manifest;
1408 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1409 EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}), "/vendor/etc/foo.xml");
1410 }
1411
TEST_F(LibVintfTest,ManifestXmlFilePathMissing)1412 TEST_F(LibVintfTest, ManifestXmlFilePathMissing) {
1413 std::string manifestXml =
1414 "<manifest " + kMetaVersionStr + " type=\"device\">"
1415 " <xmlfile>"
1416 " <name>media_profile</name>"
1417 " <version>1.1</version>"
1418 " </xmlfile>"
1419 "</manifest>";
1420 HalManifest manifest;
1421 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml));
1422 EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}), "");
1423 }
1424
TEST_F(LibVintfTest,MatrixXmlFilePathFramework)1425 TEST_F(LibVintfTest, MatrixXmlFilePathFramework) {
1426 std::string matrixXml =
1427 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">"
1428 " <xmlfile format=\"dtd\" optional=\"true\">"
1429 " <name>media_profile</name>"
1430 " <version>2.0-1</version>"
1431 " </xmlfile>"
1432 "</compatibility-matrix>";
1433 CompatibilityMatrix matrix;
1434 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1435 EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 1}),
1436 "/system/etc/media_profile_V2_1.dtd");
1437 }
1438
TEST_F(LibVintfTest,MatrixXmlFilePathDevice)1439 TEST_F(LibVintfTest, MatrixXmlFilePathDevice) {
1440 std::string matrixXml =
1441 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">"
1442 " <xmlfile format=\"xsd\" optional=\"true\">"
1443 " <name>media_profile</name>"
1444 " <version>2.0-1</version>"
1445 " </xmlfile>"
1446 "</compatibility-matrix>";
1447 CompatibilityMatrix matrix;
1448 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1449 EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 0}),
1450 "/vendor/etc/media_profile_V2_1.xsd");
1451 }
1452
TEST_F(LibVintfTest,MatrixXmlFilePathOverride)1453 TEST_F(LibVintfTest, MatrixXmlFilePathOverride) {
1454 std::string matrixXml =
1455 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">"
1456 " <xmlfile format=\"xsd\" optional=\"true\">"
1457 " <name>media_profile</name>"
1458 " <version>2.0-1</version>"
1459 " <path>/system/etc/foo.xsd</path>"
1460 " </xmlfile>"
1461 "</compatibility-matrix>";
1462 CompatibilityMatrix matrix;
1463 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1464 EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 0}), "/system/etc/foo.xsd");
1465 }
1466
TEST_F(LibVintfTest,MatrixXmlFilePathMissing)1467 TEST_F(LibVintfTest, MatrixXmlFilePathMissing) {
1468 std::string matrixXml =
1469 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">"
1470 " <xmlfile format=\"dtd\" optional=\"true\">"
1471 " <name>media_profile</name>"
1472 " <version>2.1</version>"
1473 " </xmlfile>"
1474 "</compatibility-matrix>";
1475 CompatibilityMatrix matrix;
1476 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1477 EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 0}), "");
1478 }
1479
processData(const std::string & data,bool processComments,bool relaxedFormat=false)1480 std::pair<KernelConfigParser, status_t> processData(const std::string& data, bool processComments,
1481 bool relaxedFormat = false) {
1482 KernelConfigParser parser(processComments, relaxedFormat);
1483 const char* p = data.c_str();
1484 size_t n = 0;
1485 size_t chunkSize;
1486 status_t status = OK;
1487 for (; n < data.size(); p += chunkSize, n += chunkSize) {
1488 chunkSize = std::min<size_t>(5, data.size() - n);
1489 if ((status = parser.process(p, chunkSize)) != OK) {
1490 break;
1491 }
1492 }
1493 return {std::move(parser), status};
1494 }
1495
TEST_F(LibVintfTest,KernelConfigParser)1496 TEST_F(LibVintfTest, KernelConfigParser) {
1497 // usage in /proc/config.gz
1498 const std::string data =
1499 "# CONFIG_NOT_SET is not set\n"
1500 "CONFIG_ONE=1\n"
1501 "CONFIG_Y=y\n"
1502 "CONFIG_STR=\"string\"\n";
1503 auto pair = processData(data, false /* processComments */);
1504 ASSERT_EQ(OK, pair.second) << pair.first.error();
1505 const auto& configs = pair.first.configs();
1506
1507 EXPECT_EQ(configs.find("CONFIG_ONE")->second, "1");
1508 EXPECT_EQ(configs.find("CONFIG_Y")->second, "y");
1509 EXPECT_EQ(configs.find("CONFIG_STR")->second, "\"string\"");
1510 EXPECT_EQ(configs.find("CONFIG_NOT_SET"), configs.end());
1511 }
1512
TEST_F(LibVintfTest,KernelConfigParser2)1513 TEST_F(LibVintfTest, KernelConfigParser2) {
1514 // usage in android-base.config
1515 const std::string data =
1516 "# CONFIG_NOT_SET is not set\n"
1517 "CONFIG_ONE=1\n"
1518 "CONFIG_Y=y\n"
1519 "CONFIG_STR=string\n"
1520 "# ignore_thiscomment\n"
1521 "# CONFIG_NOT_SET2 is not set\n";
1522 auto pair = processData(data, true /* processComments */);
1523 ASSERT_EQ(OK, pair.second) << pair.first.error();
1524 const auto& configs = pair.first.configs();
1525
1526 EXPECT_EQ(configs.find("CONFIG_ONE")->second, "1");
1527 EXPECT_EQ(configs.find("CONFIG_Y")->second, "y");
1528 EXPECT_EQ(configs.find("CONFIG_STR")->second, "string");
1529 EXPECT_EQ(configs.find("CONFIG_NOT_SET")->second, "n");
1530 EXPECT_EQ(configs.find("CONFIG_NOT_SET2")->second, "n");
1531 }
1532
TEST_F(LibVintfTest,KernelConfigParserSpace)1533 TEST_F(LibVintfTest, KernelConfigParserSpace) {
1534 // usage in android-base.config
1535 const std::string data =
1536 " # CONFIG_NOT_SET is not set \n"
1537 " CONFIG_ONE=1 # 'tis a one!\n"
1538 " CONFIG_TWO=2 #'tis a two! \n"
1539 " CONFIG_THREE=3#'tis a three! \n"
1540 " CONFIG_233=233#'tis a three! \n"
1541 "#yey! random comments\n"
1542 "CONFIG_Y=y \n"
1543 " CONFIG_YES=y#YES! \n"
1544 "CONFIG_STR=string\n"
1545 "CONFIG_HELLO=hello world! #still works\n"
1546 "CONFIG_WORLD=hello world! \n"
1547 "CONFIG_GOOD = good morning! #comments here\n"
1548 " CONFIG_MORNING = good morning! \n";
1549 auto pair = processData(data, true /* processComments */, true /* relaxedFormat */);
1550 ASSERT_EQ(OK, pair.second) << pair.first.error();
1551 const auto& configs = pair.first.configs();
1552
1553 EXPECT_EQ(configs.find("CONFIG_ONE")->second, "1");
1554 EXPECT_EQ(configs.find("CONFIG_TWO")->second, "2");
1555 EXPECT_EQ(configs.find("CONFIG_THREE")->second, "3");
1556 EXPECT_EQ(configs.find("CONFIG_Y")->second, "y");
1557 EXPECT_EQ(configs.find("CONFIG_STR")->second, "string");
1558 EXPECT_EQ(configs.find("CONFIG_HELLO")->second, "hello world!")
1559 << "Value should be \"hello world!\" without trailing spaces";
1560 EXPECT_EQ(configs.find("CONFIG_WORLD")->second, "hello world!")
1561 << "Value should be \"hello world!\" without trailing spaces";
1562 EXPECT_EQ(configs.find("CONFIG_GOOD")->second, "good morning!")
1563 << "Value should be \"good morning!\" without leading or trailing spaces";
1564 EXPECT_EQ(configs.find("CONFIG_MORNING")->second, "good morning!")
1565 << "Value should be \"good morning!\" without leading or trailing spaces";
1566 EXPECT_EQ(configs.find("CONFIG_NOT_SET")->second, "n");
1567 }
1568
TEST_F(LibVintfTest,NetutilsWrapperMatrix)1569 TEST_F(LibVintfTest, NetutilsWrapperMatrix) {
1570 std::string matrixXml;
1571 CompatibilityMatrix matrix;
1572
1573 matrixXml =
1574 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">"
1575 " <hal format=\"native\" optional=\"false\">"
1576 " <name>netutils-wrapper</name>"
1577 " <version>1.0</version>"
1578 " </hal>"
1579 "</compatibility-matrix>";
1580 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml))
1581 << gCompatibilityMatrixConverter.lastError();
1582
1583 // only host libvintf hardcodes netutils-wrapper version requirements
1584 #ifndef LIBVINTF_TARGET
1585
1586 matrixXml =
1587 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">"
1588 " <hal format=\"native\" optional=\"false\">"
1589 " <name>netutils-wrapper</name>"
1590 " <version>1.0-1</version>"
1591 " </hal>"
1592 "</compatibility-matrix>";
1593 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1594 EXPECT_CONTAINS(
1595 gCompatibilityMatrixConverter.lastError(),
1596 "netutils-wrapper HAL must specify exactly one version x.0, but a range is provided. "
1597 "Perhaps you mean '1.0'?");
1598
1599 matrixXml =
1600 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">"
1601 " <hal format=\"native\" optional=\"false\">"
1602 " <name>netutils-wrapper</name>"
1603 " <version>1.1</version>"
1604 " </hal>"
1605 "</compatibility-matrix>";
1606 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1607 EXPECT_CONTAINS(
1608 gCompatibilityMatrixConverter.lastError(),
1609 "netutils-wrapper HAL must specify exactly one version x.0, but minor version is not 0. "
1610 "Perhaps you mean '1.0'?");
1611
1612 matrixXml =
1613 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">"
1614 " <hal format=\"native\" optional=\"false\">"
1615 " <name>netutils-wrapper</name>"
1616 " <version>1.0</version>"
1617 " <version>2.0</version>"
1618 " </hal>"
1619 "</compatibility-matrix>";
1620 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1621 EXPECT_CONTAINS(
1622 gCompatibilityMatrixConverter.lastError(),
1623 "netutils-wrapper HAL must specify exactly one version x.0, but multiple <version> element "
1624 "is specified.");
1625
1626 #endif // LIBVINTF_TARGET
1627 }
1628
TEST_F(LibVintfTest,NetutilsWrapperManifest)1629 TEST_F(LibVintfTest, NetutilsWrapperManifest) {
1630 std::string manifestXml;
1631 HalManifest manifest;
1632
1633 manifestXml =
1634 "<manifest " + kMetaVersionStr + " type=\"framework\">"
1635 " <hal format=\"native\">"
1636 " <name>netutils-wrapper</name>"
1637 " <version>1.0</version>"
1638 " <version>2.0</version>"
1639 " </hal>"
1640 "</manifest>";
1641 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml)) << gHalManifestConverter.lastError();
1642
1643 // only host libvintf hardcodes netutils-wrapper version requirements
1644 #ifndef LIBVINTF_TARGET
1645
1646 manifestXml =
1647 "<manifest " + kMetaVersionStr + " type=\"framework\">"
1648 " <hal format=\"native\">"
1649 " <name>netutils-wrapper</name>"
1650 " <version>1.1</version>"
1651 " </hal>"
1652 "</manifest>";
1653 EXPECT_FALSE(gHalManifestConverter(&manifest, manifestXml));
1654 EXPECT_CONTAINS(
1655 gCompatibilityMatrixConverter.lastError(),
1656 "netutils-wrapper HAL must specify exactly one version x.0, but multiple <version> element "
1657 "is specified.");
1658
1659 manifestXml =
1660 "<manifest " + kMetaVersionStr + " type=\"framework\">"
1661 " <hal format=\"native\">"
1662 " <name>netutils-wrapper</name>"
1663 " <version>1.0</version>"
1664 " <version>2.1</version>"
1665 " </hal>"
1666 "</manifest>";
1667 EXPECT_FALSE(gHalManifestConverter(&manifest, manifestXml));
1668 EXPECT_CONTAINS(
1669 gCompatibilityMatrixConverter.lastError(),
1670 "netutils-wrapper HAL must specify exactly one version x.0, but multiple <version> element "
1671 "is specified.");
1672
1673 #endif // LIBVINTF_TARGET
1674 }
1675
TEST_F(LibVintfTest,KernelConfigConditionTest)1676 TEST_F(LibVintfTest, KernelConfigConditionTest) {
1677 std::string xml =
1678 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1679 " <kernel version=\"3.18.22\"/>\n"
1680 " <kernel version=\"3.18.22\">\n"
1681 " <conditions>\n"
1682 " <config>\n"
1683 " <key>CONFIG_ARM</key>\n"
1684 " <value type=\"tristate\">y</value>\n"
1685 " </config>\n"
1686 " </conditions>\n"
1687 " <config>\n"
1688 " <key>CONFIG_FOO</key>\n"
1689 " <value type=\"tristate\">y</value>\n"
1690 " </config>\n"
1691 " </kernel>\n"
1692 " <sepolicy>\n"
1693 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1694 " <sepolicy-version>25.0</sepolicy-version>\n"
1695 " </sepolicy>\n"
1696 " <avb>\n"
1697 " <vbmeta-version>2.1</vbmeta-version>\n"
1698 " </avb>\n"
1699 "</compatibility-matrix>\n";
1700
1701 CompatibilityMatrix cm;
1702 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1703 << gCompatibilityMatrixConverter.lastError();
1704 const auto& kernels = getKernels(cm);
1705 ASSERT_GE(kernels.size(), 2u);
1706 ASSERT_TRUE(kernels[0].conditions().empty());
1707 const auto& kernel = kernels[1];
1708 const auto& cond = kernel.conditions();
1709 ASSERT_FALSE(cond.empty());
1710 EXPECT_EQ("CONFIG_ARM", cond.begin()->first);
1711 EXPECT_EQ(KernelConfigTypedValue(Tristate::YES), cond.begin()->second);
1712 EXPECT_FALSE(kernel.configs().empty());
1713
1714 EXPECT_EQ(xml, gCompatibilityMatrixConverter(cm));
1715 }
1716
TEST_F(LibVintfTest,KernelConfigConditionEmptyTest)1717 TEST_F(LibVintfTest, KernelConfigConditionEmptyTest) {
1718 std::string xml =
1719 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1720 " <kernel version=\"4.4.0\"/>\n"
1721 " <kernel version=\"3.18.22\">\n"
1722 " <conditions>\n"
1723 " <config>\n"
1724 " <key>CONFIG_ARM</key>\n"
1725 " <value type=\"tristate\">y</value>\n"
1726 " </config>\n"
1727 " </conditions>\n"
1728 " </kernel>\n"
1729 "</compatibility-matrix>\n";
1730
1731 CompatibilityMatrix cm;
1732 EXPECT_FALSE(gCompatibilityMatrixConverter(&cm, xml))
1733 << "Should not accept first kernel version with non-empty conditions";
1734 EXPECT_EQ(
1735 "First <kernel> for version 3.18 must have empty <conditions> "
1736 "for backwards compatibility.",
1737 gCompatibilityMatrixConverter.lastError());
1738 }
1739
TEST_F(LibVintfTest,KernelConfigConditionMatch)1740 TEST_F(LibVintfTest, KernelConfigConditionMatch) {
1741 RuntimeInfo runtime = testRuntimeInfo();
1742 std::string error;
1743 std::string xml;
1744 CompatibilityMatrix cm;
1745
1746 xml =
1747 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1748 " <kernel version=\"3.18.22\"/>\n"
1749 " <kernel version=\"3.18.22\">\n"
1750 " <conditions>\n"
1751 " <config>\n"
1752 " <key>CONFIG_64BIT</key>\n"
1753 " <value type=\"tristate\">y</value>\n"
1754 " </config>\n"
1755 " </conditions>\n"
1756 " <config>\n"
1757 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1758 " <value type=\"int\">24</value>\n"
1759 " </config>\n"
1760 " </kernel>\n"
1761 " <sepolicy>\n"
1762 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1763 " </sepolicy>\n"
1764 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1765 "</compatibility-matrix>\n";
1766
1767 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1768 << gCompatibilityMatrixConverter.lastError();
1769 EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error;
1770
1771 xml =
1772 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1773 " <kernel version=\"3.18.22\"/>\n"
1774 " <kernel version=\"3.18.22\">\n"
1775 " <conditions>\n"
1776 " <config>\n"
1777 " <key>CONFIG_64BIT</key>\n"
1778 " <value type=\"tristate\">y</value>\n"
1779 " </config>\n"
1780 " </conditions>\n"
1781 " <config>\n"
1782 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1783 " <value type=\"int\">26</value>\n"
1784 " </config>\n"
1785 " </kernel>\n"
1786 " <sepolicy>\n"
1787 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1788 " </sepolicy>\n"
1789 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1790 "</compatibility-matrix>\n";
1791
1792 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1793 << gCompatibilityMatrixConverter.lastError();
1794 EXPECT_FALSE(runtime.checkCompatibility(cm, &error))
1795 << "conditions met, so CONFIG_ARCH_MMAP_RND_BITS should not match";
1796
1797 xml =
1798 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1799 " <kernel version=\"3.18.22\"/>\n"
1800 " <kernel version=\"3.18.22\">\n"
1801 " <conditions>\n"
1802 " <config>\n"
1803 " <key>CONFIG_64BIT</key>\n"
1804 " <value type=\"tristate\">n</value>\n"
1805 " </config>\n"
1806 " </conditions>\n"
1807 " <config>\n"
1808 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1809 " <value type=\"int\">26</value>\n"
1810 " </config>\n"
1811 " </kernel>\n"
1812 " <sepolicy>\n"
1813 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1814 " </sepolicy>\n"
1815 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1816 "</compatibility-matrix>\n";
1817
1818 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1819 << gCompatibilityMatrixConverter.lastError();
1820 EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error;
1821 xml =
1822 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1823 " <kernel version=\"3.18.22\"/>\n"
1824 " <kernel version=\"3.18.22\">\n"
1825 " <conditions>\n"
1826 " <config>\n"
1827 " <key>CONFIG_64BIT</key>\n"
1828 " <value type=\"tristate\">y</value>\n"
1829 " </config>\n"
1830 " <config>\n"
1831 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1832 " <value type=\"int\">24</value>\n"
1833 " </config>\n"
1834 " </conditions>\n"
1835 " <config>\n"
1836 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
1837 " <value type=\"int\">0xdead000000000000</value>\n"
1838 " </config>\n"
1839 " </kernel>\n"
1840 " <sepolicy>\n"
1841 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1842 " </sepolicy>\n"
1843 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1844 "</compatibility-matrix>\n";
1845
1846 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1847 << gCompatibilityMatrixConverter.lastError();
1848 EXPECT_TRUE(runtime.checkCompatibility(cm, &error));
1849
1850 xml =
1851 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1852 " <kernel version=\"3.18.22\"/>\n"
1853 " <kernel version=\"3.18.22\">\n"
1854 " <conditions>\n"
1855 " <config>\n"
1856 " <key>CONFIG_64BIT</key>\n"
1857 " <value type=\"tristate\">y</value>\n"
1858 " </config>\n"
1859 " <config>\n"
1860 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1861 " <value type=\"int\">24</value>\n"
1862 " </config>\n"
1863 " </conditions>\n"
1864 " <config>\n"
1865 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
1866 " <value type=\"int\">0xbeaf000000000000</value>\n"
1867 " </config>\n"
1868 " </kernel>\n"
1869 " <sepolicy>\n"
1870 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1871 " </sepolicy>\n"
1872 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1873 "</compatibility-matrix>\n";
1874
1875 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1876 << gCompatibilityMatrixConverter.lastError();
1877 EXPECT_FALSE(runtime.checkCompatibility(cm, &error))
1878 << "conditions have 'and' relationship, so CONFIG_ILLEGAL_POINTER_VALUE should not match";
1879
1880 xml =
1881 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1882 " <kernel version=\"3.18.22\"/>\n"
1883 " <kernel version=\"3.18.22\">\n"
1884 " <conditions>\n"
1885 " <config>\n"
1886 " <key>CONFIG_64BIT</key>\n"
1887 " <value type=\"tristate\">y</value>\n"
1888 " </config>\n"
1889 " <config>\n"
1890 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1891 " <value type=\"int\">26</value>\n"
1892 " </config>\n"
1893 " </conditions>\n"
1894 " <config>\n"
1895 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
1896 " <value type=\"int\">0xbeaf000000000000</value>\n"
1897 " </config>\n"
1898 " </kernel>\n"
1899 " <sepolicy>\n"
1900 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1901 " </sepolicy>\n"
1902 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1903 "</compatibility-matrix>\n";
1904
1905 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1906 << gCompatibilityMatrixConverter.lastError();
1907 EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error;
1908
1909 xml =
1910 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1911 " <kernel version=\"3.18.22\">\n"
1912 " <config>\n"
1913 " <key>CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES</key>\n"
1914 " <value type=\"string\"/>\n"
1915 " </config>\n"
1916 " </kernel>\n"
1917 " <kernel version=\"3.18.22\">\n"
1918 " <conditions>\n"
1919 " <config>\n"
1920 " <key>CONFIG_64BIT</key>\n"
1921 " <value type=\"tristate\">y</value>\n"
1922 " </config>\n"
1923 " </conditions>\n"
1924 " <config>\n"
1925 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
1926 " <value type=\"int\">0xdead000000000000</value>\n"
1927 " </config>\n"
1928 " </kernel>\n"
1929 " <kernel version=\"3.18.22\">\n"
1930 " <conditions>\n"
1931 " <config>\n"
1932 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1933 " <value type=\"int\">24</value>\n"
1934 " </config>\n"
1935 " </conditions>\n"
1936 " <config>\n"
1937 " <key>CONFIG_ANDROID_BINDER_DEVICES</key>\n"
1938 " <value type=\"string\">binder,hwbinder</value>\n"
1939 " </config>\n"
1940 " </kernel>\n"
1941 " <sepolicy>\n"
1942 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1943 " </sepolicy>\n"
1944 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1945 "</compatibility-matrix>\n";
1946
1947 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1948 << gCompatibilityMatrixConverter.lastError();
1949 EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error;
1950
1951 xml =
1952 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1953 " <kernel version=\"3.18.22\">\n"
1954 " <config>\n"
1955 " <key>CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES</key>\n"
1956 " <value type=\"string\"/>\n"
1957 " </config>\n"
1958 " </kernel>\n"
1959 " <kernel version=\"3.18.22\">\n"
1960 " <conditions>\n"
1961 " <config>\n"
1962 " <key>CONFIG_64BIT</key>\n"
1963 " <value type=\"tristate\">y</value>\n"
1964 " </config>\n"
1965 " </conditions>\n"
1966 " <config>\n"
1967 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
1968 " <value type=\"int\">0xbeaf000000000000</value>\n"
1969 " </config>\n"
1970 " </kernel>\n"
1971 " <kernel version=\"3.18.22\">\n"
1972 " <conditions>\n"
1973 " <config>\n"
1974 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
1975 " <value type=\"int\">24</value>\n"
1976 " </config>\n"
1977 " </conditions>\n"
1978 " <config>\n"
1979 " <key>CONFIG_ANDROID_BINDER_DEVICES</key>\n"
1980 " <value type=\"string\">binder,hwbinder</value>\n"
1981 " </config>\n"
1982 " </kernel>\n"
1983 " <sepolicy>\n"
1984 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
1985 " </sepolicy>\n"
1986 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
1987 "</compatibility-matrix>\n";
1988
1989 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
1990 << gCompatibilityMatrixConverter.lastError();
1991 EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "all fragments should be used.";
1992
1993 xml =
1994 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
1995 " <kernel version=\"3.18.22\">\n"
1996 " <config>\n"
1997 " <key>CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES</key>\n"
1998 " <value type=\"string\"/>\n"
1999 " </config>\n"
2000 " </kernel>\n"
2001 " <kernel version=\"3.18.22\">\n"
2002 " <conditions>\n"
2003 " <config>\n"
2004 " <key>CONFIG_64BIT</key>\n"
2005 " <value type=\"tristate\">y</value>\n"
2006 " </config>\n"
2007 " </conditions>\n"
2008 " <config>\n"
2009 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
2010 " <value type=\"int\">0xdead000000000000</value>\n"
2011 " </config>\n"
2012 " </kernel>\n"
2013 " <kernel version=\"3.18.22\">\n"
2014 " <conditions>\n"
2015 " <config>\n"
2016 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
2017 " <value type=\"int\">24</value>\n"
2018 " </config>\n"
2019 " </conditions>\n"
2020 " <config>\n"
2021 " <key>CONFIG_ANDROID_BINDER_DEVICES</key>\n"
2022 " <value type=\"string\">binder</value>\n"
2023 " </config>\n"
2024 " </kernel>\n"
2025 " <sepolicy>\n"
2026 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
2027 " </sepolicy>\n"
2028 " <avb><vbmeta-version>2.1</vbmeta-version></avb>\n"
2029 "</compatibility-matrix>\n";
2030
2031 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2032 << gCompatibilityMatrixConverter.lastError();
2033 EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "all fragments should be used";
2034 }
2035
2036 // Run KernelConfigParserInvalidTest on processComments = {true, false}
2037 class KernelConfigParserInvalidTest : public ::testing::TestWithParam<bool> {};
2038
TEST_P(KernelConfigParserInvalidTest,NonSet1)2039 TEST_P(KernelConfigParserInvalidTest, NonSet1) {
2040 const std::string data = "# CONFIG_NOT_EXIST is not sat\n";
2041 auto pair = processData(data, GetParam() /* processComments */, true /* relaxedFormat */);
2042 ASSERT_EQ(OK, pair.second) << pair.first.error();
2043 const auto& configs = pair.first.configs();
2044 EXPECT_EQ(configs.find("CONFIG_NOT_EXIST"), configs.end())
2045 << "CONFIG_NOT_EXIST should not exist because of typo";
2046 }
2047
TEST_P(KernelConfigParserInvalidTest,InvalidLine1)2048 TEST_P(KernelConfigParserInvalidTest, InvalidLine1) {
2049 const std::string data = "FOO_CONFIG=foo\n";
2050 ASSERT_NE(OK,
2051 processData(data, GetParam() /* processComments */, true /* relaxedFormat */).second);
2052 }
2053
TEST_P(KernelConfigParserInvalidTest,InvalidLine2)2054 TEST_P(KernelConfigParserInvalidTest, InvalidLine2) {
2055 const std::string data = "CONFIG_BAR-BAZ=foo\n";
2056 ASSERT_NE(OK,
2057 processData(data, GetParam() /* processComments */, true /* relaxedFormat */).second);
2058 }
2059
2060 INSTANTIATE_TEST_CASE_P(KernelConfigParser, KernelConfigParserInvalidTest, ::testing::Bool());
2061
TEST_F(LibVintfTest,MatrixLevel)2062 TEST_F(LibVintfTest, MatrixLevel) {
2063 CompatibilityMatrix cm;
2064 std::string xml;
2065
2066 xml = "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\"/>";
2067 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2068 << gCompatibilityMatrixConverter.lastError();
2069 EXPECT_EQ(Level::UNSPECIFIED, cm.level());
2070
2071 xml = "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"legacy\"/>";
2072 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2073 << gCompatibilityMatrixConverter.lastError();
2074 EXPECT_EQ(Level::LEGACY, cm.level());
2075
2076 xml = "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\"/>";
2077 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2078 << gCompatibilityMatrixConverter.lastError();
2079 EXPECT_EQ(1u, cm.level());
2080 }
2081
TEST_F(LibVintfTest,ManifestLevel)2082 TEST_F(LibVintfTest, ManifestLevel) {
2083 HalManifest manifest;
2084 std::string xml;
2085
2086 xml = "<manifest " + kMetaVersionStr + " type=\"device\"/>";
2087 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2088 EXPECT_EQ(Level::UNSPECIFIED, manifest.level());
2089
2090 xml = "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"legacy\"/>";
2091 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2092 EXPECT_EQ(Level::LEGACY, manifest.level());
2093
2094 xml = "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"1\"/>";
2095 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2096 EXPECT_EQ(1u, manifest.level());
2097 }
2098
TEST_F(LibVintfTest,AddOptionalHal)2099 TEST_F(LibVintfTest, AddOptionalHal) {
2100 CompatibilityMatrix cm1;
2101 CompatibilityMatrix cm2;
2102 std::string error;
2103 std::string xml;
2104
2105 xml = "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\"/>";
2106 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2107 << gCompatibilityMatrixConverter.lastError();
2108
2109 xml =
2110 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2111 " <hal format=\"hidl\" optional=\"false\">\n"
2112 " <name>android.hardware.foo</name>\n"
2113 " <version>1.0-1</version>\n"
2114 " <interface>\n"
2115 " <name>IFoo</name>\n"
2116 " <instance>default</instance>\n"
2117 " </interface>\n"
2118 " </hal>\n"
2119 "</compatibility-matrix>\n";
2120 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2121 << gCompatibilityMatrixConverter.lastError();
2122
2123 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2124 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2125 EXPECT_EQ(xml,
2126 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2127 " <hal format=\"hidl\" optional=\"true\">\n"
2128 " <name>android.hardware.foo</name>\n"
2129 " <version>1.0-1</version>\n"
2130 " <interface>\n"
2131 " <name>IFoo</name>\n"
2132 " <instance>default</instance>\n"
2133 " </interface>\n"
2134 " </hal>\n"
2135 "</compatibility-matrix>\n");
2136 }
2137
TEST_F(LibVintfTest,AddOptionalHalMinorVersion)2138 TEST_F(LibVintfTest, AddOptionalHalMinorVersion) {
2139 CompatibilityMatrix cm1;
2140 CompatibilityMatrix cm2;
2141 std::string error;
2142 std::string xml;
2143
2144 xml =
2145 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2146 " <hal format=\"hidl\" optional=\"false\">\n"
2147 " <name>android.hardware.foo</name>\n"
2148 " <version>1.2-3</version>\n"
2149 " <interface>\n"
2150 " <name>IFoo</name>\n"
2151 " <instance>default</instance>\n"
2152 " </interface>\n"
2153 " </hal>\n"
2154 "</compatibility-matrix>\n";
2155 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2156 << gCompatibilityMatrixConverter.lastError();
2157
2158 xml =
2159 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2160 " <hal format=\"hidl\" optional=\"false\">\n"
2161 " <name>android.hardware.foo</name>\n"
2162 " <version>1.0-4</version>\n"
2163 " <interface>\n"
2164 " <name>IFoo</name>\n"
2165 " <instance>default</instance>\n"
2166 " </interface>\n"
2167 " </hal>\n"
2168 "</compatibility-matrix>\n";
2169 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2170 << gCompatibilityMatrixConverter.lastError();
2171
2172 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2173 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2174 EXPECT_EQ(xml,
2175 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2176 " <hal format=\"hidl\" optional=\"false\">\n"
2177 " <name>android.hardware.foo</name>\n"
2178 " <version>1.0-4</version>\n"
2179 " <interface>\n"
2180 " <name>IFoo</name>\n"
2181 " <instance>default</instance>\n"
2182 " </interface>\n"
2183 " </hal>\n"
2184 "</compatibility-matrix>\n");
2185 }
2186
TEST_F(LibVintfTest,AddOptionalHalMajorVersion)2187 TEST_F(LibVintfTest, AddOptionalHalMajorVersion) {
2188 CompatibilityMatrix cm1;
2189 CompatibilityMatrix cm2;
2190 std::string error;
2191 std::string xml;
2192
2193 xml =
2194 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2195 " <hal format=\"hidl\" optional=\"false\">\n"
2196 " <name>android.hardware.foo</name>\n"
2197 " <version>1.2-3</version>\n"
2198 " <interface>\n"
2199 " <name>IFoo</name>\n"
2200 " <instance>default</instance>\n"
2201 " </interface>\n"
2202 " </hal>\n"
2203 "</compatibility-matrix>\n";
2204 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2205 << gCompatibilityMatrixConverter.lastError();
2206
2207 xml =
2208 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2209 " <hal format=\"hidl\" optional=\"false\">\n"
2210 " <name>android.hardware.foo</name>\n"
2211 " <version>1.2-3</version>\n"
2212 " <version>2.0-4</version>\n"
2213 " <interface>\n"
2214 " <name>IFoo</name>\n"
2215 " <instance>default</instance>\n"
2216 " </interface>\n"
2217 " </hal>\n"
2218 "</compatibility-matrix>\n";
2219 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2220 << gCompatibilityMatrixConverter.lastError();
2221
2222 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2223 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2224 EXPECT_EQ(xml,
2225 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2226 " <hal format=\"hidl\" optional=\"false\">\n"
2227 " <name>android.hardware.foo</name>\n"
2228 " <version>1.2-3</version>\n"
2229 " <version>2.0-4</version>\n"
2230 " <interface>\n"
2231 " <name>IFoo</name>\n"
2232 " <instance>default</instance>\n"
2233 " </interface>\n"
2234 " </hal>\n"
2235 "</compatibility-matrix>\n");
2236 }
2237
TEST_F(LibVintfTest,AddOptionalHalMinorVersionDiffInstance)2238 TEST_F(LibVintfTest, AddOptionalHalMinorVersionDiffInstance) {
2239 CompatibilityMatrix cm1;
2240 CompatibilityMatrix cm2;
2241 std::string error;
2242 std::string xml;
2243
2244 xml =
2245 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2246 " <hal format=\"hidl\" optional=\"false\">\n"
2247 " <name>android.hardware.foo</name>\n"
2248 " <version>1.0-1</version>\n"
2249 " <interface>\n"
2250 " <name>IFoo</name>\n"
2251 " <instance>default</instance>\n"
2252 " </interface>\n"
2253 " </hal>\n"
2254 "</compatibility-matrix>\n";
2255 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2256 << gCompatibilityMatrixConverter.lastError();
2257
2258 xml =
2259 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2260 " <hal format=\"hidl\" optional=\"false\">\n"
2261 " <name>android.hardware.foo</name>\n"
2262 " <version>1.1-2</version>\n"
2263 " <interface>\n"
2264 " <name>IFoo</name>\n"
2265 " <instance>custom</instance>\n"
2266 " </interface>\n"
2267 " </hal>\n"
2268 "</compatibility-matrix>\n";
2269 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2270 << gCompatibilityMatrixConverter.lastError();
2271
2272 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2273 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2274 EXPECT_EQ(xml,
2275 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2276 " <hal format=\"hidl\" optional=\"false\">\n"
2277 " <name>android.hardware.foo</name>\n"
2278 " <version>1.0-1</version>\n"
2279 " <interface>\n"
2280 " <name>IFoo</name>\n"
2281 " <instance>default</instance>\n"
2282 " </interface>\n"
2283 " </hal>\n"
2284 " <hal format=\"hidl\" optional=\"true\">\n"
2285 " <name>android.hardware.foo</name>\n"
2286 " <version>1.1-2</version>\n"
2287 " <interface>\n"
2288 " <name>IFoo</name>\n"
2289 " <instance>custom</instance>\n"
2290 " </interface>\n"
2291 " </hal>\n"
2292 "</compatibility-matrix>\n");
2293 }
2294
TEST_F(LibVintfTest,AddRequiredHalOverlapInstance)2295 TEST_F(LibVintfTest, AddRequiredHalOverlapInstance) {
2296 CompatibilityMatrix cm1;
2297 std::string error;
2298 std::string xml;
2299
2300 xml =
2301 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2302 " <hal format=\"hidl\" optional=\"false\">\n"
2303 " <name>android.hardware.foo</name>\n"
2304 " <version>1.0</version>\n"
2305 " <interface>\n"
2306 " <name>IFoo</name>\n"
2307 " <instance>default</instance>\n"
2308 " <instance>custom</instance>\n"
2309 " </interface>\n"
2310 " </hal>\n"
2311 "</compatibility-matrix>\n";
2312 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2313 << gCompatibilityMatrixConverter.lastError();
2314
2315 {
2316 // Test that 2.0 should be added to IFoo/default, so 1.0::IFoo/custom
2317 // should be in a new <hal> tag
2318 CompatibilityMatrix cm2;
2319 xml =
2320 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2321 " <hal format=\"hidl\" optional=\"false\">\n"
2322 " <name>android.hardware.foo</name>\n"
2323 " <version>2.0</version>\n"
2324 " <interface>\n"
2325 " <name>IFoo</name>\n"
2326 " <instance>default</instance>\n"
2327 " </interface>\n"
2328 " </hal>\n"
2329 "</compatibility-matrix>\n";
2330 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2331 << gCompatibilityMatrixConverter.lastError();
2332
2333 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2334
2335 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2336 EXPECT_EQ(xml,
2337 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2338 " <hal format=\"hidl\" optional=\"false\">\n"
2339 " <name>android.hardware.foo</name>\n"
2340 " <version>1.0</version>\n"
2341 " <interface>\n"
2342 " <name>IFoo</name>\n"
2343 " <instance>custom</instance>\n"
2344 " </interface>\n"
2345 " </hal>\n"
2346 " <hal format=\"hidl\" optional=\"false\">\n"
2347 " <name>android.hardware.foo</name>\n"
2348 " <version>1.0</version>\n"
2349 " <version>2.0</version>\n"
2350 " <interface>\n"
2351 " <name>IFoo</name>\n"
2352 " <instance>default</instance>\n"
2353 " </interface>\n"
2354 " </hal>\n"
2355 "</compatibility-matrix>\n");
2356 }
2357
2358 {
2359 // Test that 2.0::IFoo/strong should be added as an optional <hal> tag.
2360 CompatibilityMatrix cm2;
2361 xml =
2362 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2363 " <hal format=\"hidl\" optional=\"false\">\n"
2364 " <name>android.hardware.foo</name>\n"
2365 " <version>2.0</version>\n"
2366 " <interface>\n"
2367 " <name>IFoo</name>\n"
2368 " <instance>default</instance>\n"
2369 " <instance>strong</instance>\n"
2370 " </interface>\n"
2371 " </hal>\n"
2372 "</compatibility-matrix>\n";
2373 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2374 << gCompatibilityMatrixConverter.lastError();
2375
2376 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2377
2378 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2379 EXPECT_EQ(xml,
2380 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2381 " <hal format=\"hidl\" optional=\"false\">\n"
2382 " <name>android.hardware.foo</name>\n"
2383 " <version>1.0</version>\n"
2384 " <interface>\n"
2385 " <name>IFoo</name>\n"
2386 " <instance>custom</instance>\n"
2387 " </interface>\n"
2388 " </hal>\n"
2389 " <hal format=\"hidl\" optional=\"false\">\n"
2390 " <name>android.hardware.foo</name>\n"
2391 " <version>1.0</version>\n"
2392 " <version>2.0</version>\n"
2393 " <interface>\n"
2394 " <name>IFoo</name>\n"
2395 " <instance>default</instance>\n"
2396 " </interface>\n"
2397 " </hal>\n"
2398 " <hal format=\"hidl\" optional=\"true\">\n"
2399 " <name>android.hardware.foo</name>\n"
2400 " <version>2.0</version>\n"
2401 " <interface>\n"
2402 " <name>IFoo</name>\n"
2403 " <instance>strong</instance>\n"
2404 " </interface>\n"
2405 " </hal>\n"
2406 "</compatibility-matrix>\n");
2407 }
2408 }
2409
TEST_F(LibVintfTest,AddRequiredHalOverlapInstanceSplit)2410 TEST_F(LibVintfTest, AddRequiredHalOverlapInstanceSplit) {
2411 CompatibilityMatrix cm1;
2412 CompatibilityMatrix cm2;
2413 std::string error;
2414 std::string xml;
2415
2416 xml =
2417 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2418 " <hal format=\"hidl\" optional=\"false\">\n"
2419 " <name>android.hardware.foo</name>\n"
2420 " <version>1.0</version>\n"
2421 " <interface>\n"
2422 " <name>IFoo</name>\n"
2423 " <instance>default</instance>\n"
2424 " </interface>\n"
2425 " </hal>\n"
2426 " <hal format=\"hidl\" optional=\"false\">\n"
2427 " <name>android.hardware.foo</name>\n"
2428 " <version>1.0</version>\n"
2429 " <interface>\n"
2430 " <name>IFoo</name>\n"
2431 " <instance>custom</instance>\n"
2432 " </interface>\n"
2433 " </hal>\n"
2434 "</compatibility-matrix>\n";
2435 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2436 << gCompatibilityMatrixConverter.lastError();
2437
2438 xml =
2439 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2440 " <hal format=\"hidl\" optional=\"false\">\n"
2441 " <name>android.hardware.foo</name>\n"
2442 " <version>2.0</version>\n"
2443 " <interface>\n"
2444 " <name>IFoo</name>\n"
2445 " <instance>default</instance>\n"
2446 " </interface>\n"
2447 " </hal>\n"
2448 " <hal format=\"hidl\" optional=\"false\">\n"
2449 " <name>android.hardware.foo</name>\n"
2450 " <version>2.0</version>\n"
2451 " <interface>\n"
2452 " <name>IFoo</name>\n"
2453 " <instance>strong</instance>\n"
2454 " </interface>\n"
2455 " </hal>\n"
2456 "</compatibility-matrix>\n";
2457 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2458 << gCompatibilityMatrixConverter.lastError();
2459
2460 EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error;
2461 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::HALS_ONLY);
2462 EXPECT_EQ(
2463 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2464 " <hal format=\"hidl\" optional=\"false\">\n"
2465 " <name>android.hardware.foo</name>\n"
2466 " <version>1.0</version>\n"
2467 " <version>2.0</version>\n"
2468 " <interface>\n"
2469 " <name>IFoo</name>\n"
2470 " <instance>default</instance>\n"
2471 " </interface>\n"
2472 " </hal>\n"
2473 " <hal format=\"hidl\" optional=\"false\">\n"
2474 " <name>android.hardware.foo</name>\n"
2475 " <version>1.0</version>\n"
2476 " <interface>\n"
2477 " <name>IFoo</name>\n"
2478 " <instance>custom</instance>\n"
2479 " </interface>\n"
2480 " </hal>\n"
2481 " <hal format=\"hidl\" optional=\"true\">\n"
2482 " <name>android.hardware.foo</name>\n"
2483 " <version>2.0</version>\n"
2484 " <interface>\n"
2485 " <name>IFoo</name>\n"
2486 " <instance>strong</instance>\n"
2487 " </interface>\n"
2488 " </hal>\n"
2489 "</compatibility-matrix>\n",
2490 xml);
2491 }
TEST_F(LibVintfTest,AddOptionalXmlFile)2492 TEST_F(LibVintfTest, AddOptionalXmlFile) {
2493 CompatibilityMatrix cm1;
2494 CompatibilityMatrix cm2;
2495 std::string error;
2496 std::string xml;
2497
2498 xml =
2499 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2500 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2501 " <name>foo</name>\n"
2502 " <version>1.0-2</version>\n"
2503 " <path>/foo/bar/baz.xsd</path>\n"
2504 " </xmlfile>\n"
2505 "</compatibility-matrix>\n";
2506 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm1, xml))
2507 << gCompatibilityMatrixConverter.lastError();
2508
2509 xml =
2510 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"
2511 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2512 " <name>foo</name>\n"
2513 " <version>1.1-3</version>\n"
2514 " <path>/foo/bar/quux.xsd</path>\n"
2515 " </xmlfile>\n"
2516 "</compatibility-matrix>\n";
2517 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm2, xml))
2518 << gCompatibilityMatrixConverter.lastError();
2519
2520 EXPECT_TRUE(addAllXmlFilesAsOptional(&cm1, &cm2, &error)) << error;
2521 xml = gCompatibilityMatrixConverter(cm1, SerializeFlags::XMLFILES_ONLY);
2522 EXPECT_EQ(xml,
2523 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
2524 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2525 " <name>foo</name>\n"
2526 " <version>1.0-2</version>\n"
2527 " <path>/foo/bar/baz.xsd</path>\n"
2528 " </xmlfile>\n"
2529 " <xmlfile format=\"xsd\" optional=\"true\">\n"
2530 " <name>foo</name>\n"
2531 " <version>1.1-3</version>\n"
2532 " <path>/foo/bar/quux.xsd</path>\n"
2533 " </xmlfile>\n"
2534 "</compatibility-matrix>\n");
2535 }
2536
TEST_F(LibVintfTest,VendorNdk)2537 TEST_F(LibVintfTest, VendorNdk) {
2538 CompatibilityMatrix cm;
2539 std::string error;
2540 std::string xml;
2541
2542 xml =
2543 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
2544 " <vendor-ndk>\n"
2545 " <version>P</version>\n"
2546 " <library>libbase.so</library>\n"
2547 " <library>libjpeg.so</library>\n"
2548 " </vendor-ndk>\n"
2549 "</compatibility-matrix>\n";
2550 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2551 << gCompatibilityMatrixConverter.lastError();
2552 EXPECT_EQ(xml, gCompatibilityMatrixConverter(cm));
2553
2554 EXPECT_EQ("P", cm.getVendorNdkVersion());
2555
2556 {
2557 HalManifest manifest;
2558 xml =
2559 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2560 " <vendor-ndk>\n"
2561 " <version>27</version>\n"
2562 " <library>libbase.so</library>\n"
2563 " <library>libjpeg.so</library>\n"
2564 " </vendor-ndk>\n"
2565 " <vendor-ndk>\n"
2566 " <version>P</version>\n"
2567 " <library>libbase.so</library>\n"
2568 " <library>libjpeg.so</library>\n"
2569 " <library>libtinyxml2.so</library>\n"
2570 " </vendor-ndk>\n"
2571 "</manifest>\n";
2572
2573 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2574 EXPECT_EQ(xml, gHalManifestConverter(manifest));
2575 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
2576 }
2577
2578 {
2579 HalManifest manifest;
2580 xml =
2581 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2582 " <vendor-ndk>\n"
2583 " <version>27</version>\n"
2584 " <library>libbase.so</library>\n"
2585 " <library>libjpeg.so</library>\n"
2586 " </vendor-ndk>\n"
2587 "</manifest>\n";
2588
2589 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2590 EXPECT_EQ(xml, gHalManifestConverter(manifest));
2591 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
2592 EXPECT_IN("Vndk version P is not supported.", error);
2593 }
2594
2595 {
2596 HalManifest manifest;
2597 xml =
2598 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2599 " <vendor-ndk>\n"
2600 " <version>P</version>\n"
2601 " <library>libbase.so</library>\n"
2602 " </vendor-ndk>\n"
2603 "</manifest>\n";
2604
2605 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2606 EXPECT_EQ(xml, gHalManifestConverter(manifest));
2607 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
2608 EXPECT_IN("Vndk libs incompatible for version P.", error);
2609 EXPECT_IN("libjpeg.so", error);
2610 }
2611 }
2612
TEST_F(LibVintfTest,MissingVendorNdkInMatrix)2613 TEST_F(LibVintfTest, MissingVendorNdkInMatrix) {
2614 CompatibilityMatrix cm;
2615 std::string xml;
2616 std::string error;
2617
2618 xml = "<compatibility-matrix " + kMetaVersionStr + " type=\"device\"/>\n";
2619 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2620 << gCompatibilityMatrixConverter.lastError();
2621
2622 {
2623 HalManifest manifest;
2624 xml = "<manifest " + kMetaVersionStr + " type=\"framework\"/>\n";
2625 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2626
2627 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
2628 }
2629
2630 {
2631 HalManifest manifest;
2632 xml =
2633 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2634 " <vendor-ndk>\n"
2635 " <version>P</version>\n"
2636 " <library>libbase.so</library>\n"
2637 " </vendor-ndk>\n"
2638 "</manifest>\n";
2639 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2640
2641 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
2642 }
2643 }
2644
TEST_F(LibVintfTest,DuplicatedVendorNdkVersion)2645 TEST_F(LibVintfTest, DuplicatedVendorNdkVersion) {
2646 std::string error;
2647 HalManifest manifest;
2648 std::string xml =
2649 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2650 " <vendor-ndk>\n"
2651 " <version>27</version>\n"
2652 " </vendor-ndk>\n"
2653 " <vendor-ndk>\n"
2654 " <version>27</version>\n"
2655 " </vendor-ndk>\n"
2656 "</manifest>\n";
2657
2658 EXPECT_FALSE(gHalManifestConverter(&manifest, xml));
2659 EXPECT_EQ("Duplicated manifest.vendor-ndk.version 27", gHalManifestConverter.lastError());
2660 }
2661
TEST_F(LibVintfTest,ManifestHalOverride)2662 TEST_F(LibVintfTest, ManifestHalOverride) {
2663 HalManifest manifest;
2664 std::string xml =
2665 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2666 " <hal format=\"hidl\" override=\"true\">\n"
2667 " <name>android.hardware.foo</name>\n"
2668 " <transport>hwbinder</transport>\n"
2669 " <version>1.0</version>\n"
2670 " </hal>\n"
2671 " <hal format=\"hidl\">\n"
2672 " <name>android.hardware.bar</name>\n"
2673 " <transport>hwbinder</transport>\n"
2674 " <version>1.0</version>\n"
2675 " </hal>\n"
2676 "</manifest>\n";
2677 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2678 const auto& foo = getHals(manifest, "android.hardware.foo");
2679 ASSERT_FALSE(foo.empty());
2680 EXPECT_TRUE(foo.front()->isOverride());
2681 const auto& bar = getHals(manifest, "android.hardware.bar");
2682 ASSERT_FALSE(bar.empty());
2683 EXPECT_FALSE(bar.front()->isOverride());
2684 }
2685
2686 // Test functionality of override="true" tag
TEST_F(LibVintfTest,ManifestAddOverrideHalSimple)2687 TEST_F(LibVintfTest, ManifestAddOverrideHalSimple) {
2688 HalManifest manifest;
2689 std::string xml = "<manifest " + kMetaVersionStr + " type=\"device\"/>\n";
2690 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2691
2692 HalManifest newManifest;
2693 xml =
2694 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2695 " <hal format=\"hidl\" override=\"true\">\n"
2696 " <name>android.hardware.foo</name>\n"
2697 " <transport>hwbinder</transport>\n"
2698 " <version>1.1</version>\n"
2699 " <interface>\n"
2700 " <name>IFoo</name>\n"
2701 " <instance>default</instance>\n"
2702 " </interface>\n"
2703 " </hal>\n"
2704 "</manifest>\n";
2705 EXPECT_TRUE(gHalManifestConverter(&newManifest, xml)) << gHalManifestConverter.lastError();
2706
2707 manifest.addAllHals(&newManifest);
2708 EXPECT_EQ(xml, gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
2709 }
2710
TEST_F(LibVintfTest,ManifestAddOverrideHalSimpleOverride)2711 TEST_F(LibVintfTest, ManifestAddOverrideHalSimpleOverride) {
2712 HalManifest manifest;
2713 std::string xml =
2714 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2715 " <hal format=\"hidl\">\n"
2716 " <name>android.hardware.foo</name>\n"
2717 " <transport>hwbinder</transport>\n"
2718 " <version>1.0</version>\n"
2719 " </hal>\n"
2720 "</manifest>\n";
2721 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2722
2723 HalManifest newManifest;
2724 xml =
2725 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2726 " <hal format=\"hidl\" override=\"true\">\n"
2727 " <name>android.hardware.foo</name>\n"
2728 " <transport>hwbinder</transport>\n"
2729 " <version>1.1</version>\n"
2730 " <interface>\n"
2731 " <name>IFoo</name>\n"
2732 " <instance>default</instance>\n"
2733 " </interface>\n"
2734 " </hal>\n"
2735 "</manifest>\n";
2736 EXPECT_TRUE(gHalManifestConverter(&newManifest, xml)) << gHalManifestConverter.lastError();
2737
2738 manifest.addAllHals(&newManifest);
2739 EXPECT_EQ(xml, gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
2740 }
2741
2742 // Existing major versions should be removed.
TEST_F(LibVintfTest,ManifestAddOverrideHalMultiVersion)2743 TEST_F(LibVintfTest, ManifestAddOverrideHalMultiVersion) {
2744 HalManifest manifest;
2745 std::string xml =
2746 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2747 " <hal format=\"hidl\">\n"
2748 " <name>android.hardware.foo</name>\n"
2749 " <transport>hwbinder</transport>\n"
2750 " <version>1.3</version>\n"
2751 " <version>2.4</version>\n"
2752 " <interface>\n"
2753 " <name>IFoo</name>\n"
2754 " <instance>slot1</instance>\n"
2755 " </interface>\n"
2756 " </hal>\n"
2757 " <hal format=\"hidl\">\n"
2758 " <name>android.hardware.bar</name>\n"
2759 " <transport>hwbinder</transport>\n"
2760 " <version>1.3</version>\n"
2761 " </hal>\n"
2762 "</manifest>\n";
2763 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2764
2765 HalManifest newManifest;
2766 xml =
2767 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2768 " <hal format=\"hidl\" override=\"true\">\n"
2769 " <name>android.hardware.foo</name>\n"
2770 " <transport>hwbinder</transport>\n"
2771 " <version>1.1</version>\n"
2772 " <version>3.1</version>\n"
2773 " <interface>\n"
2774 " <name>IFoo</name>\n"
2775 " <instance>slot2</instance>\n"
2776 " </interface>\n"
2777 " </hal>\n"
2778 "</manifest>\n";
2779 EXPECT_TRUE(gHalManifestConverter(&newManifest, xml)) << gHalManifestConverter.lastError();
2780
2781 manifest.addAllHals(&newManifest);
2782 EXPECT_EQ(
2783 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2784 " <hal format=\"hidl\">\n"
2785 " <name>android.hardware.bar</name>\n"
2786 " <transport>hwbinder</transport>\n"
2787 " <version>1.3</version>\n"
2788 " </hal>\n"
2789 " <hal format=\"hidl\">\n"
2790 " <name>android.hardware.foo</name>\n"
2791 " <transport>hwbinder</transport>\n"
2792 " <version>2.4</version>\n"
2793 " <interface>\n"
2794 " <name>IFoo</name>\n"
2795 " <instance>slot1</instance>\n"
2796 " </interface>\n"
2797 " </hal>\n"
2798 " <hal format=\"hidl\" override=\"true\">\n"
2799 " <name>android.hardware.foo</name>\n"
2800 " <transport>hwbinder</transport>\n"
2801 " <version>1.1</version>\n"
2802 " <version>3.1</version>\n"
2803 " <interface>\n"
2804 " <name>IFoo</name>\n"
2805 " <instance>slot2</instance>\n"
2806 " </interface>\n"
2807 " </hal>\n"
2808 "</manifest>\n",
2809 gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
2810 }
2811
TEST_F(LibVintfTest,ManifestAddOverrideHalMultiVersion2)2812 TEST_F(LibVintfTest, ManifestAddOverrideHalMultiVersion2) {
2813 HalManifest manifest;
2814 std::string xml =
2815 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2816 " <hal format=\"hidl\">\n"
2817 " <name>android.hardware.foo</name>\n"
2818 " <transport>hwbinder</transport>\n"
2819 " <version>1.3</version>\n"
2820 " <version>2.4</version>\n"
2821 " <interface>\n"
2822 " <name>IFoo</name>\n"
2823 " <instance>slot1</instance>\n"
2824 " </interface>\n"
2825 " </hal>\n"
2826 "</manifest>\n";
2827 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2828
2829 HalManifest newManifest;
2830 xml =
2831 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2832 " <hal format=\"hidl\" override=\"true\">\n"
2833 " <name>android.hardware.foo</name>\n"
2834 " <transport>hwbinder</transport>\n"
2835 " <version>1.1</version>\n"
2836 " <version>2.1</version>\n"
2837 " <interface>\n"
2838 " <name>IFoo</name>\n"
2839 " <instance>slot2</instance>\n"
2840 " </interface>\n"
2841 " </hal>\n"
2842 "</manifest>\n";
2843 EXPECT_TRUE(gHalManifestConverter(&newManifest, xml)) << gHalManifestConverter.lastError();
2844
2845 manifest.addAllHals(&newManifest);
2846 EXPECT_EQ(xml, gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
2847 }
2848
2849 // if no <versions>, remove all existing <hal> with given <name>.
TEST_F(LibVintfTest,ManifestAddOverrideHalRemoveAll)2850 TEST_F(LibVintfTest, ManifestAddOverrideHalRemoveAll) {
2851 HalManifest manifest;
2852 std::string xml =
2853 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2854 " <hal format=\"hidl\">\n"
2855 " <name>android.hardware.foo</name>\n"
2856 " <transport>hwbinder</transport>\n"
2857 " <version>1.3</version>\n"
2858 " <version>2.4</version>\n"
2859 " <interface>\n"
2860 " <name>IFoo</name>\n"
2861 " <instance>slot1</instance>\n"
2862 " </interface>\n"
2863 " </hal>\n"
2864 " <hal format=\"hidl\">\n"
2865 " <name>android.hardware.foo</name>\n"
2866 " <transport>hwbinder</transport>\n"
2867 " <version>3.1</version>\n"
2868 " <version>4.3</version>\n"
2869 " <interface>\n"
2870 " <name>IBar</name>\n"
2871 " <instance>slot2</instance>\n"
2872 " </interface>\n"
2873 " </hal>\n"
2874 " <hal format=\"hidl\">\n"
2875 " <name>android.hardware.bar</name>\n"
2876 " <transport>hwbinder</transport>\n"
2877 " <version>1.3</version>\n"
2878 " </hal>\n"
2879 "</manifest>\n";
2880 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2881
2882 HalManifest newManifest;
2883 xml =
2884 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2885 " <hal format=\"hidl\" override=\"true\">\n"
2886 " <name>android.hardware.foo</name>\n"
2887 " <transport>hwbinder</transport>\n"
2888 " </hal>\n"
2889 "</manifest>\n";
2890 EXPECT_TRUE(gHalManifestConverter(&newManifest, xml)) << gHalManifestConverter.lastError();
2891
2892 manifest.addAllHals(&newManifest);
2893 EXPECT_EQ(
2894 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
2895 " <hal format=\"hidl\">\n"
2896 " <name>android.hardware.bar</name>\n"
2897 " <transport>hwbinder</transport>\n"
2898 " <version>1.3</version>\n"
2899 " </hal>\n"
2900 " <hal format=\"hidl\" override=\"true\">\n"
2901 " <name>android.hardware.foo</name>\n"
2902 " <transport>hwbinder</transport>\n"
2903 " </hal>\n"
2904 "</manifest>\n",
2905 gHalManifestConverter(manifest, SerializeFlags::HALS_ONLY));
2906 }
2907
2908 // Make sure missing tags in old VINTF files does not cause incompatibilities.
TEST_F(LibVintfTest,Empty)2909 TEST_F(LibVintfTest, Empty) {
2910 CompatibilityMatrix cm;
2911 HalManifest manifest;
2912 std::string xml;
2913 std::string error;
2914
2915 xml = "<compatibility-matrix " + kMetaVersionStr + " type=\"device\"/>\n";
2916 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2917 << gCompatibilityMatrixConverter.lastError();
2918
2919 xml = "<manifest " + kMetaVersionStr + " type=\"framework\"/>\n";
2920 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2921
2922 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
2923 }
2924
TEST_F(LibVintfTest,SystemSdk)2925 TEST_F(LibVintfTest, SystemSdk) {
2926 CompatibilityMatrix cm;
2927 std::string xml;
2928 std::string error;
2929
2930 xml =
2931 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
2932 " <system-sdk>\n"
2933 " <version>1</version>\n"
2934 " <version>P</version>\n"
2935 " </system-sdk>\n"
2936 "</compatibility-matrix>\n";
2937 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml))
2938 << gCompatibilityMatrixConverter.lastError();
2939 EXPECT_EQ(xml, gCompatibilityMatrixConverter(cm, SerializeFlags::SSDK_ONLY));
2940
2941 {
2942 HalManifest manifest;
2943 xml =
2944 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2945 " <system-sdk>\n"
2946 " <version>1</version>\n"
2947 " <version>P</version>\n"
2948 " </system-sdk>\n"
2949 "</manifest>\n";
2950 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2951 EXPECT_EQ(xml, gHalManifestConverter(manifest, SerializeFlags::SSDK_ONLY));
2952
2953 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
2954 }
2955
2956 {
2957 HalManifest manifest;
2958 xml =
2959 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2960 " <system-sdk>\n"
2961 " <version>1</version>\n"
2962 " <version>3</version>\n"
2963 " <version>P</version>\n"
2964 " </system-sdk>\n"
2965 "</manifest>\n";
2966 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2967 EXPECT_TRUE(manifest.checkCompatibility(cm, &error));
2968 }
2969
2970 {
2971 HalManifest manifest;
2972 xml =
2973 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
2974 " <system-sdk>\n"
2975 " <version>1</version>\n"
2976 " </system-sdk>\n"
2977 "</manifest>\n";
2978 EXPECT_TRUE(gHalManifestConverter(&manifest, xml)) << gHalManifestConverter.lastError();
2979 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
2980 EXPECT_TRUE(error.find("System SDK") != std::string::npos) << error;
2981 }
2982 }
2983
TEST_F(LibVintfTest,ManifestLastError)2984 TEST_F(LibVintfTest, ManifestLastError) {
2985 HalManifest e;
2986 // Set mLastError to something else before testing.
2987 EXPECT_FALSE(gHalManifestConverter(&e, "<manifest/>"));
2988 EXPECT_NE("Not a valid XML", gHalManifestConverter.lastError());
2989
2990 std::string error;
2991 std::string prevError = gHalManifestConverter.lastError();
2992 EXPECT_FALSE(gHalManifestConverter(&e, "", &error));
2993 EXPECT_EQ("Not a valid XML", error);
2994 EXPECT_EQ(prevError, gHalManifestConverter.lastError()) << "lastError() should not be modified";
2995 }
2996
TEST_F(LibVintfTest,MatrixLastError)2997 TEST_F(LibVintfTest, MatrixLastError) {
2998 CompatibilityMatrix e;
2999 // Set mLastError to something else before testing.
3000 EXPECT_FALSE(gCompatibilityMatrixConverter(&e, "<compatibility-matrix/>"));
3001 EXPECT_NE("Not a valid XML", gCompatibilityMatrixConverter.lastError());
3002
3003 std::string error;
3004 std::string prevError = gCompatibilityMatrixConverter.lastError();
3005 EXPECT_FALSE(gCompatibilityMatrixConverter(&e, "", &error));
3006 EXPECT_EQ("Not a valid XML", error);
3007 EXPECT_EQ(prevError, gCompatibilityMatrixConverter.lastError())
3008 << "lastError() should not be modified";
3009 }
3010
TEST_F(LibVintfTest,MatrixDetailErrorMsg)3011 TEST_F(LibVintfTest, MatrixDetailErrorMsg) {
3012 std::string error;
3013 std::string xml;
3014
3015 HalManifest manifest;
3016 xml =
3017 "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"103\">\n"
3018 " <hal format=\"hidl\">\n"
3019 " <name>android.hardware.foo</name>\n"
3020 " <transport>hwbinder</transport>\n"
3021 " <version>1.0</version>\n"
3022 " <interface>\n"
3023 " <name>IFoo</name>\n"
3024 " <instance>default</instance>\n"
3025 " </interface>\n"
3026 " </hal>\n"
3027 "</manifest>\n";
3028 ASSERT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3029
3030 {
3031 CompatibilityMatrix cm;
3032 xml =
3033 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"100\">\n"
3034 " <hal format=\"hidl\" optional=\"false\">\n"
3035 " <name>android.hardware.foo</name>\n"
3036 " <version>1.2-3</version>\n"
3037 " <version>4.5</version>\n"
3038 " <interface>\n"
3039 " <name>IFoo</name>\n"
3040 " <instance>default</instance>\n"
3041 " <instance>slot1</instance>\n"
3042 " </interface>\n"
3043 " <interface>\n"
3044 " <name>IBar</name>\n"
3045 " <instance>default</instance>\n"
3046 " </interface>\n"
3047 " </hal>\n"
3048 "</compatibility-matrix>\n";
3049 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml, &error)) << error;
3050 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
3051 EXPECT_IN("Manifest level = 103", error)
3052 EXPECT_IN("Matrix level = 100", error)
3053 EXPECT_IN(
3054 "android.hardware.foo:\n"
3055 " required: \n"
3056 " (@1.2-3::IBar/default AND @1.2-3::IFoo/default AND @1.2-3::IFoo/slot1) OR\n"
3057 " (@4.5::IBar/default AND @4.5::IFoo/default AND @4.5::IFoo/slot1)\n"
3058 " provided: @1.0::IFoo/default",
3059 error);
3060 }
3061
3062 {
3063 CompatibilityMatrix cm;
3064 xml =
3065 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
3066 " <hal format=\"hidl\" optional=\"false\">\n"
3067 " <name>android.hardware.foo</name>\n"
3068 " <version>1.2-3</version>\n"
3069 " <interface>\n"
3070 " <name>IFoo</name>\n"
3071 " <instance>default</instance>\n"
3072 " <instance>slot1</instance>\n"
3073 " </interface>\n"
3074 " </hal>\n"
3075 "</compatibility-matrix>\n";
3076 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml, &error)) << error;
3077 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
3078 EXPECT_IN(
3079 "android.hardware.foo:\n"
3080 " required: (@1.2-3::IFoo/default AND @1.2-3::IFoo/slot1)\n"
3081 " provided: @1.0::IFoo/default",
3082 error);
3083 }
3084
3085 // the most frequent use case.
3086 {
3087 CompatibilityMatrix cm;
3088 xml =
3089 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
3090 " <hal format=\"hidl\" optional=\"false\">\n"
3091 " <name>android.hardware.foo</name>\n"
3092 " <version>1.2-3</version>\n"
3093 " <interface>\n"
3094 " <name>IFoo</name>\n"
3095 " <instance>default</instance>\n"
3096 " </interface>\n"
3097 " </hal>\n"
3098 "</compatibility-matrix>\n";
3099 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml, &error)) << error;
3100 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
3101 EXPECT_IN(
3102 "android.hardware.foo:\n"
3103 " required: @1.2-3::IFoo/default\n"
3104 " provided: @1.0::IFoo/default",
3105 error);
3106 }
3107 }
3108
TEST_F(LibVintfTest,DisabledHal)3109 TEST_F(LibVintfTest, DisabledHal) {
3110 std::string error;
3111 std::string xml;
3112 HalManifest manifest;
3113 xml =
3114 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3115 " <hal format=\"hidl\" override=\"true\">\n"
3116 " <transport>hwbinder</transport>\n"
3117 " <name>android.hardware.foo</name>\n"
3118 " <transport>hwbinder</transport>\n"
3119 " </hal>\n"
3120 " <hal format=\"hidl\" override=\"true\">\n"
3121 " <name>android.hardware.bar</name>\n"
3122 " <transport>hwbinder</transport>\n"
3123 " <fqname>@1.1::IFoo/custom</fqname>\n"
3124 " </hal>\n"
3125 " <hal format=\"hidl\">\n"
3126 " <name>android.hardware.baz</name>\n"
3127 " <transport>hwbinder</transport>\n"
3128 " </hal>\n"
3129 "</manifest>\n";
3130 ASSERT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3131
3132 auto foo = getHals(manifest, "android.hardware.foo");
3133 ASSERT_EQ(1u, foo.size());
3134 EXPECT_TRUE(foo.front()->isDisabledHal());
3135 auto bar = getHals(manifest, "android.hardware.bar");
3136 ASSERT_EQ(1u, bar.size());
3137 EXPECT_FALSE(bar.front()->isDisabledHal());
3138 auto baz = getHals(manifest, "android.hardware.baz");
3139 ASSERT_EQ(1u, baz.size());
3140 EXPECT_FALSE(baz.front()->isDisabledHal());
3141 }
3142
TEST_F(LibVintfTest,FqNameValid)3143 TEST_F(LibVintfTest, FqNameValid) {
3144 std::string error;
3145 std::string xml;
3146
3147 CompatibilityMatrix cm;
3148 xml =
3149 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
3150 " <hal format=\"hidl\" optional=\"false\">\n"
3151 " <name>android.hardware.foo</name>\n"
3152 " <version>1.0</version>\n"
3153 " <interface>\n"
3154 " <name>IFoo</name>\n"
3155 " <instance>default</instance>\n"
3156 " </interface>\n"
3157 " </hal>\n"
3158 " <hal format=\"hidl\" optional=\"false\">\n"
3159 " <name>android.hardware.foo</name>\n"
3160 " <version>1.1</version>\n"
3161 " <interface>\n"
3162 " <name>IFoo</name>\n"
3163 " <instance>custom</instance>\n"
3164 " </interface>\n"
3165 " </hal>\n"
3166 "</compatibility-matrix>\n";
3167 EXPECT_TRUE(gCompatibilityMatrixConverter(&cm, xml, &error)) << error;
3168
3169 {
3170 HalManifest manifest;
3171 xml =
3172 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3173 " <hal format=\"hidl\">\n"
3174 " <name>android.hardware.foo</name>\n"
3175 " <transport>hwbinder</transport>\n"
3176 " <version>1.0</version>\n"
3177 " <interface>\n"
3178 " <name>IFoo</name>\n"
3179 " <instance>default</instance>\n"
3180 " <instance>custom</instance>\n"
3181 " </interface>\n"
3182 " <fqname>@1.1::IFoo/custom</fqname>\n"
3183 " </hal>\n"
3184 "</manifest>\n";
3185 ASSERT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3186 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
3187
3188 EXPECT_EQ(Transport::HWBINDER,
3189 manifest.getHidlTransport("android.hardware.foo", {1, 1}, "IFoo", "custom"));
3190 }
3191
3192 {
3193 HalManifest manifest;
3194 xml =
3195 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3196 " <hal format=\"hidl\">\n"
3197 " <name>android.hardware.foo</name>\n"
3198 " <transport>hwbinder</transport>\n"
3199 " <fqname>@1.0::IFoo/default</fqname>\n"
3200 " <fqname>@1.1::IFoo/custom</fqname>\n"
3201 " </hal>\n"
3202 "</manifest>\n";
3203 ASSERT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3204 EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error;
3205 }
3206
3207 {
3208 HalManifest manifest;
3209 xml =
3210 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3211 " <hal format=\"hidl\">\n"
3212 " <name>android.hardware.foo</name>\n"
3213 " <transport>hwbinder</transport>\n"
3214 " <version>1.0</version>\n"
3215 " <interface>\n"
3216 " <name>IFoo</name>\n"
3217 " <instance>default</instance>\n"
3218 " <instance>custom</instance>\n"
3219 " </interface>\n"
3220 " </hal>\n"
3221 "</manifest>\n";
3222 ASSERT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3223 EXPECT_FALSE(manifest.checkCompatibility(cm, &error));
3224 EXPECT_IN(
3225 "android.hardware.foo:\n"
3226 " required: @1.1::IFoo/custom\n"
3227 " provided: \n"
3228 " @1.0::IFoo/custom\n"
3229 " @1.0::IFoo/default",
3230 error);
3231 }
3232
3233 {
3234 HalManifest manifest;
3235 xml =
3236 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3237 " <hal format=\"hidl\">\n"
3238 " <name>android.hardware.foo</name>\n"
3239 " <transport>hwbinder</transport>\n"
3240 " <fqname>@1.0::IFoo/default</fqname>\n"
3241 " <fqname>@1.0::IFoo/custom</fqname>\n"
3242 " </hal>\n"
3243 "</manifest>\n";
3244 ASSERT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3245 }
3246 }
3247
TEST_F(LibVintfTest,FqNameInvalid)3248 TEST_F(LibVintfTest, FqNameInvalid) {
3249 std::string error;
3250 std::string xml;
3251 ManifestHal hal;
3252 xml =
3253 "<hal format=\"hidl\">\n"
3254 " <name>android.hardware.foo</name>\n"
3255 " <transport>hwbinder</transport>\n"
3256 " <fqname>@1.1::IFoo/custom</fqname>\n"
3257 "</hal>\n";
3258 EXPECT_TRUE(gManifestHalConverter(&hal, xml, &error)) << error;
3259 xml =
3260 "<hal format=\"hidl\">\n"
3261 " <name>android.hardware.foo</name>\n"
3262 " <transport>hwbinder</transport>\n"
3263 " <fqname>1.1::IFoo/custom</fqname>\n"
3264 "</hal>\n";
3265 ASSERT_FALSE(gManifestHalConverter(&hal, xml, &error));
3266 EXPECT_IN("Could not parse text \"1.1::IFoo/custom\" in element <fqname>", error);
3267 xml =
3268 "<hal format=\"hidl\">\n"
3269 " <name>android.hardware.foo</name>\n"
3270 " <transport>hwbinder</transport>\n"
3271 " <fqname>android.hardware.foo@1.1::IFoo/custom</fqname>\n"
3272 "</hal>\n";
3273 ASSERT_FALSE(gManifestHalConverter(&hal, xml, &error));
3274 EXPECT_IN("Should not specify package", error);
3275 xml =
3276 "<hal format=\"hidl\">\n"
3277 " <name>android.hardware.foo</name>\n"
3278 " <transport>hwbinder</transport>\n"
3279 " <fqname>IFoo/custom</fqname>\n"
3280 "</hal>\n";
3281 ASSERT_FALSE(gManifestHalConverter(&hal, xml, &error));
3282 EXPECT_IN("Should specify version", error);
3283 xml =
3284 "<hal format=\"hidl\">\n"
3285 " <name>android.hardware.foo</name>\n"
3286 " <transport>hwbinder</transport>\n"
3287 " <fqname>@1.0::IFoo</fqname>\n"
3288 "</hal>\n";
3289 ASSERT_FALSE(gManifestHalConverter(&hal, xml, &error));
3290 EXPECT_IN("Should specify instance", error);
3291 xml =
3292 "<hal format=\"hidl\">\n"
3293 " <name>n07 4 v4l1d 1n73rf4c3</name>\n"
3294 " <transport>hwbinder</transport>\n"
3295 " <fqname>@1.0::IFoo/custom</fqname>\n"
3296 "</hal>\n";
3297 ASSERT_FALSE(gManifestHalConverter(&hal, xml, &error));
3298 EXPECT_IN("Cannot create FqInstance", error);
3299 EXPECT_IN("n07 4 v4l1d 1n73rf4c3", error);
3300 }
3301
TEST_F(LibVintfTest,RegexInstanceValid)3302 TEST_F(LibVintfTest, RegexInstanceValid) {
3303 CompatibilityMatrix matrix;
3304 std::string error;
3305
3306 std::string xml =
3307 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
3308 " <hal format=\"hidl\" optional=\"false\">\n"
3309 " <name>android.hardware.foo</name>\n"
3310 " <version>1.0</version>\n"
3311 " <interface>\n"
3312 " <name>IFoo</name>\n"
3313 " <regex-instance>legacy/[0-9]+</regex-instance>\n"
3314 " <regex-instance>slot[0-9]+</regex-instance>\n"
3315 " <regex-instance>.*</regex-instance>\n"
3316 " </interface>\n"
3317 " </hal>\n"
3318 "</compatibility-matrix>\n";
3319 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, xml, &error)) << error;
3320 }
3321
TEST_F(LibVintfTest,RegexInstanceInvalid)3322 TEST_F(LibVintfTest, RegexInstanceInvalid) {
3323 CompatibilityMatrix matrix;
3324 std::string error;
3325 std::string xml =
3326 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
3327 " <hal format=\"hidl\" optional=\"false\">\n"
3328 " <name>android.hardware.foo</name>\n"
3329 " <version>1.0</version>\n"
3330 " <interface>\n"
3331 " <name>IFoo</name>\n"
3332 " <regex-instance>e{1,2,3}</regex-instance>\n"
3333 " <regex-instance>*</regex-instance>\n"
3334 " <regex-instance>+</regex-instance>\n"
3335 " <regex-instance>[0-9]+</regex-instance>\n"
3336 " <regex-instance>[0-9]+</regex-instance>\n"
3337 " </interface>\n"
3338 " </hal>\n"
3339 "</compatibility-matrix>\n";
3340 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, xml, &error));
3341 EXPECT_IN("Invalid regular expression 'e{1,2,3}'", error);
3342 EXPECT_IN("Invalid regular expression '*'", error);
3343 EXPECT_IN("Invalid regular expression '+'", error);
3344 EXPECT_IN("Duplicated regex-instance '[0-9]+'", error);
3345 }
3346
TEST_F(LibVintfTest,RegexInstanceCompat)3347 TEST_F(LibVintfTest, RegexInstanceCompat) {
3348 CompatibilityMatrix matrix;
3349 std::string error;
3350
3351 std::string xml =
3352 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\">\n"
3353 " <hal format=\"hidl\" optional=\"false\">\n"
3354 " <name>android.hardware.foo</name>\n"
3355 " <version>1.0</version>\n"
3356 " <version>3.1-2</version>\n"
3357 " <interface>\n"
3358 " <name>IFoo</name>\n"
3359 " <instance>default</instance>\n"
3360 " <regex-instance>legacy/[0-9]+</regex-instance>\n"
3361 " </interface>\n"
3362 " </hal>\n"
3363 " <sepolicy>\n"
3364 " <kernel-sepolicy-version>0</kernel-sepolicy-version>\n"
3365 " <sepolicy-version>0.0</sepolicy-version>\n"
3366 " </sepolicy>\n"
3367 "</compatibility-matrix>\n";
3368 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, xml))
3369 << gCompatibilityMatrixConverter.lastError();
3370
3371 {
3372 std::string xml =
3373 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3374 " <hal format=\"hidl\">\n"
3375 " <name>android.hardware.foo</name>\n"
3376 " <transport>hwbinder</transport>\n"
3377 " <version>1.0</version>\n"
3378 " <interface>\n"
3379 " <name>IFoo</name>\n"
3380 " <instance>default</instance>\n"
3381 " <instance>legacy/0</instance>\n"
3382 " <instance>legacy/1</instance>\n"
3383 " </interface>\n"
3384 " </hal>\n"
3385 "</manifest>\n";
3386
3387 HalManifest manifest;
3388 EXPECT_TRUE(gHalManifestConverter(&manifest, xml));
3389 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
3390
3391 auto unused = checkUnusedHals(manifest, matrix);
3392 EXPECT_TRUE(unused.empty())
3393 << "Contains unused HALs: " << android::base::Join(unused, "\n");
3394 }
3395
3396 {
3397 std::string xml =
3398 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3399 " <hal format=\"hidl\">\n"
3400 " <name>android.hardware.foo</name>\n"
3401 " <transport>hwbinder</transport>\n"
3402 " <version>1.0</version>\n"
3403 " <interface>\n"
3404 " <name>IFoo</name>\n"
3405 " <instance>default</instance>\n"
3406 " <instance>legacy0</instance>\n"
3407 " <instance>nonmatch/legacy/0</instance>\n"
3408 " <instance>legacy/0/nonmatch</instance>\n"
3409 " </interface>\n"
3410 " </hal>\n"
3411 "</manifest>\n";
3412
3413 HalManifest manifest;
3414 EXPECT_TRUE(gHalManifestConverter(&manifest, xml));
3415 EXPECT_FALSE(manifest.checkCompatibility(matrix, &error))
3416 << "Should not be compatible because no legacy/[0-9]+ is provided.";
3417
3418 auto unused = checkUnusedHals(manifest, matrix);
3419 EXPECT_EQ((std::set<std::string>{"android.hardware.foo@1.0::IFoo/nonmatch/legacy/0",
3420 "android.hardware.foo@1.0::IFoo/legacy/0/nonmatch",
3421 "android.hardware.foo@1.0::IFoo/legacy0"}),
3422 unused);
3423 }
3424 }
3425
TEST_F(LibVintfTest,Regex)3426 TEST_F(LibVintfTest, Regex) {
3427 details::Regex regex;
3428
3429 EXPECT_FALSE(regex.compile("+"));
3430 EXPECT_FALSE(regex.compile("*"));
3431
3432 ASSERT_TRUE(regex.compile("legacy/[0-9]+"));
3433 EXPECT_TRUE(regex.matches("legacy/0"));
3434 EXPECT_TRUE(regex.matches("legacy/000"));
3435 EXPECT_FALSE(regex.matches("legacy/"));
3436 EXPECT_FALSE(regex.matches("ssslegacy/0"));
3437 EXPECT_FALSE(regex.matches("legacy/0sss"));
3438 }
3439
TEST_F(LibVintfTest,ManifestGetHalNamesAndVersions)3440 TEST_F(LibVintfTest, ManifestGetHalNamesAndVersions) {
3441 HalManifest vm = testDeviceManifest();
3442 EXPECT_EQ(vm.getHalNamesAndVersions(),
3443 std::set<std::string>({"android.hardware.camera@2.0", "android.hardware.nfc@1.0"}));
3444 }
3445
TEST_F(LibVintfTest,KernelInfo)3446 TEST_F(LibVintfTest, KernelInfo) {
3447 KernelInfo ki = testKernelInfo();
3448
3449 EXPECT_EQ(
3450 "<kernel version=\"3.18.31\">\n"
3451 " <config>\n"
3452 " <key>CONFIG_64BIT</key>\n"
3453 " <value>y</value>\n"
3454 " </config>\n"
3455 " <config>\n"
3456 " <key>CONFIG_ANDROID_BINDER_DEVICES</key>\n"
3457 " <value>\"binder,hwbinder\"</value>\n"
3458 " </config>\n"
3459 " <config>\n"
3460 " <key>CONFIG_ARCH_MMAP_RND_BITS</key>\n"
3461 " <value>24</value>\n"
3462 " </config>\n"
3463 " <config>\n"
3464 " <key>CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES</key>\n"
3465 " <value>\"\"</value>\n"
3466 " </config>\n"
3467 " <config>\n"
3468 " <key>CONFIG_ILLEGAL_POINTER_VALUE</key>\n"
3469 " <value>0xdead000000000000</value>\n"
3470 " </config>\n"
3471 "</kernel>\n",
3472 gKernelInfoConverter(ki, SerializeFlags::NO_TAGS.enableKernelConfigs()));
3473 }
3474
TEST_F(LibVintfTest,ManifestAddAllDeviceManifest)3475 TEST_F(LibVintfTest, ManifestAddAllDeviceManifest) {
3476 std::string xml1 = "<manifest " + kMetaVersionStr + " type=\"device\" />\n";
3477 std::string xml2 =
3478 "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"3\">\n"
3479 " <hal format=\"hidl\">\n"
3480 " <name>android.hardware.foo</name>\n"
3481 " <transport>hwbinder</transport>\n"
3482 " <fqname>@1.0::IFoo/default</fqname>\n"
3483 " </hal>\n"
3484 " <sepolicy>\n"
3485 " <version>25.5</version>\n"
3486 " </sepolicy>\n"
3487 " <kernel version=\"3.18.31\">\n"
3488 " <config>\n"
3489 " <key>CONFIG_64BIT</key>\n"
3490 " <value>y</value>\n"
3491 " </config>\n"
3492 " </kernel>\n"
3493 " <xmlfile>\n"
3494 " <name>media_profile</name>\n"
3495 " <version>1.0</version>\n"
3496 " </xmlfile>\n"
3497 "</manifest>\n";
3498
3499 std::string error;
3500 HalManifest manifest1;
3501 ASSERT_TRUE(gHalManifestConverter(&manifest1, xml1, &error)) << error;
3502 HalManifest manifest2;
3503 ASSERT_TRUE(gHalManifestConverter(&manifest2, xml2, &error)) << error;
3504
3505 ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error;
3506
3507 EXPECT_EQ(xml2, gHalManifestConverter(manifest1));
3508 }
3509
TEST_F(LibVintfTest,ManifestAddAllFrameworkManifest)3510 TEST_F(LibVintfTest, ManifestAddAllFrameworkManifest) {
3511 std::string xml1 = "<manifest " + kMetaVersionStr + " type=\"framework\" />\n";
3512 std::string xml2 =
3513 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3514 " <hal format=\"hidl\">\n"
3515 " <name>android.hardware.foo</name>\n"
3516 " <transport>hwbinder</transport>\n"
3517 " <fqname>@1.0::IFoo/default</fqname>\n"
3518 " </hal>\n"
3519 " <vendor-ndk>\n"
3520 " <version>P</version>\n"
3521 " <library>libbase.so</library>\n"
3522 " </vendor-ndk>\n"
3523 " <system-sdk>\n"
3524 " <version>1</version>\n"
3525 " </system-sdk>\n"
3526 " <xmlfile>\n"
3527 " <name>media_profile</name>\n"
3528 " <version>1.0</version>\n"
3529 " </xmlfile>\n"
3530 "</manifest>\n";
3531
3532 std::string error;
3533 HalManifest manifest1;
3534 ASSERT_TRUE(gHalManifestConverter(&manifest1, xml1, &error)) << error;
3535 HalManifest manifest2;
3536 ASSERT_TRUE(gHalManifestConverter(&manifest2, xml2, &error)) << error;
3537
3538 ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error;
3539
3540 EXPECT_EQ(xml2, gHalManifestConverter(manifest1));
3541 }
3542
TEST_F(LibVintfTest,ManifestAddAllConflictMajorVersion)3543 TEST_F(LibVintfTest, ManifestAddAllConflictMajorVersion) {
3544 std::string head =
3545 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3546 " <hal format=\"hidl\">\n"
3547 " <name>android.hardware.foo</name>\n"
3548 " <transport>hwbinder</transport>\n"
3549 " <version>";
3550 std::string tail =
3551 "</version>\n"
3552 " <interface>\n"
3553 " <name>IFoo</name>\n"
3554 " </interface>\n"
3555 " </hal>\n"
3556 "</manifest>\n";
3557
3558 std::string xml1 = head + "1.0" + tail;
3559 std::string xml2 = head + "1.1" + tail;
3560
3561 std::string error;
3562 HalManifest manifest1;
3563 manifest1.setFileName("1.xml");
3564 ASSERT_TRUE(gHalManifestConverter(&manifest1, xml1, &error)) << error;
3565 HalManifest manifest2;
3566 manifest2.setFileName("2.xml");
3567 ASSERT_TRUE(gHalManifestConverter(&manifest2, xml2, &error)) << error;
3568
3569 ASSERT_FALSE(manifest1.addAll(&manifest2, &error));
3570
3571 EXPECT_IN("android.hardware.foo", error);
3572 EXPECT_IN("1.0 (from 1.xml)", error);
3573 EXPECT_IN("1.1 (from 2.xml)", error);
3574 }
3575
TEST_F(LibVintfTest,ManifestAddAllConflictLevel)3576 TEST_F(LibVintfTest, ManifestAddAllConflictLevel) {
3577 std::string xml1 = "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"2\" />\n";
3578 std::string xml2 = "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"3\" />\n";
3579
3580 std::string error;
3581 HalManifest manifest1;
3582 ASSERT_TRUE(gHalManifestConverter(&manifest1, xml1, &error)) << error;
3583 HalManifest manifest2;
3584 ASSERT_TRUE(gHalManifestConverter(&manifest2, xml2, &error)) << error;
3585
3586 ASSERT_FALSE(manifest1.addAll(&manifest2, &error));
3587 EXPECT_IN("Conflicting target-level", error);
3588 }
3589
TEST_F(LibVintfTest,ManifestAddAllConflictSepolicy)3590 TEST_F(LibVintfTest, ManifestAddAllConflictSepolicy) {
3591 std::string xml1 =
3592 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3593 " <sepolicy>\n"
3594 " <version>25.5</version>\n"
3595 " </sepolicy>\n"
3596 "</manifest>\n";
3597 std::string xml2 =
3598 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3599 " <sepolicy>\n"
3600 " <version>30.0</version>\n"
3601 " </sepolicy>\n"
3602 "</manifest>\n";
3603
3604 std::string error;
3605 HalManifest manifest1;
3606 ASSERT_TRUE(gHalManifestConverter(&manifest1, xml1, &error)) << error;
3607 HalManifest manifest2;
3608 ASSERT_TRUE(gHalManifestConverter(&manifest2, xml2, &error)) << error;
3609
3610 ASSERT_FALSE(manifest1.addAll(&manifest2, &error));
3611 EXPECT_IN("Conflicting sepolicy version", error);
3612 }
3613
TEST_F(LibVintfTest,ManifestAddAllConflictKernel)3614 TEST_F(LibVintfTest, ManifestAddAllConflictKernel) {
3615 std::string xml1 =
3616 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3617 " <kernel version=\"3.18.0\" />\n"
3618 "</manifest>\n";
3619 std::string xml2 =
3620 "<manifest " + kMetaVersionStr + " type=\"device\">\n"
3621 " <kernel version=\"3.18.1\" />\n"
3622 "</manifest>\n";
3623
3624 std::string error;
3625 HalManifest manifest1;
3626 ASSERT_TRUE(gHalManifestConverter(&manifest1, xml1, &error)) << error;
3627 HalManifest manifest2;
3628 ASSERT_TRUE(gHalManifestConverter(&manifest2, xml2, &error)) << error;
3629
3630 ASSERT_FALSE(manifest1.addAll(&manifest2, &error));
3631 EXPECT_IN("Conflicting kernel", error);
3632 }
3633
TEST_F(LibVintfTest,ManifestMetaVersionCompat)3634 TEST_F(LibVintfTest, ManifestMetaVersionCompat) {
3635 std::string xml = "<manifest version=\"2.0\" type=\"device\" />";
3636 std::string error;
3637 HalManifest manifest;
3638 EXPECT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3639 }
3640
TEST_F(LibVintfTest,ManifestMetaVersionIncompat)3641 TEST_F(LibVintfTest, ManifestMetaVersionIncompat) {
3642 std::string xml = "<manifest version=\"10000.0\" type=\"device\" />";
3643 std::string error;
3644 HalManifest manifest;
3645 EXPECT_FALSE(gHalManifestConverter(&manifest, xml, &error))
3646 << "Should not parse metaversion 10000.0";
3647 }
3648
TEST_F(LibVintfTest,ManifestMetaVersionWriteLatest)3649 TEST_F(LibVintfTest, ManifestMetaVersionWriteLatest) {
3650 std::string xml = "<manifest version=\"1.0\" type=\"device\" />";
3651 std::string error;
3652 HalManifest manifest;
3653 EXPECT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3654 EXPECT_IN(kMetaVersionStr, gHalManifestConverter(manifest, SerializeFlags::NO_TAGS));
3655 }
3656
TEST_F(LibVintfTest,MatrixMetaVersionCompat)3657 TEST_F(LibVintfTest, MatrixMetaVersionCompat) {
3658 std::string xml = "<compatibility-matrix version=\"2.0\" type=\"framework\" />";
3659 std::string error;
3660 CompatibilityMatrix matrix;
3661 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, xml, &error)) << error;
3662 }
3663
TEST_F(LibVintfTest,MatrixMetaVersionIncompat)3664 TEST_F(LibVintfTest, MatrixMetaVersionIncompat) {
3665 std::string xml = "<compatibility-matrix version=\"10000.0\" type=\"framework\" />";
3666 std::string error;
3667 CompatibilityMatrix matrix;
3668 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, xml, &error))
3669 << "Should not parse metaversion 10000.0";
3670 }
3671
TEST_F(LibVintfTest,MatrixMetaVersionWriteLatest)3672 TEST_F(LibVintfTest, MatrixMetaVersionWriteLatest) {
3673 std::string xml = "<compatibility-matrix version=\"1.0\" type=\"framework\" />";
3674 std::string error;
3675 CompatibilityMatrix matrix;
3676 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, xml, &error)) << error;
3677 EXPECT_IN(kMetaVersionStr, gCompatibilityMatrixConverter(matrix, SerializeFlags::NO_TAGS));
3678 }
3679
TEST_F(LibVintfTest,Aidl)3680 TEST_F(LibVintfTest, Aidl) {
3681 std::string xml =
3682 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
3683 " <hal format=\"aidl\" optional=\"false\">\n"
3684 " <name>android.system.foo</name>\n"
3685 " <interface>\n"
3686 " <name>IFoo</name>\n"
3687 " <instance>default</instance>\n"
3688 " <regex-instance>test.*</regex-instance>\n"
3689 " </interface>\n"
3690 " </hal>\n"
3691 "</compatibility-matrix>\n";
3692 std::string error;
3693 CompatibilityMatrix matrix;
3694 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, xml, &error)) << error;
3695 EXPECT_EQ(xml, gCompatibilityMatrixConverter(matrix, SerializeFlags::HALS_NO_FQNAME));
3696
3697 {
3698 HalManifest manifest;
3699 std::string manifestXml =
3700 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3701 " <hal format=\"aidl\">\n"
3702 " <name>android.system.foo</name>\n"
3703 " <interface>\n"
3704 " <name>IFoo</name>\n"
3705 " <instance>default</instance>\n"
3706 " <instance>test0</instance>\n"
3707 " </interface>\n"
3708 " </hal>\n"
3709 "</manifest>\n";
3710 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml, &error)) << error;
3711 EXPECT_EQ(manifestXml, gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
3712 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
3713 EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "default"));
3714 EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "test0"));
3715 EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IFoo", "does_not_exist"));
3716 EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IDoesNotExist", "default"));
3717 EXPECT_FALSE(manifest.hasAidlInstance("android.system.does_not_exist", "IFoo", "default"));
3718 EXPECT_EQ(manifest.getAidlInstances("android.system.foo", "IFoo"),
3719 std::set<std::string>({"default", "test0"}));
3720 EXPECT_EQ(manifest.getAidlInstances("android.system.does_not_exist", "IFoo"),
3721 std::set<std::string>({}));
3722 }
3723
3724 {
3725 HalManifest manifest;
3726 std::string manifestXml =
3727 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3728 " <hal format=\"aidl\">\n"
3729 " <name>android.system.foo</name>\n"
3730 " <fqname>IFoo/default</fqname>\n"
3731 " <fqname>IFoo/test0</fqname>\n"
3732 " </hal>\n"
3733 "</manifest>\n";
3734 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml, &error)) << error;
3735 EXPECT_EQ(manifestXml, gHalManifestConverter(manifest, SerializeFlags::HALS_ONLY));
3736 EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error;
3737 EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "default"));
3738 EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "test0"));
3739 EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IFoo", "does_not_exist"));
3740 EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IDoesNotExist", "default"));
3741 EXPECT_FALSE(manifest.hasAidlInstance("android.system.does_not_exist", "IFoo", "default"));
3742 EXPECT_EQ(manifest.getAidlInstances("android.system.foo", "IFoo"),
3743 std::set<std::string>({"default", "test0"}));
3744 EXPECT_EQ(manifest.getAidlInstances("android.system.does_not_exist", "IFoo"),
3745 std::set<std::string>({}));
3746 }
3747
3748 {
3749 HalManifest manifest;
3750 std::string manifestXml =
3751 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3752 " <hal format=\"aidl\">\n"
3753 " <name>android.system.foo</name>\n"
3754 " <interface>\n"
3755 " <name>IFoo</name>\n"
3756 " <instance>incompat_instance</instance>\n"
3757 " <instance>test0</instance>\n"
3758 " </interface>\n"
3759 " </hal>\n"
3760 "</manifest>\n";
3761 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml, &error)) << error;
3762 EXPECT_EQ(manifestXml, gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
3763 EXPECT_FALSE(manifest.checkCompatibility(matrix, &error))
3764 << "Should not be compatible because default instance is missing";
3765 EXPECT_IN("required: (IFoo/default AND IFoo/test.*)", error);
3766 EXPECT_IN("provided: \n"
3767 " IFoo/incompat_instance\n"
3768 " IFoo/test0",
3769 error);
3770 }
3771 {
3772 HalManifest manifest;
3773 std::string manifestXml =
3774 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3775 " <hal format=\"aidl\">\n"
3776 " <name>android.system.foo</name>\n"
3777 " <interface>\n"
3778 " <name>IFoo</name>\n"
3779 " <instance>default</instance>\n"
3780 " <instance>incompat_instance</instance>\n"
3781 " </interface>\n"
3782 " </hal>\n"
3783 "</manifest>\n";
3784 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml, &error)) << error;
3785 EXPECT_EQ(manifestXml, gHalManifestConverter(manifest, SerializeFlags::HALS_NO_FQNAME));
3786 EXPECT_FALSE(manifest.checkCompatibility(matrix, &error))
3787 << "Should not be compatible because test.* instance is missing";
3788 EXPECT_IN("required: (IFoo/default AND IFoo/test.*)", error);
3789 EXPECT_IN("provided: \n"
3790 " IFoo/default\n"
3791 " IFoo/incompat_instance\n",
3792 error);
3793 }
3794 }
3795
TEST_F(LibVintfTest,AidlAndHidlNamesMatrix)3796 TEST_F(LibVintfTest, AidlAndHidlNamesMatrix) {
3797 std::string xml =
3798 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
3799 " <hal format=\"aidl\" optional=\"true\">\n"
3800 " <name>android.system.foo</name>\n"
3801 " <interface>\n"
3802 " <name>IFoo</name>\n"
3803 " <instance>default</instance>\n"
3804 " </interface>\n"
3805 " </hal>\n"
3806 " <hal format=\"hidl\" optional=\"true\">\n"
3807 " <name>android.system.foo</name>\n"
3808 " <version>1.0</version>\n"
3809 " <interface>\n"
3810 " <name>IFoo</name>\n"
3811 " <instance>default</instance>\n"
3812 " </interface>\n"
3813 " </hal>\n"
3814 "</compatibility-matrix>\n";
3815 std::string error;
3816 CompatibilityMatrix matrix;
3817 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, xml, &error)) << error;
3818 EXPECT_EQ(xml, gCompatibilityMatrixConverter(matrix, SerializeFlags::HALS_ONLY));
3819 }
3820
TEST_F(LibVintfTest,AidlAndHidlNamesManifest)3821 TEST_F(LibVintfTest, AidlAndHidlNamesManifest) {
3822 std::string xml =
3823 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3824 " <hal format=\"aidl\">\n"
3825 " <name>android.system.foo</name>\n"
3826 " <fqname>IFoo/default</fqname>\n"
3827 " </hal>\n"
3828 " <hal format=\"hidl\">\n"
3829 " <name>android.system.foo</name>\n"
3830 " <transport>hwbinder</transport>\n"
3831 " <fqname>@1.0::IFoo/default</fqname>\n"
3832 " </hal>\n"
3833 "</manifest>\n";
3834 std::string error;
3835 HalManifest manifest;
3836 EXPECT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3837 EXPECT_EQ(xml, gHalManifestConverter(manifest, SerializeFlags::HALS_ONLY));
3838 }
3839
TEST_F(LibVintfTest,AidlAndHidlCheckUnused)3840 TEST_F(LibVintfTest, AidlAndHidlCheckUnused) {
3841 std::string manifestXml =
3842 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3843 " <hal format=\"aidl\">\n"
3844 " <name>android.system.foo</name>\n"
3845 " <fqname>IFoo/default</fqname>\n"
3846 " </hal>\n"
3847 " <hal format=\"hidl\">\n"
3848 " <name>android.system.foo</name>\n"
3849 " <transport>hwbinder</transport>\n"
3850 " <fqname>@1.0::IFoo/default</fqname>\n"
3851 " </hal>\n"
3852 "</manifest>\n";
3853 std::string matrixXml =
3854 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
3855 " <hal format=\"aidl\" optional=\"true\">\n"
3856 " <name>android.system.foo</name>\n"
3857 " <interface>\n"
3858 " <name>IFoo</name>\n"
3859 " <instance>default</instance>\n"
3860 " </interface>\n"
3861 " </hal>\n"
3862 " <hal format=\"hidl\" optional=\"true\">\n"
3863 " <name>android.system.foo</name>\n"
3864 " <version>1.0</version>\n"
3865 " <interface>\n"
3866 " <name>IFoo</name>\n"
3867 " <instance>default</instance>\n"
3868 " </interface>\n"
3869 " </hal>\n"
3870 "</compatibility-matrix>\n";
3871 std::string error;
3872 HalManifest manifest;
3873 CompatibilityMatrix matrix;
3874
3875 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml, &error)) << error;
3876 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml, &error)) << error;
3877 auto unused = checkUnusedHals(manifest, matrix);
3878 EXPECT_TRUE(unused.empty()) << android::base::Join(unused, "\n");
3879 }
3880
TEST_F(LibVintfTest,GetTransportHidlHalWithFakeAidlVersion)3881 TEST_F(LibVintfTest, GetTransportHidlHalWithFakeAidlVersion) {
3882 std::string xml =
3883 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3884 " <hal format=\"hidl\">\n"
3885 " <name>android.system.foo</name>\n"
3886 " <transport>hwbinder</transport>\n"
3887 " <fqname>@" + to_string(details::kFakeAidlVersion) + "::IFoo/default</fqname>\n"
3888 " </hal>\n"
3889 "</manifest>\n";
3890 std::string error;
3891 HalManifest manifest;
3892 EXPECT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3893 EXPECT_EQ(Transport::HWBINDER,
3894 manifest.getHidlTransport("android.system.foo", details::kFakeAidlVersion, "IFoo",
3895 "default"));
3896 }
3897
TEST_F(LibVintfTest,GetTransportAidlHalWithDummyTransport)3898 TEST_F(LibVintfTest, GetTransportAidlHalWithDummyTransport) {
3899 // Check that even if <transport> is specified for AIDL, it is ignored and getHidlTransport
3900 // will return EMPTY.
3901 std::string xml =
3902 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3903 " <hal format=\"aidl\">\n"
3904 " <name>android.system.foo</name>\n"
3905 " <transport>hwbinder</transport>\n"
3906 " <fqname>IFoo/default</fqname>\n"
3907 " </hal>\n"
3908 "</manifest>\n";
3909 std::string error;
3910 HalManifest manifest;
3911 EXPECT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3912 EXPECT_EQ(Transport::EMPTY,
3913 manifest.getHidlTransport("android.system.foo", details::kFakeAidlVersion, "IFoo",
3914 "default"));
3915 }
3916
TEST_F(LibVintfTest,AidlGetHalNamesAndVersions)3917 TEST_F(LibVintfTest, AidlGetHalNamesAndVersions) {
3918 HalManifest manifest;
3919 std::string xml =
3920 "<manifest " + kMetaVersionStr + " type=\"framework\">\n"
3921 " <hal format=\"aidl\">\n"
3922 " <name>android.system.foo</name>\n"
3923 " <fqname>IFoo/default</fqname>\n"
3924 " </hal>\n"
3925 "</manifest>\n";
3926 std::string error;
3927 EXPECT_TRUE(gHalManifestConverter(&manifest, xml, &error)) << error;
3928 auto names = manifest.getHalNamesAndVersions();
3929 ASSERT_EQ(1u, names.size());
3930 EXPECT_EQ("android.system.foo", *names.begin());
3931 }
3932
TEST_F(LibVintfTest,KernelInfoLevel)3933 TEST_F(LibVintfTest, KernelInfoLevel) {
3934 std::string error;
3935 std::string xml = "<kernel version=\"3.18.31\" target-level=\"1\"/>\n";
3936 KernelInfo ki;
3937 ASSERT_TRUE(gKernelInfoConverter(&ki, xml, &error)) << error;
3938 EXPECT_EQ(Level{1}, ki.level());
3939 EXPECT_EQ(xml, gKernelInfoConverter(ki));
3940 }
3941
3942 // Test merge of <kernel target-level=""> with autogenerated <kernel> by parsing
3943 // kernel prebuilt.
TEST_F(LibVintfTest,HalManifestMergeKernel)3944 TEST_F(LibVintfTest, HalManifestMergeKernel) {
3945 std::string head =
3946 "<manifest " + kMetaVersionStr + " type=\"device\" target-level=\"1\">\n";
3947 std::string tail =
3948 "</manifest>\n";
3949 std::string xml1 =
3950 " <kernel target-level=\"2\"/>\n";
3951 std::string xml2 =
3952 " <kernel version=\"3.18.31\">\n"
3953 " <config>\n"
3954 " <key>CONFIG_64BIT</key>\n"
3955 " <value>y</value>\n"
3956 " </config>\n"
3957 " </kernel>\n";
3958
3959 std::string error;
3960 HalManifest manifest1;
3961 HalManifest manifest2;
3962 ASSERT_TRUE(gHalManifestConverter(&manifest1, head + xml1 + tail, &error)) << error;
3963 ASSERT_TRUE(gHalManifestConverter(&manifest2, head + xml2 + tail, &error)) << error;
3964 ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error;
3965 std::string merged_xml = gHalManifestConverter(manifest1);
3966 EXPECT_IN(head, merged_xml);
3967 EXPECT_IN("target-level=\"2\"", merged_xml);
3968 EXPECT_IN("version=\"3.18.31\"", merged_xml);
3969 EXPECT_IN("CONFIG_64BIT", merged_xml);
3970 }
3971
3972 struct FrameworkCompatibilityMatrixCombineTest : public LibVintfTest {
SetUpandroid::vintf::FrameworkCompatibilityMatrixCombineTest3973 virtual void SetUp() override {
3974 matrices.resize(2);
3975 matrices[0].setFileName("compatibility_matrix.1_1.xml");
3976 matrices[1].setFileName("compatibility_matrix.1_2.xml");
3977 }
3978 // Access to private methods.
combineandroid::vintf::FrameworkCompatibilityMatrixCombineTest3979 std::unique_ptr<CompatibilityMatrix> combine(Level deviceLevel,
3980 std::vector<CompatibilityMatrix>* matrices,
3981 std::string* error) {
3982 return CompatibilityMatrix::combine(deviceLevel, matrices, error);
3983 }
3984
3985 std::vector<CompatibilityMatrix> matrices;
3986 std::string error;
3987 };
3988
3989 // Combining framework compatibility matrix with conflicting minlts fails
TEST_F(FrameworkCompatibilityMatrixCombineTest,ConflictMinlts)3990 TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictMinlts) {
3991 ASSERT_TRUE(gCompatibilityMatrixConverter(
3992 &matrices[0],
3993 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
3994 " <kernel version=\"3.18.5\" />\n"
3995 "</compatibility-matrix>\n",
3996 &error))
3997 << error;
3998 ASSERT_TRUE(gCompatibilityMatrixConverter(
3999 &matrices[1],
4000 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
4001 " <kernel version=\"3.18.6\" />\n"
4002 "</compatibility-matrix>\n",
4003 &error))
4004 << error;
4005
4006 auto combined = combine(Level{1}, &matrices, &error);
4007 ASSERT_EQ(nullptr, combined) << gCompatibilityMatrixConverter(*combined);
4008 EXPECT_IN("Kernel version mismatch", error);
4009 }
4010
4011 // <kernel> without <conditions> always comes first
TEST_F(FrameworkCompatibilityMatrixCombineTest,KernelNoConditions)4012 TEST_F(FrameworkCompatibilityMatrixCombineTest, KernelNoConditions) {
4013 std::string conditionedKernel =
4014 " <kernel version=\"3.18.5\" level=\"1\">\n"
4015 " <conditions>\n"
4016 " <config>\n"
4017 " <key>CONFIG_ARM</key>\n"
4018 " <value type=\"tristate\">y</value>\n"
4019 " </config>\n"
4020 " </conditions>\n"
4021 " <config>\n"
4022 " <key>CONFIG_FOO</key>\n"
4023 " <value type=\"tristate\">y</value>\n"
4024 " </config>\n"
4025 " </kernel>\n";
4026 std::string simpleKernel =
4027 " <kernel version=\"3.18.5\" level=\"1\">\n"
4028 " <config>\n"
4029 " <key>CONFIG_BAR</key>\n"
4030 " <value type=\"tristate\">y</value>\n"
4031 " </config>\n"
4032 " </kernel>\n";
4033
4034 ASSERT_TRUE(gCompatibilityMatrixConverter(
4035 &matrices[0],
4036 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
4037 " <kernel version=\"3.18.5\" />\n" +
4038 conditionedKernel + "</compatibility-matrix>\n",
4039 &error))
4040 << error;
4041 ASSERT_TRUE(gCompatibilityMatrixConverter(
4042 &matrices[1],
4043 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" + simpleKernel +
4044 "</compatibility-matrix>\n",
4045 &error))
4046 << error;
4047
4048 auto combined = combine(Level{1}, &matrices, &error);
4049 ASSERT_NE(nullptr, combined);
4050 EXPECT_EQ("", error);
4051 EXPECT_EQ("<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n" +
4052 simpleKernel + conditionedKernel + "</compatibility-matrix>\n",
4053 gCompatibilityMatrixConverter(*combined));
4054 }
4055
4056 // Combining framework compatibility matrix with conflicting sepolicy fails
TEST_F(FrameworkCompatibilityMatrixCombineTest,ConflictSepolicy)4057 TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictSepolicy) {
4058 ASSERT_TRUE(gCompatibilityMatrixConverter(
4059 &matrices[0],
4060 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
4061 " <sepolicy>\n"
4062 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
4063 " </sepolicy>\n"
4064 "</compatibility-matrix>\n",
4065 &error))
4066 << error;
4067 ASSERT_TRUE(gCompatibilityMatrixConverter(
4068 &matrices[1],
4069 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
4070 " <sepolicy>\n"
4071 " <kernel-sepolicy-version>29</kernel-sepolicy-version>\n"
4072 " </sepolicy>\n"
4073 "</compatibility-matrix>\n",
4074 &error))
4075 << error;
4076
4077 auto combined = combine(Level{1}, &matrices, &error);
4078 ASSERT_EQ(nullptr, combined) << gCompatibilityMatrixConverter(*combined);
4079 EXPECT_IN("<sepolicy> is already defined", error);
4080 }
4081
4082 // Combining framework compatibility matrix with conflicting avb fails
TEST_F(FrameworkCompatibilityMatrixCombineTest,ConflictAvb)4083 TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictAvb) {
4084 ASSERT_TRUE(gCompatibilityMatrixConverter(
4085 &matrices[0],
4086 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
4087 " <avb>\n"
4088 " <vbmeta-version>1.1</vbmeta-version>\n"
4089 " </avb>\n"
4090 "</compatibility-matrix>\n",
4091 &error))
4092 << error;
4093 ASSERT_TRUE(gCompatibilityMatrixConverter(
4094 &matrices[1],
4095 "<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"
4096 " <avb>\n"
4097 " <vbmeta-version>1.0</vbmeta-version>\n"
4098 " </avb>\n"
4099 "</compatibility-matrix>\n",
4100 &error))
4101 << error;
4102
4103 auto combined = combine(Level{1}, &matrices, &error);
4104 ASSERT_EQ(nullptr, combined) << gCompatibilityMatrixConverter(*combined);
4105 EXPECT_IN("<avb><vbmeta-version> is already defined", error);
4106 }
4107
TEST_F(FrameworkCompatibilityMatrixCombineTest,AidlAndHidlNames)4108 TEST_F(FrameworkCompatibilityMatrixCombineTest, AidlAndHidlNames) {
4109 std::string head1{"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"1\">\n"};
4110 std::string head2{"<compatibility-matrix " + kMetaVersionStr + " type=\"framework\" level=\"2\">\n"};
4111 std::string tail{"</compatibility-matrix>\n"};
4112 std::string aidl =
4113 " <hal format=\"aidl\" optional=\"false\">\n"
4114 " <name>android.system.foo</name>\n"
4115 " <interface>\n"
4116 " <name>IFoo</name>\n"
4117 " <instance>default</instance>\n"
4118 " </interface>\n"
4119 " </hal>\n";
4120 std::string hidl =
4121 " <hal format=\"hidl\" optional=\"false\">\n"
4122 " <name>android.system.foo</name>\n"
4123 " <version>1.0</version>\n"
4124 " <interface>\n"
4125 " <name>IFoo</name>\n"
4126 " <instance>default</instance>\n"
4127 " </interface>\n"
4128 " </hal>\n";
4129 std::string aidlOptional = std::string(aidl).replace(hidl.find("false"), 5, "true");
4130 std::string hidlOptional = std::string(hidl).replace(hidl.find("false"), 5, "true");
4131 std::string error;
4132 {
4133 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head1 + aidl + tail, &error))
4134 << error;
4135 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head1 + hidl + tail, &error))
4136 << error;
4137
4138 auto combined = combine(Level{1}, &matrices, &error);
4139 ASSERT_NE(nullptr, combined) << error;
4140
4141 auto combinedXml = gCompatibilityMatrixConverter(*combined);
4142 EXPECT_IN(aidl, combinedXml);
4143 EXPECT_IN(hidl, combinedXml);
4144 }
4145 {
4146 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head1 + aidl + tail, &error))
4147 << error;
4148 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head2 + hidl + tail, &error))
4149 << error;
4150
4151 auto combined = combine(Level{1}, &matrices, &error);
4152 ASSERT_NE(nullptr, combined) << error;
4153
4154 auto combinedXml = gCompatibilityMatrixConverter(*combined);
4155 EXPECT_IN(aidl, combinedXml);
4156 EXPECT_IN(hidlOptional, combinedXml);
4157 }
4158 {
4159 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head2 + aidl + tail, &error))
4160 << error;
4161 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head1 + hidl + tail, &error))
4162 << error;
4163
4164 auto combined = combine(Level{1}, &matrices, &error);
4165 ASSERT_NE(nullptr, combined) << error;
4166
4167 auto combinedXml = gCompatibilityMatrixConverter(*combined);
4168 EXPECT_IN(aidlOptional, combinedXml);
4169 EXPECT_IN(hidl, combinedXml);
4170 }
4171 }
4172
4173 struct DeviceCompatibilityMatrixCombineTest : public LibVintfTest {
SetUpandroid::vintf::DeviceCompatibilityMatrixCombineTest4174 virtual void SetUp() override {
4175 matrices.resize(2);
4176 matrices[0].setFileName("compatibility_matrix.1.xml");
4177 matrices[1].setFileName("compatibility_matrix.2.xml");
4178 }
4179 // Access to private methods.
combineandroid::vintf::DeviceCompatibilityMatrixCombineTest4180 std::unique_ptr<CompatibilityMatrix> combine(std::vector<CompatibilityMatrix>* matrices,
4181 std::string* error) {
4182 return CompatibilityMatrix::combineDeviceMatrices(matrices, error);
4183 }
4184
4185 std::vector<CompatibilityMatrix> matrices;
4186 std::string error;
4187 };
4188
TEST_F(DeviceCompatibilityMatrixCombineTest,Success)4189 TEST_F(DeviceCompatibilityMatrixCombineTest, Success) {
4190 std::string head{"<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"};
4191 std::string tail{"</compatibility-matrix>\n"};
4192 std::string halFoo{
4193 " <hal format=\"hidl\" optional=\"false\">\n"
4194 " <name>android.hardware.foo</name>\n"
4195 " <version>1.0</version>\n"
4196 " <interface>\n"
4197 " <name>IFoo</name>\n"
4198 " <instance>default</instance>\n"
4199 " </interface>\n"
4200 " </hal>\n"};
4201 std::string halBar{
4202 " <hal format=\"hidl\" optional=\"false\">\n"
4203 " <name>android.hardware.bar</name>\n"
4204 " <version>1.0</version>\n"
4205 " <interface>\n"
4206 " <name>IBar</name>\n"
4207 " <instance>default</instance>\n"
4208 " </interface>\n"
4209 " </hal>\n"};
4210 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head + halFoo + tail, &error))
4211 << error;
4212 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head + halBar + tail, &error))
4213 << error;
4214
4215 auto combined = combine(&matrices, &error);
4216 ASSERT_NE(nullptr, combined) << error;
4217 EXPECT_EQ("", error);
4218 auto combinedXml = gCompatibilityMatrixConverter(*combined);
4219 EXPECT_IN(halFoo, combinedXml);
4220 EXPECT_IN(halBar, combinedXml);
4221 }
4222
TEST_F(DeviceCompatibilityMatrixCombineTest,ConflictVendorNdk)4223 TEST_F(DeviceCompatibilityMatrixCombineTest, ConflictVendorNdk) {
4224 std::string vendorNdkP{
4225 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
4226 " <vendor-ndk>\n"
4227 " <version>P</version>\n"
4228 " </vendor-ndk>\n"
4229 "</compatibility-matrix>\n"};
4230 std::string vendorNdkQ{
4231 "<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"
4232 " <vendor-ndk>\n"
4233 " <version>Q</version>\n"
4234 " </vendor-ndk>\n"
4235 "</compatibility-matrix>\n"};
4236 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], vendorNdkP, &error)) << error;
4237 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], vendorNdkQ, &error)) << error;
4238
4239 auto combined = combine(&matrices, &error);
4240 ASSERT_EQ(nullptr, combined) << gCompatibilityMatrixConverter(*combined);
4241 EXPECT_IN("<vendor-ndk> is already defined", error);
4242 }
4243
TEST_F(DeviceCompatibilityMatrixCombineTest,AidlAndHidlNames)4244 TEST_F(DeviceCompatibilityMatrixCombineTest, AidlAndHidlNames) {
4245 std::string head{"<compatibility-matrix " + kMetaVersionStr + " type=\"device\">\n"};
4246 std::string tail{"</compatibility-matrix>\n"};
4247 std::string aidl =
4248 " <hal format=\"aidl\" optional=\"true\">\n"
4249 " <name>android.system.foo</name>\n"
4250 " <interface>\n"
4251 " <name>IFoo</name>\n"
4252 " <instance>default</instance>\n"
4253 " </interface>\n"
4254 " </hal>\n";
4255 std::string hidl =
4256 " <hal format=\"hidl\" optional=\"true\">\n"
4257 " <name>android.system.foo</name>\n"
4258 " <version>1.0</version>\n"
4259 " <interface>\n"
4260 " <name>IFoo</name>\n"
4261 " <instance>default</instance>\n"
4262 " </interface>\n"
4263 " </hal>\n";
4264 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[0], head + aidl + tail, &error))
4265 << error;
4266 ASSERT_TRUE(gCompatibilityMatrixConverter(&matrices[1], head + hidl + tail, &error))
4267 << error;
4268
4269 auto combined = combine(&matrices, &error);
4270 ASSERT_NE(nullptr, combined) << error;
4271
4272 auto combinedXml = gCompatibilityMatrixConverter(*combined);
4273 EXPECT_IN(aidl, combinedXml);
4274 EXPECT_IN(hidl, combinedXml);
4275 }
4276
4277 // clang-format on
4278
4279 } // namespace vintf
4280 } // namespace android
4281
main(int argc,char ** argv)4282 int main(int argc, char **argv) {
4283 ::testing::InitGoogleTest(&argc, argv);
4284 return RUN_ALL_TESTS();
4285 }
4286