Skip to content

Commit

Permalink
elf: skip BenchmarkWriteELF if ELF file wasn't built
Browse files Browse the repository at this point in the history
When running `go test -run=^$ -bench=. ./...` on the Cilium source,
BenchmarkWriteELF currently fails with:

  --- FAIL: BenchmarkWriteELF
        elf_test.go:201: failed to open ELF file ../../test/bpf/elf-demo.o: open ../../test/bpf/elf-demo.o: no such file or directory

That particular file is only built when running tests/benchmarks using
the Makefile-based flow. In order to still allow Cilium's benchmarks
suite to run without errors when invoked using native `go test -bench`,
just skip BenchmarkWriteELF if the ELF file doesn't exist.

In the future we might want to embed that ELF file into the
test/benchmark itself using bpf2go [1].

[1] https://pkg.go.dev/github.com/cilium/ebpf/cmd/bpf2go

For #17535

Reported-by: Emmanuel T Odeke <emmanuel@orijtech.com>
Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser authored and aanm committed Oct 11, 2021
1 parent da74607 commit 9bf8bc6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/elf/elf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ package elf
import (
"bytes"
"crypto/sha256"
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -197,7 +199,11 @@ func BenchmarkWriteELF(b *testing.B) {
defer os.RemoveAll(tmpDir)

elf, err := Open(baseObjPath)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// If the ELF file couldn't be found most likely it
// wasn't built. See https://github.com/cilium/cilium/issues/17535
b.Skip("ELF file not found, skipping benchmark")
} else if err != nil {
b.Fatal(err)
}
defer elf.Close()
Expand Down

0 comments on commit 9bf8bc6

Please sign in to comment.