Skip to content

Commit

Permalink
Adjust Program::test_run to work on shared receiver
Browse files Browse the repository at this point in the history
The Program::test_run method also does not seem to really require
exclusive access to the bpf_program object. As such, this change
switches it over to work on a shared receiver (&self).

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Sep 30, 2024
1 parent d035e43 commit a005425
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libbpf-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Unreleased
- Deprecated `Program::get_id_by_fd`
- Renamed `Program::get_fd_by_id` to `fd_from_id`
- Deprecated `Program::get_fd_by_id`
- Adjusted various `Program::attach_*` methods to work on shared
- Adjusted `Program::{attach_*, test_run}` methods to work on shared
receivers
- Adjusted `PerfBufferBuilder` to work with `MapCore` objects

Expand Down
2 changes: 1 addition & 1 deletion libbpf-rs/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ impl<'obj> ProgramMut<'obj> {
/// This function uses the
/// [BPF_PROG_RUN](https://www.kernel.org/doc/html/latest/bpf/bpf_prog_run.html)
/// facility.
pub fn test_run<'dat>(&mut self, input: Input<'dat>) -> Result<Output<'dat>> {
pub fn test_run<'dat>(&self, input: Input<'dat>) -> Result<Output<'dat>> {
unsafe fn slice_from_array<'t, T>(items: *mut T, num_items: usize) -> Option<&'t mut [T]> {
if items.is_null() {
None
Expand Down
4 changes: 2 additions & 2 deletions libbpf-rs/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ fn test_run_prog_success() {
bump_rlimit_mlock();

let mut obj = get_test_object("run_prog.bpf.o");
let mut prog = get_prog_mut(&mut obj, "test_1");
let prog = get_prog_mut(&mut obj, "test_1");

#[repr(C)]
struct bpf_dummy_ops_state {
Expand All @@ -2054,7 +2054,7 @@ fn test_run_prog_fail() {
bump_rlimit_mlock();

let mut obj = get_test_object("run_prog.bpf.o");
let mut prog = get_prog_mut(&mut obj, "test_2");
let prog = get_prog_mut(&mut obj, "test_2");

let input = ProgramInput::default();
let _err = prog.test_run(input).unwrap_err();
Expand Down

0 comments on commit a005425

Please sign in to comment.