summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhuoyao Zhang2017-11-02 11:33:29 -0500
committerandroid-build-merger2017-11-02 11:33:29 -0500
commitd818fb3522b0234a7738e8dbf4f521803928de2b (patch)
tree9ed2d30f4fdaf1202a577ed7963bbb92bcc10911
parentc458741791174dbcc207ae9b78a7788bdb07977d (diff)
parent8e368ccc2a646ecf161d8f076a4b27f479272f38 (diff)
downloadplatform-system-libvintf-d818fb3522b0234a7738e8dbf4f521803928de2b.tar.gz
platform-system-libvintf-d818fb3522b0234a7738e8dbf4f521803928de2b.tar.xz
platform-system-libvintf-d818fb3522b0234a7738e8dbf4f521803928de2b.zip
Prepare vts to use libvintf. am: c7e75bd035 am: 1b76efe3fe
am: 8e368ccc2a Change-Id: I8de2d3d6fe2ad193f31ebb5486234ffe76cc578a
-rw-r--r--HalManifest.cpp51
-rw-r--r--ManifestHal.cpp16
-rw-r--r--MatrixHal.cpp16
-rw-r--r--include/vintf/HalGroup.h47
-rw-r--r--include/vintf/HalManifest.h26
-rw-r--r--include/vintf/ManifestHal.h12
-rw-r--r--include/vintf/MatrixHal.h8
-rw-r--r--test/main.cpp155
8 files changed, 231 insertions, 100 deletions
diff --git a/HalManifest.cpp b/HalManifest.cpp
index 4345d7a..c633a7a 100644
--- a/HalManifest.cpp
+++ b/HalManifest.cpp
@@ -81,33 +81,6 @@ std::set<std::string> HalManifest::getHalNamesAndVersions() const {
81 return names; 81 return names;
82} 82}
83 83
84std::set<std::string> HalManifest::getInterfaceNames(const std::string &name) const {
85 std::set<std::string> interfaceNames{};
86 for (const ManifestHal *hal : getHals(name)) {
87 for (const auto &iface : hal->interfaces) {
88 interfaceNames.insert(iface.first);
89 }
90 }
91 return interfaceNames;
92}
93
94std::vector<const ManifestHal *> HalManifest::getHals(const std::string &name) const {
95 std::vector<const ManifestHal *> ret;
96 auto range = mHals.equal_range(name);
97 for (auto it = range.first; it != range.second; ++it) {
98 ret.push_back(&it->second);
99 }
100 return ret;
101}
102std::vector<ManifestHal *> HalManifest::getHals(const std::string &name) {
103 std::vector<ManifestHal *> ret;
104 auto range = mHals.equal_range(name);
105 for (auto it = range.first; it != range.second; ++it) {
106 ret.push_back(&it->second);
107 }
108 return ret;
109}
110
111Transport HalManifest::getTransport(const std::string &package, const Version &v, 84Transport HalManifest::getTransport(const std::string &package, const Version &v,
112 const std::string &interfaceName, const std::string &instanceName) const { 85 const std::string &interfaceName, const std::string &instanceName) const {
113 86
@@ -145,10 +118,6 @@ Transport HalManifest::getTransport(const std::string &package, const Version &v
145 118
146} 119}
147 120
148ConstMultiMapValueIterable<std::string, ManifestHal> HalManifest::getHals() const {
149 return HalGroup<ManifestHal>::getHals();
150}
151
152std::set<Version> HalManifest::getSupportedVersions(const std::string &name) const { 121std::set<Version> HalManifest::getSupportedVersions(const std::string &name) const {
153 std::set<Version> ret; 122 std::set<Version> ret;
154 for (const ManifestHal *hal : getHals(name)) { 123 for (const ManifestHal *hal : getHals(name)) {
@@ -157,22 +126,10 @@ std::set<Version> HalManifest::getSupportedVersions(const std::string &name) con
157 return ret; 126 return ret;
158} 127}
159 128
160 129bool HalManifest::hasInstance(const std::string& halName, const Version& version,
161std::set<std::string> HalManifest::getInstances( 130 const std::string& interfaceName,
162 const std::string &halName, const std::string &interfaceName) const { 131 const std::string& instanceName) const {
163 std::set<std::string> ret; 132 const auto& instances = getInstances(halName, version, interfaceName);
164 for (const ManifestHal *hal : getHals(halName)) {
165 auto it = hal->interfaces.find(interfaceName);
166 if (it != hal->interfaces.end()) {
167 ret.insert(it->second.instances.begin(), it->second.instances.end());
168 }
169 }
170 return ret;
171}
172
173bool HalManifest::hasInstance(const std::string &halName,
174 const std::string &interfaceName, const std::string &instanceName) const {
175 const auto &instances = getInstances(halName, interfaceName);
176 return instances.find(instanceName) != instances.end(); 133 return instances.find(instanceName) != instances.end();
177} 134}
178 135
diff --git a/ManifestHal.cpp b/ManifestHal.cpp
index 95d0f3c..00d0d95 100644
--- a/ManifestHal.cpp
+++ b/ManifestHal.cpp
@@ -42,5 +42,21 @@ bool ManifestHal::operator==(const ManifestHal &other) const {
42 return true; 42 return true;
43} 43}
44 44
45bool ManifestHal::containsVersion(const Version& version) const {
46 for (Version v : versions) {
47 if (v.minorAtLeast(version)) return true;
48 }
49 return false;
50}
51
52std::set<std::string> ManifestHal::getInstances(const std::string& interfaceName) const {
53 std::set<std::string> ret;
54 auto it = interfaces.find(interfaceName);
55 if (it != interfaces.end()) {
56 ret.insert(it->second.instances.begin(), it->second.instances.end());
57 }
58 return ret;
59}
60
45} // namespace vintf 61} // namespace vintf
46} // namespace android 62} // namespace android
diff --git a/MatrixHal.cpp b/MatrixHal.cpp
index 1db7f40..50c5116 100644
--- a/MatrixHal.cpp
+++ b/MatrixHal.cpp
@@ -32,5 +32,21 @@ bool MatrixHal::operator==(const MatrixHal &other) const {
32 return true; 32 return true;
33} 33}
34 34
35bool MatrixHal::containsVersion(const Version& version) const {
36 for (VersionRange vRange : versionRanges) {
37 if (vRange.contains(version)) return true;
38 }
39 return false;
40}
41
42std::set<std::string> MatrixHal::getInstances(const std::string& interfaceName) const {
43 std::set<std::string> ret;
44 auto it = interfaces.find(interfaceName);
45 if (it != interfaces.end()) {
46 ret.insert(it->second.instances.begin(), it->second.instances.end());
47 }
48 return ret;
49}
50
35} // namespace vintf 51} // namespace vintf
36} // namespace android 52} // namespace android
diff --git a/include/vintf/HalGroup.h b/include/vintf/HalGroup.h
index 8ef6f38..e3f0c7c 100644
--- a/include/vintf/HalGroup.h
+++ b/include/vintf/HalGroup.h
@@ -18,8 +18,10 @@
18#define ANDROID_VINTF_HAL_GROUP_H 18#define ANDROID_VINTF_HAL_GROUP_H
19 19
20#include <map> 20#include <map>
21#include <set>
21 22
22#include "MapValueIterator.h" 23#include "MapValueIterator.h"
24#include "Version.h"
23 25
24namespace android { 26namespace android {
25namespace vintf { 27namespace vintf {
@@ -53,6 +55,51 @@ struct HalGroup {
53 return true; 55 return true;
54 } 56 }
55 57
58 // Get all hals with the given name (e.g "android.hardware.camera").
59 // There could be multiple hals that matches the same given name.
60 std::vector<const Hal*> getHals(const std::string& name) const {
61 std::vector<const Hal*> ret;
62 auto range = mHals.equal_range(name);
63 for (auto it = range.first; it != range.second; ++it) {
64 ret.push_back(&it->second);
65 }
66 return ret;
67 }
68
69 // Get all hals with the given name (e.g "android.hardware.camera").
70 // There could be multiple hals that matches the same given name.
71 // Non-const version of the above getHals() method.
72 std::vector<Hal*> getHals(const std::string& name) {
73 std::vector<Hal*> ret;
74 auto range = mHals.equal_range(name);
75 for (auto it = range.first; it != range.second; ++it) {
76 ret.push_back(&it->second);
77 }
78 return ret;
79 }
80
81 // Get the hal that matches the given name and version (e.g.
82 // "android.hardware.camera@2.4")
83 // There should be a single hal that matches the given name and version.
84 const Hal* getHal(const std::string& name, const Version& version) const {
85 for (const Hal* hal : getHals(name)) {
86 if (hal->containsVersion(version)) return hal;
87 }
88 return nullptr;
89 }
90
91 // Get all instance names for hal that matches the given component name, version
92 // and interface name (e.g. "android.hardware.camera@2.4::ICameraProvider").
93 // * If the component ("android.hardware.camera@2.4") does not exist, return empty set.
94 // * If the component ("android.hardware.camera@2.4") does exist,
95 // * If the interface (ICameraProvider) does not exist, return empty set.
96 // * Else return the list hal.interface.instance.
97 std::set<std::string> getInstances(const std::string& halName, const Version& version,
98 const std::string& interfaceName) const {
99 const Hal* hal = getHal(halName, version);
100 return hal->getInstances(interfaceName);
101 }
102
56 protected: 103 protected:
57 // sorted map from component name to the component. 104 // sorted map from component name to the component.
58 // The component name looks like: android.hardware.foo 105 // The component name looks like: android.hardware.foo
diff --git a/include/vintf/HalManifest.h b/include/vintf/HalManifest.h
index bf224db..b553371 100644
--- a/include/vintf/HalManifest.h
+++ b/include/vintf/HalManifest.h
@@ -58,18 +58,9 @@ struct HalManifest : public HalGroup<ManifestHal>, public XmlFileGroup<ManifestX
58 // (dupes removed) 58 // (dupes removed)
59 std::set<Version> getSupportedVersions(const std::string &name) const; 59 std::set<Version> getSupportedVersions(const std::string &name) const;
60 60
61 // Given a component name (e.g. "android.hardware.camera") and an interface
62 // name, return all instance names for that interface.
63 // * If the component ("android.hardware.camera") does not exist, return empty list
64 // * If the component ("android.hardware.camera") does exist,
65 // * If the interface (ICamera) does not exist, return empty list
66 // * Else return the list hal.interface.instance
67 std::set<std::string> getInstances(
68 const std::string &halName, const std::string &interfaceName) const;
69
70 // Convenience method for checking if instanceName is in getInstances(halName, interfaceName) 61 // Convenience method for checking if instanceName is in getInstances(halName, interfaceName)
71 bool hasInstance(const std::string &halName, 62 bool hasInstance(const std::string& halName, const Version& version,
72 const std::string &interfaceName, const std::string &instanceName) const; 63 const std::string& interfaceName, const std::string& instanceName) const;
73 64
74 // Return a list of component names that does NOT conform to 65 // Return a list of component names that does NOT conform to
75 // the given compatibility matrix. It contains components that are optional 66 // the given compatibility matrix. It contains components that are optional
@@ -99,18 +90,9 @@ struct HalManifest : public HalGroup<ManifestHal>, public XmlFileGroup<ManifestX
99 // "android.hardware.nfc@1.0"] 90 // "android.hardware.nfc@1.0"]
100 std::set<std::string> getHalNamesAndVersions() const; 91 std::set<std::string> getHalNamesAndVersions() const;
101 92
102 // Given a component name (e.g. "android.hardware.camera"),
103 // return a list of interface names of that component.
104 // If the component is not found, empty list is returned.
105 std::set<std::string> getInterfaceNames(const std::string &name) const;
106
107 // Type of the manifest. FRAMEWORK or DEVICE. 93 // Type of the manifest. FRAMEWORK or DEVICE.
108 SchemaType type() const; 94 SchemaType type() const;
109 95
110 // Get all hals with the name
111 std::vector<const ManifestHal *> getHals(const std::string &name) const;
112 std::vector<ManifestHal *> getHals(const std::string &name);
113
114 // device.mSepolicyVersion. Assume type == device. 96 // device.mSepolicyVersion. Assume type == device.
115 // Abort if type != device. 97 // Abort if type != device.
116 const Version &sepolicyVersion() const; 98 const Version &sepolicyVersion() const;
@@ -141,10 +123,6 @@ struct HalManifest : public HalGroup<ManifestHal>, public XmlFileGroup<ManifestX
141 friend std::string dump(const HalManifest &vm); 123 friend std::string dump(const HalManifest &vm);
142 friend bool operator==(const HalManifest &lft, const HalManifest &rgt); 124 friend bool operator==(const HalManifest &lft, const HalManifest &rgt);
143 125
144 // Return an iterable to all ManifestHal objects. Call it as follows:
145 // for (const ManifestHal &e : vm.getHals()) { }
146 ConstMultiMapValueIterable<std::string, ManifestHal> getHals() const;
147
148 status_t fetchAllInformation(const std::string &path); 126 status_t fetchAllInformation(const std::string &path);
149 127
150 // Check if all instances in matrixHal is supported in this manifest. 128 // Check if all instances in matrixHal is supported in this manifest.
diff --git a/include/vintf/ManifestHal.h b/include/vintf/ManifestHal.h
index cd862ff..c569570 100644
--- a/include/vintf/ManifestHal.h
+++ b/include/vintf/ManifestHal.h
@@ -18,9 +18,10 @@
18#ifndef ANDROID_VINTF_MANIFEST_HAL_H 18#ifndef ANDROID_VINTF_MANIFEST_HAL_H
19#define ANDROID_VINTF_MANIFEST_HAL_H 19#define ANDROID_VINTF_MANIFEST_HAL_H
20 20
21#include <map>
22#include <set>
21#include <string> 23#include <string>
22#include <vector> 24#include <vector>
23#include <map>
24 25
25#include "HalFormat.h" 26#include "HalFormat.h"
26#include "HalInterface.h" 27#include "HalInterface.h"
@@ -34,6 +35,12 @@ namespace vintf {
34struct ManifestHal { 35struct ManifestHal {
35 36
36 bool operator==(const ManifestHal &other) const; 37 bool operator==(const ManifestHal &other) const;
38 // Check whether the ManifestHal contains the given version.
39 // E.g. if hal has version "1.0" and "2.1", it contains version
40 // "1.0", "2.0", "2.1".
41 bool containsVersion(const Version& version) const;
42 // Get all instances of the ManifestHal with given interface name.
43 std::set<std::string> getInstances(const std::string& interfaceName) const;
37 44
38 HalFormat format = HalFormat::HIDL; 45 HalFormat format = HalFormat::HIDL;
39 std::string name; 46 std::string name;
@@ -41,6 +48,9 @@ struct ManifestHal {
41 TransportArch transportArch; 48 TransportArch transportArch;
42 std::map<std::string, HalInterface> interfaces; 49 std::map<std::string, HalInterface> interfaces;
43 50
51 inline bool hasInterface(const std::string& interface_name) const {
52 return interfaces.find(interface_name) != interfaces.end();
53 }
44 inline bool hasVersion(Version v) const { 54 inline bool hasVersion(Version v) const {
45 return std::find(versions.begin(), versions.end(), v) != versions.end(); 55 return std::find(versions.begin(), versions.end(), v) != versions.end();
46 } 56 }
diff --git a/include/vintf/MatrixHal.h b/include/vintf/MatrixHal.h
index 5a4ccf0..203aa57 100644
--- a/include/vintf/MatrixHal.h
+++ b/include/vintf/MatrixHal.h
@@ -18,6 +18,7 @@
18#define ANDROID_VINTF_MATRIX_HAL_H 18#define ANDROID_VINTF_MATRIX_HAL_H
19 19
20#include <map> 20#include <map>
21#include <set>
21#include <string> 22#include <string>
22#include <vector> 23#include <vector>
23 24
@@ -32,6 +33,10 @@ namespace vintf {
32struct MatrixHal { 33struct MatrixHal {
33 34
34 bool operator==(const MatrixHal &other) const; 35 bool operator==(const MatrixHal &other) const;
36 // Check whether the MatrixHal contains the given version.
37 bool containsVersion(const Version& version) const;
38 // Get all instances of the ManifestHal with given interface name.
39 std::set<std::string> getInstances(const std::string& interfaceName) const;
35 40
36 HalFormat format = HalFormat::HIDL; 41 HalFormat format = HalFormat::HIDL;
37 std::string name; 42 std::string name;
@@ -40,6 +45,9 @@ struct MatrixHal {
40 std::map<std::string, HalInterface> interfaces; 45 std::map<std::string, HalInterface> interfaces;
41 46
42 inline const std::string& getName() const { return name; } 47 inline const std::string& getName() const { return name; }
48 inline bool hasInterface(const std::string& interface_name) const {
49 return interfaces.find(interface_name) != interfaces.end();
50 }
43}; 51};
44 52
45} // namespace vintf 53} // namespace vintf
diff --git a/test/main.cpp b/test/main.cpp
index 507e0d1..8ec02a8 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -398,25 +398,25 @@ TEST_F(LibVintfTest, HalManifestGetTransport) {
398 398
399TEST_F(LibVintfTest, HalManifestInstances) { 399TEST_F(LibVintfTest, HalManifestInstances) {
400 HalManifest vm = testDeviceManifest(); 400 HalManifest vm = testDeviceManifest();
401 EXPECT_EQ(vm.getInstances("android.hardware.camera", "ICamera"), 401 EXPECT_EQ(vm.getInstances("android.hardware.camera", {2, 0}, "ICamera"),
402 std::set<std::string>({"default", "legacy/0"})); 402 std::set<std::string>({"default", "legacy/0"}));
403 EXPECT_EQ(vm.getInstances("android.hardware.camera", "IBetterCamera"), 403 EXPECT_EQ(vm.getInstances("android.hardware.camera", {2, 0}, "IBetterCamera"),
404 std::set<std::string>({"camera"})); 404 std::set<std::string>({"camera"}));
405 EXPECT_EQ(vm.getInstances("android.hardware.camera", "INotExist"), 405 EXPECT_EQ(vm.getInstances("android.hardware.camera", {2, 0}, "INotExist"),
406 std::set<std::string>({})); 406 std::set<std::string>({}));
407 EXPECT_EQ(vm.getInstances("android.hardware.nfc", "INfc"), 407 EXPECT_EQ(vm.getInstances("android.hardware.nfc", {1, 0}, "INfc"),
408 std::set<std::string>({"default"})); 408 std::set<std::string>({"default"}));
409 409
410 EXPECT_TRUE(vm.hasInstance("android.hardware.camera", "ICamera", "default")); 410 EXPECT_TRUE(vm.hasInstance("android.hardware.camera", {2, 0}, "ICamera", "default"));
411 EXPECT_TRUE(vm.hasInstance("android.hardware.camera", "ICamera", "legacy/0")); 411 EXPECT_TRUE(vm.hasInstance("android.hardware.camera", {2, 0}, "ICamera", "legacy/0"));
412 EXPECT_TRUE(vm.hasInstance("android.hardware.camera", "IBetterCamera", "camera")); 412 EXPECT_TRUE(vm.hasInstance("android.hardware.camera", {2, 0}, "IBetterCamera", "camera"));
413 EXPECT_TRUE(vm.hasInstance("android.hardware.nfc", "INfc", "default")); 413 EXPECT_TRUE(vm.hasInstance("android.hardware.nfc", {1, 0}, "INfc", "default"));
414 414
415 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", "INotExist", "default")); 415 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", {2, 0}, "INotExist", "default"));
416 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", "ICamera", "notexist")); 416 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", {2, 0}, "ICamera", "notexist"));
417 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", "IBetterCamera", "default")); 417 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", {2, 0}, "IBetterCamera", "default"));
418 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", "INotExist", "notexist")); 418 EXPECT_FALSE(vm.hasInstance("android.hardware.camera", {2, 0}, "INotExist", "notexist"));
419 EXPECT_FALSE(vm.hasInstance("android.hardware.nfc", "INfc", "notexist")); 419 EXPECT_FALSE(vm.hasInstance("android.hardware.nfc", {1, 0}, "INfc", "notexist"));
420} 420}
421 421
422TEST_F(LibVintfTest, VersionConverter) { 422TEST_F(LibVintfTest, VersionConverter) {
@@ -663,15 +663,7 @@ TEST_F(LibVintfTest, HalManifestGetHalNames) {
663 {"android.hardware.camera", "android.hardware.nfc"})); 663 {"android.hardware.camera", "android.hardware.nfc"}));
664} 664}
665 665
666TEST_F(LibVintfTest, HalManifestGetInterfaceNames) { 666TEST_F(LibVintfTest, HalManifestGetAllHals) {
667 HalManifest vm = testDeviceManifest();
668 EXPECT_EQ(vm.getInterfaceNames("android.hardware.camera"),
669 std::set<std::string>({"ICamera", "IBetterCamera"}));
670 EXPECT_EQ(vm.getInterfaceNames("android.hardware.nfc"),
671 std::set<std::string>({"INfc"}));
672}
673
674TEST_F(LibVintfTest, HalManifestGetHal) {
675 HalManifest vm = testDeviceManifest(); 667 HalManifest vm = testDeviceManifest();
676 EXPECT_NE(getAnyHal(vm, "android.hardware.camera"), nullptr); 668 EXPECT_NE(getAnyHal(vm, "android.hardware.camera"), nullptr);
677 EXPECT_EQ(getAnyHal(vm, "non-existent"), nullptr); 669 EXPECT_EQ(getAnyHal(vm, "non-existent"), nullptr);
@@ -683,6 +675,113 @@ TEST_F(LibVintfTest, HalManifestGetHal) {
683 } 675 }
684} 676}
685 677
678TEST_F(LibVintfTest, HalManifestGetHals) {
679 HalManifest vm;
680 EXPECT_TRUE(
681 add(vm, ManifestHal{.format = HalFormat::HIDL,
682 .name = "android.hardware.camera",
683 .versions = {Version(1, 2)},
684 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY},
685 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
686 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}));
687 EXPECT_TRUE(
688 add(vm, ManifestHal{.format = HalFormat::HIDL,
689 .name = "android.hardware.camera",
690 .versions = {Version(2, 0)},
691 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY},
692 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
693 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}}));
694 EXPECT_TRUE(add(vm, ManifestHal{.format = HalFormat::HIDL,
695 .name = "android.hardware.nfc",
696 .versions = {Version(1, 0), Version(2, 1)},
697 .transportArch = {Transport::PASSTHROUGH, Arch::ARCH_32_64},
698 .interfaces = {{"INfc", {"INfc", {"default"}}}}}));
699 ManifestHal expectedCameraHalV1_2 =
700 ManifestHal{.format = HalFormat::HIDL,
701 .name = "android.hardware.camera",
702 .versions = {Version(1, 2)},
703 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY},
704 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
705 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}};
706 ManifestHal expectedCameraHalV2_0 =
707 ManifestHal{.format = HalFormat::HIDL,
708 .name = "android.hardware.camera",
709 .versions = {Version(2, 0)},
710 .transportArch = {Transport::HWBINDER, Arch::ARCH_EMPTY},
711 .interfaces = {{"ICamera", {"ICamera", {"legacy/0", "default"}}},
712 {"IBetterCamera", {"IBetterCamera", {"camera"}}}}};
713 ManifestHal expectedNfcHal =
714 ManifestHal{.format = HalFormat::HIDL,
715 .name = "android.hardware.nfc",
716 .versions = {Version(1, 0), Version(2, 1)},
717 .transportArch = {Transport::PASSTHROUGH, Arch::ARCH_32_64},
718 .interfaces = {{"INfc", {"INfc", {"default"}}}}};
719 auto cameraHals = vm.getHals("android.hardware.camera");
720 EXPECT_EQ((int)cameraHals.size(), 2);
721 EXPECT_EQ(*cameraHals[0], expectedCameraHalV1_2);
722 EXPECT_EQ(*cameraHals[1], expectedCameraHalV2_0);
723 auto nfcHals = vm.getHals("android.hardware.nfc");
724 EXPECT_EQ((int)nfcHals.size(), 1);
725 EXPECT_EQ(*nfcHals[0], expectedNfcHal);
726
727 EXPECT_EQ(*vm.getHal("android.hardware.camera", {1, 1}), expectedCameraHalV1_2);
728 EXPECT_EQ(*vm.getHal("android.hardware.camera", {2, 0}), expectedCameraHalV2_0);
729 EXPECT_EQ(*vm.getHal("android.hardware.nfc", {1, 0}), expectedNfcHal);
730 EXPECT_EQ(*vm.getHal("android.hardware.nfc", {2, 0}), expectedNfcHal);
731 EXPECT_EQ(*vm.getHal("android.hardware.nfc", {2, 1}), expectedNfcHal);
732
733 EXPECT_EQ(vm.getHal("non-existent", {1, 0}), nullptr);
734 EXPECT_EQ(vm.getHal("android.hardware.camera", {2, 1}), nullptr);
735 EXPECT_EQ(vm.getHal("android.hardware.camera", {1, 3}), nullptr);
736 EXPECT_EQ(vm.getHal("android.hardware.nfc", {1, 1}), nullptr);
737 EXPECT_EQ(vm.getHal("android.hardware.nfc", {3, 0}), nullptr);
738}
739
740TEST_F(LibVintfTest, CompatibilityMatrixGetHals) {
741 CompatibilityMatrix cm;
742 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE,
743 "android.hardware.camera",
744 {{VersionRange(1, 2, 3), VersionRange(4, 5, 6)}},
745 false /* optional */,
746 testHalInterfaces()}));
747 EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE,
748 "android.hardware.nfc",
749 {{VersionRange(4, 5, 6), VersionRange(10, 11, 12)}},
750 true /* optional */,
751 testHalInterfaces()}));
752
753 MatrixHal expectedCameraHal = MatrixHal{
754 HalFormat::NATIVE,
755 "android.hardware.camera",
756 {{VersionRange(1, 2, 3), VersionRange(4, 5, 6)}},
757 false /* optional */,
758 testHalInterfaces(),
759 };
760 MatrixHal expectedNfcHal = MatrixHal{HalFormat::NATIVE,
761 "android.hardware.nfc",
762 {{VersionRange(4, 5, 6), VersionRange(10, 11, 12)}},
763 true /* optional */,
764 testHalInterfaces()};
765 auto cameraHals = cm.getHals("android.hardware.camera");
766 EXPECT_EQ((int)cameraHals.size(), 1);
767 EXPECT_EQ(*cameraHals[0], expectedCameraHal);
768 auto nfcHals = cm.getHals("android.hardware.nfc");
769 EXPECT_EQ((int)nfcHals.size(), 1);
770 EXPECT_EQ(*nfcHals[0], expectedNfcHal);
771
772 EXPECT_EQ(*cm.getHal("android.hardware.camera", {1, 2}), expectedCameraHal);
773 EXPECT_EQ(*cm.getHal("android.hardware.camera", {1, 3}), expectedCameraHal);
774 EXPECT_EQ(*cm.getHal("android.hardware.camera", {4, 5}), expectedCameraHal);
775 EXPECT_EQ(*cm.getHal("android.hardware.nfc", {4, 5}), expectedNfcHal);
776 EXPECT_EQ(*cm.getHal("android.hardware.nfc", {10, 12}), expectedNfcHal);
777
778 EXPECT_EQ(cm.getHal("non-existent", {1, 0}), nullptr);
779 EXPECT_EQ(cm.getHal("android.hardware.camera", {2, 1}), nullptr);
780 EXPECT_EQ(cm.getHal("android.hardware.camera", {1, 0}), nullptr);
781 EXPECT_EQ(cm.getHal("android.hardware.nfc", {3, 0}), nullptr);
782 EXPECT_EQ(cm.getHal("android.hardware.nfc", {4, 7}), nullptr);
783}
784
686TEST_F(LibVintfTest, RuntimeInfo) { 785TEST_F(LibVintfTest, RuntimeInfo) {
687 RuntimeInfo ki = testRuntimeInfo(); 786 RuntimeInfo ki = testRuntimeInfo();
688 using KernelConfigs = std::vector<KernelConfig>; 787 using KernelConfigs = std::vector<KernelConfig>;