/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "LibVintfTest" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "constants-private.h" #include "parse_xml_for_test.h" #include "parse_xml_internal.h" #include "test_constants.h" #include "utils.h" using android::base::StringPrintf; using ::testing::Combine; using ::testing::ElementsAre; using ::testing::Eq; using ::testing::HasSubstr; using ::testing::IsEmpty; using ::testing::Optional; using ::testing::Property; using ::testing::Range; using ::testing::SizeIs; using ::testing::TestParamInfo; using std::string_literals::operator""s; namespace android { namespace vintf { #define EXPECT_IN(sub, str) EXPECT_THAT(str, HasSubstr(sub)) struct LibVintfTest : public ::testing::Test { public: virtual void SetUp() override { } virtual void TearDown() override { } bool add(CompatibilityMatrix &cm, MatrixHal &&hal) { return cm.add(std::move(hal)); } bool add(CompatibilityMatrix &cm, MatrixKernel &&kernel) { std::string error; bool success = cm.addKernel(std::move(kernel), &error); EXPECT_EQ(success, error == "") << "success: " << success << ", error: " << error; return success; } bool add(HalManifest& vm, ManifestHal&& hal) { return vm.add(std::move(hal), nullptr); } void addXmlFile(CompatibilityMatrix& cm, std::string name, VersionRange range) { MatrixXmlFile f; f.mName = name; f.mVersionRange = range; f.mFormat = XmlSchemaFormat::DTD; f.mOptional = true; cm.addXmlFile(std::move(f)); } void set(CompatibilityMatrix &cm, Sepolicy &&sepolicy) { cm.framework.mSepolicy = sepolicy; } void set(CompatibilityMatrix &cm, SchemaType type) { cm.mType = type; } void set(CompatibilityMatrix &cm, VndkVersionRange &&range, std::set &&libs) { cm.device.mVndk.mVersionRange = range; cm.device.mVndk.mLibraries = libs; } void setAvb(RuntimeInfo &ki, Version vbmeta, Version boot) { ki.mBootVbmetaAvbVersion = vbmeta; ki.mBootAvbVersion = boot; } void setAvb(CompatibilityMatrix &cm, Version &&avbVersion) { cm.framework.mAvbMetaVersion = avbVersion; } Version getAvb(CompatibilityMatrix &cm) { return cm.framework.mAvbMetaVersion; } const ManifestHal *getAnyHal(HalManifest &vm, const std::string &name) { return vm.getAnyHal(name); } MatrixHal *getAnyHal(CompatibilityMatrix &cm, const std::string &name) { return cm.getAnyHal(name); } ConstMultiMapValueIterable getHals(const HalManifest& vm) { return vm.getHals(); } std::vector getHals(const HalManifest& vm, const std::string& name) { return vm.getHals(name); } std::vector getHals(const CompatibilityMatrix& cm, const std::string& name) { return cm.getHals(name); } bool isValid(const ManifestHal &mh) { return mh.isValid(); } std::vector& getKernels(CompatibilityMatrix& cm) { return cm.framework.mKernels; } bool addAllHalsAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2, std::string* e) { return cm1->addAllHalsAsOptional(cm2, e); } bool addAllXmlFilesAsOptional(CompatibilityMatrix* cm1, CompatibilityMatrix* cm2, std::string* e) { return cm1->addAllXmlFilesAsOptional(cm2, e); } std::set checkUnusedHals(const HalManifest& m, const CompatibilityMatrix& cm) { return m.checkUnusedHals(cm, {}); } Level getLevel(const KernelInfo& ki) { return ki.level(); } static status_t parseGkiKernelRelease(RuntimeInfo::FetchFlags flags, const std::string& kernelRelease, KernelVersion* version, Level* kernelLevel) { return RuntimeInfo::parseGkiKernelRelease(flags, kernelRelease, version, kernelLevel); } std::map testHalInterfaces() { HalInterface intf("IFoo", {"default"}); std::map map; map[intf.name()] = intf; return map; } ManifestHal createManifestHal(HalFormat format, std::string name, TransportArch ta, const std::set& fqInstances) { ManifestHal ret; ret.format = format; ret.name = std::move(name); ret.transportArch = ta; std::string error; EXPECT_TRUE(ret.insertInstances(fqInstances, false, &error)) << error; return ret; } HalManifest testDeviceManifestWithSepolicy(SepolicyVersion sepolicyVersion) { HalManifest vm; vm.mType = SchemaType::DEVICE; vm.device.mSepolicyVersion = sepolicyVersion; vm.add(createManifestHal(HalFormat::HIDL, "android.hardware.camera", {Transport::HWBINDER, Arch::ARCH_EMPTY}, { *FqInstance::from(2, 0, "ICamera", "legacy/0"), *FqInstance::from(2, 0, "ICamera", "default"), *FqInstance::from(2, 0, "IBetterCamera", "camera"), })); vm.add(createManifestHal(HalFormat::HIDL, "android.hardware.nfc", {Transport::PASSTHROUGH, Arch::ARCH_32_64}, std::set({*FqInstance::from(1, 0, "INfc", "default")}))); return vm; } HalManifest testDeviceManifest() { return testDeviceManifestWithSepolicy({25, 0}); } HalManifest testDeviceManifestWithXmlFile() { HalManifest vm = testDeviceManifest(); ManifestXmlFile xmlFile; xmlFile.mName = "media_profile"; xmlFile.mVersion = {1, 0}; vm.addXmlFile(std::move(xmlFile)); return vm; } HalManifest testFrameworkManfiest() { HalManifest vm; vm.mType = SchemaType::FRAMEWORK; vm.add(createManifestHal( HalFormat::HIDL, "android.hidl.manager", {Transport::HWBINDER, Arch::ARCH_EMPTY}, std::set({*FqInstance::from(1, 0, "IServiceManager", "default")}))); Vndk vndk2505; vndk2505.mVersionRange = {25, 0, 5}; vndk2505.mLibraries = {"libjpeg.so", "libbase.so"}; Vndk vndk2513; vndk2513.mVersionRange = {25, 1, 3}; vndk2513.mLibraries = {"libjpeg.so", "libbase.so", "libtinyxml2.so"}; vm.framework.mVndks = { std::move(vndk2505), std::move(vndk2513) }; return vm; } RuntimeInfo testRuntimeInfo() { RuntimeInfo info; info.mOsName = "Linux"; info.mNodeName = "localhost"; info.mOsRelease = "3.18.31-g936f9a479d0f"; info.mOsVersion = "#4 SMP PREEMPT Wed Feb 1 18:10:52 PST 2017"; info.mHardwareId = "aarch64"; info.mKernelSepolicyVersion = 30; info.mKernel = testKernelInfo(); setAvb(info, {2, 1}, {2, 1}); return info; } KernelInfo testKernelInfo() { KernelInfo info; info.mVersion = {3, 18, 31}; info.mConfigs = {{"CONFIG_64BIT", "y"}, {"CONFIG_ANDROID_BINDER_DEVICES", "\"binder,hwbinder\""}, {"CONFIG_ARCH_MMAP_RND_BITS", "24"}, {"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", "\"\""}, {"CONFIG_ILLEGAL_POINTER_VALUE", "0xdead000000000000"}}; return info; } status_t fetchManifest(HalManifest& manifest, FileSystem* files, const std::string& path, std::string* error) { return manifest.fetchAllInformation(files, path, error); } }; // clang-format off TEST_F(LibVintfTest, ArchOperatorOr) { Arch a = Arch::ARCH_EMPTY; a |= Arch::ARCH_32; EXPECT_EQ(Arch::ARCH_32, a); a |= Arch::ARCH_64; EXPECT_EQ(Arch::ARCH_32_64, a); a = Arch::ARCH_EMPTY; a |= Arch::ARCH_64; EXPECT_EQ(Arch::ARCH_64, a); } TEST_F(LibVintfTest, Stringify) { HalManifest vm = testDeviceManifest(); EXPECT_EQ(dump(vm), "hidl/android.hardware.camera/hwbinder/:" "hidl/android.hardware.nfc/passthrough32+64/"); EXPECT_EQ(to_string(HalFormat::HIDL), "hidl"); EXPECT_EQ(to_string(HalFormat::NATIVE), "native"); VersionRange v(1, 2, 3); EXPECT_EQ(to_string(v), "1.2-3"); VersionRange v2; EXPECT_TRUE(parse("1.2-3", &v2)); EXPECT_EQ(v, v2); SepolicyVersionRange v3(4, std::nullopt); EXPECT_EQ(to_string(v3), "4"); SepolicyVersionRange v4; EXPECT_TRUE(parse("4", &v4)); EXPECT_EQ(v3, v4); SepolicyVersion v5(5, std::nullopt); EXPECT_EQ(to_string(v5), "5"); SepolicyVersion v6; EXPECT_TRUE(parse("5", &v6)); EXPECT_EQ(v5, v6); } TEST_F(LibVintfTest, GetTransport) { HalManifest vm = testDeviceManifest(); EXPECT_EQ(Transport::HWBINDER, vm.getHidlTransport("android.hardware.camera", {2, 0}, "ICamera", "default")); } TEST_F(LibVintfTest, FutureManifestCompatible) { HalManifest expectedManifest; expectedManifest.add(createManifestHal(HalFormat::HIDL, "android.hardware.foo", {Transport::HWBINDER, Arch::ARCH_EMPTY}, {*FqInstance::from(1, 0, "IFoo", "default")})); std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml)); EXPECT_EQ(expectedManifest, manifest); } TEST_F(LibVintfTest, HalManifestConverter) { HalManifest vm = testDeviceManifest(); std::string xml = toXml(vm, SerializeFlags::HALS_ONLY.enableSepolicy()); EXPECT_EQ(xml, "\n" " \n" " android.hardware.camera\n" " hwbinder\n" " @2.0::IBetterCamera/camera\n" " @2.0::ICamera/default\n" " @2.0::ICamera/legacy/0\n" " \n" " \n" " android.hardware.nfc\n" " passthrough\n" " @1.0::INfc/default\n" " \n" " \n" " 25.0\n" " \n" "\n"); HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, HalManifestConverterWithVfrcSepolicy) { HalManifest vm = testDeviceManifestWithSepolicy({202404, std::nullopt}); std::string xml = toXml(vm, SerializeFlags::HALS_ONLY.enableSepolicy()); EXPECT_EQ(xml, "\n" " \n" " android.hardware.camera\n" " hwbinder\n" " @2.0::IBetterCamera/camera\n" " @2.0::ICamera/default\n" " @2.0::ICamera/legacy/0\n" " \n" " \n" " android.hardware.nfc\n" " passthrough\n" " @1.0::INfc/default\n" " \n" " \n" " 202404\n" " \n" "\n"); HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, HalManifestConverterWithInterface) { HalManifest vm = testDeviceManifest(); std::string xml = "\n" " \n" " android.hardware.camera\n" " hwbinder\n" " 2.0\n" " \n" " IBetterCamera\n" " camera\n" " \n" " \n" " ICamera\n" " default\n" " legacy/0\n" " \n" " \n" " \n" " android.hardware.nfc\n" " passthrough\n" " 1.0\n" " \n" " INfc\n" " default\n" " \n" " \n" " \n" " 25.0\n" " \n" "\n"; HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, HalManifestConverterFramework) { HalManifest vm = testFrameworkManfiest(); std::string xml = toXml(vm, SerializeFlags::HALS_ONLY.enableVndk()); EXPECT_EQ(xml, "\n" " \n" " android.hidl.manager\n" " hwbinder\n" " @1.0::IServiceManager/default\n" " \n" " \n" " 25.0.5\n" " libbase.so\n" " libjpeg.so\n" " \n" " \n" " 25.1.3\n" " libbase.so\n" " libjpeg.so\n" " libtinyxml2.so\n" " \n" "\n"); HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, HalManifestConverterFrameworkWithInterface) { HalManifest vm = testFrameworkManfiest(); std::string xml = "\n" " \n" " android.hidl.manager\n" " hwbinder\n" " 1.0\n" " \n" " IServiceManager\n" " default\n" " \n" " \n" " \n" " 25.0.5\n" " libbase.so\n" " libjpeg.so\n" " \n" " \n" " 25.1.3\n" " libbase.so\n" " libjpeg.so\n" " libtinyxml2.so\n" " \n" "\n"; HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, HalManifestOptional) { HalManifest vm; EXPECT_TRUE(fromXml(&vm, "")); EXPECT_TRUE(fromXml(&vm, "" " " " android.hidl.manager" " hwbinder" " 1.0" " " "")); EXPECT_FALSE(fromXml(&vm, "" " " " android.hidl.manager" " 1.0" " " "")); } TEST_F(LibVintfTest, HalManifestNativeNoInstance) { std::string error; HalManifest vm; EXPECT_TRUE(fromXml(&vm, "" " " " foo" " 1.0" " " "", &error)) << error; } TEST_F(LibVintfTest, HalManifestNativeWithTransport) { std::string error; HalManifest vm; EXPECT_FALSE(fromXml(&vm, "" " " " foo" " 1.0" " hwbinder" " " "", &error)); EXPECT_THAT(error, HasSubstr("Native HAL 'foo' should not have defined")); } // clang-format on TEST_F(LibVintfTest, HalManifestNativeInstancesWithInterface) { std::string error; HalManifest manifest; std::string xml = " foo 1.0 IFoo inst )"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; manifest.forEachInstance([](const auto& manifestInstance) { EXPECT_EQ(manifestInstance.package(), "foo"); EXPECT_EQ(manifestInstance.version(), Version(1, 0)); EXPECT_EQ(manifestInstance.interface(), "IFoo"); EXPECT_EQ(manifestInstance.instance(), "inst"); return true; // continue }); } TEST_F(LibVintfTest, HalManifestNativeFqInstancesWithInterface) { std::string error; HalManifest manifest; std::string xml = " foo @1.0::IFoo/inst )"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; manifest.forEachInstance([](const auto& manifestInstance) { EXPECT_EQ(manifestInstance.package(), "foo"); EXPECT_EQ(manifestInstance.version(), Version(1, 0)); EXPECT_EQ(manifestInstance.interface(), "IFoo"); EXPECT_EQ(manifestInstance.instance(), "inst"); return true; // continue }); } TEST_F(LibVintfTest, HalManifestNativeInstancesNoInterface) { std::string error; HalManifest manifest; std::string xml = " foo 1.0 inst )"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; manifest.forEachInstance([](const auto& manifestInstance) { EXPECT_EQ(manifestInstance.package(), "foo"); EXPECT_EQ(manifestInstance.version(), Version(1, 0)); EXPECT_EQ(manifestInstance.interface(), ""); EXPECT_EQ(manifestInstance.instance(), "inst"); return true; // continue }); } TEST_F(LibVintfTest, HalManifestNativeFqInstancesNoInterface) { std::string error; HalManifest manifest; std::string xml = " foo @1.0/inst )"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; manifest.forEachInstance([](const auto& manifestInstance) { EXPECT_EQ(manifestInstance.package(), "foo"); EXPECT_EQ(manifestInstance.version(), Version(1, 0)); EXPECT_EQ(manifestInstance.interface(), ""); EXPECT_EQ(manifestInstance.instance(), "inst"); return true; // continue }); } TEST_F(LibVintfTest, QueryNativeInstances) { std::string error; HalManifest manifest; std::string xml = " foo 1.0 fooinst bar @1.0::I/barinst )"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(manifest.getNativeInstances("foo"), std::set{"fooinst"}); EXPECT_TRUE(manifest.hasNativeInstance("foo", "fooinst")); EXPECT_EQ(manifest.getNativeInstances("bar"), std::set{"barinst"}); EXPECT_TRUE(manifest.hasNativeInstance("bar", "barinst")); EXPECT_EQ(manifest.getNativeInstances("baz"), std::set{}); EXPECT_FALSE(manifest.hasNativeInstance("baz", "bazinst")); } // clang-format off TEST_F(LibVintfTest, HalManifestDuplicate) { HalManifest vm; EXPECT_FALSE(fromXml(&vm, "" " " " android.hidl.manager" " hwbinder" " 1.0" " 1.1" " " "")) << "Should not allow duplicated major version in "; EXPECT_FALSE(fromXml(&vm, "" " " " android.hidl.manager" " hwbinder" " 1.0" " " " " " android.hidl.manager" " passthrough" " 1.1" " " "")) << "Should not allow duplicated major version across "; } TEST_F(LibVintfTest, HalManifestGetTransport) { HalManifest vm; EXPECT_TRUE(fromXml(&vm, "" " " " android.hidl.manager" " hwbinder" " 1.0" " " " IServiceManager" " default" " " " " " " " android.hidl.manager" " passthrough" " 2.1" " " " IServiceManager" " default" " " " " "")); EXPECT_EQ(Transport::PASSTHROUGH, vm.getHidlTransport("android.hidl.manager", {2, 1}, "IServiceManager", "default")); EXPECT_EQ(Transport::PASSTHROUGH, vm.getHidlTransport("android.hidl.manager", {2, 0}, "IServiceManager", "default")); EXPECT_EQ(Transport::EMPTY, vm.getHidlTransport("android.hidl.manager", {2, 2}, "IServiceManager", "default")); EXPECT_EQ(Transport::HWBINDER, vm.getHidlTransport("android.hidl.manager", {1, 0}, "IServiceManager", "default")); } TEST_F(LibVintfTest, HalManifestInstances) { HalManifest vm = testDeviceManifest(); EXPECT_EQ(vm.getHidlInstances("android.hardware.camera", {2, 0}, "ICamera"), std::set({"default", "legacy/0"})); EXPECT_EQ(vm.getHidlInstances("android.hardware.camera", {2, 0}, "IBetterCamera"), std::set({"camera"})); EXPECT_EQ(vm.getHidlInstances("android.hardware.camera", {2, 0}, "INotExist"), std::set({})); EXPECT_EQ(vm.getHidlInstances("android.hardware.nfc", {1, 0}, "INfc"), std::set({"default"})); EXPECT_TRUE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "ICamera", "default")); EXPECT_TRUE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "ICamera", "legacy/0")); EXPECT_TRUE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "IBetterCamera", "camera")); EXPECT_TRUE(vm.hasHidlInstance("android.hardware.nfc", {1, 0}, "INfc", "default")); EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "INotExist", "default")); EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "ICamera", "notexist")); EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "IBetterCamera", "default")); EXPECT_FALSE(vm.hasHidlInstance("android.hardware.camera", {2, 0}, "INotExist", "notexist")); EXPECT_FALSE(vm.hasHidlInstance("android.hardware.nfc", {1, 0}, "INfc", "notexist")); } TEST_F(LibVintfTest, VersionConverter) { Version v(3, 6); std::string xml = toXml(v); EXPECT_EQ(xml, "3.6\n"); Version v2; EXPECT_TRUE(fromXml(&v2, xml)); EXPECT_EQ(v, v2); SepolicyVersion v3(202404, std::nullopt); std::string xml2 = toXml(v3); EXPECT_EQ(xml2, "202404\n"); SepolicyVersion v4; EXPECT_TRUE(fromXml(&v4, xml2)); EXPECT_EQ(v3, v4); } static bool insert(std::map* map, HalInterface&& intf) { std::string name{intf.name()}; return map->emplace(std::move(name), std::move(intf)).second; } TEST_F(LibVintfTest, MatrixHalConverter) { MatrixHal mh{HalFormat::NATIVE, "android.hardware.camera", {{VersionRange(1,2,3), VersionRange(4,5,6)}}, false /* optional */, false /* updatableViaApex */, {}}; EXPECT_TRUE(insert(&mh.interfaces, {"IBetterCamera", {"default", "great"}})); EXPECT_TRUE(insert(&mh.interfaces, {"ICamera", {"default"}})); std::string xml = toXml(mh); EXPECT_EQ(xml, "\n" " android.hardware.camera\n" " 1.2-3\n" " 4.5-6\n" " \n" " IBetterCamera\n" " default\n" " great\n" " \n" " \n" " ICamera\n" " default\n" " \n" "\n"); MatrixHal mh2; EXPECT_TRUE(fromXml(&mh2, xml)); EXPECT_EQ(mh, mh2); } TEST_F(LibVintfTest, KernelConfigTypedValueConverter) { KernelConfigTypedValue converted; auto testOne = [] (const KernelConfigTypedValue &original, const std::string &expectXml) { std::string xml; KernelConfigTypedValue converted; xml = toXml(original); EXPECT_EQ(xml, expectXml); EXPECT_TRUE(fromXml(&converted, xml)); EXPECT_EQ(original, converted); }; auto testParse = [] (const KernelConfigTypedValue &original, const std::string &xml) { KernelConfigTypedValue converted; EXPECT_TRUE(fromXml(&converted, xml)); EXPECT_EQ(original, converted); }; testOne(KernelConfigTypedValue("stringvalue"), "stringvalue\n"); testOne(KernelConfigTypedValue(""), "\n"); testOne(KernelConfigTypedValue(Tristate::YES), "y\n"); testOne(KernelConfigTypedValue(Tristate::NO), "n\n"); testOne(KernelConfigTypedValue(Tristate::MODULE), "m\n"); EXPECT_FALSE(fromXml(&converted, "q\n")); testOne(KernelConfigTypedValue(KernelConfigRangeValue{4, 20}), "4-20\n"); testOne(KernelConfigTypedValue(KernelConfigRangeValue{0, UINT64_MAX}), "0-18446744073709551615\n"); testParse(KernelConfigTypedValue(KernelConfigRangeValue{0, UINT64_MAX}), "0x0-0xffffffffffffffff\n"); EXPECT_FALSE(fromXml(&converted, "-18446744073709551616\n")); testOne(KernelConfigTypedValue(INT64_MIN), "-9223372036854775808\n"); testParse(KernelConfigTypedValue(INT64_MIN), "0x8000000000000000\n"); testParse(KernelConfigTypedValue(INT64_MIN), "-0X8000000000000000\n"); testParse(KernelConfigTypedValue(INT64_MIN + 1), "-0X7FFFFFFFFFFFFFFF\n"); testParse(KernelConfigTypedValue(-0x50), "-0x50\n"); testOne(KernelConfigTypedValue(0), "0\n"); // Truncation for underflow. testParse(KernelConfigTypedValue(1), "-0xffffffffffffffff\n"); testParse(KernelConfigTypedValue(1), "-18446744073709551615\n"); testOne(KernelConfigTypedValue(INT64_MAX), "9223372036854775807\n"); testParse(KernelConfigTypedValue(INT64_MAX), "0x7FFFFFFFFFFFFFFF\n"); // Truncation for underflow. testParse(KernelConfigTypedValue(INT64_MAX), "-9223372036854775809\n"); testParse(KernelConfigTypedValue(-1), "18446744073709551615\n"); testParse(KernelConfigTypedValue(-1), "0xffffffffffffffff\n"); EXPECT_FALSE(fromXml(&converted, "18446744073709551616\n")); } TEST_F(LibVintfTest, CompatibilityMatrixConverter) { CompatibilityMatrix cm; EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.camera", {{VersionRange(1,2,3), VersionRange(4,5,6)}}, false /* optional */, false /* updatableViaApex */, testHalInterfaces()})); EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.nfc", {{VersionRange(4,5,6), VersionRange(10,11,12)}}, true /* optional */, false /* updatableViaApex */, testHalInterfaces()})); EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(3, 18, 22), {KernelConfig{"CONFIG_FOO", Tristate::YES}, KernelConfig{"CONFIG_BAR", "stringvalue"}}})); EXPECT_TRUE(add(cm, MatrixKernel{KernelVersion(4, 4, 1), {KernelConfig{"CONFIG_BAZ", 20}, KernelConfig{"CONFIG_BAR", KernelConfigRangeValue{3, 5} }}})); set(cm, Sepolicy(30, {{25, 0}, {26, 0, 3}, {202404, std::nullopt}})); setAvb(cm, Version{2, 1}); std::string xml = toXml(cm); EXPECT_EQ(xml, "\n" " \n" " android.hardware.camera\n" " 1.2-3\n" " 4.5-6\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.nfc\n" " 4.5-6\n" " 10.11-12\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " \n" " CONFIG_FOO\n" " y\n" " \n" " \n" " CONFIG_BAR\n" " stringvalue\n" " \n" " \n" " \n" " \n" " CONFIG_BAZ\n" " 20\n" " \n" " \n" " CONFIG_BAR\n" " 3-5\n" " \n" " \n" " \n" " 30\n" " 25.0\n" " 26.0-3\n" " 202404\n" " \n" " \n" " 2.1\n" " \n" "\n"); CompatibilityMatrix cm2; EXPECT_TRUE(fromXml(&cm2, xml)); EXPECT_EQ(cm, cm2); } TEST_F(LibVintfTest, DeviceCompatibilityMatrixCoverter) { CompatibilityMatrix cm; EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hidl.manager", {{VersionRange(1,0)}}, false /* optional */, false /* updatableViaApex */, testHalInterfaces()})); set(cm, SchemaType::DEVICE); set(cm, VndkVersionRange{25,0,1,5}, {"libjpeg.so", "libbase.so"}); std::string xml = toXml(cm); EXPECT_EQ(xml, "\n" " \n" " android.hidl.manager\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " 25.0.1-5\n" " libbase.so\n" " libjpeg.so\n" " \n" "\n"); CompatibilityMatrix cm2; EXPECT_TRUE(fromXml(&cm2, xml)); EXPECT_EQ(cm, cm2); } // clang-format on TEST_F(LibVintfTest, CompatibilityMatrixDefaultOptionalTrue) { auto xml = " android.foo.bar 1 IFoo default )"; CompatibilityMatrix cm; EXPECT_TRUE(fromXml(&cm, xml)); auto hal = getAnyHal(cm, "android.foo.bar"); ASSERT_NE(nullptr, hal); EXPECT_TRUE(hal->optional) << "If optional is not specified, it should be true by default"; } TEST_F(LibVintfTest, IsValid) { EXPECT_TRUE(isValid(ManifestHal())); auto invalidHal = createManifestHal(HalFormat::HIDL, "android.hardware.camera", {Transport::PASSTHROUGH, Arch::ARCH_32_64}, {}); invalidHal.versions = {{Version(2, 0), Version(2, 1)}}; EXPECT_FALSE(isValid(invalidHal)); HalManifest vm2; EXPECT_FALSE(add(vm2, std::move(invalidHal))); } // clang-format off TEST_F(LibVintfTest, HalManifestGetHalNames) { HalManifest vm = testDeviceManifest(); EXPECT_EQ(vm.getHalNames(), std::set( {"android.hardware.camera", "android.hardware.nfc"})); } TEST_F(LibVintfTest, HalManifestGetAllHals) { HalManifest vm = testDeviceManifest(); EXPECT_NE(getAnyHal(vm, "android.hardware.camera"), nullptr); EXPECT_EQ(getAnyHal(vm, "non-existent"), nullptr); std::vector arr{"android.hardware.camera", "android.hardware.nfc"}; size_t i = 0; for (const auto &hal : getHals(vm)) { EXPECT_EQ(hal.name, arr[i++]); } } // clang-format on TEST_F(LibVintfTest, HalManifestGetHals) { HalManifest vm; EXPECT_TRUE(add(vm, createManifestHal(HalFormat::HIDL, "android.hardware.camera", {Transport::HWBINDER, Arch::ARCH_EMPTY}, { *FqInstance::from(1, 2, "ICamera", "legacy/0"), *FqInstance::from(1, 2, "ICamera", "default"), *FqInstance::from(1, 2, "IBetterCamera", "camera"), }))); EXPECT_TRUE(add(vm, createManifestHal(HalFormat::HIDL, "android.hardware.camera", {Transport::HWBINDER, Arch::ARCH_EMPTY}, { *FqInstance::from(2, 0, "ICamera", "legacy/0"), *FqInstance::from(2, 0, "ICamera", "default"), *FqInstance::from(2, 0, "IBetterCamera", "camera"), }))); EXPECT_TRUE(add(vm, createManifestHal(HalFormat::HIDL, "android.hardware.nfc", {Transport::PASSTHROUGH, Arch::ARCH_32_64}, {*FqInstance::from(1, 0, "INfc", "default"), *FqInstance::from(2, 1, "INfc", "default")}))); ManifestHal expectedCameraHalV1_2 = createManifestHal( HalFormat::HIDL, "android.hardware.camera", {Transport::HWBINDER, Arch::ARCH_EMPTY}, { *FqInstance::from(1, 2, "ICamera", "legacy/0"), *FqInstance::from(1, 2, "ICamera", "default"), *FqInstance::from(1, 2, "IBetterCamera", "camera"), }); ManifestHal expectedCameraHalV2_0 = createManifestHal( HalFormat::HIDL, "android.hardware.camera", {Transport::HWBINDER, Arch::ARCH_EMPTY}, { *FqInstance::from(2, 0, "ICamera", "legacy/0"), *FqInstance::from(2, 0, "ICamera", "default"), *FqInstance::from(2, 0, "IBetterCamera", "camera"), }); ManifestHal expectedNfcHal = createManifestHal( HalFormat::HIDL, "android.hardware.nfc", {Transport::PASSTHROUGH, Arch::ARCH_32_64}, {*FqInstance::from(1, 0, "INfc", "default"), *FqInstance::from(2, 1, "INfc", "default")}); auto cameraHals = getHals(vm, "android.hardware.camera"); EXPECT_EQ((int)cameraHals.size(), 2); EXPECT_EQ(*cameraHals[0], expectedCameraHalV1_2); EXPECT_EQ(*cameraHals[1], expectedCameraHalV2_0); auto nfcHals = getHals(vm, "android.hardware.nfc"); EXPECT_EQ((int)nfcHals.size(), 1); EXPECT_EQ(*nfcHals[0], expectedNfcHal); } // clang-format off TEST_F(LibVintfTest, CompatibilityMatrixGetHals) { CompatibilityMatrix cm; EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.camera", {{VersionRange(1, 2, 3), VersionRange(4, 5, 6)}}, false /* optional */, false /* updatableViaApex */, testHalInterfaces()})); EXPECT_TRUE(add(cm, MatrixHal{HalFormat::NATIVE, "android.hardware.nfc", {{VersionRange(4, 5, 6), VersionRange(10, 11, 12)}}, true /* optional */, false /* updatableViaApex */, testHalInterfaces()})); MatrixHal expectedCameraHal = MatrixHal{ HalFormat::NATIVE, "android.hardware.camera", {{VersionRange(1, 2, 3), VersionRange(4, 5, 6)}}, false /* optional */, false /* updatableViaApex */, testHalInterfaces(), }; MatrixHal expectedNfcHal = MatrixHal{HalFormat::NATIVE, "android.hardware.nfc", {{VersionRange(4, 5, 6), VersionRange(10, 11, 12)}}, true /* optional */, false /* updatableViaApex */, testHalInterfaces()}; auto cameraHals = getHals(cm, "android.hardware.camera"); EXPECT_EQ((int)cameraHals.size(), 1); EXPECT_EQ(*cameraHals[0], expectedCameraHal); auto nfcHals = getHals(cm, "android.hardware.nfc"); EXPECT_EQ((int)nfcHals.size(), 1); EXPECT_EQ(*nfcHals[0], expectedNfcHal); } TEST_F(LibVintfTest, RuntimeInfo) { RuntimeInfo ki = testRuntimeInfo(); using KernelConfigs = std::vector; const KernelConfigs configs { KernelConfig{"CONFIG_64BIT", Tristate::YES}, KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", "binder,hwbinder"}, KernelConfig{"CONFIG_ARCH_MMAP_RND_BITS", 24}, KernelConfig{"CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES", ""}, KernelConfig{"CONFIG_ILLEGAL_POINTER_VALUE", 0xdead000000000000}, KernelConfig{"CONFIG_NOTEXIST", Tristate::NO}, }; auto testMatrix = [&] (MatrixKernel &&kernel) { CompatibilityMatrix cm; add(cm, std::move(kernel)); set(cm, {30, {{25, 0}}}); setAvb(cm, {2, 1}); return cm; }; std::string error; { MatrixKernel kernel(KernelVersion{4, 4, 1}, KernelConfigs(configs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Kernel version shouldn't match"; } { MatrixKernel kernel(KernelVersion{3, 18, 60}, KernelConfigs(configs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Kernel version shouldn't match"; } { MatrixKernel kernel(KernelVersion{3, 18, 22}, KernelConfigs(configs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_TRUE(ki.checkCompatibility(cm, &error)) << error; } { MatrixKernel kernel(KernelVersion{3, 18, 22}, KernelConfigs(configs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); set(cm, Sepolicy{22, {{25, 0}}}); EXPECT_TRUE(ki.checkCompatibility(cm, &error)) << error; set(cm, Sepolicy{40, {{25, 0}}}); EXPECT_FALSE(ki.checkCompatibility(cm, &error)) << "kernel-sepolicy-version shouldn't match"; EXPECT_IN("kernelSepolicyVersion = 30 but required >= 40", error); } { KernelConfigs newConfigs(configs); newConfigs[0] = KernelConfig{"CONFIG_64BIT", Tristate::NO}; MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for tristate"; } { KernelConfigs newConfigs(configs); newConfigs[0] = KernelConfig{"CONFIG_64BIT", 20}; MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Type shouldn't match"; } { KernelConfigs newConfigs(configs); newConfigs[1] = KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", "binder"}; MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for string"; } { KernelConfigs newConfigs(configs); newConfigs[1] = KernelConfig{"CONFIG_ANDROID_BINDER_DEVICES", Tristate::YES}; MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Type shouldn't match"; } { KernelConfigs newConfigs(configs); newConfigs[2] = KernelConfig{"CONFIG_ARCH_MMAP_RND_BITS", 30}; MatrixKernel kernel(KernelVersion{3, 18, 22}, std::move(newConfigs)); CompatibilityMatrix cm = testMatrix(std::move(kernel)); EXPECT_FALSE(ki.checkCompatibility(cm)) << "Value shouldn't match for integer"; } RuntimeInfo badAvb = testRuntimeInfo(); CompatibilityMatrix cm = testMatrix(MatrixKernel(KernelVersion{3, 18, 31}, {})); { setAvb(badAvb, {1, 0}, {2, 1}); EXPECT_FALSE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS)); EXPECT_STREQ(error.c_str(), "Vbmeta version 1.0 does not match framework matrix 2.1"); } { setAvb(badAvb, {2, 1}, {3, 0}); EXPECT_FALSE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS)); } { setAvb(badAvb, {2, 1}, {2, 3}); EXPECT_TRUE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS)); } { setAvb(badAvb, {2, 3}, {2, 1}); EXPECT_TRUE(badAvb.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS)); } } TEST_F(LibVintfTest, MissingAvb) { std::string xml = "\n" " " " \n" " 30\n" " 25.5\n" " \n" "\n"; CompatibilityMatrix cm; EXPECT_TRUE(fromXml(&cm, xml)); EXPECT_EQ(getAvb(cm), Version(0, 0)); } TEST_F(LibVintfTest, DisableAvb) { std::string xml = "\n" " " " \n" " 30\n" " 25.5\n" " \n" " \n" " 1.0\n" " \n" "\n"; CompatibilityMatrix cm; EXPECT_TRUE(fromXml(&cm, xml)); RuntimeInfo ki = testRuntimeInfo(); std::string error; EXPECT_FALSE(ki.checkCompatibility(cm, &error, CheckFlags::ENABLE_ALL_CHECKS)); EXPECT_STREQ(error.c_str(), "AVB version 2.1 does not match framework matrix 1.0"); EXPECT_TRUE(ki.checkCompatibility(cm, &error, CheckFlags::DISABLE_AVB_CHECK)) << error; } // This is the test extracted from VINTF Object doc TEST_F(LibVintfTest, HalCompat) { CompatibilityMatrix matrix; std::string error; std::string matrixXml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " 3.1-2\n" " \n" " IFoo\n" " default\n" " specific\n" " \n" " \n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IBar\n" " default\n" " \n" " \n" " \n" " 30\n" " 25.5\n" " \n" "\n"; EXPECT_TRUE(fromXml(&matrix, matrixXml, &error)) << error; { std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " specific\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 2.0\n" " \n" " IBar\n" " default\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; } { std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " specific\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "should not be compatible because IBar is missing"; } { std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 2.0\n" " \n" " IBar\n" " default\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "should not be compatible because IFoo/specific is missing"; } { std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 3.3\n" " \n" " IFoo\n" " default\n" " specific\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 2.0\n" " \n" " IBar\n" " default\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; } { std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 3.2\n" " \n" " IFoo\n" " specific\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 2.0\n" " \n" " IBar\n" " default\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "should not be compatible even though @1.0::IFoo/default " << "and @3.2::IFoo/specific present"; } { std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " specific\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 2.0\n" " \n" " IBar\n" " default\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; } } TEST_F(LibVintfTest, FullCompat) { std::string manifestXml = "\n" " \n" " android.hardware.camera\n" " hwbinder\n" " 3.5\n" " \n" " IBetterCamera\n" " camera\n" " \n" " \n" " ICamera\n" " default\n" " legacy/0\n" " \n" " \n" " \n" " android.hardware.nfc\n" " hwbinder\n" " 1.0\n" " \n" " INfc\n" " nfc_nci\n" " \n" " \n" " \n" " android.hardware.nfc\n" " hwbinder\n" " 2.0\n" " \n" " INfc\n" " default\n" " nfc_nci\n" " \n" " \n" " \n" " 25.5\n" " \n" "\n"; std::string matrixXml = "\n" " \n" " android.hardware.camera\n" " 2.0-5\n" " 3.4-16\n" " \n" " IBetterCamera\n" " camera\n" " \n" " \n" " ICamera\n" " default\n" " legacy/0\n" " \n" " \n" " \n" " android.hardware.nfc\n" " 1.0\n" " 2.0\n" " \n" " INfc\n" " nfc_nci\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " \n" " 30\n" " 25.5\n" " 26.0-3\n" " 202404\n" " \n" " \n" " 2.1\n" " \n" "\n"; HalManifest manifest; CompatibilityMatrix matrix; std::string error; EXPECT_TRUE(fromXml(&manifest, manifestXml)); EXPECT_TRUE(fromXml(&matrix, matrixXml)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; // some smaller test cases matrixXml = "\n" " \n" " android.hardware.camera\n" " 3.4\n" " \n" " \n" " 30\n" " 25.5\n" " \n" " 2.1\n" "\n"; matrix = {}; EXPECT_TRUE(fromXml(&matrix, matrixXml)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; MatrixHal *camera = getAnyHal(matrix, "android.hardware.camera"); EXPECT_NE(camera, nullptr); camera->versionRanges[0] = {3, 5}; EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; camera->versionRanges[0] = {3, 6}; EXPECT_FALSE(manifest.checkCompatibility(matrix)); // reset it matrix = {}; EXPECT_TRUE(fromXml(&matrix, matrixXml)); set(matrix, Sepolicy{30, {{26, 0}}}); EXPECT_FALSE(manifest.checkCompatibility(matrix)); set(matrix, Sepolicy{30, {{25, 6}}}); EXPECT_FALSE(manifest.checkCompatibility(matrix)); set(matrix, Sepolicy{30, {{25, 4}}}); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; set(matrix, Sepolicy{30, {{202404, std::nullopt}}}); EXPECT_FALSE(manifest.checkCompatibility(matrix)); // vFRC sepolicy test cases manifestXml = "\n" " \n" " 202404\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml)); set(matrix, Sepolicy{30, {{202404, std::nullopt}}}); EXPECT_TRUE(manifest.checkCompatibility(matrix)) << error; set(matrix, Sepolicy{30, {{202404, 0}}}); EXPECT_FALSE(manifest.checkCompatibility(matrix)) << error; set(matrix, Sepolicy{30, {{202504, std::nullopt}}}); EXPECT_FALSE(manifest.checkCompatibility(matrix)); } // clang-format on TEST_F(LibVintfTest, ApexInterfaceShouldBeOkayWithoutApexInfoList) { details::FileSystemNoOp fs; details::PropertyFetcherNoOp pf; EXPECT_THAT(apex::GetModifiedTime(&fs, &pf), std::nullopt); std::vector dirs; ASSERT_EQ(OK, apex::GetDeviceVintfDirs(&fs, &pf, &dirs, nullptr)); ASSERT_EQ(dirs, std::vector{}); } struct NativeHalCompatTestParam { std::string matrixXml; std::string manifestXml; bool compatible; std::string expectedError; }; class NativeHalCompatTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::string matrixIntf = " foo 1.0 IFoo default )"; std::string matrixNoIntf = " foo 1.0 default )"; std::string matrixNoInst = " foo 1.0 )"; std::string manifestFqnameIntf = " foo @1.0::IFoo/default )"; std::string manifestLegacyIntf = " foo 1.0 IFoo default )"; std::string manifestFqnameNoIntf = " foo @1.0/default )"; std::string manifestLegacyNoIntf = " foo 1.0 default )"; std::string manifestNoInst = " foo 1.0 )"; std::vector ret; // If the matrix specifies interface name, the manifest must also do. ret.emplace_back(NativeHalCompatTestParam{matrixIntf, manifestFqnameIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixIntf, manifestLegacyIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixIntf, manifestFqnameNoIntf, false, "required: @1.0::IFoo/default"}); ret.emplace_back(NativeHalCompatTestParam{matrixIntf, manifestLegacyNoIntf, false, "required: @1.0::IFoo/default"}); ret.emplace_back(NativeHalCompatTestParam{matrixIntf, manifestNoInst, false, "required: @1.0::IFoo/default"}); // If the matrix does not specify an interface name, the manifest must not do that either. ret.emplace_back(NativeHalCompatTestParam{matrixNoIntf, manifestFqnameIntf, false, "required: @1.0/default"}); ret.emplace_back(NativeHalCompatTestParam{matrixNoIntf, manifestLegacyIntf, false, "required: @1.0/default"}); ret.emplace_back(NativeHalCompatTestParam{matrixNoIntf, manifestFqnameNoIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixNoIntf, manifestLegacyNoIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixNoIntf, manifestNoInst, false, "required: @1.0/default"}); // If the matrix does not specify interface name nor instances, the manifest may either // provide instances of that version, or just a version number with no instances. ret.emplace_back(NativeHalCompatTestParam{matrixNoInst, manifestFqnameIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixNoInst, manifestLegacyIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixNoInst, manifestFqnameNoIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixNoInst, manifestLegacyNoIntf, true, ""}); ret.emplace_back(NativeHalCompatTestParam{matrixNoInst, manifestNoInst, true, ""}); return ret; } }; TEST_P(NativeHalCompatTest, Compat) { auto params = GetParam(); std::string error; HalManifest manifest; ASSERT_TRUE(fromXml(&manifest, params.manifestXml, &error)) << error; CompatibilityMatrix matrix; ASSERT_TRUE(fromXml(&matrix, params.matrixXml, &error)) << error; EXPECT_EQ(params.compatible, manifest.checkCompatibility(matrix, &error)) << error; if (!params.expectedError.empty()) { EXPECT_THAT(error, HasSubstr(params.expectedError)); } else { EXPECT_THAT(error, IsEmpty()); } } INSTANTIATE_TEST_CASE_P(LibVintfTest, NativeHalCompatTest, ::testing::ValuesIn(NativeHalCompatTest::createParams())); // clang-format off /////////////////// xmlfile tests TEST_F(LibVintfTest, HalManifestConverterXmlFile) { HalManifest vm = testDeviceManifestWithXmlFile(); std::string xml = toXml( vm, SerializeFlags::HALS_ONLY.enableSepolicy().enableXmlFiles()); EXPECT_EQ(xml, "\n" " \n" " android.hardware.camera\n" " hwbinder\n" " @2.0::IBetterCamera/camera\n" " @2.0::ICamera/default\n" " @2.0::ICamera/legacy/0\n" " \n" " \n" " android.hardware.nfc\n" " passthrough\n" " @1.0::INfc/default\n" " \n" " \n" " 25.0\n" " \n" " \n" " media_profile\n" " 1.0\n" " \n" "\n"); HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, HalManifestConverterXmlFileWithInterface) { HalManifest vm = testDeviceManifestWithXmlFile(); std::string xml = "\n" " \n" " android.hardware.camera\n" " hwbinder\n" " 2.0\n" " \n" " IBetterCamera\n" " camera\n" " \n" " \n" " ICamera\n" " default\n" " legacy/0\n" " \n" " \n" " \n" " android.hardware.nfc\n" " passthrough\n" " 1.0\n" " \n" " INfc\n" " default\n" " \n" " \n" " \n" " 25.0\n" " \n" " \n" " media_profile\n" " 1.0\n" " \n" "\n"; HalManifest vm2; EXPECT_TRUE(fromXml(&vm2, xml)); EXPECT_EQ(vm, vm2); } TEST_F(LibVintfTest, CompatibilityMatrixConverterXmlFile) { CompatibilityMatrix cm; addXmlFile(cm, "media_profile", {1, 0}); std::string xml = toXml(cm, SerializeFlags::XMLFILES_ONLY); EXPECT_EQ(xml, "\n" " \n" " media_profile\n" " 1.0\n" " \n" "\n"); CompatibilityMatrix cm2; EXPECT_TRUE(fromXml(&cm2, xml)); EXPECT_EQ(cm, cm2); } TEST_F(LibVintfTest, CompatibilityMatrixConverterXmlFile2) { std::string error; std::string xml = "\n" " \n" " media_profile\n" " 1.0\n" " \n" "\n"; CompatibilityMatrix cm; EXPECT_FALSE(fromXml(&cm, xml, &error)); EXPECT_EQ("compatibility-matrix.xmlfile entry media_profile has to be optional for " "compatibility matrix version 1.0", error); } TEST_F(LibVintfTest, ManifestXmlFilePathDevice) { std::string manifestXml = "" " " " media_profile" " 1.0" " " ""; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml)); EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}), "/vendor/etc/media_profile_V1_0.xml"); } TEST_F(LibVintfTest, ManifestXmlFilePathFramework) { std::string manifestXml = "" " " " media_profile" " 1.0" " " ""; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml)); EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}), "/system/etc/media_profile_V1_0.xml"); } TEST_F(LibVintfTest, ManifestXmlFilePathOverride) { std::string manifestXml = "" " " " media_profile" " 1.0" " /vendor/etc/foo.xml" " " ""; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml)); EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}), "/vendor/etc/foo.xml"); } TEST_F(LibVintfTest, ManifestXmlFilePathMissing) { std::string manifestXml = "" " " " media_profile" " 1.1" " " ""; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, manifestXml)); EXPECT_EQ(manifest.getXmlFilePath("media_profile", {1, 0}), ""); } TEST_F(LibVintfTest, MatrixXmlFilePathFramework) { std::string matrixXml = "" " " " media_profile" " 2.0-1" " " ""; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, matrixXml)); EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 1}), "/system/etc/media_profile_V2_1.dtd"); } TEST_F(LibVintfTest, MatrixXmlFilePathDevice) { std::string matrixXml = "" " " " media_profile" " 2.0-1" " " ""; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, matrixXml)); EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 0}), "/vendor/etc/media_profile_V2_1.xsd"); } TEST_F(LibVintfTest, MatrixXmlFilePathOverride) { std::string matrixXml = "" " " " media_profile" " 2.0-1" " /system/etc/foo.xsd" " " ""; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, matrixXml)); EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 0}), "/system/etc/foo.xsd"); } TEST_F(LibVintfTest, MatrixXmlFilePathMissing) { std::string matrixXml = "" " " " media_profile" " 2.1" " " ""; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, matrixXml)); EXPECT_EQ(matrix.getXmlSchemaPath("media_profile", {2, 0}), ""); } std::pair processData(const std::string& data, bool processComments, bool relaxedFormat = false) { KernelConfigParser parser(processComments, relaxedFormat); const char* p = data.c_str(); size_t n = 0; size_t chunkSize; status_t status = OK; for (; n < data.size(); p += chunkSize, n += chunkSize) { chunkSize = std::min(5, data.size() - n); if ((status = parser.process(p, chunkSize)) != OK) { break; } } return {std::move(parser), status}; } TEST_F(LibVintfTest, KernelConfigParser) { // usage in /proc/config.gz const std::string data = "# CONFIG_NOT_SET is not set\n" "CONFIG_ONE=1\n" "CONFIG_Y=y\n" "CONFIG_STR=\"string\"\n"; auto pair = processData(data, false /* processComments */); ASSERT_EQ(OK, pair.second) << pair.first.error(); const auto& configs = pair.first.configs(); EXPECT_EQ(configs.find("CONFIG_ONE")->second, "1"); EXPECT_EQ(configs.find("CONFIG_Y")->second, "y"); EXPECT_EQ(configs.find("CONFIG_STR")->second, "\"string\""); EXPECT_EQ(configs.find("CONFIG_NOT_SET"), configs.end()); } TEST_F(LibVintfTest, KernelConfigParser2) { // usage in android-base.config const std::string data = "# CONFIG_NOT_SET is not set\n" "CONFIG_ONE=1\n" "CONFIG_Y=y\n" "CONFIG_STR=string\n" "# ignore_thiscomment\n" "# CONFIG_NOT_SET2 is not set\n"; auto pair = processData(data, true /* processComments */); ASSERT_EQ(OK, pair.second) << pair.first.error(); const auto& configs = pair.first.configs(); EXPECT_EQ(configs.find("CONFIG_ONE")->second, "1"); EXPECT_EQ(configs.find("CONFIG_Y")->second, "y"); EXPECT_EQ(configs.find("CONFIG_STR")->second, "string"); EXPECT_EQ(configs.find("CONFIG_NOT_SET")->second, "n"); EXPECT_EQ(configs.find("CONFIG_NOT_SET2")->second, "n"); } TEST_F(LibVintfTest, KernelConfigParserSpace) { // usage in android-base.config const std::string data = " # CONFIG_NOT_SET is not set \n" " CONFIG_ONE=1 # 'tis a one!\n" " CONFIG_TWO=2 #'tis a two! \n" " CONFIG_THREE=3#'tis a three! \n" " CONFIG_233=233#'tis a three! \n" "#yey! random comments\n" "CONFIG_Y=y \n" " CONFIG_YES=y#YES! \n" "CONFIG_STR=string\n" "CONFIG_HELLO=hello world! #still works\n" "CONFIG_WORLD=hello world! \n" "CONFIG_GOOD = good morning! #comments here\n" " CONFIG_MORNING = good morning! \n"; auto pair = processData(data, true /* processComments */, true /* relaxedFormat */); ASSERT_EQ(OK, pair.second) << pair.first.error(); const auto& configs = pair.first.configs(); EXPECT_EQ(configs.find("CONFIG_ONE")->second, "1"); EXPECT_EQ(configs.find("CONFIG_TWO")->second, "2"); EXPECT_EQ(configs.find("CONFIG_THREE")->second, "3"); EXPECT_EQ(configs.find("CONFIG_Y")->second, "y"); EXPECT_EQ(configs.find("CONFIG_STR")->second, "string"); EXPECT_EQ(configs.find("CONFIG_HELLO")->second, "hello world!") << "Value should be \"hello world!\" without trailing spaces"; EXPECT_EQ(configs.find("CONFIG_WORLD")->second, "hello world!") << "Value should be \"hello world!\" without trailing spaces"; EXPECT_EQ(configs.find("CONFIG_GOOD")->second, "good morning!") << "Value should be \"good morning!\" without leading or trailing spaces"; EXPECT_EQ(configs.find("CONFIG_MORNING")->second, "good morning!") << "Value should be \"good morning!\" without leading or trailing spaces"; EXPECT_EQ(configs.find("CONFIG_NOT_SET")->second, "n"); } TEST_F(LibVintfTest, NetutilsWrapperMatrix) { std::string matrixXml; CompatibilityMatrix matrix; std::string error; matrixXml = "" " " " netutils-wrapper" " 1.0" " " ""; EXPECT_TRUE(fromXml(&matrix, matrixXml, &error)) << error; // only host libvintf hardcodes netutils-wrapper version requirements #ifndef LIBVINTF_TARGET matrixXml = "" " " " netutils-wrapper" " 1.0-1" " " ""; EXPECT_FALSE(fromXml(&matrix, matrixXml, &error)); EXPECT_THAT(error, HasSubstr( "netutils-wrapper HAL must specify exactly one version x.0, but a range is provided. " "Perhaps you mean '1.0'?")); matrixXml = "" " " " netutils-wrapper" " 1.1" " " ""; EXPECT_FALSE(fromXml(&matrix, matrixXml, &error)); EXPECT_THAT(error, HasSubstr( "netutils-wrapper HAL must specify exactly one version x.0, but minor version is not 0. " "Perhaps you mean '1.0'?")); matrixXml = "" " " " netutils-wrapper" " 1.0" " 2.0" " " ""; EXPECT_FALSE(fromXml(&matrix, matrixXml, &error)); EXPECT_THAT(error, HasSubstr( "netutils-wrapper HAL must specify exactly one version x.0, but multiple element " "is specified.")); #endif // LIBVINTF_TARGET } TEST_F(LibVintfTest, NetutilsWrapperManifest) { std::string manifestXml; HalManifest manifest; std::string error; manifestXml = "" " " " netutils-wrapper" " 1.0" " 2.0" " " ""; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; // only host libvintf hardcodes netutils-wrapper version requirements #ifndef LIBVINTF_TARGET manifestXml = "" " " " netutils-wrapper" " 1.1" " " ""; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_THAT(error, HasSubstr( "netutils-wrapper HAL must specify exactly one version x.0, but minor version is not 0.")); manifestXml = "" " " " netutils-wrapper" " 1.0" " 2.1" " " ""; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_THAT(error, HasSubstr( "netutils-wrapper HAL must specify exactly one version x.0, but minor version is not 0.")); #endif // LIBVINTF_TARGET } TEST_F(LibVintfTest, KernelConfigConditionTest) { std::string error; std::string xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_ARM\n" " y\n" " \n" " \n" " \n" " CONFIG_FOO\n" " y\n" " \n" " \n" " \n" " 30\n" " 25.0\n" " \n" " \n" " 2.1\n" " \n" "\n"; CompatibilityMatrix cm; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; const auto& kernels = getKernels(cm); ASSERT_GE(kernels.size(), 2u); ASSERT_TRUE(kernels[0].conditions().empty()); const auto& kernel = kernels[1]; const auto& cond = kernel.conditions(); ASSERT_FALSE(cond.empty()); EXPECT_EQ("CONFIG_ARM", cond.begin()->first); EXPECT_EQ(KernelConfigTypedValue(Tristate::YES), cond.begin()->second); EXPECT_FALSE(kernel.configs().empty()); EXPECT_EQ(xml, toXml(cm)); } TEST_F(LibVintfTest, KernelConfigConditionEmptyTest) { std::string error; std::string xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_ARM\n" " y\n" " \n" " \n" " \n" "\n"; CompatibilityMatrix cm; EXPECT_FALSE(fromXml(&cm, xml, &error)) << "Should not accept first kernel version with non-empty conditions"; EXPECT_EQ( "First for version 3.18 must have empty " "for backwards compatibility.", error); } TEST_F(LibVintfTest, KernelConfigConditionMatch) { RuntimeInfo runtime = testRuntimeInfo(); std::string error; std::string xml; CompatibilityMatrix cm; xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error; xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 26\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "conditions met, so CONFIG_ARCH_MMAP_RND_BITS should not match"; xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " n\n" " \n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 26\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error; xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xdead000000000000\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_TRUE(runtime.checkCompatibility(cm, &error)); xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xbeaf000000000000\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "conditions have 'and' relationship, so CONFIG_ILLEGAL_POINTER_VALUE should not match"; xml = "\n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 26\n" " \n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xbeaf000000000000\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error; xml = "\n" " \n" " \n" " CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES\n" " \n" " \n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xdead000000000000\n" " \n" " \n" " \n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " \n" " CONFIG_ANDROID_BINDER_DEVICES\n" " binder,hwbinder\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_TRUE(runtime.checkCompatibility(cm, &error)) << error; xml = "\n" " \n" " \n" " CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES\n" " \n" " \n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xbeaf000000000000\n" " \n" " \n" " \n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " \n" " CONFIG_ANDROID_BINDER_DEVICES\n" " binder,hwbinder\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "all fragments should be used."; xml = "\n" " \n" " \n" " CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES\n" " \n" " \n" " \n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xdead000000000000\n" " \n" " \n" " \n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " \n" " CONFIG_ANDROID_BINDER_DEVICES\n" " binder\n" " \n" " \n" " \n" " 30\n" " \n" " 2.1\n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "all fragments should be used"; } // Run KernelConfigParserInvalidTest on processComments = {true, false} class KernelConfigParserInvalidTest : public ::testing::TestWithParam {}; TEST_P(KernelConfigParserInvalidTest, NonSet1) { const std::string data = "# CONFIG_NOT_EXIST is not sat\n"; auto pair = processData(data, GetParam() /* processComments */, true /* relaxedFormat */); ASSERT_EQ(OK, pair.second) << pair.first.error(); const auto& configs = pair.first.configs(); EXPECT_EQ(configs.find("CONFIG_NOT_EXIST"), configs.end()) << "CONFIG_NOT_EXIST should not exist because of typo"; } TEST_P(KernelConfigParserInvalidTest, InvalidLine1) { const std::string data = "FOO_CONFIG=foo\n"; ASSERT_NE(OK, processData(data, GetParam() /* processComments */, true /* relaxedFormat */).second); } TEST_P(KernelConfigParserInvalidTest, InvalidLine2) { const std::string data = "CONFIG_BAR-BAZ=foo\n"; ASSERT_NE(OK, processData(data, GetParam() /* processComments */, true /* relaxedFormat */).second); } INSTANTIATE_TEST_CASE_P(KernelConfigParser, KernelConfigParserInvalidTest, ::testing::Bool()); TEST_F(LibVintfTest, MatrixLevel) { std::string error; CompatibilityMatrix cm; std::string xml; xml = ""; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_EQ(Level::UNSPECIFIED, cm.level()); xml = ""; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_EQ(Level::LEGACY, cm.level()); xml = ""; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_EQ(Level{1}, cm.level()); } TEST_F(LibVintfTest, ManifestLevel) { std::string error; HalManifest manifest; std::string xml; xml = ""; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(Level::UNSPECIFIED, manifest.level()); xml = ""; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(Level::LEGACY, manifest.level()); xml = ""; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(Level{1}, manifest.level()); } TEST_F(LibVintfTest, AddOptionalHal) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = ""; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " android.hardware.foo\n" " 1.0-1\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " 1.0-1\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"); } TEST_F(LibVintfTest, AddOptionalHalMinorVersion) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " android.hardware.foo\n" " 1.0-4\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " 1.0-4\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"); } TEST_F(LibVintfTest, AddOptionalHalMajorVersion) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " 2.0-4\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " 2.0-4\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"); } TEST_F(LibVintfTest, AddOptionalHalMinorVersionDiffInstance) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = "\n" " \n" " android.hardware.foo\n" " 1.0-1\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " android.hardware.foo\n" " 1.1-2\n" " \n" " IFoo\n" " custom\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " 1.0-1\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.1-2\n" " \n" " IFoo\n" " custom\n" " \n" " \n" "\n"); } TEST_F(LibVintfTest, AddRequiredHalOverlapInstance) { CompatibilityMatrix cm1; std::string error; std::string xml; xml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " custom\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; { // Test that 2.0 should be added to IFoo/default, so 1.0::IFoo/custom // should be in a new tag CompatibilityMatrix cm2; xml = "\n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " custom\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.0\n" " 2.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"); } { // Test that 2.0::IFoo/strong should be added as an optional tag. CompatibilityMatrix cm2; xml = "\n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IFoo\n" " default\n" " strong\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " custom\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.0\n" " 2.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IFoo\n" " strong\n" " \n" " \n" "\n"); } } TEST_F(LibVintfTest, AddRequiredHalOverlapInstanceSplit) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " custom\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IFoo\n" " strong\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ( "\n" " \n" " android.hardware.foo\n" " 1.0\n" " 2.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " custom\n" " \n" " \n" " \n" " android.hardware.foo\n" " 2.0\n" " \n" " IFoo\n" " strong\n" " \n" " \n" "\n", xml); } TEST_F(LibVintfTest, AddOptionalHalUpdatableViaApex) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = "\n" " \n" " android.hardware.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " android.hardware.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllHalsAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::HALS_ONLY); EXPECT_EQ(xml, "\n" " \n" " android.hardware.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"); } TEST_F(LibVintfTest, AddOptionalXmlFile) { CompatibilityMatrix cm1; CompatibilityMatrix cm2; std::string error; std::string xml; xml = "\n" " \n" " foo\n" " 1.0-2\n" " /foo/bar/baz.xsd\n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm1, xml, &error)) << error; xml = "\n" " \n" " foo\n" " 1.1-3\n" " /foo/bar/quux.xsd\n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm2, xml, &error)) << error; EXPECT_TRUE(addAllXmlFilesAsOptional(&cm1, &cm2, &error)) << error; xml = toXml(cm1, SerializeFlags::XMLFILES_ONLY); EXPECT_EQ(xml, "\n" " \n" " foo\n" " 1.0-2\n" " /foo/bar/baz.xsd\n" " \n" " \n" " foo\n" " 1.1-3\n" " /foo/bar/quux.xsd\n" " \n" "\n"); } TEST_F(LibVintfTest, VendorNdk) { CompatibilityMatrix cm; std::string error; std::string xml; xml = "\n" " \n" " P\n" " libbase.so\n" " libjpeg.so\n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_EQ(xml, toXml(cm)); EXPECT_EQ("P", cm.getVendorNdkVersion()); { HalManifest manifest; xml = "\n" " \n" " 27\n" " libbase.so\n" " libjpeg.so\n" " \n" " \n" " P\n" " libbase.so\n" " libjpeg.so\n" " libtinyxml2.so\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(xml, toXml(manifest)); EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; } { HalManifest manifest; xml = "\n" " \n" " 27\n" " libbase.so\n" " libjpeg.so\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(xml, toXml(manifest)); EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_IN("Vndk version P is not supported.", error); } { HalManifest manifest; xml = "\n" " \n" " P\n" " libbase.so\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(xml, toXml(manifest)); EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_IN("Vndk libs incompatible for version P.", error); EXPECT_IN("libjpeg.so", error); } } TEST_F(LibVintfTest, MissingVendorNdkInMatrix) { CompatibilityMatrix cm; std::string xml; std::string error; xml = "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; { HalManifest manifest; xml = "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; } { HalManifest manifest; xml = "\n" " \n" " P\n" " libbase.so\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; } } TEST_F(LibVintfTest, DuplicatedVendorNdkVersion) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " 27\n" " \n" " \n" " 27\n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, xml, &error)); EXPECT_EQ("Duplicated manifest.vendor-ndk.version 27", error); } TEST_F(LibVintfTest, ManifestHalOverride) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " \n" " android.hardware.bar\n" " hwbinder\n" " 1.0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; const auto& foo = getHals(manifest, "android.hardware.foo"); ASSERT_FALSE(foo.empty()); EXPECT_TRUE(foo.front()->isOverride()); const auto& bar = getHals(manifest, "android.hardware.bar"); ASSERT_FALSE(bar.empty()); EXPECT_FALSE(bar.front()->isOverride()); } TEST_F(LibVintfTest, ManifestHalOverrideLatest) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; const auto& foo = getHals(manifest, "android.hardware.foo"); ASSERT_FALSE(foo.empty()); EXPECT_TRUE(foo.front()->isOverride()); } // Test functionality of override="true" tag TEST_F(LibVintfTest, ManifestAddOverrideHalSimple) { std::string error; HalManifest manifest; std::string xml = "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ(xml, toXml(manifest, SerializeFlags::HALS_ONLY)); } // Test functionality of override="true" tag TEST_F(LibVintfTest, ManifestAddOverrideHalSimpleWithInterface) { std::string error; HalManifest manifest; std::string xml = "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.1\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ( "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/default\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); } TEST_F(LibVintfTest, ManifestAddOverrideHalSimpleOverride) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ(xml, toXml(manifest, SerializeFlags::HALS_ONLY)); } TEST_F(LibVintfTest, ManifestAddOverrideHalSimpleOverrideWithInterface) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.1\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ( "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/default\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); } // Existing major versions should be removed. TEST_F(LibVintfTest, ManifestAddOverrideHalMultiVersion) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.3\n" " 2.4\n" " \n" " IFoo\n" " slot1\n" " \n" " \n" " \n" " android.hardware.bar\n" " hwbinder\n" " 1.3\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.1\n" " 3.1\n" " \n" " IFoo\n" " slot2\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ( "\n" " \n" " android.hardware.bar\n" " hwbinder\n" " 1.3\n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " @2.4::IFoo/slot1\n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/slot2\n" " @3.1::IFoo/slot2\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); } TEST_F(LibVintfTest, ManifestAddOverrideHalMultiVersion2) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.3\n" " 2.4\n" " \n" " IFoo\n" " slot1\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/slot2\n" " @2.1::IFoo/slot2\n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ(xml, toXml(manifest, SerializeFlags::HALS_ONLY)); } TEST_F(LibVintfTest, ManifestAddOverrideHalMultiVersion2WithInterface) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.3\n" " 2.4\n" " \n" " IFoo\n" " slot1\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.1\n" " 2.1\n" " \n" " IFoo\n" " slot2\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ( "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/slot2\n" " @2.1::IFoo/slot2\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); } // if no , remove all existing with given . TEST_F(LibVintfTest, ManifestAddOverrideHalRemoveAll) { std::string error; HalManifest manifest; std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.3\n" " 2.4\n" " \n" " IFoo\n" " slot1\n" " \n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " 3.1\n" " 4.3\n" " \n" " IBar\n" " slot2\n" " \n" " \n" " \n" " android.hardware.bar\n" " hwbinder\n" " 1.3\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; HalManifest newManifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " \n" "\n"; EXPECT_TRUE(fromXml(&newManifest, xml, &error)) << error; manifest.addAllHals(&newManifest); EXPECT_EQ( "\n" " \n" " android.hardware.bar\n" " hwbinder\n" " 1.3\n" " \n" " \n" " android.hardware.foo\n" " hwbinder\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); } // Make sure missing tags in old VINTF files does not cause incompatibilities. TEST_F(LibVintfTest, Empty) { CompatibilityMatrix cm; HalManifest manifest; std::string xml; std::string error; xml = "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; xml = "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; } TEST_F(LibVintfTest, ParsingUpdatableHals) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); // check by calling the API: updatableViaApex() auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); EXPECT_THAT(foo.front()->updatableViaApex(), Optional(Eq("com.android.foo"))); } TEST_F(LibVintfTest, ParsingUpdatableViaApex_EmptyIsValidForNonUpdatableHal) { std::string error; HalManifest manifest; manifest.setFileName("/apex/com.foo/etc/vintf/manifest.xml"); std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); // check by calling the API: updatableViaApex() auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); EXPECT_THAT(foo.front()->updatableViaApex(), Optional(Eq(""))); } TEST_F(LibVintfTest, ParsingUpdatableViaApex_UpdatableHalCanExplicitlySet) { std::string error; HalManifest manifest; manifest.setFileName("/apex/com.foo/etc/vintf/manifest.xml"); std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); // check by calling the API: updatableViaApex() auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); EXPECT_THAT(foo.front()->updatableViaApex(), Optional(Eq("com.foo"))); } TEST_F(LibVintfTest, ParsingUpdatableViaApex_ErrorIfExplicitValueMismatch) { std::string error; HalManifest manifest; manifest.setFileName("/apex/com.bar/etc/vintf/manifest.xml"); std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("updatable-via-apex com.foo doesn't match", error); } TEST_F(LibVintfTest, ParsingUpdatableViaApex_SetToCurrentApex) { std::string error; HalManifest manifest; manifest.setFileName("/apex/com.foo/etc/vintf/manifest.xml"); std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("updatable-via-apex=\"com.foo\"", toXml(manifest, SerializeFlags::HALS_ONLY)); // check by calling the API: updatableViaApex() auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); EXPECT_THAT(foo.front()->updatableViaApex(), Optional(Eq("com.foo"))); } TEST_F(LibVintfTest, ParsingUpdatableHalsWithInterface) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); // check by calling the API: updatableViaApex() auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); EXPECT_THAT(foo.front()->updatableViaApex(), Optional(Eq("com.android.foo"))); } TEST_F(LibVintfTest, ParsingHalsInetTransport) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " inet\n" " IFoo/default\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); ASSERT_TRUE(foo.front()->ip().has_value()); ASSERT_TRUE(foo.front()->port().has_value()); EXPECT_EQ("1.2.3.4", *foo.front()->ip()); EXPECT_EQ(12, *foo.front()->port()); } TEST_F(LibVintfTest, ParsingHalsInetTransportWithInterface) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " inet\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.hardware.foo\n" " inet\n" " IFoo/default\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); ASSERT_TRUE(foo.front()->ip().has_value()); ASSERT_TRUE(foo.front()->port().has_value()); EXPECT_EQ("1.2.3.4", *foo.front()->ip()); EXPECT_EQ(12, *foo.front()->port()); } TEST_F(LibVintfTest, RejectHalsInetTransportNoAttrs) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " inet\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("Transport inet requires ip and port attributes", error); } TEST_F(LibVintfTest, RejectHalsInetTransportMissingAttrs) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " inet\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("Transport inet requires ip and port", error); } TEST_F(LibVintfTest, RejectHalsEmptyTransportWithInetAttrs) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " \n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("Transport requires empty ip and port attributes", error); } TEST_F(LibVintfTest, RejectHidlHalsInetTransport) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " inet\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN( "HIDL HAL 'android.hardware.foo' should not have \"inet\" or ip or port", error); } TEST_F(LibVintfTest, RejectHidlHalsHwbinderInetAttrs) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("Transport hwbinder requires empty ip and port attributes", error); } TEST_F(LibVintfTest, SystemSdk) { CompatibilityMatrix cm; std::string xml; std::string error; xml = "\n" " \n" " 1\n" " P\n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_EQ(xml, toXml(cm, SerializeFlags::SSDK_ONLY)); { HalManifest manifest; xml = "\n" " \n" " 1\n" " P\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(xml, toXml(manifest, SerializeFlags::SSDK_ONLY)); EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; } { HalManifest manifest; xml = "\n" " \n" " 1\n" " 3\n" " P\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(cm, &error)); } { HalManifest manifest; xml = "\n" " \n" " 1\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_TRUE(error.find("System SDK") != std::string::npos) << error; } } TEST_F(LibVintfTest, ManifestEmpty) { std::string error; HalManifest e; EXPECT_FALSE(fromXml(&e, "", &error)); EXPECT_NE("Not a valid XML", error); std::string prevError = error; EXPECT_FALSE(fromXml(&e, "", &error)); EXPECT_EQ("Not a valid XML", error); } TEST_F(LibVintfTest, MatrixEmpty) { std::string error; CompatibilityMatrix e; EXPECT_FALSE(fromXml(&e, "", &error)); EXPECT_NE("Not a valid XML", error); std::string prevError = error; EXPECT_FALSE(fromXml(&e, "", &error)); EXPECT_EQ("Not a valid XML", error); } TEST_F(LibVintfTest, MatrixDetailErrorMsg) { std::string error; std::string xml; HalManifest manifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; { CompatibilityMatrix cm; xml = "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " 4.5\n" " \n" " IFoo\n" " default\n" " slot1\n" " \n" " \n" " IBar\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_IN("Manifest level = 8", error); EXPECT_IN("Matrix level = 7", error); EXPECT_IN( "android.hardware.foo:\n" " required: \n" " (@1.2-3::IBar/default AND @1.2-3::IFoo/default AND @1.2-3::IFoo/slot1) OR\n" " (@4.5::IBar/default AND @4.5::IFoo/default AND @4.5::IFoo/slot1)\n" " provided: @1.0::IFoo/default", error); } { CompatibilityMatrix cm; xml = "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " \n" " IFoo\n" " default\n" " slot1\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_IN( "android.hardware.foo:\n" " required: (@1.2-3::IFoo/default AND @1.2-3::IFoo/slot1)\n" " provided: @1.0::IFoo/default", error); } // the most frequent use case. { CompatibilityMatrix cm; xml = "\n" " \n" " android.hardware.foo\n" " 1.2-3\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_IN( "android.hardware.foo:\n" " required: @1.2-3::IFoo/default\n" " provided: @1.0::IFoo/default", error); } } TEST_F(LibVintfTest, DisabledHal) { std::string error; std::string xml; HalManifest manifest; xml = "\n" " \n" " hwbinder\n" " android.hardware.foo\n" " hwbinder\n" " \n" " \n" " android.hardware.bar\n" " hwbinder\n" " @1.1::IFoo/custom\n" " \n" " \n" " android.hardware.baz\n" " hwbinder\n" " \n" "\n"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; auto foo = getHals(manifest, "android.hardware.foo"); ASSERT_EQ(1u, foo.size()); EXPECT_TRUE(foo.front()->isDisabledHal()); auto bar = getHals(manifest, "android.hardware.bar"); ASSERT_EQ(1u, bar.size()); EXPECT_FALSE(bar.front()->isDisabledHal()); auto baz = getHals(manifest, "android.hardware.baz"); ASSERT_EQ(1u, baz.size()); EXPECT_FALSE(baz.front()->isDisabledHal()); } TEST_F(LibVintfTest, FqNameValid) { std::string error; std::string xml; CompatibilityMatrix cm; xml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.hardware.foo\n" " 1.1\n" " \n" " IFoo\n" " custom\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&cm, xml, &error)) << error; { HalManifest manifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " custom\n" " \n" " @1.1::IFoo/custom\n" " \n" "\n"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; EXPECT_EQ(Transport::HWBINDER, manifest.getHidlTransport("android.hardware.foo", {1, 1}, "IFoo", "custom")); } { HalManifest manifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.0::IFoo/default\n" " @1.1::IFoo/custom\n" " \n" "\n"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_TRUE(manifest.checkCompatibility(cm, &error)) << error; } { HalManifest manifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " custom\n" " \n" " \n" "\n"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_FALSE(manifest.checkCompatibility(cm, &error)); EXPECT_IN( "android.hardware.foo:\n" " required: @1.1::IFoo/custom\n" " provided: \n" " @1.0::IFoo/custom\n" " @1.0::IFoo/default", error); } { HalManifest manifest; xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.0::IFoo/default\n" " @1.0::IFoo/custom\n" " \n" "\n"; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; } } TEST_F(LibVintfTest, FqNameInvalid) { std::string error; std::string xml; { ManifestHal hal; xml = "\n" " android.hardware.foo\n" " hwbinder\n" " @1.1::IFoo/custom\n" "\n"; EXPECT_TRUE(fromXml(&hal, xml, &error)) << error; } ManifestHal hal; xml = "\n" " android.hardware.foo\n" " hwbinder\n" " 1.1::IFoo/custom\n" "\n"; ASSERT_FALSE(fromXml(&hal, xml, &error)); EXPECT_IN("Could not parse text \"1.1::IFoo/custom\" in element ", error); xml = "\n" " android.hardware.foo\n" " hwbinder\n" " android.hardware.foo@1.1::IFoo/custom\n" "\n"; ASSERT_FALSE(fromXml(&hal, xml, &error)); EXPECT_IN("Should not specify package", error); xml = "\n" " android.hardware.foo\n" " hwbinder\n" " IFoo/custom\n" "\n"; ASSERT_FALSE(fromXml(&hal, xml, &error)); EXPECT_IN("Should specify version", error); xml = "\n" " android.hardware.foo\n" " hwbinder\n" " @1.0::IFoo\n" "\n"; ASSERT_FALSE(fromXml(&hal, xml, &error)); EXPECT_IN("Could not parse text \"@1.0::IFoo\" in element ", error); xml = "\n" " n07 4 v4l1d 1n73rf4c3\n" " hwbinder\n" " @1.0::IFoo/custom\n" "\n"; ASSERT_FALSE(fromXml(&hal, xml, &error)); EXPECT_IN("Cannot create FqInstance", error); EXPECT_IN("n07 4 v4l1d 1n73rf4c3", error); } TEST_F(LibVintfTest, RegexInstanceValid) { CompatibilityMatrix matrix; std::string error; std::string xml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " legacy/[0-9]+\n" " slot[0-9]+\n" " .*\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&matrix, xml, &error)) << error; } TEST_F(LibVintfTest, RegexInstanceInvalid) { CompatibilityMatrix matrix; std::string error; std::string xml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " e{1,2,3}\n" " *\n" " +\n" " [0-9]+\n" " [0-9]+\n" " \n" " \n" "\n"; EXPECT_FALSE(fromXml(&matrix, xml, &error)); EXPECT_IN("Invalid regular expression 'e{1,2,3}'", error); EXPECT_IN("Invalid regular expression '*'", error); EXPECT_IN("Invalid regular expression '+'", error); EXPECT_IN("Duplicated regex-instance '[0-9]+'", error); } TEST_F(LibVintfTest, RegexInstanceCompat) { CompatibilityMatrix matrix; std::string error; std::string matrixXml = "\n" " \n" " android.hardware.foo\n" " 1.0\n" " 3.1-2\n" " \n" " IFoo\n" " default\n" " legacy/[0-9]+\n" " \n" " \n" " \n" " 0\n" " 0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&matrix, matrixXml, &error)) << error; { std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " legacy/0\n" " legacy/1\n" " \n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; auto unused = checkUnusedHals(manifest, matrix); EXPECT_TRUE(unused.empty()) << "Contains unused HALs: " << android::base::Join(unused, "\n"); } { std::string xml = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " 1.0\n" " \n" " IFoo\n" " default\n" " legacy0\n" " nonmatch/legacy/0\n" " legacy/0/nonmatch\n" " \n" " \n" "\n"; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because no legacy/[0-9]+ is provided."; auto unused = checkUnusedHals(manifest, matrix); EXPECT_EQ((std::set{"android.hardware.foo@1.0::IFoo/nonmatch/legacy/0", "android.hardware.foo@1.0::IFoo/legacy/0/nonmatch", "android.hardware.foo@1.0::IFoo/legacy0"}), unused); } } TEST_F(LibVintfTest, Regex) { details::Regex regex; EXPECT_FALSE(regex.compile("+")); EXPECT_FALSE(regex.compile("*")); ASSERT_TRUE(regex.compile("legacy/[0-9]+")); EXPECT_TRUE(regex.matches("legacy/0")); EXPECT_TRUE(regex.matches("legacy/000")); EXPECT_FALSE(regex.matches("legacy/")); EXPECT_FALSE(regex.matches("ssslegacy/0")); EXPECT_FALSE(regex.matches("legacy/0sss")); } TEST_F(LibVintfTest, ManifestGetHalNamesAndVersions) { HalManifest vm = testDeviceManifest(); EXPECT_EQ(vm.getHalNamesAndVersions(), std::set({"android.hardware.camera@2.0", "android.hardware.nfc@1.0"})); } TEST_F(LibVintfTest, KernelInfo) { KernelInfo ki = testKernelInfo(); EXPECT_EQ( "\n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " CONFIG_ANDROID_BINDER_DEVICES\n" " \"binder,hwbinder\"\n" " \n" " \n" " CONFIG_ARCH_MMAP_RND_BITS\n" " 24\n" " \n" " \n" " CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE_NAMES\n" " \"\"\n" " \n" " \n" " CONFIG_ILLEGAL_POINTER_VALUE\n" " 0xdead000000000000\n" " \n" "\n", toXml(ki, SerializeFlags::NO_TAGS.enableKernelConfigs())); } TEST_F(LibVintfTest, ManifestAddAllDeviceManifest) { std::string xml1 = "\n"; std::string xml2 = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.0::IFoo/default\n" " \n" " \n" " 25.5\n" " \n" " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n" " \n" " media_profile\n" " 1.0\n" " \n" "\n"; std::string error; HalManifest manifest1; ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error; EXPECT_EQ(xml2, toXml(manifest1)); } TEST_F(LibVintfTest, ManifestAddAllFrameworkManifest) { std::string xml1 = "\n"; std::string xml2 = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " @1.0::IFoo/default\n" " \n" " \n" " P\n" " libbase.so\n" " \n" " \n" " 1\n" " \n" " \n" " media_profile\n" " 1.0\n" " \n" "\n"; std::string error; HalManifest manifest1; ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error; EXPECT_EQ(xml2, toXml(manifest1)); } TEST_F(LibVintfTest, ManifestAddAllConflictMajorVersion) { std::string head = "\n" " \n" " android.hardware.foo\n" " hwbinder\n" " "; std::string tail = "\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; std::string xml1 = head + "1.0" + tail; std::string xml2 = head + "1.1" + tail; std::string error; HalManifest manifest1; manifest1.setFileName("1.xml"); ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; manifest2.setFileName("2.xml"); ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_FALSE(manifest1.addAll(&manifest2, &error)); EXPECT_IN("android.hardware.foo", error); EXPECT_IN("@1.0::IFoo/default (from 1.xml)", error); EXPECT_IN("@1.1::IFoo/default (from 2.xml)", error); } TEST_F(LibVintfTest, ManifestAddAllConflictLevel) { std::string xml1 = "\n"; std::string xml2 = "\n"; std::string error; HalManifest manifest1; ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_FALSE(manifest1.addAll(&manifest2, &error)); EXPECT_IN("Conflicting target-level", error); } TEST_F(LibVintfTest, ManifestAddAllConflictSepolicy) { std::string xml1 = "\n" " \n" " 25.5\n" " \n" "\n"; std::string xml2 = "\n" " \n" " 30.0\n" " \n" "\n"; std::string error; HalManifest manifest1; ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_FALSE(manifest1.addAll(&manifest2, &error)); EXPECT_IN("Conflicting sepolicy version", error); } TEST_F(LibVintfTest, ManifestAddAllConflictKernel) { std::string xml1 = "\n" " \n" "\n"; std::string xml2 = "\n" " \n" "\n"; std::string error; HalManifest manifest1; ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_FALSE(manifest1.addAll(&manifest2, &error)); EXPECT_IN("Conflicting kernel", error); } TEST_F(LibVintfTest, ManifestMetaVersionCompat) { std::string xml = ""; std::string error; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; } TEST_F(LibVintfTest, ManifestMetaVersionIncompat) { std::string xml = ""; std::string error; HalManifest manifest; EXPECT_FALSE(fromXml(&manifest, xml, &error)) << "Should not parse metaversion 10000.0"; } TEST_F(LibVintfTest, ManifestMetaVersionWriteLatest) { std::string xml = ""; std::string error; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_IN(kMetaVersionStr, toXml(manifest, SerializeFlags::NO_TAGS)); } TEST_F(LibVintfTest, MatrixMetaVersionCompat) { std::string xml = ""; std::string error; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, xml, &error)) << error; } TEST_F(LibVintfTest, MatrixMetaVersionIncompat) { std::string xml = ""; std::string error; CompatibilityMatrix matrix; EXPECT_FALSE(fromXml(&matrix, xml, &error)) << "Should not parse metaversion 10000.0"; } TEST_F(LibVintfTest, MatrixMetaVersionWriteLatest) { std::string xml = ""; std::string error; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, xml, &error)) << error; EXPECT_IN(kMetaVersionStr, toXml(matrix, SerializeFlags::NO_TAGS)); } // clang-format on struct InMemoryFileSystem : FileSystem { std::map files; InMemoryFileSystem(std::map files) : files(std::move(files)) {} status_t fetch(const std::string& path, std::string* fetched, std::string* error) const override { (void)error; if (auto it = files.find(path); it != files.end()) { *fetched = it->second; return OK; } return NAME_NOT_FOUND; } status_t listFiles(const std::string& path, std::vector* out, std::string* error) const override { (void)error; std::set entries; for (const auto& pair : files) { std::string_view entry{pair.first}; if (android::base::ConsumePrefix(&entry, path)) { android::base::ConsumePrefix(&entry, "/"); entries.emplace(entry.substr(0, entry.find('/'))); } } *out = std::vector{begin(entries), end(entries)}; return OK; } status_t modifiedTime(const std::string& path, timespec* mtime, std::string* error) const { (void)error; if (auto it = files.find(path); it != files.end()) { *mtime = timespec{}; return OK; } return NAME_NOT_FOUND; } }; TEST_F(LibVintfTest, HalManifestWithMultipleFiles) { std::string vendorXmlPath = "/vendor/etc/vintf/manifest.xml"; std::string vendorXml = "\n" " \n" " android.hardware.foo\n" " IFoo/default\n" " \n" ""; std::string apexXmlPath = "/apex/com.android.bar/etc/vintf/manifest.xml"; std::string apexXml = "\n" " \n" " android.hardware.bar\n" " IBar/default\n" " \n" ""; InMemoryFileSystem files{{ {vendorXmlPath, vendorXml}, {apexXmlPath, apexXml}, }}; // Read apexXml later. This shouldn't affect the result except HalManifest::fileName. { std::string error; HalManifest manifest; EXPECT_EQ(OK, fetchManifest(manifest, &files, vendorXmlPath, &error)) << error; EXPECT_EQ(OK, fetchManifest(manifest, &files, apexXmlPath, &error)) << error; EXPECT_EQ(vendorXmlPath + ":" + apexXmlPath, manifest.fileName()); EXPECT_EQ(std::nullopt, getAnyHal(manifest, "android.hardware.foo")->updatableViaApex()); EXPECT_EQ(std::make_optional("com.android.bar"s), getAnyHal(manifest, "android.hardware.bar")->updatableViaApex()); } // Read apexXml first. This shouldn't affect the result except HalManifest::fileName. { std::string error; HalManifest manifest; EXPECT_EQ(OK, fetchManifest(manifest, &files, apexXmlPath, &error)) << error; EXPECT_EQ(OK, fetchManifest(manifest, &files, vendorXmlPath, &error)) << error; EXPECT_EQ(apexXmlPath + ":" + vendorXmlPath, manifest.fileName()); EXPECT_EQ(std::nullopt, getAnyHal(manifest, "android.hardware.foo")->updatableViaApex()); EXPECT_EQ(std::make_optional("com.android.bar"s), getAnyHal(manifest, "android.hardware.bar")->updatableViaApex()); } } // clang-format off TEST_F(LibVintfTest, Aidl) { std::string xml = "\n" " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " test.*\n" " \n" " \n" "\n"; std::string error; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, xml, &error)) << error; EXPECT_EQ(xml, toXml(matrix, SerializeFlags::HALS_NO_FQNAME)); { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " test0\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " IFoo/default\n" " IFoo/test0\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "default")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "test0")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IFoo", "does_not_exist")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IDoesNotExist", "default")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.does_not_exist", "IFoo", "default")); EXPECT_EQ(manifest.getAidlInstances("android.system.foo", "IFoo"), std::set({"default", "test0"})); EXPECT_EQ(manifest.getAidlInstances("android.system.does_not_exist", "IFoo"), std::set({})); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " IFoo/default\n" " IFoo/test0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "default")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "test0")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IFoo", "does_not_exist")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IDoesNotExist", "default")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.does_not_exist", "IFoo", "default")); EXPECT_EQ(manifest.getAidlInstances("android.system.foo", "IFoo"), std::set({"default", "test0"})); EXPECT_EQ(manifest.getAidlInstances("android.system.does_not_exist", "IFoo"), std::set({})); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " IFoo/incompat_instance\n" " IFoo/test0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because default instance is missing"; EXPECT_IN("required: (IFoo/default (@1) AND IFoo/test.* (@1))", error); EXPECT_IN("provided: \n" " IFoo/incompat_instance (@1)\n" " IFoo/test0 (@1)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " \n" " IFoo\n" " incompat_instance\n" " test0\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " IFoo/incompat_instance\n" " IFoo/test0\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because default instance is missing"; EXPECT_IN("required: (IFoo/default (@1) AND IFoo/test.* (@1))", error); EXPECT_IN("provided: \n" " IFoo/incompat_instance (@1)\n" " IFoo/test0 (@1)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " IFoo/default\n" " IFoo/incompat_instance\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because test.* instance is missing"; EXPECT_IN("required: (IFoo/default (@1) AND IFoo/test.* (@1))", error); EXPECT_IN("provided: \n" " IFoo/default (@1)\n" " IFoo/incompat_instance (@1)\n", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " incompat_instance\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " IFoo/default\n" " IFoo/incompat_instance\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because test.* instance is missing"; EXPECT_IN("required: (IFoo/default (@1) AND IFoo/test.* (@1))", error); EXPECT_IN("provided: \n" " IFoo/default (@1)\n" " IFoo/incompat_instance (@1)\n", error); } } TEST_F(LibVintfTest, AidlAndHidlNamesMatrix) { std::string xml = "\n" " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.system.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; std::string error; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, xml, &error)) << error; EXPECT_EQ(xml, toXml(matrix, SerializeFlags::HALS_ONLY)); } TEST_F(LibVintfTest, AidlAndHidlNamesManifest) { std::string xml = "\n" " \n" " android.system.foo\n" " IFoo/default\n" " \n" " \n" " android.system.foo\n" " hwbinder\n" " @1.0::IFoo/default\n" " \n" "\n"; std::string error; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(xml, toXml(manifest, SerializeFlags::HALS_ONLY)); } TEST_F(LibVintfTest, AidlAndHidlCheckUnused) { std::string manifestXml = "\n" " \n" " android.system.foo\n" " IFoo/default\n" " \n" " \n" " android.system.foo\n" " hwbinder\n" " @1.0::IFoo/default\n" " \n" "\n"; std::string matrixXml = "\n" " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n" " \n" " android.system.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n" "\n"; std::string error; HalManifest manifest; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_TRUE(fromXml(&matrix, matrixXml, &error)) << error; auto unused = checkUnusedHals(manifest, matrix); EXPECT_TRUE(unused.empty()) << android::base::Join(unused, "\n"); } TEST_F(LibVintfTest, AidlVersion) { std::string xml = "\n" " \n" " android.system.foo\n" " 4-100\n" " \n" " IFoo\n" " default\n" " test.*\n" " \n" " \n" "\n"; std::string error; CompatibilityMatrix matrix; EXPECT_TRUE(fromXml(&matrix, xml, &error)) << error; EXPECT_EQ(xml, toXml(matrix, SerializeFlags::HALS_NO_FQNAME)); { std::vector matrixInstances; (void)matrix.forEachInstance([&](const MatrixInstance& matrixInstance) { EXPECT_EQ(matrixInstance.versionRange(), VersionRange(details::kFakeAidlMajorVersion, 4, 100)); matrixInstances.push_back(matrixInstance.description( matrixInstance.versionRange().minVer())); return true; }); EXPECT_THAT(matrixInstances, SizeIs(2)) << android::base::Join(matrixInstances, ", "); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 5\n" " \n" " IFoo\n" " default\n" " test0\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " 5\n" " IFoo/default\n" " IFoo/test0\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "default")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "test0")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", 5, "IFoo", "default")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", 5, "IFoo", "test0")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IFoo", "does_not_exist")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IDoesNotExist", "default")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.does_not_exist", "IFoo", "default")); EXPECT_EQ(manifest.getAidlInstances("android.system.foo", "IFoo"), std::set({"default", "test0"})); EXPECT_EQ(manifest.getAidlInstances("android.system.foo", 5, "IFoo"), std::set({"default", "test0"})); EXPECT_EQ(manifest.getAidlInstances("android.system.does_not_exist", "IFoo"), std::set({})); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 5\n" " IFoo/default\n" " IFoo/test0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_TRUE(manifest.checkCompatibility(matrix, &error)) << error; EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "default")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", "IFoo", "test0")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", 5, "IFoo", "default")); EXPECT_TRUE(manifest.hasAidlInstance("android.system.foo", 5, "IFoo", "test0")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IFoo", "does_not_exist")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.foo", "IDoesNotExist", "default")); EXPECT_FALSE(manifest.hasAidlInstance("android.system.does_not_exist", "IFoo", "default")); EXPECT_EQ(manifest.getAidlInstances("android.system.foo", "IFoo"), std::set({"default", "test0"})); EXPECT_EQ(manifest.getAidlInstances("android.system.foo", 5, "IFoo"), std::set({"default", "test0"})); EXPECT_EQ(manifest.getAidlInstances("android.system.does_not_exist", "IFoo"), std::set({})); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 5\n" " IFoo/incompat_instance\n" " IFoo/test0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because default instance is missing"; EXPECT_IN("required: (IFoo/default (@4-100) AND IFoo/test.* (@4-100))", error); EXPECT_IN("provided: \n" " IFoo/incompat_instance (@5)\n" " IFoo/test0 (@5)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 5\n" " \n" " IFoo\n" " incompat_instance\n" " test0\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " 5\n" " IFoo/incompat_instance\n" " IFoo/test0\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because default instance is missing"; EXPECT_IN("required: (IFoo/default (@4-100) AND IFoo/test.* (@4-100))", error); EXPECT_IN("provided: \n" " IFoo/incompat_instance (@5)\n" " IFoo/test0 (@5)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 5\n" " IFoo/default\n" " IFoo/incompat_instance\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because test.* instance is missing"; EXPECT_IN("required: (IFoo/default (@4-100) AND IFoo/test.* (@4-100))", error); EXPECT_IN("provided: \n" " IFoo/default (@5)\n" " IFoo/incompat_instance (@5)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 5\n" " \n" " IFoo\n" " default\n" " incompat_instance\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " 5\n" " IFoo/default\n" " IFoo/incompat_instance\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because test.* instance is missing"; EXPECT_IN("required: (IFoo/default (@4-100) AND IFoo/test.* (@4-100))", error); EXPECT_IN("provided: \n" " IFoo/default (@5)\n" " IFoo/incompat_instance (@5)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 3\n" " IFoo/default\n" " IFoo/test0\n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ(manifestXml, toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because version 3 cannot satisfy version 4-100"; EXPECT_IN("required: (IFoo/default (@4-100) AND IFoo/test.* (@4-100))", error); EXPECT_IN("provided: \n" " IFoo/default (@3)\n" " IFoo/test0 (@3)", error); } { HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " 3\n" " \n" " IFoo\n" " default\n" " test0\n" " \n" " \n" "\n"; EXPECT_TRUE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_EQ( "\n" " \n" " android.system.foo\n" " 3\n" " IFoo/default\n" " IFoo/test0\n" " \n" "\n", toXml(manifest, SerializeFlags::HALS_ONLY)); EXPECT_FALSE(manifest.checkCompatibility(matrix, &error)) << "Should not be compatible because version 3 cannot satisfy version 4-100"; EXPECT_IN("required: (IFoo/default (@4-100) AND IFoo/test.* (@4-100))", error); EXPECT_IN("provided: \n" " IFoo/default (@3)\n" " IFoo/test0 (@3)", error); } } TEST_F(LibVintfTest, AidlFqnameNoVersion) { std::string error; HalManifest manifest; std::string manifestXml = "\n" " \n" " android.system.foo\n" " @1.0::IFoo/default\n" " \n" "\n"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)) << error; EXPECT_IN("Should not specify version in for AIDL HAL: \"@1.0::IFoo/default\"", error); } TEST_F(LibVintfTest, GetTransportHidlHalWithFakeAidlVersion) { std::string xml = "\n" " \n" " android.system.foo\n" " hwbinder\n" " @" + to_string(details::kDefaultAidlVersion) + "::IFoo/default\n" " \n" "\n"; std::string error; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(Transport::HWBINDER, manifest.getHidlTransport("android.system.foo", details::kDefaultAidlVersion, "IFoo", "default")); } TEST_F(LibVintfTest, RejectAidlHalsWithUnsupportedTransport) { std::string error; HalManifest manifest; std::string manifestXml = "" android.system.foo hwbinder IFoo/default )"; EXPECT_FALSE(fromXml(&manifest, manifestXml, &error)); EXPECT_IN("android.system.foo", error); EXPECT_IN("hwbinder", error); } TEST_F(LibVintfTest, GetTransportAidlHalWithDummyTransport) { // Check that even if is specified for AIDL, it is ignored and getHidlTransport // will return EMPTY. // This is only supported for libvintf 4.0 and below. constexpr Version kLegacyMetaVersion{4, 0}; ASSERT_GE(kMetaVersionAidlInet, kLegacyMetaVersion); std::string xml = "\n" " \n" " android.system.foo\n" " hwbinder\n" " IFoo/default\n" " \n" "\n"; std::string error; HalManifest manifest; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; EXPECT_EQ(Transport::EMPTY, manifest.getHidlTransport("android.system.foo", details::kDefaultAidlVersion, "IFoo", "default")); } TEST_F(LibVintfTest, AidlGetHalNamesAndVersions) { HalManifest manifest; std::string xml = "\n" " \n" " android.system.foo\n" " IFoo/default\n" " \n" "\n"; std::string error; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; auto names = manifest.getHalNamesAndVersions(); ASSERT_EQ(1u, names.size()); EXPECT_EQ("android.system.foo@1", *names.begin()); } TEST_F(LibVintfTest, ManifestAddAidl) { std::string head = "\n" " \n" " android.hardware.foo\n" " "; std::string tail = "\n" " \n" "\n"; std::string xml1 = head + "IFoo/default" + tail; std::string xml2 = head + "IFoo/another" + tail; std::string error; HalManifest manifest1; manifest1.setFileName("1.xml"); ASSERT_TRUE(fromXml(&manifest1, xml1, &error)) << error; HalManifest manifest2; manifest2.setFileName("2.xml"); ASSERT_TRUE(fromXml(&manifest2, xml2, &error)) << error; ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error; } // clang-format on TEST_F(LibVintfTest, NativeGetHalNamesAndVersions) { HalManifest manifest; std::string xml = " foo 1.0 inst )"; std::string error; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; auto names = manifest.getHalNamesAndVersions(); ASSERT_EQ(1u, names.size()); EXPECT_EQ("foo@1.0", *names.begin()); } TEST_F(LibVintfTest, NativeGetHalNamesAndVersionsFqName) { HalManifest manifest; std::string xml = " foo @1.0/inst )"; std::string error; EXPECT_TRUE(fromXml(&manifest, xml, &error)) << error; auto names = manifest.getHalNamesAndVersions(); ASSERT_EQ(1u, names.size()); EXPECT_EQ("foo@1.0", *names.begin()); } // clang-format off TEST_F(LibVintfTest, KernelInfoLevel) { std::string error; std::string xml = "\n"; KernelInfo ki; ASSERT_TRUE(fromXml(&ki, xml, &error)) << error; EXPECT_EQ(Level{1}, getLevel(ki)); EXPECT_EQ(xml, toXml(ki)); } // Test merge of with autogenerated by parsing // kernel prebuilt. TEST_F(LibVintfTest, HalManifestMergeKernel) { std::string head = "\n"; std::string tail = "\n"; std::string xml1 = " \n"; std::string xml2 = " \n" " \n" " CONFIG_64BIT\n" " y\n" " \n" " \n"; std::string error; HalManifest manifest1; HalManifest manifest2; ASSERT_TRUE(fromXml(&manifest1, head + xml1 + tail, &error)) << error; ASSERT_TRUE(fromXml(&manifest2, head + xml2 + tail, &error)) << error; ASSERT_TRUE(manifest1.addAll(&manifest2, &error)) << error; std::string merged_xml = toXml(manifest1); EXPECT_IN(head, merged_xml); EXPECT_IN("target-level=\"2\"", merged_xml); EXPECT_IN("version=\"3.18.31\"", merged_xml); EXPECT_IN("CONFIG_64BIT", merged_xml); } // clang-format on TEST_F(LibVintfTest, FrameworkManifestHalMaxLevel) { std::string xml = " android.frameworks.schedulerservice hwbinder @1.0::ISchedulingPolicyService/default android.frameworks.myaidl IAidl/default some-native-hal 1.0 )"; std::string error; HalManifest manifest; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; auto hals = getHals(manifest, "android.frameworks.schedulerservice"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMaxLevel, Eq(static_cast(3))))); hals = getHals(manifest, "android.frameworks.myaidl"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMaxLevel, Eq(static_cast(4))))); hals = getHals(manifest, "some-native-hal"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMaxLevel, Eq(static_cast(5))))); } TEST_F(LibVintfTest, FrameworkManifestHalMinLevel) { std::string xml = " android.frameworks.schedulerservice hwbinder @1.0::ISchedulingPolicyService/default android.frameworks.myaidl IAidl/default some-native-hal 1.0 )"; std::string error; HalManifest manifest; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; auto hals = getHals(manifest, "android.frameworks.schedulerservice"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMinLevel, Eq(static_cast(3))))); hals = getHals(manifest, "android.frameworks.myaidl"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMinLevel, Eq(static_cast(4))))); hals = getHals(manifest, "some-native-hal"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMinLevel, Eq(static_cast(5))))); } TEST_F(LibVintfTest, FrameworkManifestHalMinMaxLevel) { std::string xml = " android.frameworks.schedulerservice hwbinder @1.0::ISchedulingPolicyService/default android.frameworks.myaidl IAidl/default some-native-hal 1.0 )"; std::string error; HalManifest manifest; ASSERT_TRUE(fromXml(&manifest, xml, &error)) << error; auto hals = getHals(manifest, "android.frameworks.schedulerservice"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMinLevel, Eq(static_cast(2))))); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMaxLevel, Eq(static_cast(5))))); hals = getHals(manifest, "android.frameworks.myaidl"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMinLevel, Eq(static_cast(3))))); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMaxLevel, Eq(static_cast(6))))); hals = getHals(manifest, "some-native-hal"); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMinLevel, Eq(static_cast(4))))); EXPECT_THAT(hals, ElementsAre(Property(&ManifestHal::getMaxLevel, Eq(static_cast(7))))); } TEST_F(LibVintfTest, RuntimeInfoParseGkiKernelReleaseOk) { KernelVersion version; Level level = Level::UNSPECIFIED; EXPECT_EQ(OK, parseGkiKernelRelease(RuntimeInfo::FetchFlag::ALL, "5.4.42-android12-0-something", &version, &level)); EXPECT_EQ(KernelVersion(5, 4, 42), version); EXPECT_EQ(Level::S, level); } TEST_F(LibVintfTest, RuntimeInfoParseGkiKernelReleaseVersionOnly) { KernelVersion version; EXPECT_EQ(OK, parseGkiKernelRelease(RuntimeInfo::FetchFlag::CPU_VERSION, "5.4.42-android12-0-something", &version, nullptr)); EXPECT_EQ(KernelVersion(5, 4, 42), version); } TEST_F(LibVintfTest, RuntimeInfoParseGkiKernelReleaseLevelOnly) { Level level = Level::UNSPECIFIED; EXPECT_EQ(OK, parseGkiKernelRelease(RuntimeInfo::FetchFlag::KERNEL_FCM, "5.4.42-android12-0-something", nullptr, &level)); EXPECT_EQ(Level::S, level); } TEST_F(LibVintfTest, RuntimeInfoParseGkiKernelReleaseLevelConsistent) { Level level = Level::S; EXPECT_EQ(OK, parseGkiKernelRelease(RuntimeInfo::FetchFlag::KERNEL_FCM, "5.4.42-android12-0-something", nullptr, &level)); EXPECT_EQ(Level::S, level); } TEST_F(LibVintfTest, RuntimeInfoParseGkiKernelReleaseLevelInconsistent) { Level level = Level::R; EXPECT_EQ(UNKNOWN_ERROR, parseGkiKernelRelease(RuntimeInfo::FetchFlag::KERNEL_FCM, "5.4.42-android12-0-something", nullptr, &level)); } // We bump level numbers for V, so check for consistency TEST_F(LibVintfTest, RuntimeInfoGkiReleaseV) { Level level = Level::UNSPECIFIED; EXPECT_EQ(OK, parseGkiKernelRelease(RuntimeInfo::FetchFlag::KERNEL_FCM, "6.1.0-android15-0", nullptr, &level)); EXPECT_EQ(Level::V, level); } class ManifestMissingITest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; ret.push_back(" android.hardware.foo 1 MyFoo default )"); ret.push_back(" android.hardware.foo hwbinder 1.0 MyFoo default )"); ret.push_back(" android.hardware.foo 1.0 MyFoo default )"); return ret; } }; TEST_P(ManifestMissingITest, CheckErrorMsg) { std::string xml = GetParam(); HalManifest manifest; std::string error; ASSERT_FALSE(fromXml(&manifest, xml, &error)) << "Should not be valid:\n" << xml; EXPECT_THAT(error, HasSubstr("Interface 'MyFoo' should have the format I[a-zA-Z0-9_]*")) << "\n" << xml; } INSTANTIATE_TEST_SUITE_P(LibVintfTest, ManifestMissingITest, ::testing::ValuesIn(ManifestMissingITest::createParams())); struct ManifestMissingInterfaceTestParam { std::string xml; std::string expectedError; }; class ManifestMissingInterfaceTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; ret.emplace_back(ManifestMissingInterfaceTestParam{ " android.hardware.foo 1 default )", "Interface '' should have the format I[a-zA-Z0-9_]*", }); ret.emplace_back(ManifestMissingInterfaceTestParam{ " android.hardware.foo 1 /default )", "Could not parse text \"/default\" in element ", }); ret.emplace_back(ManifestMissingInterfaceTestParam{ " android.hardware.foo hwbinder 1.0 default )", "Interface '' should have the format I[a-zA-Z0-9_]*", }); ret.emplace_back(ManifestMissingInterfaceTestParam{ " android.hardware.foo hwbinder @1.0/default )", "Should specify interface: \"@1.0/default\"", }); return ret; } }; TEST_P(ManifestMissingInterfaceTest, CheckErrorMsg) { auto&& [xml, expectedError] = GetParam(); HalManifest manifest; std::string error; ASSERT_FALSE(fromXml(&manifest, xml, &error)) << "Should not be valid:\n" << xml; EXPECT_THAT(error, HasSubstr(expectedError)) << "\n" << xml; } INSTANTIATE_TEST_SUITE_P(LibVintfTest, ManifestMissingInterfaceTest, ::testing::ValuesIn(ManifestMissingInterfaceTest::createParams())); TEST_F(LibVintfTest, HalManifestInvalidPackage) { // If package name, interface or instance contains characters invalid to FqInstance, // it must be rejected because forEachInstance requires them to fit into FqInstance. std::string xml = " not_a_valid_package! 1 MyFoo default )"; HalManifest manifest; std::string error; ASSERT_FALSE(fromXml(&manifest, xml, &error)) << "Should not be valid:\n" << xml; EXPECT_THAT(error, HasSubstr("not_a_valid_package!")); } class MatrixMissingITest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; ret.push_back(" android.hardware.foo 1 MyFoo default )"); ret.push_back(" android.hardware.foo 1.0 MyFoo default )"); ret.push_back(" android.hardware.foo 1.0 MyFoo default )"); return ret; } }; TEST_P(MatrixMissingITest, CheckErrorMsg) { std::string xml = GetParam(); CompatibilityMatrix matrix; std::string error; ASSERT_FALSE(fromXml(&matrix, xml, &error)) << "Should not be valid:\n" << xml; EXPECT_THAT(error, HasSubstr("Interface 'MyFoo' should have the format I[a-zA-Z0-9_]*")); } INSTANTIATE_TEST_SUITE_P(LibVintfTest, MatrixMissingITest, ::testing::ValuesIn(MatrixMissingITest::createParams())); struct MatrixMissingInterfaceTestParam { std::string xml; std::string expectedError; }; class MatrixMissingInterfaceTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; ret.emplace_back(MatrixMissingInterfaceTestParam{ " android.hardware.foo 1 default )", "Interface '' should have the format I[a-zA-Z0-9_]*", }); ret.emplace_back(MatrixMissingInterfaceTestParam{ " android.hardware.foo 1.0 default )", "Interface '' should have the format I[a-zA-Z0-9_]*", }); return ret; } }; TEST_P(MatrixMissingInterfaceTest, CheckErrorMsg) { auto&& [xml, expectedError] = GetParam(); CompatibilityMatrix matrix; std::string error; ASSERT_FALSE(fromXml(&matrix, xml, &error)) << "Should not be valid:\n" << xml; EXPECT_THAT(error, HasSubstr(expectedError)) << "\n" << xml; } INSTANTIATE_TEST_SUITE_P(LibVintfTest, MatrixMissingInterfaceTest, ::testing::ValuesIn(MatrixMissingInterfaceTest::createParams())); TEST_F(LibVintfTest, CompatibilityMatrixInvalidPackage) { // If package name, interface or instance contains characters invalid to FqInstance, // it must be rejected because forEachInstance requires them to fit into FqInstance. std::string xml = " not_a_valid_package! 1-2 MyFoo default )"; CompatibilityMatrix matrix; std::string error; ASSERT_FALSE(fromXml(&matrix, xml, &error)) << "Should not be valid:\n" << xml; EXPECT_THAT(error, HasSubstr("not_a_valid_package!")); } struct DupInterfaceAndFqnameTestParam { HalFormat format; std::string footer; std::string halName; }; class DupInterfaceAndFqnameTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; std::string hidlFooter = R"( android.hardware.nfc hwbinder 1.0 INfc default @1.0::INfc/default )"; std::string aidlFooter = R"( android.hardware.nfc INfc default INfc/default )"; return { {HalFormat::HIDL, hidlFooter, "android.hardware.nfc@1.0::INfc/default"}, {HalFormat::AIDL, aidlFooter, "android.hardware.nfc.INfc/default"}, }; } static std::string getTestSuffix(const TestParamInfo& info) { return to_string(info.param.format); } }; TEST_P(DupInterfaceAndFqnameTest, Test5_0) { auto&& [_, footer, halName] = GetParam(); std::string xml = R"()" + footer; HalManifest vm; std::string error; EXPECT_TRUE(fromXml(&vm, xml, &error)) << " and are allowed to exist " "together for the same instance for libvintf 5.0, but error is: " << error; } TEST_P(DupInterfaceAndFqnameTest, Test6_0) { auto&& [_, footer, halName] = GetParam(); std::string xml = R"()" + footer; HalManifest vm; std::string error; EXPECT_FALSE(fromXml(&vm, xml, &error)); EXPECT_THAT(error, HasSubstr("Duplicated " + halName + " in and .")) << " and are not allowed to exist " "together for the same instance for libvintf " << kMetaVersionNoHalInterfaceInstance << "."; } INSTANTIATE_TEST_SUITE_P(LibVintfTest, DupInterfaceAndFqnameTest, ::testing::ValuesIn(DupInterfaceAndFqnameTest::createParams()), &DupInterfaceAndFqnameTest::getTestSuffix); struct AllowDupMajorVersionTestParam { std::string testName; std::string expectedError; std::string footer; }; class AllowDupMajorVersionTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; ret.push_back({"HidlInterfaceAndFqName", "Duplicated major version", R"( android.hardware.nfc hwbinder 1.0 INfc default @1.1::INfc/default )"}); ret.push_back({"HidlFqNameInTheSameHal", "Duplicated major version", R"( android.hardware.nfc hwbinder @1.0::INfc/default @1.1::INfc/default )"}); ret.push_back({"HidlFqNameInDifferentHals", "Conflicting FqInstance", R"( android.hardware.nfc hwbinder @1.0::INfc/default android.hardware.nfc hwbinder @1.1::INfc/default )"}); ret.push_back({"HidlInterfaceAndFqNameInDifferentHals", "Conflicting FqInstance", R"( android.hardware.nfc hwbinder 1.0 INfc default android.hardware.nfc hwbinder @1.1::INfc/default )"}); ret.push_back({"AidlInterfaceInDifferentHals", "Conflicting FqInstance", R"( android.hardware.nfc 1 INfc default android.hardware.nfc 2 INfc default )"}); ret.push_back({"AidlFqNameInDifferentHals", "Conflicting FqInstance", R"( android.hardware.nfc 1 INfc/default android.hardware.nfc 2 INfc/default )"}); ret.push_back({"AidlInterfaceAndFqNameInDifferentHals", "Conflicting FqInstance", R"( android.hardware.nfc 1 INfc default android.hardware.nfc 2 INfc/default )"}); return ret; } static std::string getTestSuffix(const TestParamInfo& info) { return info.param.testName; } }; TEST_P(AllowDupMajorVersionTest, Allow5_0) { auto&& [_, expectedError, footer] = GetParam(); std::string xml = R"()" + footer; HalManifest vm; std::string error; EXPECT_TRUE(fromXml(&vm, xml, &error)) << "Conflicting major version in is allowed in libvintf 5.0. However, error is: " << error; } TEST_P(AllowDupMajorVersionTest, DoNotAllow6_0) { auto&& [_, expectedError, footer] = GetParam(); std::string xml = R"()" + footer; HalManifest vm; std::string error; EXPECT_FALSE(fromXml(&vm, xml, &error)); EXPECT_THAT(error, HasSubstr(expectedError)); } INSTANTIATE_TEST_SUITE_P(LibVintfTest, AllowDupMajorVersionTest, ::testing::ValuesIn(AllowDupMajorVersionTest::createParams()), &AllowDupMajorVersionTest::getTestSuffix); struct InterfaceMissingInstanceTestParam { HalFormat format; std::string footer; }; class InterfaceMissingInstanceTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; std::string hidlFooter = R"( android.hardware.nfc hwbinder 1.0 INfc )"; std::string aidlFooter = R"( android.hardware.nfc INfc )"; return {{HalFormat::HIDL, hidlFooter}, {HalFormat::AIDL, aidlFooter}}; } static std::string getTestSuffix(const TestParamInfo& info) { return to_string(info.param.format); } }; TEST_P(InterfaceMissingInstanceTest, Test5_0) { auto&& [testName, footer] = GetParam(); std::string header = R"()"; std::string xml = header + footer; HalManifest vm; std::string error; EXPECT_TRUE(fromXml(&vm, xml, &error)) << error; } TEST_P(InterfaceMissingInstanceTest, Test6_0) { auto&& [testName, footer] = GetParam(); std::string header = R"()"; std::string xml = header + footer; HalManifest vm; std::string error; EXPECT_FALSE(fromXml(&vm, xml, &error)); EXPECT_THAT(error, HasSubstr(" android.hardware.nfc INfc has no .")); } INSTANTIATE_TEST_SUITE_P(LibVintfTest, InterfaceMissingInstanceTest, ::testing::ValuesIn(InterfaceMissingInstanceTest::createParams()), &InterfaceMissingInstanceTest::getTestSuffix); struct ManifestHalNoInstanceTestParam { HalFormat format; std::string footer; }; class ManifestHalNoInstanceTest : public LibVintfTest, public ::testing::WithParamInterface { public: static std::vector createParams() { std::vector ret; std::string hidlFooter = R"( android.hardware.nfc hwbinder 1.0 )"; std::string aidlFooter = R"( android.hardware.nfc )"; return {{HalFormat::HIDL, hidlFooter}, {HalFormat::AIDL, aidlFooter}}; } static std::string getTestSuffix(const TestParamInfo& info) { return to_string(info.param.format); } }; TEST_P(ManifestHalNoInstanceTest, Test5_0) { auto&& [testName, footer] = GetParam(); std::string header = R"()"; std::string xml = header + footer; HalManifest vm; std::string error; EXPECT_TRUE(fromXml(&vm, xml, &error)) << error; } TEST_P(ManifestHalNoInstanceTest, Test6_0) { auto&& [testName, footer] = GetParam(); std::string header = R"()"; std::string xml = header + footer; HalManifest vm; std::string error; EXPECT_FALSE(fromXml(&vm, xml, &error)); EXPECT_THAT(error, HasSubstr(" android.hardware.nfc has no instance. Fix by adding .")); } INSTANTIATE_TEST_SUITE_P(LibVintfTest, ManifestHalNoInstanceTest, ::testing::ValuesIn(ManifestHalNoInstanceTest::createParams()), &ManifestHalNoInstanceTest::getTestSuffix); // clang-format off struct FrameworkCompatibilityMatrixCombineTest : public LibVintfTest { virtual void SetUp() override { matrices.resize(2); matrices[0].setFileName("compatibility_matrix.1_1.xml"); matrices[1].setFileName("compatibility_matrix.1_2.xml"); } // Access to private methods. std::unique_ptr combine(Level deviceLevel, std::vector* theMatrices, std::string* errorPtr) { return CompatibilityMatrix::combine(deviceLevel, Level::UNSPECIFIED, theMatrices, errorPtr); } std::unique_ptr combine(Level deviceLevel, Level kernellevel, std::vector* theMatrices, std::string* errorPtr) { return CompatibilityMatrix::combine(deviceLevel, kernellevel, theMatrices, errorPtr); } std::vector matrices; std::string error; }; // Combining framework compatibility matrix with conflicting minlts fails TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictMinlts) { ASSERT_TRUE(fromXml( &matrices[0], "\n" " \n" "\n", &error)) << error; ASSERT_TRUE(fromXml( &matrices[1], "\n" " \n" "\n", &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_EQ(nullptr, combined) << toXml(*combined); EXPECT_IN("Kernel version mismatch", error); } // without always comes first TEST_F(FrameworkCompatibilityMatrixCombineTest, KernelNoConditions) { std::string conditionedKernel = " \n" " \n" " \n" " CONFIG_ARM\n" " y\n" " \n" " \n" " \n" " CONFIG_FOO\n" " y\n" " \n" " \n"; std::string simpleKernel = " \n" " \n" " CONFIG_BAR\n" " y\n" " \n" " \n"; ASSERT_TRUE(fromXml( &matrices[0], "\n" " \n" + conditionedKernel + "\n", &error)) << error; ASSERT_TRUE(fromXml( &matrices[1], "\n" + simpleKernel + "\n", &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_NE(nullptr, combined); EXPECT_EQ("", error); EXPECT_EQ("\n" + simpleKernel + conditionedKernel + "\n", toXml(*combined)); } // Combining framework compatibility matrix with conflicting sepolicy fails TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictSepolicy) { ASSERT_TRUE(fromXml( &matrices[0], "\n" " \n" " 30\n" " \n" "\n", &error)) << error; ASSERT_TRUE(fromXml( &matrices[1], "\n" " \n" " 29\n" " \n" "\n", &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_EQ(nullptr, combined) << toXml(*combined); EXPECT_IN(" is already defined", error); } // Combining framework compatibility matrix with conflicting avb fails TEST_F(FrameworkCompatibilityMatrixCombineTest, ConflictAvb) { ASSERT_TRUE(fromXml( &matrices[0], "\n" " \n" " 1.1\n" " \n" "\n", &error)) << error; ASSERT_TRUE(fromXml( &matrices[1], "\n" " \n" " 1.0\n" " \n" "\n", &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_EQ(nullptr, combined) << toXml(*combined); EXPECT_IN(" is already defined", error); } TEST_F(FrameworkCompatibilityMatrixCombineTest, AidlAndHidlNames) { std::string head1{"\n"}; std::string head2{"\n"}; std::string tail{"\n"}; std::string aidl = " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n"; std::string hidl = " \n" " android.system.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n"; std::string aidlOptional = std::string(aidl).replace(hidl.find("false"), 5, "true"); std::string hidlOptional = std::string(hidl).replace(hidl.find("false"), 5, "true"); std::string error; { ASSERT_TRUE(fromXml(&matrices[0], head1 + aidl + tail, &error)) << error; ASSERT_TRUE(fromXml(&matrices[1], head1 + hidl + tail, &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_NE(nullptr, combined) << error; auto combinedXml = toXml(*combined); EXPECT_IN(aidl, combinedXml); EXPECT_IN(hidl, combinedXml); } { ASSERT_TRUE(fromXml(&matrices[0], head1 + aidl + tail, &error)) << error; ASSERT_TRUE(fromXml(&matrices[1], head2 + hidl + tail, &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_NE(nullptr, combined) << error; auto combinedXml = toXml(*combined); EXPECT_IN(aidl, combinedXml); EXPECT_IN(hidlOptional, combinedXml); } { ASSERT_TRUE(fromXml(&matrices[0], head2 + aidl + tail, &error)) << error; ASSERT_TRUE(fromXml(&matrices[1], head1 + hidl + tail, &error)) << error; auto combined = combine(Level{1}, &matrices, &error); ASSERT_NE(nullptr, combined) << error; auto combinedXml = toXml(*combined); EXPECT_IN(aidlOptional, combinedXml); EXPECT_IN(hidl, combinedXml); } } // clang-format on class FcmCombineKernelTest : public FrameworkCompatibilityMatrixCombineTest, public ::testing::WithParamInterface> { public: static std::string PrintTestParams(const TestParamInfo& info) { auto [deviceLevelNum, kernelLevelNum] = info.param; return "device_" + std::to_string(deviceLevelNum) + "_kernel_" + std::to_string(kernelLevelNum); } static constexpr size_t kMinLevel = 1; static constexpr size_t kMaxLevel = 5; }; TEST_P(FcmCombineKernelTest, OlderKernel) { auto [deviceLevelNum, kernelLevelNum] = GetParam(); std::vector levelNums; for (size_t i = kMinLevel; i <= kMaxLevel; ++i) levelNums.push_back(i); constexpr auto fmt = R"( android.system.foo %zu.0 IFoo default CONFIG_%zu y )"; std::string error; std::vector matrices; for (size_t levelNum : levelNums) { auto levelStr = android::vintf::to_string((Level)levelNum); auto xml = StringPrintf(fmt, kMetaVersionStr.c_str(), levelStr.c_str(), levelNum, levelNum, levelNum); CompatibilityMatrix& matrix = matrices.emplace_back(); ASSERT_TRUE(fromXml(&matrix, xml, &error)) << error; } ASSERT_FALSE(matrices.empty()); auto combined = combine(Level(deviceLevelNum), Level(kernelLevelNum), &matrices, &error); ASSERT_NE(nullptr, combined); auto combinedXml = toXml(*combined); // Check that HALs are combined correctly. for (size_t i = kMinLevel; i < deviceLevelNum; ++i) EXPECT_THAT(combinedXml, Not(HasSubstr(StringPrintf("%zu.0", i)))); for (size_t i = deviceLevelNum; i <= kMaxLevel; ++i) EXPECT_THAT(combinedXml, HasSubstr(StringPrintf("%zu.0", i))); // Check that kernels are combined correctly. tags from // matrices with level >= min(kernelLevel, deviceLevel) are added. // The "level" tag on must also be set properly so that old kernel requirements from // deviceLevel <= x < kernelLevel won't be used. auto hasKernelFrom = std::min(kernelLevelNum, deviceLevelNum); for (size_t i = kMinLevel; i < hasKernelFrom; ++i) { EXPECT_THAT(combinedXml, Not(HasSubstr(StringPrintf(R"( combine(std::vector* theMatrices, std::string* errorPtr) { return CompatibilityMatrix::combineDeviceMatrices(theMatrices, errorPtr); } std::vector matrices; std::string error; }; TEST_F(DeviceCompatibilityMatrixCombineTest, Success) { std::string head{"\n"}; std::string tail{"\n"}; std::string halFoo{ " \n" " android.hardware.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n"}; std::string halBar{ " \n" " android.hardware.bar\n" " 1.0\n" " \n" " IBar\n" " default\n" " \n" " \n"}; ASSERT_TRUE(fromXml(&matrices[0], head + halFoo + tail, &error)) << error; ASSERT_TRUE(fromXml(&matrices[1], head + halBar + tail, &error)) << error; auto combined = combine(&matrices, &error); ASSERT_NE(nullptr, combined) << error; EXPECT_EQ("", error); auto combinedXml = toXml(*combined); EXPECT_IN(halFoo, combinedXml); EXPECT_IN(halBar, combinedXml); } TEST_F(DeviceCompatibilityMatrixCombineTest, ConflictVendorNdk) { std::string vendorNdkP{ "\n" " \n" " P\n" " \n" "\n"}; std::string vendorNdkQ{ "\n" " \n" " Q\n" " \n" "\n"}; ASSERT_TRUE(fromXml(&matrices[0], vendorNdkP, &error)) << error; ASSERT_TRUE(fromXml(&matrices[1], vendorNdkQ, &error)) << error; auto combined = combine(&matrices, &error); ASSERT_EQ(nullptr, combined) << toXml(*combined); EXPECT_IN(" is already defined", error); } TEST_F(DeviceCompatibilityMatrixCombineTest, AidlAndHidlNames) { std::string head{"\n"}; std::string tail{"\n"}; std::string aidl = " \n" " android.system.foo\n" " \n" " IFoo\n" " default\n" " \n" " \n"; std::string hidl = " \n" " android.system.foo\n" " 1.0\n" " \n" " IFoo\n" " default\n" " \n" " \n"; ASSERT_TRUE(fromXml(&matrices[0], head + aidl + tail, &error)) << error; ASSERT_TRUE(fromXml(&matrices[1], head + hidl + tail, &error)) << error; auto combined = combine(&matrices, &error); ASSERT_NE(nullptr, combined) << error; auto combinedXml = toXml(*combined); EXPECT_IN(aidl, combinedXml); EXPECT_IN(hidl, combinedXml); } // clang-format on } // namespace vintf } // namespace android int main(int argc, char **argv) { ::testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); }