xref: /aosp_15_r20/kernel/configs/xsd/approvedBuild/vts/ValidateApprovedBuild.cpp (revision 1d3556b860e096874ddca674556f5d20fb3a73b0)
1 /*
2  * Copyright (C) 2024 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 <android-base/file.h>
18 #include <kver/kernel_release.h>
19 #include <unistd.h>
20 #include <vintf/VintfObject.h>
21 
22 #include <string>
23 
24 #include "utility/ValidateXml.h"
25 
TEST(CheckConfig,approvedBuildValidation)26 TEST(CheckConfig, approvedBuildValidation) {
27   const auto kernel_release = android::kver::KernelRelease::Parse(
28       android::vintf::VintfObject::GetRuntimeInfo()->osRelease(),
29       /* allow_suffix = */ true);
30   if (!kernel_release.has_value()) {
31     GTEST_FAIL() << "Failed to parse the kernel release string";
32   }
33   if (kernel_release->android_release() < 14) {
34     GTEST_SKIP() << "Kernel releases below android14 are exempt";
35   }
36 
37   RecordProperty("description",
38                  "Verify that the approved OGKI builds file "
39                  "is valid according to the schema");
40 
41   std::string xml_schema_path =
42       android::base::GetExecutableDirectory() + "/approved_build.xsd";
43   std::vector<const char*> locations = {"/system/etc/kernel"};
44   EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("approved-ogki-builds.xml", locations,
45                                           xml_schema_path.c_str());
46 }
47