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 1dd5b01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 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
18 changes: 14 additions & 4 deletions cmd/bpf2go/compile_test.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"fmt"
"os"
"path/filepath"
"reflect"
Expand All @@ -11,10 +12,19 @@ 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"
)
var clangBin string

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

fmt.Println("Testing against", clangBin)
}

func TestCompile(t *testing.T) {
dir := mustWriteTempFile(t, "test.c", minimalSocketFilter)
Expand Down
2 changes: 1 addition & 1 deletion cmd/bpf2go/main_test.go
Expand Up @@ -110,7 +110,7 @@ func TestDisableStripping(t *testing.T) {
dir := mustWriteTempFile(t, "test.c", minimalSocketFilter)

err := run(io.Discard, "foo", dir, []string{
"-cc", "clang-9",
"-cc", clangBin,
"-strip", "binary-that-certainly-doesnt-exist",
"-no-strip",
"bar",
Expand Down

0 comments on commit 1dd5b01

Please sign in to comment.