integration-test: distinguish between success and noop

These tests previously produced the same result on certain failures as
they did on success.
pull/796/head
Tamir Duberstein 1 year ago
parent 2f9c67c735
commit 8cee3f8b01
No known key found for this signature in database

@ -15,11 +15,11 @@ macro_rules! read_str_bytes {
let Some(ptr) = RESULT.get_ptr_mut(0) else {
return;
};
let TestResult {
did_error,
len,
buf,
} = unsafe { &mut *ptr };
let dst = unsafe { ptr.as_mut() };
let Some(TestResult { buf, len }) = dst else {
return;
};
*len = None;
// $len comes from ctx.arg(1) so it's dynamic and the verifier
// doesn't see any bounds. We do $len.min(RESULT_BUF_LEN) here to
@ -35,22 +35,14 @@ macro_rules! read_str_bytes {
return;
};
match unsafe { $fun($ptr, buf) } {
Ok(s) => {
*len = s.len();
}
Err(_) => {
*did_error = 1;
}
}
*len = Some(unsafe { $fun($ptr, buf) }.map(<[_]>::len));
};
}
#[repr(C)]
struct TestResult {
did_error: u64,
len: usize,
buf: [u8; RESULT_BUF_LEN],
len: Option<Result<usize, i64>>,
}
#[map]

@ -5,9 +5,8 @@ const RESULT_BUF_LEN: usize = 1024;
#[derive(Copy, Clone)]
#[repr(C)]
struct TestResult {
did_error: u64,
len: usize,
buf: [u8; RESULT_BUF_LEN],
len: Option<Result<usize, i64>>,
}
unsafe impl aya::Pod for TestResult {}
@ -96,11 +95,12 @@ fn set_kernel_buffer_element(bpf: &mut Bpf, bytes: &[u8]) {
#[track_caller]
fn result_bytes(bpf: &Bpf) -> Vec<u8> {
let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).unwrap();
let result = m.get(&0, 0).unwrap();
assert_eq!(result.did_error, 0);
let TestResult { buf, len } = m.get(&0, 0).unwrap();
let len = len.unwrap();
let len = len.unwrap();
// assert that the buffer is always null terminated
assert_eq!(result.buf[result.len], 0);
result.buf[..result.len].to_vec()
assert_eq!(buf[len], 0);
buf[..len].to_vec()
}
fn load_and_attach_uprobe(prog_name: &str, func_name: &str, bytes: &[u8]) -> Bpf {

Loading…
Cancel
Save