From 45e5f72a1433f385afcda5ebf28c38a4010f8fda Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 23 Aug 2017 14:46:44 -0700 Subject: Add tests for kernel config fragments in fwk comp mat. Test: libvintf_test Bug: 64124223 Change-Id: I04f3332c84ec9e9c025079f6f83e2573dab27a81 Merged-In: I04f3332c84ec9e9c025079f6f83e2573dab27a81 --- test/main.cpp | 367 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) diff --git a/test/main.cpp b/test/main.cpp index d8cfaf3..94a4d8e 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -100,6 +100,7 @@ public: bool isValid(const ManifestHal &mh) { return mh.isValid(); } + std::vector& getKernels(CompatibilityMatrix& cm) { return cm.framework.mKernels; } std::map testHalInterfaces() { HalInterface intf; @@ -708,6 +709,12 @@ TEST_F(LibVintfTest, RuntimeInfo) { 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)); @@ -1534,6 +1541,366 @@ TEST_F(LibVintfTest, NetutilsWrapperManifest) { #endif // LIBVINTF_HOST } +TEST_F(LibVintfTest, KernelConfigConditionTest) { + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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, gCompatibilityMatrixConverter(cm)); +} + +TEST_F(LibVintfTest, KernelConfigConditionEmptyTest) { + std::string xml = + "\n" + " \n" + " \n" + " \n" + " \n" + " CONFIG_ARM\n" + " y\n" + " \n" + " \n" + " \n" + "\n"; + + CompatibilityMatrix cm; + EXPECT_FALSE(gCompatibilityMatrixConverter(&cm, xml)) + << "Should not accept first kernel version with non-empty conditions"; + EXPECT_EQ( + "First for version 3.18 must have empty " + "for backwards compatibility.", + gCompatibilityMatrixConverter.lastError()); +} + +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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + 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(gCompatibilityMatrixConverter(&cm, xml)) + << gCompatibilityMatrixConverter.lastError(); + EXPECT_FALSE(runtime.checkCompatibility(cm, &error)) << "all fragments should be used"; +} + // Run KernelConfigParserInvalidTest on processComments = {true, false} class KernelConfigParserInvalidTest : public ::testing::TestWithParam {}; -- cgit v1.2.3-54-g00ecf