Commit Graph

133 Commits (dca5e6c1674f1f9d9db70c7ea522e77228d637eb)

Author SHA1 Message Date
Tamir Duberstein dca5e6c167
integration-test: Remove runtime toolchain deps
Move the use of clang and llvm-objcopy from run-time to build-time. This
allows the integration tests to run on VMs with simpler userlands.

Create a new CI job to build the integration tests separately from
running them. Ship them from that job to the runner job using github
actions artifacts.
1 year ago
Tamir Duberstein 5a398504cf
test: appease shellcheck 1 year ago
Tamir Duberstein 571c38b1c6
test: add some #[track_caller] annotations 1 year ago
Tamir Duberstein 6f3cce75cf
test: s/assert!(.*) ==/assert_eq!\1,/
One case manually adjusted to `assert_matches!`.
1 year ago
Dave Tucker e833a71b02
Merge pull request #413 from dave-tucker/fix-names-once-and-for-all
aya: fix names once and for all
1 year ago
Tamir Duberstein 868a9b00b3
Merge pull request #704 from aya-rs/better-panic
all: better panic messages
1 year ago
Dave Tucker 6d92119fbc integration-test: Add test for 2 progs in same section
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker c72aab5f7b aya-bpf-macros: Refactor for ease of testing
The aya-bpf-macros needed refactoring for:

1. Ease of testing
2. To be consistent with when we use K/V args vs. idents
3. To deprecate the use of `name` to change the exported name of a
   function - we now use the symbol table.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker bf7fdff1ce aya: Find programs using the symbol table
This makes a few changes to the way that Aya reads the ELF object
files.

1. To find programs in a section, we use the symbols table. This allows
   for cases where multiple programs could appear in the same section.
2. When parsing our ELF file we build symbols_by_section_index as an
   optimization as we use it for legacy maps, BTF maps and now programs.

As a result of theses changes the "NAME" used in `bpf.prog_mut("NAME")`
is now ALWAYS the same as the function name in the eBPF code, making the
user experience more consistent.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 17f25a6793
all: better panic messages
Always include operands in failing assertions. Use assert_matches over
manual match + panic.
1 year ago
Tuetuopay c74813f8c5 test: add the possibility to run a test inside a network namespace
For tests that do networking operations, this allows to have a
clean-state network namespace and interfaces for each test. Mainly, this
avoids "device or resource busy" errors when reusing the loopback
interface across tests.
1 year ago
Tamir Duberstein 49cbb1366f
integration-test: rerun-if-changed=integration-ebpf
See code commentary for details.
1 year ago
Tamir Duberstein d62ae98889
integration-test: Remove RUSTC from cargo-in-cargo
Fixes #686.
1 year ago
Andrew Werner 7575628d1b integration-tests: run in release also
In release, the trigger functions were being optimized out and the
tests did not work. Use core::hint::black_box to ensure that the
functions are not optimized out. Also, run these integration tests
in CI to ensure that we don't regress.
1 year ago
vadorovsky aed74d5ab3
Merge pull request #669 from aya-rs/bpf-linker-hella-warnings
integration-test: shuttle linker logs to user
1 year ago
Tamir Duberstein 74fc50bf7e
integration-test: shuttle stdio to user
Trampoline cargo-in-cargo stdio through cargo:warning to ensure the user
sees all the output.

Use bpf-linker from git in CI so we can see what's going on there.
1 year ago
Tamir Duberstein a84bd1a95d
test: document cargo build scripts 1 year ago
Mike Rostecki 96fa08bd82 cargo: Define dependencies on the workspace level
This way we will avoid version mismatches and make differences in
features across our crates clearer.
1 year ago
Tamir Duberstein 6fc09ca07a
integration-test: build-dep on integration-ebpf
Remove the manual dependency tracking machinery in
integration-test/build.rs in favor of a build-dependency on
integration-ebpf. This required adding an empty lib.rs to create the
library target.

This allows integration-test/build.rs to be ignorant of bpf-linker.
Remove that in favor of the logic now in integration-ebpf.
1 year ago
Tamir Duberstein e276c07f73
integration-ebpf: invalidate on bpf-linker
Extract the symlink-to-bpf-linker logic from integration-test to xtask
and use it in a new build script in integration-ebpf, causing ebpf
probes to be rebuilt when bpf-linker changes. Previously bpf-linker
changes would rebuild integration-test, but not integration-ebpf,
resulting in stale tests.

