xref: /aosp_15_r20/bootable/libbootloader/vts/VtsBootconfigTest.cpp (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1 /**
2  * Copyright (C) 2021 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 "gtest/gtest.h"
18 #include <android-base/file.h>
19 #include <android-base/properties.h>
20 #include "bpf/BpfUtils.h"
21 
22 class VtsBootconfigTest : public testing::Test {};
23 
TEST_F(VtsBootconfigTest,ProcCmdlineAndroidbootTest)24 TEST_F(VtsBootconfigTest, ProcCmdlineAndroidbootTest) {
25   // This is supported and required in Android S with kernel version
26   // 5.10+. Devices are allowed to launch with kernels < 5.10
27   // through Android T so the expectation from the Android framework, and the
28   // enforcement of this requirement, can only be on devices launched with
29   // Android U and beyond.
30   int first_api_level = android::base::GetIntProperty(
31         "ro.board.first_api_level",
32         android::base::GetIntProperty("ro.vendor.api_level", 1000000));
33   if (first_api_level < __ANDROID_API_U__) {
34     GTEST_SKIP() << "Bootconfig requirements do not apply";
35   }
36 
37   std::string cmdline;
38   ASSERT_TRUE(android::base::ReadFileToString("/proc/cmdline", &cmdline));
39   EXPECT_TRUE(cmdline.size() > 0);
40   EXPECT_EQ(cmdline.find("androidboot"), cmdline.npos)
41     << "\"androidboot\" parameters are not allowed in the kernel cmdline for "
42     << "devices using kernel version 5.10 or greater with Android S and beyond. "
43     << "These parameters are to be placed in bootconfig."
44     << "\n/proc/cmdline contents:\n" << cmdline;
45 }
46