Commit Graph

56 Commits (b875f83f22d1653b43a4dd40ffe1f5e5505d9b4f)

Author SHA1 Message Date
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
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 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 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
Tamir Duberstein 5a2906a6c9
test,xtask: Replace lazy_static with OnceCell
This doesn't affect MSRV because this is testing code.
1 year ago
Tamir Duberstein ff86f1385c
Remove dependency on bpftool in integration tests 1 year ago
Alessandro Decina 11c227743d bpf: improve bpf_probe_read_kernel_str_bytes and bpf_probe_read_user_str_bytes
This change does a few things:

- it fixes a bug in the wrappers, where we were expecting the kernel to
  return len=1 for b"\0" where it instead returns 0 and doesn't write
  out the NULL terminator

- it makes the helpers more robust by hardcoding bound checks in
  assembly so that LLVM optimizations can't transform the checks in a
  way that the verifier can't understand.

- it adds integration tests
1 year ago
Mary 85ad0197e0
Merge pull request #563 from marysaka/fix/reloc-less-strict
aya-obj: Make relocations less strict
1 year ago
Mary 35eaa50736 aya-obj: Make relocations less strict
Missing relocations at load time shouldn't cause an error in aya-obj
but instead poison related instructions.

This makes struct flavors work.
1 year ago
Alessandro Decina 3a9a54fd9b
Merge pull request #602 from marysaka/fix/btf-reloc-all-functions
aya: Apply BTF relocations to all functions
1 year ago
Mary c4e721f3d3 aya: Apply BTF relocations to all functions
This fix aya wrong logic causing non entrypoint functions to not have
any BTF relocations working.

Also fix missing section_offset computation for instruction offset in
multiple spots.
1 year ago
Tamir Duberstein d9f966ec9e
aya-log-common: support logging byte slices
These only support LowerHex and UpperHex hints for now.
1 year ago
Mary 9e1109b3ce aya: Move program's functions to the same map 1 year ago
Michal Rostecki 5fa17a192b integration-test: Add tests for aya-log 1 year ago
Michal Rostecki d31a1805da integration-test: Add `tokio_integration_test` macro
This new macro runs a test in a Tokio runtime and it can be used for
asynchronous tests (defined as `async fn`).
1 year ago
Alessandro Decina 3a8380df26 integration-test: expand full path for IntegrationTest 1 year ago
Alessandro Decina 93ac3e94bc aya: support relocations across multiple text sections + fixes
Fix R_BPF_64_64 text relocations in sections other than .text (for
instance .text.unlikely). Also fix misc bugs triggered by integration
tests.
1 year ago
Alessandro Decina b2b9bd2edf integration tests: add relocation tests 1 year ago
Alessandro Decina bc8f4ef1c8 integration-tests: rename relocations to btf_relocations
In preparation of adding actual ELF relocation tests
1 year ago
Michal Rostecki ed9c2a1780 integration-tests: Build eBPF programs always with release profile
Also, add the `codegen-unit` option to the profile.
1 year ago
Dave Tucker 7a720ab0c1 aya: Add from_pin for Programs
This commit adds from_pin() which allows the creation of a Program
from a path on bpffs. This is useful to be able to call `attach` or
other APIs for programs that are already loaded to the kernel.

This differs from #444 since it implements this on the concrete program
type, not the Program enum, allowing the user to pass in any additional
context that isn't available from bpf_prog_info.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Alessandro Decina 9a6f8143a1 aya: btf: add support for BTF_KIND_ENUM64 2 years ago
Alessandro Decina 4482db42d8 aya: btf: fix relocations for signed enums (32 bits)
Enums now carry a signed bit in the info flags. Take it into account
when applying enum relocations.
2 years ago
Alessandro Decina d6b976c6f1 aya: btf: switch ComputedRelocationValue::value to u64
This is in preparation of adding Enum64 relocation support
2 years ago
Alessandro Decina 405c6a8533
Merge pull request #485 from MatteoNardi/remove_libbpf_dependency
Remove libbpf dependency from relocation tests
2 years ago
Michal Rostecki 75336e5a35 integration-test: Fix the kernel version chceck for smoke test
Before this chane, the check was always negative if the minor version
was less then 9. So, for example, the smoke test was skipped for kernel
6.1:

