Merge pull request #398 from vadorovsky/fix-miri

Fix CI errors
pull/401/head
Michal Rostecki 2 years ago committed by GitHub
commit 3f2f3a8be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -475,6 +475,10 @@ mod tests {
} }
#[test] #[test]
// Syscall overrides are performing integer-to-pointer conversions, which
// should be done with `ptr::from_exposed_addr` in Rust nightly, but we have
// to support stable as well.
#[cfg_attr(miri, ignore)]
fn test_keys() { fn test_keys() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Bpf {
@ -497,6 +501,10 @@ mod tests {
} }
#[test] #[test]
// Syscall overrides are performing integer-to-pointer conversions, which
// should be done with `ptr::from_exposed_addr` in Rust nightly, but we have
// to support stable as well.
#[cfg_attr(miri, ignore)]
fn test_keys_error() { fn test_keys_error() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Bpf {
@ -532,6 +540,10 @@ mod tests {
} }
#[test] #[test]
// Syscall overrides are performing integer-to-pointer conversions, which
// should be done with `ptr::from_exposed_addr` in Rust nightly, but we have
// to support stable as well.
#[cfg_attr(miri, ignore)]
fn test_iter() { fn test_iter() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Bpf {
@ -556,6 +568,10 @@ mod tests {
} }
#[test] #[test]
// Syscall overrides are performing integer-to-pointer conversions, which
// should be done with `ptr::from_exposed_addr` in Rust nightly, but we have
// to support stable as well.
#[cfg_attr(miri, ignore)]
fn test_iter_key_deleted() { fn test_iter_key_deleted() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Bpf {
@ -591,6 +607,10 @@ mod tests {
} }
#[test] #[test]
// Syscall overrides are performing integer-to-pointer conversions, which
// should be done with `ptr::from_exposed_addr` in Rust nightly, but we have
// to support stable as well.
#[cfg_attr(miri, ignore)]
fn test_iter_key_error() { fn test_iter_key_error() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Bpf {
@ -632,6 +652,10 @@ mod tests {
} }
#[test] #[test]
// Syscall overrides are performing integer-to-pointer conversions, which
// should be done with `ptr::from_exposed_addr` in Rust nightly, but we have
// to support stable as well.
#[cfg_attr(miri, ignore)]
fn test_iter_value_error() { fn test_iter_value_error() {
override_syscall(|call| match call { override_syscall(|call| match call {
Syscall::Bpf { Syscall::Bpf {

@ -894,12 +894,12 @@ unsafe fn read_array<T>(data: &[u8], len: usize) -> Result<Vec<T>, BtfError> {
if mem::size_of::<T>() * len > data.len() { if mem::size_of::<T>() * len > data.len() {
return Err(BtfError::InvalidTypeInfo); return Err(BtfError::InvalidTypeInfo);
} }
let data = &data[0..mem::size_of::<T>() * len];
Ok((0..len) let r = data
.map(|i| { .chunks(mem::size_of::<T>())
ptr::read_unaligned::<T>((data.as_ptr() as usize + i * mem::size_of::<T>()) as *const T) .map(|chunk| ptr::read_unaligned(chunk.as_ptr() as *const T))
}) .collect();
.collect::<Vec<T>>()) Ok(r)
} }
impl BtfType { impl BtfType {

@ -1348,15 +1348,10 @@ pub(crate) fn copy_instructions(data: &[u8]) -> Result<Vec<bpf_insn>, ParseError
if data.len() % mem::size_of::<bpf_insn>() > 0 { if data.len() % mem::size_of::<bpf_insn>() > 0 {
return Err(ParseError::InvalidProgramCode); return Err(ParseError::InvalidProgramCode);
} }
let num_instructions = data.len() / mem::size_of::<bpf_insn>(); let instructions = data
let instructions = (0..num_instructions) .chunks_exact(mem::size_of::<bpf_insn>())
.map(|i| unsafe { .map(|d| unsafe { ptr::read_unaligned(d.as_ptr() as *const bpf_insn) })
ptr::read_unaligned(
(data.as_ptr() as usize + i * mem::size_of::<bpf_insn>()) as *const bpf_insn,
)
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Ok(instructions) Ok(instructions)
} }

@ -1,47 +0,0 @@
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
const int XDP_ACTION_MAX = (XDP_TX + 1);
struct datarec {
__u64 rx_packets;
};
// stats keyed by XDP Action
struct bpf_map_def SEC("maps") xdp_stats_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(__u32),
.value_size = sizeof(struct datarec),
.max_entries = XDP_ACTION_MAX,
};
// tracks number of times called
struct bpf_map_def SEC("maps") prog_stats_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(__u32),
.value_size = sizeof(__u64),
.max_entries = 1,
};
SEC("xdp/stats")
int xdp_stats(struct xdp_md *ctx)
{
__u64 *stats;
struct datarec *rec;
__u32 key = XDP_PASS;
__u32 k1 = 0;
stats = bpf_map_lookup_elem(&prog_stats_map, &k1);
if (!stats)
return XDP_ABORTED;
__sync_fetch_and_add(stats, 1);
rec = bpf_map_lookup_elem(&xdp_stats_map, &key);
if (!rec)
return XDP_ABORTED;
__sync_fetch_and_add(&rec->rx_packets, 1);
return XDP_PASS;
}
char _license[] SEC("license") = "GPL";

@ -27,17 +27,6 @@ fn long_name() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[integration_test]
fn multiple_maps() -> anyhow::Result<()> {
let bytes =
include_bytes_aligned!("../../../../target/bpfel-unknown-none/debug/multimap.bpf.o");
let mut bpf = Bpf::load(bytes)?;
let pass: &mut Xdp = bpf.program_mut("stats").unwrap().try_into().unwrap();
pass.load().unwrap();
pass.attach("lo", XdpFlags::default()).unwrap();
Ok(())
}
#[integration_test] #[integration_test]
fn multiple_btf_maps() -> anyhow::Result<()> { fn multiple_btf_maps() -> anyhow::Result<()> {
let bytes = let bytes =

Loading…
Cancel
Save