Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/bpf2go: test against clang-14 by default #794

Merged
merged 2 commits into from Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .semaphore/semaphore.yml
Expand Up @@ -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
Expand All @@ -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 All @@ -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:
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
}