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 test only applies to devices launching with S(or greater) AND with
26 // kernel version 5.10(or greater)
27 bool kernel_support = android::bpf::isAtLeastKernelVersion(5, 10, 0);
28 if (std::stoi(android::base::GetProperty("ro.product.first_api_level", "0"))
29 < __ANDROID_API_S__ || !kernel_support) {
30 GTEST_SKIP() << "Bootconfig requirements do not apply";
31 }
32
33 std::string cmdline;
34 ASSERT_TRUE(android::base::ReadFileToString("/proc/cmdline", &cmdline));
35 EXPECT_TRUE(cmdline.size() > 0);
36 EXPECT_EQ(cmdline.find("androidboot"), cmdline.npos)
37 << "\"androidboot\" parameters are not allowed in the kernel cmdline for "
38 << "devices using kernel version 5.10 or greater with Android S and beyond. "
39 << "These parameters are to be placed in bootconfig."
40 << "\n/proc/cmdline contents:\n" << cmdline;
41 }
42