Commit Graph

68 Commits (571c38b1c6f8bdac3acb6a37417e4c2a4ad060cb)

Author SHA1 Message Date
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
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
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 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
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