1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <dirent.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 #include <string>
23
24 #include <android-base/properties.h>
25 #include "utility/ValidateXml.h"
26
get_files_in_dirs(const char * dir_path,std::vector<std::string> & files)27 static void get_files_in_dirs(const char* dir_path, std::vector<std::string>& files) {
28 DIR* d;
29 struct dirent* de;
30
31 d = opendir(dir_path);
32 if (d == nullptr) {
33 return;
34 }
35
36 while ((de = readdir(d))) {
37 if (de->d_type != DT_REG) {
38 continue;
39 }
40 files.push_back(de->d_name);
41 }
42 closedir(d);
43 }
44
TEST(CheckConfig,halManifestValidation)45 TEST(CheckConfig, halManifestValidation) {
46 if (android::base::GetIntProperty("ro.product.first_api_level", 0) <= 28) {
47 GTEST_SKIP();
48 }
49
50 RecordProperty("description",
51 "Verify that the hal manifest file "
52 "is valid according to the schema");
53
54 EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("manifest.xml", {"/vendor/etc/vintf/"},
55 "/data/local/tmp/hal_manifest.xsd");
56
57 std::vector<const char*> locations = {"/vendor/etc/vintf/manifest", "/odm/etc/vintf"};
58
59 for (const char* dir_path : locations) {
60 std::vector<std::string> files;
61 get_files_in_dirs(dir_path, files);
62 for (std::string file_name : files) {
63 EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(file_name.c_str(), {dir_path},
64 "/data/local/tmp/hal_manifest.xsd");
65 }
66 }
67 }
68