Skip to content

Commit

Permalink
prog: recognize ENOTSUPP in testRun()
Browse files Browse the repository at this point in the history
Not all program types support PROG_TEST_RUN on all kernel versions.
Previously, when testing a program type that didn't have a test runner
implemented, the following error would be returned:

  Error when running: can't test program: can't run test: errno 524

Since this isn't overly descriptive, make it clear to the caller that
the kernel supports test runs, just not for the particular program type.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed May 2, 2022
1 parent 96aa1a7 commit d1732f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion prog.go
Expand Up @@ -585,7 +585,9 @@ func (p *Program) Benchmark(in []byte, repeat int, reset func()) (uint32, time.D

var haveProgTestRun = internal.FeatureTest("BPF_PROG_TEST_RUN", "4.12", func() error {
prog, err := NewProgram(&ProgramSpec{
Type: SocketFilter,
// The first PROG_TEST_RUN patches shipped in 4.12 only supported testing
// SKB and XDP programs.
Type: SchedACT,
Instructions: asm.Instructions{
asm.LoadImm(asm.R0, 0, asm.DWord),
asm.Return(),
Expand Down Expand Up @@ -665,6 +667,10 @@ func (p *Program) testRun(in []byte, repeat int, reset func()) (uint32, []byte,
continue
}

if errors.Is(err, unix.ENOTSUPP) {
return 0, nil, 0, fmt.Errorf("can't test program type %s: %w", p.Type(), ErrNotSupported)
}

return 0, nil, 0, fmt.Errorf("can't run test: %w", err)
}

Expand Down

0 comments on commit d1732f5

Please sign in to comment.