Ryan Zuklie | ccd5eb9 | 2022-11-30 10:21:47 -0800 | [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 | #include <android-base/file.h> |
| 18 | #include <android-base/macros.h> |
| 19 | #include <android-base/result-gmock.h> |
| 20 | #include <gmock/gmock.h> |
| 21 | #include <gtest/gtest.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | |
Maciej Żenczykowski | 6776e3b | 2022-12-10 12:18:23 +0000 | [diff] [blame^] | 25 | #include "BpfSyscallWrappers.h" |
Ryan Zuklie | ccd5eb9 | 2022-11-30 10:21:47 -0800 | [diff] [blame] | 26 | #include "bpf/BpfUtils.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace bpf { |
| 30 | using ::android::base::testing::HasError; |
| 31 | using ::android::base::testing::HasValue; |
| 32 | using ::android::base::testing::WithMessage; |
| 33 | using ::testing::HasSubstr; |
| 34 | |
| 35 | class BpfRingbufTest : public ::testing::Test { |
| 36 | protected: |
| 37 | BpfRingbufTest() |
| 38 | : mProgPath("/sys/fs/bpf/prog_bpfRingbufProg_skfilter_ringbuf_test"), |
| 39 | mRingbufPath("/sys/fs/bpf/map_bpfRingbufProg_test_ringbuf") {} |
| 40 | |
| 41 | void SetUp() { |
| 42 | if (!android::bpf::isAtLeastKernelVersion(5, 8, 0)) { |
| 43 | GTEST_SKIP() << "BPF ring buffers not supported"; |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | errno = 0; |
| 48 | mProgram.reset(retrieveProgram(mProgPath.c_str())); |
| 49 | EXPECT_EQ(errno, 0); |
| 50 | ASSERT_GE(mProgram.get(), 0) |
| 51 | << mProgPath << " was either not found or inaccessible."; |
| 52 | } |
| 53 | |
| 54 | std::string mProgPath; |
| 55 | std::string mRingbufPath; |
| 56 | android::base::unique_fd mProgram; |
| 57 | }; |
| 58 | |
| 59 | TEST_F(BpfRingbufTest, CheckSetUp) {} |
| 60 | |
| 61 | } // namespace bpf |
| 62 | } // namespace android |