Note that this still doesn't address the possibility that a new
bpf-linker is added to the PATH ahead of the cached one. Solving this in
the general case would require rebuild-if-changed-env=PATH *and*
rebuild-if-changed={every-directory-in-PATH} which would likely mean far
too much cache invalidation.
1 year ago
Tamir Duberstein 0168396604
integration-ebpf: add cargo config
Same reasoning as the one in bpf.
1 year ago
Andrew Werner 97eb8afeac integration-test: use nightly toolchain with ebpf
The ebpf probes require a nightly compiler. Before this change, if you
ran `cargo xtask integration-test` with a stable compiler toolchain as
default, or you ran `cargo +stable xtask integration-test`, you would
have seen an error like the one below. This is now fixed by running the
cargo build command in the integration-ebpf directory and making sure
to clear the RUSTUP_TOOLCHAIN env var.

```
  --- stderr
  /home/ajwerner/src/github.com/aya-rs/aya/test/integration-test/bpf/ring_buf_sched_tracepoint.bpf.c:18:21: warning: declaration of 'struct switch_args' will not be visible outside of this function [-Wvisibility]
  int bpf_prog(struct switch_args* ctx)
                      ^
  1 warning generated.
  error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
  See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
  thread 'main' panicked at '"cargo" "build" "-p" "integration-ebpf" "-Z" "build-std=core" "--release" "--message-format=json" "--target" "bpfel-unknown-none" "--target-dir" "/home/ajwerner/src/github.com/aya-rs/aya/target/debug/build/integration-test-9bbcb3db5e9f8f57/out/integration-ebpf" exited
with status code 101:
  ', test/integration-test/build.rs:219:25
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: error while building userspace application

Caused by:
    Child { stdin: None, stdout: None, stderr: None, .. } exited with status code 101:
```
1 year ago
Andrew Werner af747f8caa test: update README.md
A checkout of libbpf is no longer required.
1 year ago
ajwerner 78ede184bd
Merge pull request #664 from ajwerner/always-initialize-submodules
xtask: ensure libbpf submodule is initialized
1 year ago
Tamir Duberstein 55b2010f19
integration-test: invalidate on bpf-linker
It turns out that cargo ignores rerun-if-changed directives that point
into $CARGO_HOME; use a symlink to trick cargo into respecting my
authoritah.
1 year ago
Andrew Werner 15b3c459ae xtask: ensure libbpf submodule is initialized
Libbpf is used by xtasks, in the command, ensure that the submodules
are initialized. This eases the user-experience so that users don't
need to think about the submodule, while retaining all the benefits
of using a submodule vs forcing the user to manually check out libbpf
and stick it in some pre-defined place.

We use the symbol pointing to libbpf in xtask in the build script
to avoid repeating this constant.

Also, we install git in the vm so that we can init the submodule
when we build in the vm.
1 year ago
Tamir Duberstein 703e7108f2
Make logging test output more legible
Presently when this test fails you just get "5 items instead of 6" but
not which item was lost.
1 year ago
Tamir Duberstein bbc6a73f4b
Merge pull request #657 from aya-rs/build-rs-invalidate-deps
integration-test: better cache invalidation
1 year ago
Tamir Duberstein 581d5c8f5f
integration-test: bust cache on bpf-linker
This is useful when iterating on bpf-linker locally, which is otherwise
an undeclared input to this build.

We could use an artifact dependency[0] here, but they are unstable and
bpf-linker requires gymnastics to build correctly (for now).

[0] https://doc.rust-lang.org/cargo/reference/unstable.html#artifact-dependencies-dependency-declarations
1 year ago
Tamir Duberstein 2a6d2a6402
integration-test: transitive dep on Rust ebpf
Emit "cargo:rerun-if-changed={}" for each transitive dependency on
integration-ebpf. In a normal world we'd just add integration-ebpf to
our build-dependencies, but cargo ignores this because integration-ebpf
has no library targets.
1 year ago
Tamir Duberstein 961f45da37
Replace matches with assert_matches
The matches crate has been archived now that `matches!` is in std.
However `assert_matches!` is still unstable in std, and the
assert_matches crate provides a more expressive form:

```
assert_matches!(foo, Ok(bar) => {
  assert_eq!(bar, baz);
});
```
1 year ago
Tamir Duberstein fa91fb4f59
Remove "async" feature
This feature is equivalent to async_tokio || async_std; removing it
avoids warnings emitted during `cargo hack check --feature-powerset`
where async is selected without either of the other features.

Use cargo hack to ensure clippy runs on the powerset of features.
1 year ago
Tamir Duberstein c250c6c9db
integration-test: avoid cargo deadflock 1 year ago
Tamir Duberstein 38a2711720
integration-test: properly rebuild bpf on change 1 year ago
Andrew Stoycos 94f554a52f
fix loaded_programs() race in int-tests
in the integration tests we recenctly switched to using
our internal api to list programs. I was seeing times when
this would race and panic internally (program fd was deleted
by aya WHILE we were trying to get it).  This ensures that
the list succeeded without panicking.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Andrew Stoycos fb075636c1
Add integration test for perf link pin
Add integration testing for link pinning and
loading/unloading of tracepoint, kprobe, and
uprobe programs.

