Patrick Rohr | bdafd74 | 2022-02-23 19:29:52 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | namespace android { |
| 25 | namespace net { |
| 26 | |
| 27 | namespace { |
| 28 | |
| 29 | using ::android::vintf::RuntimeInfo; |
| 30 | using ::android::vintf::VintfObject; |
| 31 | |
| 32 | class 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 Rohr | 64b965a | 2022-03-07 17:14:58 +0100 | [diff] [blame] | 49 | bool isGsiImage() { |
| 50 | std::ifstream ifs("/system/system_ext/etc/init/init.gsi.rc"); |
| 51 | return ifs.good(); |
| 52 | } |
| 53 | |
Patrick Rohr | bdafd74 | 2022-02-23 19:29:52 +0100 | [diff] [blame] | 54 | } // 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 | */ |
| 62 | TEST(KernelTest, TestRateLimitingSupport) { |
Patrick Rohr | 64b965a | 2022-03-07 17:14:58 +0100 | [diff] [blame] | 63 | if (isGsiImage()) { |
| 64 | // skip test on gsi images |
| 65 | GTEST_SKIP() << "GSI Image"; |
| 66 | } |
Patrick Rohr | bdafd74 | 2022-02-23 19:29:52 +0100 | [diff] [blame] | 67 | 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 |