blob: 2cc5c99aff73515aeee5bedf53dd5cea85b755f1 [file] [log] [blame]
Patrick Rohrbdafd742022-02-23 19:29:52 +01001/*
2 * Copyright (C) 2022 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
18#include <gtest/gtest.h>
19#include <vintf/VintfObject.h>
20
21#include <fstream>
22#include <string>
23
24namespace android {
25namespace net {
26
27namespace {
28
29using ::android::vintf::RuntimeInfo;
30using ::android::vintf::VintfObject;
31
32class KernelConfigVerifier final {
33 public:
34 KernelConfigVerifier() : mRuntimeInfo(VintfObject::GetRuntimeInfo()) {}
35
36 bool hasOption(const std::string& option) const {
37 const auto& configMap = mRuntimeInfo->kernelConfigs();
38 auto it = configMap.find(option);
39 if (it != configMap.cend()) {
40 return it->second == "y";
41 }
42 return false;
43 }
44
45 private:
46 std::shared_ptr<const RuntimeInfo> mRuntimeInfo;
47};
48
Patrick Rohr64b965a2022-03-07 17:14:58 +010049bool isGsiImage() {
50 std::ifstream ifs("/system/system_ext/etc/init/init.gsi.rc");
51 return ifs.good();
52}
53
Patrick Rohrbdafd742022-02-23 19:29:52 +010054} // namespace
55
56/**
57 * If this test fails, enable the following kernel modules in your kernel config:
58 * CONFIG_NET_CLS_MATCHALL=y
59 * CONFIG_NET_ACT_POLICE=y
60 * CONFIG_NET_ACT_BPF=y
61 */
62TEST(KernelTest, TestRateLimitingSupport) {
Patrick Rohr64b965a2022-03-07 17:14:58 +010063 if (isGsiImage()) {
64 // skip test on gsi images
65 GTEST_SKIP() << "GSI Image";
66 }
Patrick Rohrbdafd742022-02-23 19:29:52 +010067 KernelConfigVerifier configVerifier;
68 ASSERT_TRUE(configVerifier.hasOption("CONFIG_NET_CLS_MATCHALL"));
69 ASSERT_TRUE(configVerifier.hasOption("CONFIG_NET_ACT_POLICE"));
70 ASSERT_TRUE(configVerifier.hasOption("CONFIG_NET_ACT_BPF"));
71}
72
73} // namespace net
74} // namespace android