Redo how we utilize bpftool to verify that programs
are loaded to be explicit with names. Also add a helper
to verify that a program is loaded AND linked.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Andrew Stoycos e668ae0c1b
re-add bpftool to integration tests
We need bpftool to add tests for the link APIs since we don't yet have
and aya API for listing links.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
1 year ago
Tamir Duberstein 23bea22ac1
integration-test: build one binary instead of N
"integration tests" as defined by Cargo produce a binary per file in the
tests directory. This is really not what we want and has a number of
downsides, but the main one is binary size.

Before:
  tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah
      Finished dev [unoptimized + debuginfo] target(s) in 0.05s
       Running `target/debug/xtask build-integration-test`
     Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test)
      Finished dev [unoptimized + debuginfo] target(s) in 0.68s
  -rwxrwxr-x 1 tamird tamird  34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/bpf_probe_read-e03eb905a5e6209c
  -rwxrwxr-x 1 tamird tamird  35M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/btf_relocations-57a4fbb38bf06064
  -rwxrwxr-x 1 tamird tamird  31M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/elf-98b7a32d6d04effb
  -rwxrwxr-x 1 tamird tamird 6.9M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77
  -rwxrwxr-x 1 tamird tamird  34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/load-0718562e85b86d03
  -rwxrwxr-x 1 tamird tamird  40M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/log-dbf355f9ea34068a
  -rwxrwxr-x 1 tamird tamird  36M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/rbpf-89a1bb848fa5cc3c
  -rwxrwxr-x 1 tamird tamird  34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/relocations-cfe655c3bb413d8b
  -rwxrwxr-x 1 tamird tamird  34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/smoke-ccd3974180a3fd29

After:
  tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah
      Finished dev [unoptimized + debuginfo] target(s) in 0.05s
       Running `target/debug/xtask build-integration-test`
     Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test)
      Finished dev [unoptimized + debuginfo] target(s) in 0.90s
  -rwxrwxr-x 1 tamird tamird 47M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77

Since we plan to run these tests in a VM, copying 10x fewer bytes seems
like a win.
1 year ago
Tamir Duberstein 6ac1320707
integration-test: build "fake" by default
Use the environment variable AYA_BUILD_INTEGRATION_BPF to indicate to
the build script that it should *actually* build bpf, otherwise emitting
empty files.

This allows metadata builds to skip costly build steps without
sacrificing ergonomics; all compile-time tools such as cargo clippy work
out of the box.

Cargo even gives each of these builds (depending on the value of the
environment variable) its own cache key, so they do not invalidate each
other when the user alternates between metadata and real builds.

This allows the lint action to move out of the VM.
1 year ago
Tamir Duberstein c76d5a9950
integration-test: compile without touching disk 1 year ago
Tamir Duberstein 3d463a3610
integration-test: compile Rust probes using build.rs 1 year ago
Tamir Duberstein 8c61fc9ea6
integration-test: compile C probes using build.rs
- Add libbpf as a submodule. This prevents having to plumb its location
  around (which can't be passed to Cargo build scripts) and also
  controls the version against which codegen has run.
- Move bpf written in C to the integration-test crate and define
  constants for each probe.
- Remove magic; each C source file must be directly enumerated in the
  build script and in lib.rs.
1 year ago
Tamir Duberstein 6ca7d53733
Remove detritus
- rustfmt settings are hierarchical.
- integration-ebpf is always compiled at a distance with flags provided.
- .cargo/config.toml is not respected except at the root of the
  workspace[0].

[0] https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure
1 year ago
Tamir Duberstein e621a09181
Clippy over tests and integration-ebpf
Replace all `assert!(matches!(..))` with `assert_matches!(..)`.

Remove the now-unused build-integration-test xtask command whose logic
doesn't match that of the build-and-run command.
1 year ago
Tamir Duberstein cc2bc0acc1
Remove procfs dependency 1 year ago
Tamir Duberstein b8252f46d9
Skip BPF_F_XDP_HAS_FRAGS tests on unsupported kernels 1 year ago
Tamir Duberstein 91a415f095
Skip relocation tests on unsupported kernels 1 year ago
Tamir Duberstein b0a4ab5f20
xtask: Standardize command logging
Don't run `cargo build --verbose`; it's too noisy.
1 year ago
Tamir Duberstein b611038d5b
Use procfs crate for kernel version parsing
This allows the logic to be shared between aya and the integration tests
without exposing additional public API surface.
1 year ago
Tamir Duberstein 9ca0af1a79
integration-test: Remove integration-test-macros
This doesn't add any value; use `cargo build --tests` with
`--message-format=json` instead; parse the output using `cargo_metadata`
to discover the location of the test binary.

Move test/integration-test/src/tests -> test/integration-test/tests to
conform to
https://doc.rust-lang.org/book/ch11-03-test-organization.html#integration-tests.
1 year ago