summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2018-03-29 02:25:04 -0500
committerandroid-build-team Robot2018-03-29 02:25:04 -0500
commitd2d2f72a38b42b029de7092e12b8c2d56b3c4a37 (patch)
tree2ecbc8c706a277b5c788de45f9cfb2a9d155003e
parent804cfa5802b89600b204ff194d879ec03ce2a26f (diff)
parent9295851019e7f8c4ecec7fa07ca5c9d7f0278ffe (diff)
downloadplatform-system-libvintf-d2d2f72a38b42b029de7092e12b8c2d56b3c4a37.tar.gz
platform-system-libvintf-d2d2f72a38b42b029de7092e12b8c2d56b3c4a37.tar.xz
platform-system-libvintf-d2d2f72a38b42b029de7092e12b8c2d56b3c4a37.zip
Snap for 4686875 from 9295851019e7f8c4ecec7fa07ca5c9d7f0278ffe to pi-release
Change-Id: Ia053172ff699ca89fd5e86e3d460445978432988
-rw-r--r--AssembleVintf.cpp18
-rw-r--r--CompatibilityMatrix.cpp49
-rw-r--r--test/AssembleVintfTest.cpp82
3 files changed, 109 insertions, 40 deletions
diff --git a/AssembleVintf.cpp b/AssembleVintf.cpp
index 39bdd3a..7f86b94 100644
--- a/AssembleVintf.cpp
+++ b/AssembleVintf.cpp
@@ -368,6 +368,11 @@ class AssembleVintfImpl : public AssembleVintf {
368 } 368 }
369 369
370 bool setDeviceFcmVersion(HalManifest* manifest) { 370 bool setDeviceFcmVersion(HalManifest* manifest) {
371 // Not needed for generating empty manifest for DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE.
372 if (getBooleanFlag("IGNORE_TARGET_FCM_VERSION")) {
373 return true;
374 }
375
371 size_t shippingApiLevel = getIntegerFlag("PRODUCT_SHIPPING_API_LEVEL"); 376 size_t shippingApiLevel = getIntegerFlag("PRODUCT_SHIPPING_API_LEVEL");
372 377
373 if (manifest->level() != Level::UNSPECIFIED) { 378 if (manifest->level() != Level::UNSPECIFIED) {
@@ -457,15 +462,10 @@ class AssembleVintfImpl : public AssembleVintf {
457 deviceLevel = getLowestFcmVersion(*matrices); 462 deviceLevel = getLowestFcmVersion(*matrices);
458 } 463 }
459 464
460 if (deviceLevel == Level::UNSPECIFIED) { 465 matrix = CompatibilityMatrix::combine(deviceLevel, matrices, &error);
461 // building empty.xml 466 if (matrix == nullptr) {
462 matrix = &matrices->front().object; 467 std::cerr << error << std::endl;
463 } else { 468 return false;
464 matrix = CompatibilityMatrix::combine(deviceLevel, matrices, &error);
465 if (matrix == nullptr) {
466 std::cerr << error << std::endl;
467 return false;
468 }
469 } 469 }
470 470
471 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) { 471 if (!assembleFrameworkCompatibilityMatrixKernels(matrix)) {
diff --git a/CompatibilityMatrix.cpp b/CompatibilityMatrix.cpp
index 88ecd26..451ca60 100644
--- a/CompatibilityMatrix.cpp
+++ b/CompatibilityMatrix.cpp
@@ -215,35 +215,25 @@ bool operator==(const CompatibilityMatrix &lft, const CompatibilityMatrix &rgt)
215// as a base matrix. 215// as a base matrix.
216CompatibilityMatrix* CompatibilityMatrix::findOrInsertBaseMatrix( 216CompatibilityMatrix* CompatibilityMatrix::findOrInsertBaseMatrix(
217 std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) { 217 std::vector<Named<CompatibilityMatrix>>* matrices, std::string* error) {
218 bool multipleFound = false; 218 std::vector<CompatibilityMatrix*> matricesUnspecified;
219 CompatibilityMatrix* matrix = nullptr; 219 std::vector<CompatibilityMatrix*> matricesEmpty;
220 for (auto& e : *matrices) { 220 for (auto& e : *matrices) {
221 if (e.object.level() == Level::UNSPECIFIED) { 221 if (e.object.level() == Level::UNSPECIFIED) {
222 matricesUnspecified.push_back(&e.object);
223
222 if (!e.object.mHals.empty()) { 224 if (!e.object.mHals.empty()) {
223 if (error) { 225 continue;
224 *error = "Error: File \"" + e.name + "\" should not contain " + "HAL elements.";
225 }
226 return nullptr;
227 } 226 }
228 227
229 if (!e.object.mXmlFiles.empty()) { 228 if (!e.object.mXmlFiles.empty()) {
230 if (error) { 229 continue;
231 *error =
232 "Error: File \"" + e.name + "\" should not contain " + "XML File elements.";
233 }
234 return nullptr;
235 }
236
237 if (matrix != nullptr) {
238 multipleFound = true;
239 } 230 }
240 231
241 matrix = &e.object; 232 matricesEmpty.push_back(&e.object);
242 // continue to detect multiple files with "unspecified" levels
243 } 233 }
244 } 234 }
245 235
246 if (multipleFound) { 236 if (matricesEmpty.size() > 1) {
247 if (error) { 237 if (error) {
248 *error = 238 *error =
249 "Error: multiple framework compatibility matrix files have " 239 "Error: multiple framework compatibility matrix files have "
@@ -256,25 +246,21 @@ CompatibilityMatrix* CompatibilityMatrix::findOrInsertBaseMatrix(
256 } 246 }
257 return nullptr; 247 return nullptr;
258 } 248 }
259 249 if (matricesEmpty.size() == 1) {
260 if (matrix == nullptr) { 250 return matricesEmpty.front();
261 matrix = &matrices->emplace(matrices->end())->object;
262 matrix->mType = SchemaType::FRAMEWORK;
263 matrix->mLevel = Level::UNSPECIFIED;
264 } 251 }
265 252 if (!matricesUnspecified.empty()) {
253 return matricesUnspecified.front();
254 }
255 auto matrix = &matrices->emplace(matrices->end())->object;
256 matrix->mType = SchemaType::FRAMEWORK;
257 matrix->mLevel = Level::UNSPECIFIED;
266 return matrix; 258 return matrix;
267} 259}
268 260
269CompatibilityMatrix* CompatibilityMatrix::combine(Level deviceLevel, 261CompatibilityMatrix* CompatibilityMatrix::combine(Level deviceLevel,
270 std::vector<Named<CompatibilityMatrix>>* matrices, 262 std::vector<Named<CompatibilityMatrix>>* matrices,
271 std::string* error) { 263 std::string* error) {
272 if (deviceLevel == Level::UNSPECIFIED) {
273 if (error) {
274 *error = "Error: device level is unspecified.";
275 }
276 return nullptr;
277 }
278 264
279 CompatibilityMatrix* matrix = findOrInsertBaseMatrix(matrices, error); 265 CompatibilityMatrix* matrix = findOrInsertBaseMatrix(matrices, error);
280 if (matrix == nullptr) { 266 if (matrix == nullptr) {
@@ -284,7 +270,8 @@ CompatibilityMatrix* CompatibilityMatrix::combine(Level deviceLevel,
284 matrix->mLevel = deviceLevel; 270 matrix->mLevel = deviceLevel;
285 271
286 for (auto& e : *matrices) { 272 for (auto& e : *matrices) {
287 if (&e.object != matrix && e.object.level() == deviceLevel) { 273 if (&e.object != matrix &&
274 (e.object.level() == deviceLevel || e.object.level() == Level::UNSPECIFIED)) {
288 if (!matrix->addAllHals(&e.object, error)) { 275 if (!matrix->addAllHals(&e.object, error)) {
289 if (error) { 276 if (error) {
290 *error = "File \"" + e.name + "\" cannot be added: HAL " + *error + 277 *error = "File \"" + e.name + "\" cannot be added: HAL " + *error +
diff --git a/test/AssembleVintfTest.cpp b/test/AssembleVintfTest.cpp
index e01a15e..b629c74 100644
--- a/test/AssembleVintfTest.cpp
+++ b/test/AssembleVintfTest.cpp
@@ -374,5 +374,87 @@ TEST_F(AssembleVintfTest, ManifestSystemSdk) {
374 getOutput()); 374 getOutput());
375} 375}
376 376
377const std::string gEmptyOutManifest =
378 "<manifest version=\"1.0\" type=\"device\">\n"
379 " <sepolicy>\n"
380 " <version>10000.0</version>\n"
381 " </sepolicy>\n"
382 "</manifest>\n";
383
384TEST_F(AssembleVintfTest, EmptyManifest) {
385 const std::string emptyManifest = "<manifest version=\"1.0\" type=\"device\" />";
386 setFakeEnvs({{"BOARD_SEPOLICY_VERS", "10000.0"}, {"IGNORE_TARGET_FCM_VERSION", "true"}});
387 addInput("manifest.empty.xml", emptyManifest);
388 EXPECT_TRUE(getInstance()->assemble());
389 EXPECT_IN(gEmptyOutManifest, getOutput());
390}
391
392TEST_F(AssembleVintfTest, DeviceFrameworkMatrixOptional) {
393 setFakeEnvs({{"POLICYVERS", "30"},
394 {"PLATFORM_SEPOLICY_VERSION", "10000.0"},
395 {"PLATFORM_SEPOLICY_COMPAT_VERSIONS", "26.0 27.0"},
396 {"FRAMEWORK_VBMETA_VERSION", "1.0"},
397 {"PRODUCT_ENFORCE_VINTF_MANIFEST", "true"}});
398 getInstance()->setCheckInputStream(makeStream(gEmptyOutManifest));
399
400 addInput("compatibility_matrix.empty.xml",
401 "<compatibility-matrix version=\"1.0\" type=\"framework\">\n"
402 " <hal format=\"hidl\" optional=\"true\">\n"
403 " <name>vendor.foo.bar</name>\n"
404 " <version>1.0</version>\n"
405 " <interface>\n"
406 " <name>IFoo</name>\n"
407 " <instance>default</instance>\n"
408 " </interface>\n"
409 " </hal>\n"
410 "</compatibility-matrix>");
411
412 EXPECT_TRUE(getInstance()->assemble());
413 EXPECT_IN(
414 "<compatibility-matrix version=\"1.0\" type=\"framework\">\n"
415 " <hal format=\"hidl\" optional=\"true\">\n"
416 " <name>vendor.foo.bar</name>\n"
417 " <version>1.0</version>\n"
418 " <interface>\n"
419 " <name>IFoo</name>\n"
420 " <instance>default</instance>\n"
421 " </interface>\n"
422 " </hal>\n"
423 " <sepolicy>\n"
424 " <kernel-sepolicy-version>30</kernel-sepolicy-version>\n"
425 " <sepolicy-version>26.0</sepolicy-version>\n"
426 " <sepolicy-version>27.0</sepolicy-version>\n"
427 " <sepolicy-version>10000.0</sepolicy-version>\n"
428 " </sepolicy>\n"
429 " <avb>\n"
430 " <vbmeta-version>1.0</vbmeta-version>\n"
431 " </avb>\n"
432 "</compatibility-matrix>",
433 getOutput());
434}
435
436TEST_F(AssembleVintfTest, DeviceFrameworkMatrixRequired) {
437 setFakeEnvs({{"POLICYVERS", "30"},
438 {"PLATFORM_SEPOLICY_VERSION", "10000.0"},
439 {"PLATFORM_SEPOLICY_COMPAT_VERSIONS", "26.0 27.0"},
440 {"FRAMEWORK_VBMETA_VERSION", "1.0"},
441 {"PRODUCT_ENFORCE_VINTF_MANIFEST", "true"}});
442 getInstance()->setCheckInputStream(makeStream(gEmptyOutManifest));
443
444 addInput("compatibility_matrix.empty.xml",
445 "<compatibility-matrix version=\"1.0\" type=\"framework\">\n"
446 " <hal format=\"hidl\" optional=\"false\">\n"
447 " <name>vendor.foo.bar</name>\n"
448 " <version>1.0</version>\n"
449 " <interface>\n"
450 " <name>IFoo</name>\n"
451 " <instance>default</instance>\n"
452 " </interface>\n"
453 " </hal>\n"
454 "</compatibility-matrix>");
455
456 EXPECT_FALSE(getInstance()->assemble());
457}
458
377} // namespace vintf 459} // namespace vintf
378} // namespace android 460} // namespace android