Skip to content

Commit

Permalink
cmd/bpf2go: test against clang-14 by default
Browse files Browse the repository at this point in the history
clang-9 is getting difficult to get a hold of on recent distributions.
Default to clang-14 for bpf2go tests, but allow CI to still use clang-9.
This avoids regressing clang-9 support by for example using a new
command line option.
  • Loading branch information
lmb committed Sep 20, 2022
1 parent 713c8dc commit ef0f691
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .semaphore/semaphore.yml
Expand Up @@ -45,6 +45,8 @@ blocks:
value: /tmp
- name: CI_MAX_KERNEL_VERSION
value: "5.19"
- name: CI_MIN_CLANG_VERSION
value: "9"
jobs:
- name: Build and Lint
commands:
Expand Down
10 changes: 3 additions & 7 deletions cmd/bpf2go/compile_test.go
Expand Up @@ -11,17 +11,12 @@ import (

const minimalSocketFilter = `__attribute__((section("socket"), used)) int main() { return 0; }`

// Test against the minimum supported version of clang to avoid regressions.
const (
clangBin = "clang-9"
)

func TestCompile(t *testing.T) {
dir := mustWriteTempFile(t, "test.c", minimalSocketFilter)

var dep bytes.Buffer
err := compile(compileArgs{
cc: clangBin,
cc: clangBin(t),
dir: dir,
source: filepath.Join(dir, "test.c"),
dest: filepath.Join(dir, "test.o"),
Expand Down Expand Up @@ -50,6 +45,7 @@ func TestCompile(t *testing.T) {
}

func TestReproducibleCompile(t *testing.T) {
clangBin := clangBin(t)
dir := mustWriteTempFile(t, "test.c", minimalSocketFilter)

err := compile(compileArgs{
Expand Down Expand Up @@ -91,7 +87,7 @@ func TestTriggerMissingTarget(t *testing.T) {
dir := mustWriteTempFile(t, "test.c", `_Pragma(__BPF_TARGET_MISSING);`)

err := compile(compileArgs{
cc: clangBin,
cc: clangBin(t),
dir: dir,
source: filepath.Join(dir, "test.c"),
dest: filepath.Join(dir, "a.o"),
Expand Down
27 changes: 21 additions & 6 deletions cmd/bpf2go/main_test.go
Expand Up @@ -17,10 +17,7 @@ import (
)

func TestRun(t *testing.T) {
if testing.Short() {
t.Skip("Not compiling with -short")
}

clangBin := clangBin(t)
dir := mustWriteTempFile(t, "test.c", minimalSocketFilter)

cwd, err := os.Getwd()
Expand Down Expand Up @@ -110,7 +107,7 @@ func TestDisableStripping(t *testing.T) {
dir := mustWriteTempFile(t, "test.c", minimalSocketFilter)

err := run(io.Discard, "foo", dir, []string{
"-cc", "clang-9",
"-cc", clangBin(t),
"-strip", "binary-that-certainly-doesnt-exist",
"-no-strip",
"bar",
Expand Down Expand Up @@ -234,7 +231,7 @@ func TestConvertGOARCH(t *testing.T) {
pkg: "test",
stdout: io.Discard,
ident: "test",
cc: clangBin,
cc: clangBin(t),
disableStripping: true,
sourceFile: tmp + "/test.c",
outputDir: tmp,
Expand Down Expand Up @@ -278,3 +275,21 @@ func TestCTypes(t *testing.T) {
qt.Assert(t, ct.Set("foo"), qt.IsNil)
qt.Assert(t, ct.Set("foo"), qt.IsNotNil)
}

func clangBin(t *testing.T) string {
t.Helper()

if testing.Short() {
t.Skip("Not compiling with -short")
}

// Use a recent clang version for local development, but allow CI to run
// against oldest supported clang.
clang := "clang-14"
if minVersion := os.Getenv("CI_MIN_CLANG_VERSION"); minVersion != "" {
clang = fmt.Sprintf("clang-%s", minVersion)
}

t.Log("Testing against", clang)
return clang
}

0 comments on commit ef0f691

Please sign in to comment.