Skip to content

Commit e4d0542

Browse files
wdullaerqmonnet
authored andcommitted
fix(examples): Restructure allowed_memory test
Moving the source code for the ebpf program into a subfolder will prevent it from accidentally being run as an example. We are still committing the resulting object file, to prevent creating a hard dependency on the aya build toolchain to run the example tests in this repository. Signed-off-by: Wouter Dullaert <wouter.dullaert@exoscale.ch>
1 parent 384c882 commit e4d0542

File tree

7 files changed

+52
-9
lines changed

7 files changed

+52
-9
lines changed

examples/allowed-memory.o

-45.3 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build]
2+
target = "bpfel-unknown-none"
3+
rustflags = "-C debuginfo=2 -C link-arg=--btf"
4+
5+
[unstable]
6+
build-std = ["core"]

examples/allowed-memory/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "allowed-memory"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "Apache-2.0/MIT"
6+
7+
[dependencies]
8+
aya-ebpf = "0.1.0"
9+
10+
[[bin]]
11+
name = "allowed-memory"
12+
path = "src/main.rs"
13+
test = false
14+
bench = false
15+
16+
[profile.dev]
17+
opt-level = 3
18+
debug = false
19+
debug-assertions = false
20+
overflow-checks = false
21+
lto = true
22+
panic = "abort"
23+
incremental = false
24+
codegen-units = 1
25+
rpath = false
26+
27+
[profile.release]
28+
lto = true
29+
panic = "abort"
30+
codegen-units = 1
31+
45.3 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[toolchain]
2+
channel = "nightly"
3+
# The source code of rustc, provided by the rust-src component, is needed for
4+
# building eBPF programs.
5+
components = [
6+
"cargo",
7+
"clippy",
8+
"rust-docs",
9+
"rust-src",
10+
"rust-std",
11+
"rustc",
12+
"rustfmt",
13+
]
File renamed without changes.

examples/allowed_memory.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ use std::{iter::FromIterator, ptr::addr_of};
88

99
extern crate rbpf;
1010

11-
// The following example uses an ELF file that was compiled from the ebpf-allowed-memory.rs file
12-
// It is built using the [aya framework](https://aya-rs.dev/).
13-
// Once the aya dependencies (rust-nightly, latest llvm and latest bpf-linker) are installed, it
14-
// can be compiled via
15-
//
16-
// ```bash
17-
// cargo build --target=bpfel-unknown-none -Z build-std=core
18-
// ```
11+
const OBJ_FILE_PATH: &str = "examples/allowed-memory/allowed-memory.o";
1912

2013
const BPF_MAP_LOOKUP_ELEM_IDX: u32 = 1;
2114

@@ -41,7 +34,7 @@ fn bpf_lookup_elem(_map: u64, key_addr: u64, _flags: u64, _u4: u64, _u5: u64) ->
4134
}
4235

4336
fn main() {
44-
let file = elf::File::open_path("examples/allowed-memory.o").unwrap();
37+
let file = elf::File::open_path(OBJ_FILE_PATH).unwrap();
4538
let func = file.get_section("classifier").unwrap();
4639

4740
let mut vm = rbpf::EbpfVmNoData::new(Some(&func.data)).unwrap();

0 commit comments

Comments
 (0)