summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-08-17 02:30:00 -0500
committerandroid-build-team Robot2017-08-17 02:30:00 -0500
commitf4cc7d50905f972e573594c7484d4d0607e49518 (patch)
treec6659d8ed65768783c44a2ad34a2dec1ff1c6a00
parent797804942182e118cd63b3161843a03c1601a84b (diff)
parentcef6437c31623647ec2200d46272f7ac5485aeb1 (diff)
downloadplatform-system-libvintf-f4cc7d50905f972e573594c7484d4d0607e49518.tar.gz
platform-system-libvintf-f4cc7d50905f972e573594c7484d4d0607e49518.tar.xz
platform-system-libvintf-f4cc7d50905f972e573594c7484d4d0607e49518.zip
release-request-edd71ba9-6f93-47be-957d-774c9d43a2dc-for-git_oc-mr1-release-4281935 snap-temp-L68100000094184972
Change-Id: Idba23eb68d6b0af1c647be21bf5d85ed39df11bf
-rw-r--r--Android.bp5
-rw-r--r--RuntimeInfo.cpp3
-rw-r--r--parse_xml.cpp60
-rw-r--r--test/Android.bp6
-rw-r--r--test/main.cpp113
5 files changed, 183 insertions, 4 deletions
diff --git a/Android.bp b/Android.bp
index 7203222..70c7dc8 100644
--- a/Android.bp
+++ b/Android.bp
@@ -56,7 +56,10 @@ cc_library {
56 host: { 56 host: {
57 srcs: [ 57 srcs: [
58 "RuntimeInfo-host.cpp" 58 "RuntimeInfo-host.cpp"
59 ] 59 ],
60 cflags: [
61 "-DLIBVINTF_HOST",
62 ],
60 }, 63 },
61 android: { 64 android: {
62 shared_libs: [ 65 shared_libs: [
diff --git a/RuntimeInfo.cpp b/RuntimeInfo.cpp
index 213d898..b29a146 100644
--- a/RuntimeInfo.cpp
+++ b/RuntimeInfo.cpp
@@ -118,8 +118,6 @@ bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
118 } 118 }
119 } 119 }
120 120
121 // TODO(b/38325029) enable avb check when avb version is injected to fwk matrix.
122#if 0
123 const Version &matAvb = mat.framework.mAvbMetaVersion; 121 const Version &matAvb = mat.framework.mAvbMetaVersion;
124 if (mBootAvbVersion.majorVer != matAvb.majorVer || mBootAvbVersion.minorVer < matAvb.minorVer) { 122 if (mBootAvbVersion.majorVer != matAvb.majorVer || mBootAvbVersion.minorVer < matAvb.minorVer) {
125 if (error != nullptr) { 123 if (error != nullptr) {
@@ -140,7 +138,6 @@ bool RuntimeInfo::checkCompatibility(const CompatibilityMatrix &mat,
140 } 138 }
141 return false; 139 return false;
142 } 140 }
143#endif
144 141
145 return true; 142 return true;
146} 143}
diff --git a/parse_xml.cpp b/parse_xml.cpp
index 518faec..5239275 100644
--- a/parse_xml.cpp
+++ b/parse_xml.cpp
@@ -507,8 +507,44 @@ struct MatrixHalConverter : public XmlNodeConverter<MatrixHal> {
507 return false; 507 return false;
508 } 508 }
509 } 509 }
510// Do not check for target-side libvintf to avoid restricting ability for upgrade accidentally.
511#ifdef LIBVINTF_HOST
512 if (!checkAdditionalRestrictionsOnHal(*object)) {
513 return false;
514 }
515#endif
516 return true;
517 }
518
519#ifdef LIBVINTF_HOST
520 private:
521 bool checkAdditionalRestrictionsOnHal(const MatrixHal& hal) const {
522 if (hal.getName() == "netutils-wrapper") {
523 if (hal.versionRanges.size() != 1) {
524 this->mLastError =
525 "netutils-wrapper HAL must specify exactly one version x.0, "
526 "but multiple <version> element is specified.";
527 return false;
528 }
529 const VersionRange& v = hal.versionRanges.at(0);
530 if (!v.isSingleVersion()) {
531 this->mLastError =
532 "netutils-wrapper HAL must specify exactly one version x.0, "
533 "but a range is provided. Perhaps you mean '" +
534 to_string(Version{v.majorVer, 0}) + "'?";
535 return false;
536 }
537 if (v.minMinor != 0) {
538 this->mLastError =
539 "netutils-wrapper HAL must specify exactly one version x.0, "
540 "but minor version is not 0. Perhaps you mean '" +
541 to_string(Version{v.majorVer, 0}) + "'?";
542 return false;
543 }
544 }
510 return true; 545 return true;
511 } 546 }
547#endif
512}; 548};
513 549
514const MatrixHalConverter matrixHalConverter{}; 550const MatrixHalConverter matrixHalConverter{};
@@ -589,8 +625,32 @@ struct ManifestHalConverter : public XmlNodeConverter<ManifestHal> {
589 this->mLastError = "'" + object->name + "' is not a valid Manifest HAL."; 625 this->mLastError = "'" + object->name + "' is not a valid Manifest HAL.";
590 return false; 626 return false;
591 } 627 }
628// Do not check for target-side libvintf to avoid restricting upgrade accidentally.
629#ifdef LIBVINTF_HOST
630 if (!checkAdditionalRestrictionsOnHal(*object)) {
631 return false;
632 }
633#endif
634 return true;
635 }
636
637#ifdef LIBVINTF_HOST
638 private:
639 bool checkAdditionalRestrictionsOnHal(const ManifestHal& hal) const {
640 if (hal.getName() == "netutils-wrapper") {
641 for (const Version& v : hal.versions) {
642 if (v.minorVer != 0) {
643 this->mLastError =
644 "netutils-wrapper HAL must specify exactly one version x.0, "
645 "but minor version is not 0. Perhaps you mean '" +
646 to_string(Version{v.majorVer, 0}) + "'?";
647 return false;
648 }
649 }
650 }
592 return true; 651 return true;
593 } 652 }
653#endif
594}; 654};
595 655
596// Convert ManifestHal from and to XML. Returned object is guaranteed to have 656// Convert ManifestHal from and to XML. Returned object is guaranteed to have
diff --git a/test/Android.bp b/test/Android.bp
index f6053ea..c5aa618 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -14,6 +14,7 @@
14 14
15cc_test { 15cc_test {
16 name: "libvintf_test", 16 name: "libvintf_test",
17 host_supported: true,
17 gtest: false, 18 gtest: false,
18 srcs: ["main.cpp"], 19 srcs: ["main.cpp"],
19 20
@@ -29,6 +30,11 @@ cc_test {
29 "-O0", 30 "-O0",
30 "-g", 31 "-g",
31 ], 32 ],
33 target: {
34 host: {
35 cflags: ["-DLIBVINTF_HOST"],
36 }
37 }
32} 38}
33 39
34cc_test { 40cc_test {
diff --git a/test/main.cpp b/test/main.cpp
index 42932e5..d8cfaf3 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -39,6 +39,12 @@ extern const XmlConverter<KernelConfigTypedValue> &gKernelConfigTypedValueConver
39extern const XmlConverter<HalManifest> &gHalManifestConverter; 39extern const XmlConverter<HalManifest> &gHalManifestConverter;
40extern const XmlConverter<CompatibilityMatrix> &gCompatibilityMatrixConverter; 40extern const XmlConverter<CompatibilityMatrix> &gCompatibilityMatrixConverter;
41 41
42static bool Contains(const std::string& str, const std::string& sub) {
43 return str.find(sub) != std::string::npos;
44}
45#define EXPECT_CONTAINS(str, sub) \
46 EXPECT_TRUE(Contains((str), (sub))) << "Cannot find \"" << (sub) << "\" in \"" << (str) << "\""
47
42struct LibVintfTest : public ::testing::Test { 48struct LibVintfTest : public ::testing::Test {
43public: 49public:
44 virtual void SetUp() override { 50 virtual void SetUp() override {
@@ -1421,6 +1427,113 @@ TEST_F(LibVintfTest, KernelConfigParserSpace) {
1421 EXPECT_EQ(configs.find("CONFIG_NOT_SET")->second, "n"); 1427 EXPECT_EQ(configs.find("CONFIG_NOT_SET")->second, "n");
1422} 1428}
1423 1429
1430TEST_F(LibVintfTest, NetutilsWrapperMatrix) {
1431 std::string matrixXml;
1432 CompatibilityMatrix matrix;
1433
1434 matrixXml =
1435 "<compatibility-matrix version=\"1.0\" type=\"device\">"
1436 " <hal format=\"native\" optional=\"false\">"
1437 " <name>netutils-wrapper</name>"
1438 " <version>1.0</version>"
1439 " </hal>"
1440 "</compatibility-matrix>";
1441 EXPECT_TRUE(gCompatibilityMatrixConverter(&matrix, matrixXml))
1442 << gCompatibilityMatrixConverter.lastError();
1443
1444// only host libvintf hardcodes netutils-wrapper version requirements
1445#ifdef LIBVINTF_HOST
1446
1447 matrixXml =
1448 "<compatibility-matrix version=\"1.0\" type=\"device\">"
1449 " <hal format=\"native\" optional=\"false\">"
1450 " <name>netutils-wrapper</name>"
1451 " <version>1.0-1</version>"
1452 " </hal>"
1453 "</compatibility-matrix>";
1454 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1455 EXPECT_CONTAINS(
1456 gCompatibilityMatrixConverter.lastError(),
1457 "netutils-wrapper HAL must specify exactly one version x.0, but a range is provided. "
1458 "Perhaps you mean '1.0'?");
1459
1460 matrixXml =
1461 "<compatibility-matrix version=\"1.0\" type=\"device\">"
1462 " <hal format=\"native\" optional=\"false\">"
1463 " <name>netutils-wrapper</name>"
1464 " <version>1.1</version>"
1465 " </hal>"
1466 "</compatibility-matrix>";
1467 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1468 EXPECT_CONTAINS(
1469 gCompatibilityMatrixConverter.lastError(),
1470 "netutils-wrapper HAL must specify exactly one version x.0, but minor version is not 0. "
1471 "Perhaps you mean '1.0'?");
1472
1473 matrixXml =
1474 "<compatibility-matrix version=\"1.0\" type=\"device\">"
1475 " <hal format=\"native\" optional=\"false\">"
1476 " <name>netutils-wrapper</name>"
1477 " <version>1.0</version>"
1478 " <version>2.0</version>"
1479 " </hal>"
1480 "</compatibility-matrix>";
1481 EXPECT_FALSE(gCompatibilityMatrixConverter(&matrix, matrixXml));
1482 EXPECT_CONTAINS(
1483 gCompatibilityMatrixConverter.lastError(),
1484 "netutils-wrapper HAL must specify exactly one version x.0, but multiple <version> element "
1485 "is specified.");
1486
1487#endif // LIBVINTF_HOST
1488}
1489
1490TEST_F(LibVintfTest, NetutilsWrapperManifest) {
1491 std::string manifestXml;
1492 HalManifest manifest;
1493
1494 manifestXml =
1495 "<manifest version=\"1.0\" type=\"framework\">"
1496 " <hal format=\"native\">"
1497 " <name>netutils-wrapper</name>"
1498 " <version>1.0</version>"
1499 " <version>2.0</version>"
1500 " </hal>"
1501 "</manifest>";
1502 EXPECT_TRUE(gHalManifestConverter(&manifest, manifestXml)) << gHalManifestConverter.lastError();
1503
1504// only host libvintf hardcodes netutils-wrapper version requirements
1505#ifdef LIBVINTF_HOST
1506
1507 manifestXml =
1508 "<manifest version=\"1.0\" type=\"framework\">"
1509 " <hal format=\"native\">"
1510 " <name>netutils-wrapper</name>"
1511 " <version>1.1</version>"
1512 " </hal>"
1513 "</manifest>";
1514 EXPECT_FALSE(gHalManifestConverter(&manifest, manifestXml));
1515 EXPECT_CONTAINS(
1516 gCompatibilityMatrixConverter.lastError(),
1517 "netutils-wrapper HAL must specify exactly one version x.0, but multiple <version> element "
1518 "is specified.");
1519
1520 manifestXml =
1521 "<manifest version=\"1.0\" type=\"framework\">"
1522 " <hal format=\"native\">"
1523 " <name>netutils-wrapper</name>"
1524 " <version>1.0</version>"
1525 " <version>2.1</version>"
1526 " </hal>"
1527 "</manifest>";
1528 EXPECT_FALSE(gHalManifestConverter(&manifest, manifestXml));
1529 EXPECT_CONTAINS(
1530 gCompatibilityMatrixConverter.lastError(),
1531 "netutils-wrapper HAL must specify exactly one version x.0, but multiple <version> element "
1532 "is specified.");
1533
1534#endif // LIBVINTF_HOST
1535}
1536
1424// Run KernelConfigParserInvalidTest on processComments = {true, false} 1537// Run KernelConfigParserInvalidTest on processComments = {true, false}
1425class KernelConfigParserInvalidTest : public ::testing::TestWithParam<bool> {}; 1538class KernelConfigParserInvalidTest : public ::testing::TestWithParam<bool> {};
1426 1539