From ec518814037c10da45b71d5382ec6e74a9b82cad Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 19 Dec 2023 14:42:04 +0000 Subject: [PATCH 1/3] ci: Add doctests to workflow Signed-off-by: Dave Tucker --- .github/workflows/ci.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a9f3d16..50eb5138 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: - name: Check C formatting run: git ls-files -- '*.c' '*.h' | xargs clang-format --dry-run --Werror - + - name: Check Markdown uses: DavidAnson/markdownlint-cli2-action@v14 @@ -111,6 +111,20 @@ jobs: --exclude integration-test \ --workspace + - name: Doctests + env: + RUST_BACKTRACE: full + run: | + set -euxo pipefail + cargo hack test --doc --feature-powerset \ + --exclude aya-bpf \ + --exclude aya-bpf-bindings \ + --exclude aya-log-ebpf \ + --exclude init \ + --exclude integration-ebpf \ + --exclude integration-test \ + --workspace + build-test-aya-bpf: strategy: fail-fast: false @@ -149,6 +163,17 @@ jobs: --target ${{ matrix.target }} \ -Z build-std=core + - name: Test + env: + CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }} + RUST_BACKTRACE: full + run: | + set -euxo pipefail + cargo hack test --doc \ + --package aya-bpf \ + --package aya-log-ebpf \ + --feature-powerset + run-integration-test: strategy: fail-fast: false From e9e2f48d4fa8825fec9d343e76999d58b170cdd8 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 19 Dec 2023 14:32:25 +0000 Subject: [PATCH 2/3] aya: Fix ringbuf docs doctests are not running in CI and therefore the didn't catch the ringbuf docs failures. This commit fixes the issues in the examples. Signed-off-by: Dave Tucker --- aya/src/maps/ring_buf.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aya/src/maps/ring_buf.rs b/aya/src/maps/ring_buf.rs index de7e138e..434606d5 100644 --- a/aya/src/maps/ring_buf.rs +++ b/aya/src/maps/ring_buf.rs @@ -68,15 +68,15 @@ use crate::{ /// # } /// # fn clear_ready(&mut self) {} /// # } -/// # let bpf = aya::Bpf::load(&[])?; +/// # let mut bpf = aya::Bpf::load(&[])?; /// use aya::maps::RingBuf; /// use std::convert::TryFrom; /// -/// let ring_buf = RingBuf::try_from(bpf.map_mut("ARRAY")?)?; -/// let poll = poll_fd(ring_buf); +/// let ring_buf = RingBuf::try_from(bpf.map_mut("ARRAY").unwrap()).unwrap(); +/// let mut poll = poll_fd(ring_buf); /// loop { -/// let mut guard = poll.readable()?; -/// let ring_buf = guard.inner_mut() +/// let mut guard = poll.readable(); +/// let ring_buf = guard.inner_mut(); /// while let Some(item) = ring_buf.next() { /// println!("Received: {:?}", item); /// } From 19af2497d79fdaa7dfe747e04934c0b0f5187b12 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 19 Dec 2023 14:53:12 +0000 Subject: [PATCH 3/3] aya-bpf: Fix XDP Map documentation Signed-off-by: Dave Tucker --- bpf/aya-bpf/src/maps/xdp/cpu_map.rs | 4 ++-- bpf/aya-bpf/src/maps/xdp/dev_map.rs | 6 +++--- bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs | 6 +++--- bpf/aya-bpf/src/maps/xdp/xsk_map.rs | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bpf/aya-bpf/src/maps/xdp/cpu_map.rs b/bpf/aya-bpf/src/maps/xdp/cpu_map.rs index 0ada7010..6a86351a 100644 --- a/bpf/aya-bpf/src/maps/xdp/cpu_map.rs +++ b/bpf/aya-bpf/src/maps/xdp/cpu_map.rs @@ -25,9 +25,9 @@ use crate::{ /// static MAP: CpuMap = CpuMap::with_max_entries(8, 0); /// /// #[xdp] -/// fn xdp(_ctx: XdpContext) -> i32 { +/// fn xdp(_ctx: XdpContext) -> u32 { /// // Redirect to CPU 7 or drop packet if no entry found. -/// MAP.redirect(7, xdp_action::XDP_DROP as u64) +/// MAP.redirect(7, xdp_action::XDP_DROP as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[repr(transparent)] diff --git a/bpf/aya-bpf/src/maps/xdp/dev_map.rs b/bpf/aya-bpf/src/maps/xdp/dev_map.rs index d7e62dd0..2d015b46 100644 --- a/bpf/aya-bpf/src/maps/xdp/dev_map.rs +++ b/bpf/aya-bpf/src/maps/xdp/dev_map.rs @@ -27,8 +27,8 @@ use crate::{ /// static MAP: DevMap = DevMap::with_max_entries(1, 0); /// /// #[xdp] -/// fn xdp(_ctx: XdpContext) -> i32 { -/// MAP.redirect(0, xdp_action::XDP_PASS as u64) +/// fn xdp(_ctx: XdpContext) -> u32 { +/// MAP.redirect(0, xdp_action::XDP_PASS as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[repr(transparent)] @@ -100,7 +100,7 @@ impl DevMap { /// #[map] /// static MAP: DevMap = DevMap::with_max_entries(1, 0); /// - /// let target_if_index = MAP.get(0).target_if_index; + /// let target_if_index = MAP.get(0).unwrap().if_index; /// /// // redirect to if_index /// ``` diff --git a/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs b/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs index 809215aa..d268bf5f 100644 --- a/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs +++ b/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs @@ -29,8 +29,8 @@ use crate::{ /// static MAP: DevMapHash = DevMapHash::with_max_entries(1, 0); /// /// #[xdp] -/// fn xdp(_ctx: XdpContext) -> i32 { -/// MAP.redirect(42, xdp_action::XDP_PASS as u64) +/// fn xdp(_ctx: XdpContext) -> u32 { +/// MAP.redirect(42, xdp_action::XDP_PASS as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[repr(transparent)] @@ -102,7 +102,7 @@ impl DevMapHash { /// #[map] /// static MAP: DevMapHash = DevMapHash::with_max_entries(1, 0); /// - /// let target_if_index = MAP.get(42).target_if_index; + /// let target_if_index = MAP.get(42).unwrap().if_index; /// /// // redirect to ifindex /// ``` diff --git a/bpf/aya-bpf/src/maps/xdp/xsk_map.rs b/bpf/aya-bpf/src/maps/xdp/xsk_map.rs index 934785c1..328c92b2 100644 --- a/bpf/aya-bpf/src/maps/xdp/xsk_map.rs +++ b/bpf/aya-bpf/src/maps/xdp/xsk_map.rs @@ -28,9 +28,9 @@ use crate::{ /// static SOCKS: XskMap = XskMap::with_max_entries(8, 0); /// /// #[xdp] -/// fn xdp(ctx, XdpContext) -> i32 { +/// fn xdp(ctx: XdpContext) -> u32 { /// let queue_id = unsafe { (*ctx.ctx).rx_queue_index }; -/// MAP.redirect(queue_id, xdp_action::XDP_DROP as u64) +/// SOCKS.redirect(queue_id, xdp_action::XDP_DROP as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` /// @@ -68,7 +68,7 @@ impl XskMap { /// use aya_bpf::{macros::map, maps::XskMap}; /// /// #[map] - /// static SOCKS: XskMap::with_max_entries(8, 0); + /// static SOCKS: XskMap = XskMap::with_max_entries(8, 0); /// ``` pub const fn with_max_entries(max_entries: u32, flags: u32) -> XskMap { XskMap { @@ -93,7 +93,7 @@ impl XskMap { /// use aya_bpf::{macros::map, maps::XskMap}; /// /// #[map] - /// static SOCKS: XskMap::pinned(8, 0); + /// static SOCKS: XskMap = XskMap::pinned(8, 0); /// ``` pub const fn pinned(max_entries: u32, flags: u32) -> XskMap { XskMap { @@ -151,9 +151,9 @@ impl XskMap { /// static SOCKS: XskMap = XskMap::with_max_entries(8, 0); /// /// #[xdp] - /// fn xdp(ctx, XdpContext) -> u32 { + /// fn xdp(ctx: XdpContext) -> u32 { /// let queue_id = unsafe { (*ctx.ctx).rx_queue_index }; - /// MAP.redirect(queue_id, 0).unwrap_or(xdp_action::XDP_DROP) + /// SOCKS.redirect(queue_id, 0).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[inline(always)]