diff options
author | Yifan Hong | 2017-05-17 20:36:08 -0500 |
---|---|---|
committer | Yifan Hong | 2017-05-19 15:59:22 -0500 |
commit | 9cd9eb0f06e77347beaf141c011fb1989af82475 (patch) | |
tree | 96b36eb988d83897d6ce1d189760469a8cafcd19 | |
parent | 476b63fcdca477971fb33da225efcb4cdc6104b1 (diff) | |
download | platform-system-libvintf-9cd9eb0f06e77347beaf141c011fb1989af82475.tar.gz platform-system-libvintf-9cd9eb0f06e77347beaf141c011fb1989af82475.tar.xz platform-system-libvintf-9cd9eb0f06e77347beaf141c011fb1989af82475.zip |
Add HalInterface to compatibility matrix
Test: libvintf_test
Test: vintf_object_test
Bug: 38395193
Change-Id: I6dfc21bbfb63b575558405e441f3926ff3813eb8
Merged-In: I6dfc21bbfb63b575558405e441f3926ff3813eb8
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | HalInterface.cpp | 35 | ||||
-rw-r--r-- | MatrixHal.cpp | 2 | ||||
-rw-r--r-- | include/vintf/HalInterface.h | 2 | ||||
-rw-r--r-- | include/vintf/MatrixHal.h | 3 | ||||
-rw-r--r-- | parse_xml.cpp | 13 | ||||
-rw-r--r-- | test/main.cpp | 48 |
7 files changed, 99 insertions, 6 deletions
@@ -39,6 +39,7 @@ cc_library { | |||
39 | "parse_xml.cpp", | 39 | "parse_xml.cpp", |
40 | "CompatibilityMatrix.cpp", | 40 | "CompatibilityMatrix.cpp", |
41 | "HalManifest.cpp", | 41 | "HalManifest.cpp", |
42 | "HalInterface.cpp", | ||
42 | "KernelConfigTypedValue.cpp", | 43 | "KernelConfigTypedValue.cpp", |
43 | "RuntimeInfo.cpp", | 44 | "RuntimeInfo.cpp", |
44 | "ManifestHal.cpp", | 45 | "ManifestHal.cpp", |
@@ -108,6 +109,7 @@ cc_library { | |||
108 | "parse_xml.cpp", | 109 | "parse_xml.cpp", |
109 | "CompatibilityMatrix.cpp", | 110 | "CompatibilityMatrix.cpp", |
110 | "HalManifest.cpp", | 111 | "HalManifest.cpp", |
112 | "HalInterface.cpp", | ||
111 | "KernelConfigTypedValue.cpp", | 113 | "KernelConfigTypedValue.cpp", |
112 | "RuntimeInfo.cpp", | 114 | "RuntimeInfo.cpp", |
113 | "ManifestHal.cpp", | 115 | "ManifestHal.cpp", |
diff --git a/HalInterface.cpp b/HalInterface.cpp new file mode 100644 index 0000000..2dbf57c --- /dev/null +++ b/HalInterface.cpp | |||
@@ -0,0 +1,35 @@ | |||
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 | #include <set> | ||
18 | #include <string> | ||
19 | |||
20 | #include "HalInterface.h" | ||
21 | |||
22 | namespace android { | ||
23 | namespace vintf { | ||
24 | |||
25 | bool operator==(const HalInterface& lft, const HalInterface& rgt) { | ||
26 | if (lft.name != rgt.name) | ||
27 | return false; | ||
28 | if (lft.instances != rgt.instances) | ||
29 | return false; | ||
30 | return true; | ||
31 | } | ||
32 | |||
33 | } // namespace vintf | ||
34 | } // namespace android | ||
35 | |||
diff --git a/MatrixHal.cpp b/MatrixHal.cpp index aa6f7f3..1db7f40 100644 --- a/MatrixHal.cpp +++ b/MatrixHal.cpp | |||
@@ -26,6 +26,8 @@ bool MatrixHal::operator==(const MatrixHal &other) const { | |||
26 | return false; | 26 | return false; |
27 | if (versionRanges != other.versionRanges) | 27 | if (versionRanges != other.versionRanges) |
28 | return false; | 28 | return false; |
29 | if (interfaces != other.interfaces) | ||
30 | return false; | ||
29 | // do not compare optional | 31 | // do not compare optional |
30 | return true; | 32 | return true; |
31 | } | 33 | } |
diff --git a/include/vintf/HalInterface.h b/include/vintf/HalInterface.h index 7926b49..a5645d3 100644 --- a/include/vintf/HalInterface.h +++ b/include/vintf/HalInterface.h | |||
@@ -29,6 +29,8 @@ struct HalInterface { | |||
29 | std::set<std::string> instances; | 29 | std::set<std::string> instances; |
30 | }; | 30 | }; |
31 | 31 | ||
32 | bool operator==(const HalInterface&, const HalInterface&); | ||
33 | |||
32 | } // namespace vintf | 34 | } // namespace vintf |
33 | } // namespace android | 35 | } // namespace android |
34 | 36 | ||
diff --git a/include/vintf/MatrixHal.h b/include/vintf/MatrixHal.h index ed34d24..e8c4a2a 100644 --- a/include/vintf/MatrixHal.h +++ b/include/vintf/MatrixHal.h | |||
@@ -17,10 +17,12 @@ | |||
17 | #ifndef ANDROID_VINTF_MATRIX_HAL_H | 17 | #ifndef ANDROID_VINTF_MATRIX_HAL_H |
18 | #define ANDROID_VINTF_MATRIX_HAL_H | 18 | #define ANDROID_VINTF_MATRIX_HAL_H |
19 | 19 | ||
20 | #include <map> | ||
20 | #include <string> | 21 | #include <string> |
21 | #include <vector> | 22 | #include <vector> |
22 | 23 | ||
23 | #include "HalFormat.h" | 24 | #include "HalFormat.h" |
25 | #include "HalInterface.h" | ||
24 | #include "VersionRange.h" | 26 | #include "VersionRange.h" |
25 | 27 | ||
26 | namespace android { | 28 | namespace android { |
@@ -35,6 +37,7 @@ struct MatrixHal { | |||
35 | std::string name; | 37 | std::string name; |
36 | std::vector<VersionRange> versionRanges; | 38 | std::vector<VersionRange> versionRanges; |
37 | bool optional = false; | 39 | bool optional = false; |
40 | std::map<std::string, HalInterface> interfaces; | ||
38 | }; | 41 | }; |
39 | 42 | ||
40 | } // namespace vintf | 43 | } // namespace vintf |
diff --git a/parse_xml.cpp b/parse_xml.cpp index 7287604..8caab4f 100644 --- a/parse_xml.cpp +++ b/parse_xml.cpp | |||
@@ -470,14 +470,25 @@ struct MatrixHalConverter : public XmlNodeConverter<MatrixHal> { | |||
470 | appendAttr(root, "optional", hal.optional); | 470 | appendAttr(root, "optional", hal.optional); |
471 | appendTextElement(root, "name", hal.name, d); | 471 | appendTextElement(root, "name", hal.name, d); |
472 | appendChildren(root, versionRangeConverter, hal.versionRanges, d); | 472 | appendChildren(root, versionRangeConverter, hal.versionRanges, d); |
473 | appendChildren(root, halInterfaceConverter, iterateValues(hal.interfaces), d); | ||
473 | } | 474 | } |
474 | bool buildObject(MatrixHal *object, NodeType *root) const override { | 475 | bool buildObject(MatrixHal *object, NodeType *root) const override { |
476 | std::vector<HalInterface> interfaces; | ||
475 | if (!parseOptionalAttr(root, "format", HalFormat::HIDL, &object->format) || | 477 | if (!parseOptionalAttr(root, "format", HalFormat::HIDL, &object->format) || |
476 | !parseOptionalAttr(root, "optional", false /* defaultValue */, &object->optional) || | 478 | !parseOptionalAttr(root, "optional", false /* defaultValue */, &object->optional) || |
477 | !parseTextElement(root, "name", &object->name) || | 479 | !parseTextElement(root, "name", &object->name) || |
478 | !parseChildren(root, versionRangeConverter, &object->versionRanges)) { | 480 | !parseChildren(root, versionRangeConverter, &object->versionRanges) || |
481 | !parseChildren(root, halInterfaceConverter, &interfaces)) { | ||
479 | return false; | 482 | return false; |
480 | } | 483 | } |
484 | for (auto&& interface : interfaces) { | ||
485 | std::string name{interface.name}; | ||
486 | auto res = object->interfaces.emplace(std::move(name), std::move(interface)); | ||
487 | if (!res.second) { | ||
488 | this->mLastError = "Duplicated instance entry " + res.first->first; | ||
489 | return false; | ||
490 | } | ||
491 | } | ||
481 | return true; | 492 | return true; |
482 | } | 493 | } |
483 | }; | 494 | }; |
diff --git a/test/main.cpp b/test/main.cpp index fce4d6d..9bdaead 100644 --- a/test/main.cpp +++ b/test/main.cpp | |||
@@ -84,6 +84,16 @@ public: | |||
84 | bool isValid(const ManifestHal &mh) { | 84 | bool isValid(const ManifestHal &mh) { |
85 | return mh.isValid(); | 85 | return mh.isValid(); |
86 | } | 86 | } |
87 | |||
88 | std::map<std::string, HalInterface> testHalInterfaces() { | ||
89 | HalInterface intf; | ||
90 | intf.name = "IFoo"; | ||
91 | intf.instances.insert("default"); | ||
92 | std::map<std::string, HalInterface> map; | ||
93 | map[intf.name] = intf; | ||
94 | return map; | ||
95 | } | ||
96 | |||
87 | HalManifest testDeviceManifest() { | 97 | HalManifest testDeviceManifest() { |
88 | HalManifest vm; | 98 | HalManifest vm; |
89 | vm.mType = SchemaType::DEVICE; | 99 | vm.mType = SchemaType::DEVICE; |
@@ -296,16 +306,32 @@ TEST_F(LibVintfTest, VersionConverter) { | |||
296 | EXPECT_EQ(v, v2); | 306 | EXPECT_EQ(v, v2); |
297 | } | 307 | } |
298 | 308 | ||
309 | static bool insert(std::map<std::string, HalInterface>* map, HalInterface&& intf) { | ||
310 | std::string name{intf.name}; | ||
311 | return map->emplace(std::move(name), std::move(intf)).second; | ||
312 | } | ||
313 | |||
299 | TEST_F(LibVintfTest, MatrixHalConverter) { | 314 | TEST_F(LibVintfTest, MatrixHalConverter) { |
300 | MatrixHal mh{HalFormat::NATIVE, "android.hardware.camera", | 315 | MatrixHal mh{HalFormat::NATIVE, "android.hardware.camera", |
301 | {{VersionRange(1,2,3), VersionRange(4,5,6)}}, | 316 | {{VersionRange(1,2,3), VersionRange(4,5,6)}}, |
302 | false /* optional */}; | 317 | false /* optional */, {}}; |
318 | EXPECT_TRUE(insert(&mh.interfaces, {"IBetterCamera", {"default", "great"}})); | ||
319 | EXPECT_TRUE(insert(&mh.interfaces, {"ICamera", {"default"}})); | ||
303 | std::string xml = gMatrixHalConverter(mh); | 320 | std::string xml = gMatrixHalConverter(mh); |
304 | EXPECT_EQ(xml, | 321 | EXPECT_EQ(xml, |
305 | "<hal format=\"native\" optional=\"false\">\n" | 322 | "<hal format=\"native\" optional=\"false\">\n" |
306 | " <name>android.hardware.camera</name>\n" | 323 | " <name>android.hardware.camera</name>\n" |
307 | " <version>1.2-3</version>\n" | 324 | " <version>1.2-3</version>\n" |
308 | " <version>4.5-6</version>\n" | 325 | " <version>4.5-6</version>\n" |
326 | " <interface>\n" | ||
327 | " <name>IBetterCamera</name>\n" | ||
328 | " <instance>default</instance>\n" | ||
329 | " <instance>great</instance>\n" | ||
330 | " </interface>\n" | ||
331 | " <interface>\n" | ||
332 | " <name>ICamera</name>\n" | ||
333 | " <instance>default</instance>\n" | ||
334 | " </interface>\n" | ||
309 | "</hal>\n"); | 335 | "</hal>\n"); |
310 | MatrixHal mh2; | 336 | MatrixHal mh2; |
311 | EXPECT_TRUE(gMatrixHalConverter(&mh2, xml)); | 337 | EXPECT_TRUE(gMatrixHalConverter(&mh2, xml)); |
@@ -396,14 +422,14 @@ TEST_F(LibVintfTest, KernelConfigTypedValueConverter) { | |||
396 | "<value type=\"int\">18446744073709551616</value>\n")); | 422 | "<value type=\"int\">18446744073709551616</value>\n")); |
397 | } | 423 | } |
398 | 424 | ||
399 | TEST_F(LibVintfTest, CompatibilityMatrixCoverter) { | 425 | TEST_F(LibVintfTest, CompatibilityMatrixConverter) { |
400 | CompatibilityMatrix cm; | 426 | CompatibilityMatrix cm; |
401 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.camera", | 427 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.camera", |
402 | {{VersionRange(1,2,3), VersionRange(4,5,6)}}, | 428 | {{VersionRange(1,2,3), VersionRange(4,5,6)}}, |
403 | false /* optional */})); | 429 | false /* optional */, testHalInterfaces()})); |
404 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.nfc", | 430 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.nfc", |
405 | {{VersionRange(4,5,6), VersionRange(10,11,12)}}, | 431 | {{VersionRange(4,5,6), VersionRange(10,11,12)}}, |
406 | true /* optional */})); | 432 | true /* optional */, testHalInterfaces()})); |
407 | EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(3, 18, 22), | 433 | EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(3, 18, 22), |
408 | {KernelConfig{"CONFIG_FOO", Tristate::YES}, KernelConfig{"CONFIG_BAR", "stringvalue"}}})); | 434 | {KernelConfig{"CONFIG_FOO", Tristate::YES}, KernelConfig{"CONFIG_BAR", "stringvalue"}}})); |
409 | EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(4, 4, 1), | 435 | EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(4, 4, 1), |
@@ -417,11 +443,19 @@ TEST_F(LibVintfTest, CompatibilityMatrixCoverter) { | |||
417 | " <name>android.hardware.camera</name>\n" | 443 | " <name>android.hardware.camera</name>\n" |
418 | " <version>1.2-3</version>\n" | 444 | " <version>1.2-3</version>\n" |
419 | " <version>4.5-6</version>\n" | 445 | " <version>4.5-6</version>\n" |
446 | " <interface>\n" | ||
447 | " <name>IFoo</name>\n" | ||
448 | " <instance>default</instance>\n" | ||
449 | " </interface>\n" | ||
420 | " </hal>\n" | 450 | " </hal>\n" |
421 | " <hal format=\"native\" optional=\"true\">\n" | 451 | " <hal format=\"native\" optional=\"true\">\n" |
422 | " <name>android.hardware.nfc</name>\n" | 452 | " <name>android.hardware.nfc</name>\n" |
423 | " <version>4.5-6</version>\n" | 453 | " <version>4.5-6</version>\n" |
424 | " <version>10.11-12</version>\n" | 454 | " <version>10.11-12</version>\n" |
455 | " <interface>\n" | ||
456 | " <name>IFoo</name>\n" | ||
457 | " <instance>default</instance>\n" | ||
458 | " </interface>\n" | ||
425 | " </hal>\n" | 459 | " </hal>\n" |
426 | " <kernel version=\"3.18.22\">\n" | 460 | " <kernel version=\"3.18.22\">\n" |
427 | " <config>\n" | 461 | " <config>\n" |
@@ -461,7 +495,7 @@ TEST_F(LibVintfTest, DeviceCompatibilityMatrixCoverter) { | |||
461 | CompatibilityMatrix cm; | 495 | CompatibilityMatrix cm; |
462 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hidl.manager", | 496 | EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hidl.manager", |
463 | {{VersionRange(1,0)}}, | 497 | {{VersionRange(1,0)}}, |
464 | false /* optional */})); | 498 | false /* optional */, testHalInterfaces()})); |
465 | set(cm, SchemaType::DEVICE); | 499 | set(cm, SchemaType::DEVICE); |
466 | set(cm, VndkVersionRange{25,0,1,5}, {"libjpeg.so", "libbase.so"}); | 500 | set(cm, VndkVersionRange{25,0,1,5}, {"libjpeg.so", "libbase.so"}); |
467 | std::string xml = gCompatibilityMatrixConverter(cm); | 501 | std::string xml = gCompatibilityMatrixConverter(cm); |
@@ -470,6 +504,10 @@ TEST_F(LibVintfTest, DeviceCompatibilityMatrixCoverter) { | |||
470 | " <hal format=\"native\" optional=\"false\">\n" | 504 | " <hal format=\"native\" optional=\"false\">\n" |
471 | " <name>android.hidl.manager</name>\n" | 505 | " <name>android.hidl.manager</name>\n" |
472 | " <version>1.0</version>\n" | 506 | " <version>1.0</version>\n" |
507 | " <interface>\n" | ||
508 | " <name>IFoo</name>\n" | ||
509 | " <instance>default</instance>\n" | ||
510 | " </interface>\n" | ||
473 | " </hal>\n" | 511 | " </hal>\n" |
474 | " <vndk>\n" | 512 | " <vndk>\n" |
475 | " <version>25.0.1-5</version>\n" | 513 | " <version>25.0.1-5</version>\n" |