Ryan Zuklie | 6574820 | 2022-12-07 18:22:21 -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 "bpf_helpers.h" |
| 18 | |
| 19 | // This can't be easily changed since the program is loaded on boot and may be |
| 20 | // run against tests at a slightly different version. |
| 21 | #define TEST_RINGBUF_MAGIC_NUM 12345 |
| 22 | |
| 23 | // This ring buffer is for testing purposes only. |
Maciej Żenczykowski | 4038b8f | 2023-10-06 14:42:38 -0700 | [diff] [blame] | 24 | DEFINE_BPF_RINGBUF_EXT(test_ringbuf, __u64, 4096, AID_ROOT, AID_ROOT, 0660, "", "", PRIVATE, |
| 25 | BPFLOADER_MIN_VER, BPFLOADER_MAX_VER, |
| 26 | LOAD_ON_ENG, LOAD_ON_USER, LOAD_ON_USERDEBUG); |
Ryan Zuklie | 6574820 | 2022-12-07 18:22:21 -0800 | [diff] [blame] | 27 | |
| 28 | // This program is for test purposes only - it should never be attached to a |
| 29 | // socket, only executed manually with BPF_PROG_RUN. |
| 30 | DEFINE_BPF_PROG_KVER("skfilter/ringbuf_test", AID_ROOT, AID_ROOT, test_ringbuf_prog, KVER(5, 8, 0)) |
Neill Kapron | 8ebb223 | 2024-07-25 00:54:04 +0000 | [diff] [blame] | 31 | (void* __unused ctx) { |
Ryan Zuklie | 6574820 | 2022-12-07 18:22:21 -0800 | [diff] [blame] | 32 | __u64* output = bpf_test_ringbuf_reserve(); |
| 33 | if (output == NULL) return 1; |
| 34 | |
| 35 | (*output) = TEST_RINGBUF_MAGIC_NUM; |
| 36 | bpf_test_ringbuf_submit(output); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | LICENSE("Apache 2.0"); |
| 42 | CRITICAL("BPF Ringbuf test"); |