OSDN Git Service

Fix the vts error
authorSundong Ahn <sundongahn@google.com>
Tue, 7 May 2019 13:06:48 +0000 (22:06 +0900)
committerSundong Ahn <sundongahn@google.com>
Wed, 8 May 2019 01:21:44 +0000 (10:21 +0900)
On some devices, default-permissions.xml file is on the product
partition. Modify the test case so that VTS passes even if
default-permissions.xml doesn't exist.
According to the parser code, the xml file can exist in an odm
partition. So add the odm partition to the location.

Bug: 132048214
Test: m -j vts
Test: vts-tradefed run vts -m VtsValidateDefaultPermissions
Change-Id: Ia518a51129b8acb2de68ee2cd537b57ef6378b32

services/core/xsd/vts/Android.bp
services/core/xsd/vts/ValidateDefaultPermissions.cpp

index 967750d..5545656 100644 (file)
@@ -25,6 +25,7 @@ cc_test {
     ],
     shared_libs: [
         "liblog",
+        "libbase",
     ],
     cflags: [
         "-Wall",
index 54c115b..518f7bb 100644 (file)
 
 #include "utility/ValidateXml.h"
 
-TEST(CheckConfig, mediaDefaultPermissions) {
+#include <dirent.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <string>
+
+#include <android-base/strings.h>
+
+static std::vector<std::string> get_files_in_dirs(const char* dir_path) {
+    std::vector<std::string> files;
+    std::unique_ptr<DIR, decltype(&closedir)> d(opendir(dir_path), closedir);
+
+    if (d == nullptr) {
+        return files;
+    }
+
+    struct dirent* de;
+    while ((de = readdir(d.get()))) {
+        if (de->d_type != DT_REG) {
+            continue;
+        }
+        if (android::base::EndsWith(de->d_name, ".xml")) {
+            files.push_back(de->d_name);
+        }
+    }
+    return files;
+}
+
+TEST(CheckConfig, defaultPermissions) {
     RecordProperty("description",
                    "Verify that the default-permissions file "
                    "is valid according to the schema");
 
-    const char* location = "/vendor/etc/default-permissions";
+    std::vector<const char*> locations = {"/vendor/etc/default-permissions",
+                                          "/odm/etc/default-permissions"};
 
-    EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("default-permissions.xml", {location},
-                                            "/data/local/tmp/default-permissions.xsd");
+    for (const char* dir_path : locations) {
+        std::vector<std::string> files = get_files_in_dirs(dir_path);
+        for (auto& file_name : files) {
+            EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(file_name.c_str(), {dir_path},
+                                                    "/data/local/tmp/default-permissions.xsd");
+        }
+    }
 }