```
skipping as 6.1 does not meet version requirement of 5.9
```

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Matteo Nardi 3000949bcc Remove libbpf dependency from relocation tests
Simplifiy the relocation tests build process by removing the need for libbpf
at runtime. Its usage is replaced with local `__builtin_*` attributes.
This removes the need for the `LIBBPF_INCLUDE` env variable.
2 years ago
Matteo Nardi 34e040b8e9 tests: use libtest-mimic and fix CI 2 years ago
Matteo Nardi 27f22f205d Make relocations tests actually pass 2 years ago
Matteo Nardi 702f77b565 tests: explain libbpf env variable 2 years ago
Matteo Nardi b72abcc7de tests: add pointer relocation test 2 years ago
Matteo Nardi 7e6a7d9005 btf: add integration tests for relocations
Add new integrations tests for BTF relocations.
2 years ago
Shenghui Ye 772af170ae aya-obj: add documentation on program names
This commit adds documentation on how program names are parsed from
section names, as is used by `aya_obj::Object.programs` as HashMap keys,
and updates the examples into using program names.
2 years ago
Shenghui Ye 311ead6760 aya-obj: add integration tests against rbpf 2 years ago
Alessandro Decina b3ae7786d3 aya: fix detaching links on drop
https://github.com/aya-rs/aya/pull/366 broke detaching links on drop for
everything but FdLink. This restores detach on drop for all links.
2 years ago
Alessandro Decina 9ce1530695 tests: skip tests that assume bpf_link based XDP on older kernels 2 years ago
Dmitry Savintsev 82773f46c8 Make the integration tests handle errors internally.
Instead of returning anyhow>>Result<()> handle errors
'in-place' with unwrap or panic, for more informative
and user-friendly error messages on test failures.

Fixes #421.

Signed-off-by: Dmitry Savintsev <dsavints@gmail.com>
2 years ago
Andrew Stoycos f3262e87bd Make map APIs return an option
switch map() and map_mut() from returning a
`Result` to an `Option` since it's just getting
a value from a Hashmap, and to stay in line with
the Programs API.

Remove `MapError::MapNotFound`

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2 years ago
Andrew Stoycos 1aefa2e5e6 Core refactor of Map API
Build completing tests passing

Refactor the Map API to better align
with the aya programs API.  Specifically
remove all internal locking mechanisms
and custom Deref/DerefMut implementations.
They are replaced with a Map enum
and AsRef/AsMut implementations.

All Try_From implementations have been moved
to standardized enums, with a slightly
special one for PerfEventArray's.

Also cleanup/fix all associated tests and
documentation.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
2 years ago
abhijeetbhagat c83d012c51 preserve existing behavior and avoid changes to gh workflows/xtask 2 years ago
abhijeetbhagat 7499661670 fix formatting 2 years ago
abhijeetbhagat 638cf514fb use macro to log, execute test and handle error 2 years ago
abhijeetbhagat 5b3e0ee856 add list, run cli flags to integration tests.
fixes: #338
2 years ago
Michal Rostecki b15e1f8226 integration-test: Change `assert_loaded` to a macro with timeouts
We often need to wait a bit until the program or link gets unloaded
after dropping.

Also, using a macro makes it clear in which particular test the panic
happened.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Michal Rostecki 325391892c integration-test: Remove multimap C test
libbpf 1.0 doesn't support multimaps defined in `maps` section, it
supports only BTF maps.

At the same time, we already test multimaps loading with the Rust
example (`integration-ebpf/src/bpf/map_test.rs`), so we can just remove
the failing C test.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
2 years ago
Dave Tucker 5693fb9941 aya: Rename from_pinned and from_path to from_pin
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 7c244e1f65 tests: Add integration test for pinning lifecycle
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago
Dave Tucker 8305ee1eca test: Fix clippy lint
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2 years ago