From d1732f595cb44d53fa59036f69b2d18deaac973d Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Mon, 2 May 2022 17:25:05 +0200 Subject: [PATCH] prog: recognize ENOTSUPP in testRun() 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 --- prog.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prog.go b/prog.go index 5e990af7f..e9c7bdb99 100644 --- a/prog.go +++ b/prog.go @@ -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(), @@ -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) }