From f4eeb2ca159bc1b0c41db85635d3f0af3b06f846 Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Tue, 20 Sep 2022 12:05:43 +0000 Subject: [PATCH 1/2] cmd/bpf2go: test against clang-14 by default 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. Also skip tests that invoke clang from inside the VM, since they tend to be quite slow. Instead, run them when testing on the previous stable version of Go. --- .semaphore/semaphore.yml | 4 +++- cmd/bpf2go/compile_test.go | 10 +++------- cmd/bpf2go/main_test.go | 27 +++++++++++++++++++++------ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index 5b821df5f..cb9e60564 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -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: @@ -62,7 +64,7 @@ blocks: - name: Run unit tests on previous stable Go commands: - sem-version go 1.18 - - go test -v ./cmd/bpf2go -run TestRun + - go test -v ./cmd/bpf2go - gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- ./run-tests.sh $CI_MAX_KERNEL_VERSION -short -count 1 -json ./... - name: Run unit tests matrix: diff --git a/cmd/bpf2go/compile_test.go b/cmd/bpf2go/compile_test.go index d1bea873c..56eefddd8 100644 --- a/cmd/bpf2go/compile_test.go +++ b/cmd/bpf2go/compile_test.go @@ -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"), @@ -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{ @@ -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"), diff --git a/cmd/bpf2go/main_test.go b/cmd/bpf2go/main_test.go index 56884d281..81c37054c 100644 --- a/cmd/bpf2go/main_test.go +++ b/cmd/bpf2go/main_test.go @@ -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() @@ -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", @@ -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, @@ -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 +} From a42d42236642276c2c8bf61a86d4bf008595807a Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Tue, 20 Sep 2022 12:07:17 +0000 Subject: [PATCH 2/2] CI: update to Go 1.19.1 --- .semaphore/semaphore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index cb9e60564..3d87f9053 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -23,7 +23,7 @@ blocks: prologue: commands: - sudo sh -c 'swapoff -a && fallocate -l 2G /swapfile && chmod 0600 /swapfile && mkswap /swapfile && swapon /swapfile' - - sudo mkdir -p /usr/local/golang/1.19 && curl -fL "https://go.dev/dl/go1.19.linux-amd64.tar.gz" | sudo tar -xz -C /usr/local/golang/1.19 + - sudo mkdir -p /usr/local/golang/1.19 && curl -fL "https://go.dev/dl/go1.19.1.linux-amd64.tar.gz" | sudo tar -xz -C /usr/local/golang/1.19 - sem-version go 1.19 - export PATH="$PATH:$(go env GOPATH)/bin" - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.48.0