xref: /aosp_15_r20/bootable/libbootloader/vts/VtsBootconfigTest.cpp (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1*5225e6b1SAndroid Build Coastguard Worker /**
2*5225e6b1SAndroid Build Coastguard Worker  * Copyright (C) 2021 The Android Open Source Project
3*5225e6b1SAndroid Build Coastguard Worker  *
4*5225e6b1SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*5225e6b1SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*5225e6b1SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*5225e6b1SAndroid Build Coastguard Worker  *
8*5225e6b1SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*5225e6b1SAndroid Build Coastguard Worker  *
10*5225e6b1SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*5225e6b1SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*5225e6b1SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*5225e6b1SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*5225e6b1SAndroid Build Coastguard Worker  * limitations under the License.
15*5225e6b1SAndroid Build Coastguard Worker  */
16*5225e6b1SAndroid Build Coastguard Worker 
17*5225e6b1SAndroid Build Coastguard Worker #include "gtest/gtest.h"
18*5225e6b1SAndroid Build Coastguard Worker #include <android-base/file.h>
19*5225e6b1SAndroid Build Coastguard Worker #include <android-base/properties.h>
20*5225e6b1SAndroid Build Coastguard Worker #include "bpf/BpfUtils.h"
21*5225e6b1SAndroid Build Coastguard Worker 
22*5225e6b1SAndroid Build Coastguard Worker class VtsBootconfigTest : public testing::Test {};
23*5225e6b1SAndroid Build Coastguard Worker 
TEST_F(VtsBootconfigTest,ProcCmdlineAndroidbootTest)24*5225e6b1SAndroid Build Coastguard Worker TEST_F(VtsBootconfigTest, ProcCmdlineAndroidbootTest) {
25*5225e6b1SAndroid Build Coastguard Worker   // This is supported and required in Android S with kernel version
26*5225e6b1SAndroid Build Coastguard Worker   // 5.10+. Devices are allowed to launch with kernels < 5.10
27*5225e6b1SAndroid Build Coastguard Worker   // through Android T so the expectation from the Android framework, and the
28*5225e6b1SAndroid Build Coastguard Worker   // enforcement of this requirement, can only be on devices launched with
29*5225e6b1SAndroid Build Coastguard Worker   // Android U and beyond.
30*5225e6b1SAndroid Build Coastguard Worker   int first_api_level = android::base::GetIntProperty(
31*5225e6b1SAndroid Build Coastguard Worker         "ro.board.first_api_level",
32*5225e6b1SAndroid Build Coastguard Worker         android::base::GetIntProperty("ro.vendor.api_level", 1000000));
33*5225e6b1SAndroid Build Coastguard Worker   if (first_api_level < __ANDROID_API_U__) {
34*5225e6b1SAndroid Build Coastguard Worker     GTEST_SKIP() << "Bootconfig requirements do not apply";
35*5225e6b1SAndroid Build Coastguard Worker   }
36*5225e6b1SAndroid Build Coastguard Worker 
37*5225e6b1SAndroid Build Coastguard Worker   std::string cmdline;
38*5225e6b1SAndroid Build Coastguard Worker   ASSERT_TRUE(android::base::ReadFileToString("/proc/cmdline", &cmdline));
39*5225e6b1SAndroid Build Coastguard Worker   EXPECT_TRUE(cmdline.size() > 0);
40*5225e6b1SAndroid Build Coastguard Worker   EXPECT_EQ(cmdline.find("androidboot"), cmdline.npos)
41*5225e6b1SAndroid Build Coastguard Worker     << "\"androidboot\" parameters are not allowed in the kernel cmdline for "
42*5225e6b1SAndroid Build Coastguard Worker     << "devices using kernel version 5.10 or greater with Android S and beyond. "
43*5225e6b1SAndroid Build Coastguard Worker     << "These parameters are to be placed in bootconfig."
44*5225e6b1SAndroid Build Coastguard Worker     << "\n/proc/cmdline contents:\n" << cmdline;
45*5225e6b1SAndroid Build Coastguard Worker }
46