mirror of https://github.com/aya-rs/aya
test: Add integration test for SkBuffContext::load_bytes
Adds a test program `read_one` that triggers a verifier error when attempting to read one byte from the SkBuffContext.reviewable/pr1218/r4
parent
fe8e1c48b0
commit
25aa5ebcf2
@ -0,0 +1,20 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use aya_ebpf::{macros::socket_filter, programs::SkBuffContext};
|
||||
|
||||
|
||||
#[socket_filter]
|
||||
pub fn read_one(ctx: SkBuffContext) -> i64 {
|
||||
// Read 1 byte
|
||||
let mut dst = [0; 1];
|
||||
let _ = ctx.load_bytes(0, &mut dst);
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
use aya::{programs::SocketFilter, Ebpf};
|
||||
|
||||
#[test]
|
||||
fn socket_filter_load() {
|
||||
let mut bpf = Ebpf::load(crate::SOCKET_FILTER).unwrap();
|
||||
let prog: &mut SocketFilter = bpf
|
||||
.program_mut("read_one")
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
prog.load().unwrap();
|
||||
|
||||
}
|
Loading…
Reference in New Issue