Add clippy coverage for doctests

pull/1386/head
Tamir Duberstein 1 week ago
parent 18c7f7ccd6
commit 112ab47fcd
No known key found for this signature in database

@ -119,29 +119,26 @@ jobs:
RUST_BACKTRACE: full
run: |
set -euxo pipefail
cargo hack test --all-targets --feature-powerset \
cargo hack test --all-targets \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
--exclude integration-ebpf \
--exclude integration-test \
--exclude xtask \
--workspace
--feature-powerset
- name: Doctests
env:
RUST_BACKTRACE: full
run: |
set -euxo pipefail
cargo hack test --doc --feature-powerset \
cargo hack test --doc \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
--exclude init \
--exclude integration-ebpf \
--exclude integration-test \
--exclude xtask \
--workspace
--feature-powerset
build-test-aya-ebpf:
runs-on: ubuntu-latest
@ -175,28 +172,36 @@ jobs:
# to the overhead of setting up the job - so this saves a bunch of
# machine time.
for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do
echo "::group::arch=$arch"
export RUSTFLAGS="--cfg bpf_target_arch=\"$arch\""
for target in bpfeb-unknown-none bpfel-unknown-none; do
echo "::group::Build and test for $arch / $target"
echo "::group::target=$target"
if ! (
RUSTFLAGS="--cfg bpf_target_arch=\"$arch\"" cargo +nightly hack build \
cargo +nightly hack build \
--release \
--target "$target" \
-Z build-std=core \
--package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \
--feature-powerset
cargo hack test \
--doc \
--package aya-ebpf \
--package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset
); then
echo "FAILED: $arch / $target"
failures+=("$arch/$target")
failures+=("build: $arch/$target")
fi
echo "::endgroup::"
done
if ! (
RUSTDOCFLAGS=$RUSTFLAGS cargo +nightly hack test --doc \
--package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset
); then
failures+=("doctests: $arch")
fi
echo "::endgroup::"
done
if ((${#failures[@]})); then
@ -204,6 +209,7 @@ jobs:
printf ' %s\n' "${failures[@]}"
exit 1
fi
run-integration-test:
strategy:
fail-fast: false

@ -216,14 +216,11 @@ pub fn cgroup_skb(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// pub fn connect4(ctx: SockAddrContext) -> i32 {
/// match try_connect4(ctx) {
/// Ok(ret) => ret,
/// Err(ret) => match ret.try_into() {
/// Ok(rt) => rt,
/// Err(_) => 1,
/// },
/// Err(ret) => ret,
/// }
/// }
///
/// fn try_connect4(ctx: SockAddrContext) -> Result<i32, i64> {
/// fn try_connect4(ctx: SockAddrContext) -> Result<i32, i32> {
/// Ok(0)
/// }
/// ```
@ -440,7 +437,7 @@ pub fn btf_tracepoint(attrs: TokenStream, item: TokenStream) -> TokenStream {
///
///#[stream_parser]
///fn stream_parser(ctx: SkBuffContext) -> u32 {
/// match { try_stream_parser(ctx) } {
/// match try_stream_parser(ctx) {
/// Ok(ret) => ret,
/// Err(ret) => ret,
/// }
@ -470,7 +467,7 @@ pub fn stream_parser(attrs: TokenStream, item: TokenStream) -> TokenStream {
///
///#[stream_verdict]
///fn stream_verdict(ctx: SkBuffContext) -> u32 {
/// match { try_stream_verdict(ctx) } {
/// match try_stream_verdict(ctx) {
/// Ok(ret) => ret,
/// Err(ret) => ret,
/// }
@ -507,7 +504,7 @@ fn sk_skb(kind: SkSkbKind, attrs: TokenStream, item: TokenStream) -> TokenStream
///
/// #[socket_filter]
/// pub fn accept_all(_ctx: SkBuffContext) -> i64 {
/// return 0
/// 0
/// }
/// ```
#[proc_macro_attribute]
@ -531,9 +528,10 @@ pub fn socket_filter(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// # Examples
///
/// ```no_run
/// # #![expect(non_camel_case_types)]
/// use aya_ebpf::{macros::fentry, programs::FEntryContext};
/// # #[expect(non_camel_case_types)]
/// # type filename = u32;
/// # #[expect(non_camel_case_types)]
/// # type path = u32;
///
/// #[fentry(function = "filename_lookup")]
@ -573,9 +571,10 @@ pub fn fentry(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// # Examples
///
/// ```no_run
/// # #![expect(non_camel_case_types)]
/// use aya_ebpf::{macros::fexit, programs::FExitContext};
/// # #[expect(non_camel_case_types)]
/// # type filename = u32;
/// # #[expect(non_camel_case_types)]
/// # type path = u32;
///
/// #[fexit(function = "filename_lookup")]
@ -658,7 +657,7 @@ pub fn flow_dissector(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// #[sk_lookup]
/// pub fn accept_all(_ctx: SkLookupContext) -> u32 {
/// // use sk_assign to redirect
/// return 0
/// 0
/// }
/// ```
#[proc_macro_attribute]
@ -688,7 +687,7 @@ pub fn sk_lookup(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// #[cgroup_device]
/// pub fn cgroup_dev(ctx: DeviceContext) -> i32 {
/// // Reject all device access
/// return 0;
/// 0
/// }
/// ```
#[proc_macro_attribute]

@ -36,13 +36,13 @@ use crate::{
/// let flags = 0;
///
/// // bpf_tail_call(ctx, JUMP_TABLE, 0) will jump to prog_0
/// prog_array.set(0, &prog_0_fd, flags);
/// prog_array.set(0, prog_0_fd, flags);
///
/// // bpf_tail_call(ctx, JUMP_TABLE, 1) will jump to prog_1
/// prog_array.set(1, &prog_1_fd, flags);
/// prog_array.set(1, prog_1_fd, flags);
///
/// // bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2
/// prog_array.set(2, &prog_2_fd, flags);
/// prog_array.set(2, prog_2_fd, flags);
/// # Ok::<(), aya::EbpfError>(())
/// ```
#[doc(alias = "BPF_MAP_TYPE_PROG_ARRAY")]

@ -1229,9 +1229,8 @@ impl_info!(
/// use aya::programs::loaded_links;
///
/// for info in loaded_links() {
/// if let Ok(info) = info {
/// println!("loaded link: {}", info.id());
/// }
/// let info = info.unwrap();
/// println!("loaded link: {}", info.id());
/// }
/// ```
pub fn loaded_links() -> impl Iterator<Item = Result<LinkInfo, LinkError>> {

@ -323,7 +323,9 @@ fn parse_kernel_symbols(reader: impl BufRead) -> Result<BTreeMap<u64, String>, i
/// # Example
///
/// ```no_run
/// # #[expect(deprecated)]
/// use aya::util::syscall_prefix;
/// # #[expect(deprecated)]
/// let prefix = syscall_prefix().unwrap();
/// let syscall_fname = format!("{prefix}exec");
/// ```

@ -18,17 +18,30 @@ cargo +nightly hack clippy "$@" \
-C panic=abort \
-Zpanic_abort_tests
export CLIPPY_ARGS='--deny=warnings'
export RUSTDOCFLAGS='--no-run -Z unstable-options --test-builder clippy-driver'
cargo +nightly hack test --doc "$@" --feature-powerset
for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do
export RUSTFLAGS="--cfg bpf_target_arch=\"$arch\""
for target in bpfeb-unknown-none bpfel-unknown-none; do
RUSTFLAGS="--cfg bpf_target_arch=\"$arch\"" cargo +nightly hack clippy \
cargo +nightly hack clippy \
--target "$target" \
-Zbuild-std=core \
--package aya-ebpf-bindings \
--package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset \
-- --deny warnings
done
done
RUSTDOCFLAGS="$RUSTDOCFLAGS $RUSTFLAGS" cargo +nightly hack test --doc "$@" \
--package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset
done

@ -35,7 +35,6 @@ use crate::{
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read};
/// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const c_int = 0 as _;
@ -74,7 +73,6 @@ pub unsafe fn bpf_probe_read<T>(src: *const T) -> Result<T, c_long> {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_buf};
/// # fn try_test() -> Result<(), c_long> {
/// # let ptr: *const u8 = 0 as _;
@ -103,7 +101,6 @@ pub unsafe fn bpf_probe_read_buf(src: *const u8, dst: &mut [u8]) -> Result<(), c
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_user};
/// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const c_int = 0 as _;
@ -140,7 +137,6 @@ pub unsafe fn bpf_probe_read_user<T>(src: *const T) -> Result<T, c_long> {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_user_buf};
/// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const u8 = 0 as _;
@ -170,7 +166,6 @@ pub unsafe fn bpf_probe_read_user_buf(src: *const u8, dst: &mut [u8]) -> Result<
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_kernel};
/// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const c_int = 0 as _;
@ -207,7 +202,6 @@ pub unsafe fn bpf_probe_read_kernel<T>(src: *const T) -> Result<T, c_long> {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_kernel_buf};
/// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _;
@ -240,11 +234,12 @@ pub unsafe fn bpf_probe_read_kernel_buf(src: *const u8, dst: &mut [u8]) -> Resul
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # #[expect(deprecated)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_str};
/// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _;
/// let mut my_str = [0u8; 16];
/// # #[expect(deprecated)]
/// let num_read = unsafe { bpf_probe_read_str(kernel_ptr, &mut my_str)? };
///
/// // Do something with num_read and my_str
@ -276,11 +271,12 @@ pub unsafe fn bpf_probe_read_str(src: *const u8, dest: &mut [u8]) -> Result<usiz
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # #[expect(deprecated)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_user_str};
/// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const u8 = 0 as _;
/// let mut my_str = [0u8; 16];
/// # #[expect(deprecated)]
/// let num_read = unsafe { bpf_probe_read_user_str(user_ptr, &mut my_str)? };
///
/// // Do something with num_read and my_str
@ -315,7 +311,6 @@ pub unsafe fn bpf_probe_read_user_str(src: *const u8, dest: &mut [u8]) -> Result
/// eBPF stack limit is 512 bytes):
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_user_str_bytes};
/// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const u8 = 0 as _;
@ -421,11 +416,12 @@ fn read_str_bytes(len: i64, dest: &[u8]) -> Result<&[u8], c_long> {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # #[expect(deprecated)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_kernel_str};
/// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _;
/// let mut my_str = [0u8; 16];
/// # #[expect(deprecated)]
/// let num_read = unsafe { bpf_probe_read_kernel_str(kernel_ptr, &mut my_str)? };
///
/// // Do something with num_read and my_str
@ -464,7 +460,6 @@ pub unsafe fn bpf_probe_read_kernel_str(src: *const u8, dest: &mut [u8]) -> Resu
/// eBPF stack limit is 512 bytes):
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_kernel_str_bytes};
/// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _;
@ -554,7 +549,6 @@ pub unsafe fn bpf_probe_read_kernel_str_bytes(
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{
/// # cty::{c_int, c_long},
/// # helpers::bpf_probe_write_user,
@ -587,7 +581,6 @@ pub unsafe fn bpf_probe_write_user<T>(dst: *mut T, src: *const T) -> Result<(),
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::helpers::bpf_get_current_comm;
/// let comm = bpf_get_current_comm();
///
@ -622,7 +615,6 @@ pub fn bpf_get_current_comm() -> Result<[u8; 16], c_long> {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::helpers::bpf_get_current_pid_tgid;
/// let tgid = (bpf_get_current_pid_tgid() >> 32) as u32;
/// let pid = bpf_get_current_pid_tgid() as u32;
@ -645,7 +637,6 @@ pub fn bpf_get_current_pid_tgid() -> u64 {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::helpers::bpf_get_current_uid_gid;
/// let gid = (bpf_get_current_uid_gid() >> 32) as u32;
/// let uid = bpf_get_current_uid_gid() as u32;

@ -14,7 +14,6 @@ use crate::{
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// use aya_ebpf::{macros::map, maps::ProgramArray, cty::c_long};
/// # use aya_ebpf::{programs::LsmContext};
///
@ -24,8 +23,8 @@ use crate::{
/// # unsafe fn try_test(ctx: &LsmContext) -> Result<(), c_long> {
/// let index: u32 = 13;
///
/// if let Err(e) = JUMP_TABLE.tail_call(ctx, index) {
/// return Err(e);
/// unsafe {
/// JUMP_TABLE.tail_call(ctx, index)?;
/// }
///
/// # Err(-1)

@ -16,10 +16,10 @@ impl FEntryContext {
/// # Examples
///
/// ```no_run
/// # #![expect(non_camel_case_types)]
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_int, programs::FEntryContext};
/// # #[expect(non_camel_case_types)]
/// # type pid_t = c_int;
/// # #[expect(non_camel_case_types)]
/// # struct task_struct {
/// # pid: pid_t,
/// # }

@ -16,10 +16,10 @@ impl FExitContext {
/// # Examples
///
/// ```no_run
/// # #![expect(non_camel_case_types)]
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_int, programs::FExitContext};
/// # #[expect(non_camel_case_types)]
/// # type pid_t = c_int;
/// # #[expect(non_camel_case_types)]
/// # struct task_struct {
/// # pid: pid_t,
/// # }

@ -25,7 +25,6 @@ impl LsmContext {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::LsmContext, cty::{c_int, c_ulong}};
/// unsafe fn try_lsm_mmap_addr(ctx: LsmContext) -> Result<i32, i32> {
/// // In the kernel, this hook is defined as:

@ -16,16 +16,18 @@ impl ProbeContext {
/// # Examples
///
/// ```no_run
/// # #![expect(non_camel_case_types)]
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::ProbeContext, cty::c_int, helpers::bpf_probe_read};
/// # #[expect(non_camel_case_types)]
/// # type pid_t = c_int;
/// # #[expect(non_camel_case_types)]
/// # struct task_struct {
/// # pid: pid_t,
/// # }
/// unsafe fn try_kprobe_try_to_wake_up(ctx: ProbeContext) -> Result<u32, u32> {
/// let tp: *const task_struct = ctx.arg(0).ok_or(1u32)?;
/// let pid = bpf_probe_read(&(*tp).pid as *const pid_t).map_err(|_| 1u32)?;
/// let pid = unsafe {
/// bpf_probe_read(core::ptr::addr_of!((*tp).pid))
/// }.map_err(|err| err as u32)?;
///
/// // Do something with pid or something else with tp
///

@ -16,7 +16,6 @@ impl RetProbeContext {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::RetProbeContext, cty::c_int};
/// unsafe fn try_kretprobe_try_to_wake_up(ctx: RetProbeContext) -> Result<u32, u32> {
/// let retval: c_int = ctx.ret();

@ -384,8 +384,8 @@ impl SkBuffContext {
/// fn try_cgroup_skb(ctx: SkBuffContext) -> Result<i32, i32> {
/// let len = ETH_HLEN + IP_HLEN + UDP_HLEN;
/// match ctx.pull_data(len as u32) {
/// Ok(()) => return Ok(0),
/// Err(ret) => return Err(ret as i32),
/// Ok(()) => Ok(0),
/// Err(ret) => Err(ret as i32),
/// }
/// }
/// ```

@ -176,8 +176,8 @@ impl TcContext {
/// fn try_classifier(ctx: TcContext) -> Result<i32, i32> {
/// let len = ETH_HLEN + IP_HLEN + UDP_HLEN;
/// match ctx.pull_data(len as u32) {
/// Ok(()) => return Ok(0),
/// Err(ret) => return Err(ret as i32),
/// Ok(()) => Ok(0),
/// Err(ret) => Err(ret as i32),
/// }
/// }
/// ```

@ -19,7 +19,6 @@ impl BtfTracePointContext {
/// # Examples
///
/// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::BtfTracePointContext, cty::{c_int, c_ulong, c_char}};
/// unsafe fn try_tp_btf_sched_process_fork(ctx: BtfTracePointContext) -> Result<u32, u32> {
/// // Grab arguments

@ -115,10 +115,10 @@ fn test_log(ctx: ProbeContext) {
let buf = &buf[..core::cmp::min(len, buf.len())];
info!(&ctx, "variable length buffer: {:x}", buf);
info!(&ctx, "2KiB array: {:x}", &TWO_KB_ARRAY);
info!(&ctx, "4KiB array: {:x}", &FOUR_KB_ARRAY);
info!(&ctx, "2KiB array: {:x}", TWO_KB_ARRAY.as_slice());
info!(&ctx, "4KiB array: {:x}", FOUR_KB_ARRAY.as_slice());
// This one is too big and should be dropped.
info!(&ctx, "8KiB array: {:x}", &EIGHT_KB_ARRAY);
info!(&ctx, "8KiB array: {:x}", EIGHT_KB_ARRAY.as_slice());
}
#[uprobe]

Loading…
Cancel
Save