1*1d3556b8SAndroid Build Coastguard Worker /*
2*1d3556b8SAndroid Build Coastguard Worker * Copyright (C) 2024 The Android Open Source Project
3*1d3556b8SAndroid Build Coastguard Worker *
4*1d3556b8SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*1d3556b8SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*1d3556b8SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*1d3556b8SAndroid Build Coastguard Worker *
8*1d3556b8SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*1d3556b8SAndroid Build Coastguard Worker *
10*1d3556b8SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*1d3556b8SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*1d3556b8SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*1d3556b8SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*1d3556b8SAndroid Build Coastguard Worker * limitations under the License.
15*1d3556b8SAndroid Build Coastguard Worker */
16*1d3556b8SAndroid Build Coastguard Worker
17*1d3556b8SAndroid Build Coastguard Worker #include <android-base/file.h>
18*1d3556b8SAndroid Build Coastguard Worker #include <kver/kernel_release.h>
19*1d3556b8SAndroid Build Coastguard Worker #include <unistd.h>
20*1d3556b8SAndroid Build Coastguard Worker #include <vintf/VintfObject.h>
21*1d3556b8SAndroid Build Coastguard Worker
22*1d3556b8SAndroid Build Coastguard Worker #include <string>
23*1d3556b8SAndroid Build Coastguard Worker
24*1d3556b8SAndroid Build Coastguard Worker #include "utility/ValidateXml.h"
25*1d3556b8SAndroid Build Coastguard Worker
TEST(CheckConfig,approvedBuildValidation)26*1d3556b8SAndroid Build Coastguard Worker TEST(CheckConfig, approvedBuildValidation) {
27*1d3556b8SAndroid Build Coastguard Worker const auto kernel_release = android::kver::KernelRelease::Parse(
28*1d3556b8SAndroid Build Coastguard Worker android::vintf::VintfObject::GetRuntimeInfo()->osRelease(),
29*1d3556b8SAndroid Build Coastguard Worker /* allow_suffix = */ true);
30*1d3556b8SAndroid Build Coastguard Worker if (!kernel_release.has_value()) {
31*1d3556b8SAndroid Build Coastguard Worker GTEST_FAIL() << "Failed to parse the kernel release string";
32*1d3556b8SAndroid Build Coastguard Worker }
33*1d3556b8SAndroid Build Coastguard Worker if (kernel_release->android_release() < 14) {
34*1d3556b8SAndroid Build Coastguard Worker GTEST_SKIP() << "Kernel releases below android14 are exempt";
35*1d3556b8SAndroid Build Coastguard Worker }
36*1d3556b8SAndroid Build Coastguard Worker
37*1d3556b8SAndroid Build Coastguard Worker RecordProperty("description",
38*1d3556b8SAndroid Build Coastguard Worker "Verify that the approved OGKI builds file "
39*1d3556b8SAndroid Build Coastguard Worker "is valid according to the schema");
40*1d3556b8SAndroid Build Coastguard Worker
41*1d3556b8SAndroid Build Coastguard Worker std::string xml_schema_path =
42*1d3556b8SAndroid Build Coastguard Worker android::base::GetExecutableDirectory() + "/approved_build.xsd";
43*1d3556b8SAndroid Build Coastguard Worker std::vector<const char*> locations = {"/system/etc/kernel"};
44*1d3556b8SAndroid Build Coastguard Worker EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS("approved-ogki-builds.xml", locations,
45*1d3556b8SAndroid Build Coastguard Worker xml_schema_path.c_str());
46*1d3556b8SAndroid Build Coastguard Worker }
47