From 55f6c8babd5d5343a4836ad3f874ee96ac028b8a Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 4 Jan 2024 22:18:35 -0800 Subject: [PATCH 1/3] tests: update go version detection for riscv Signed-off-by: Tonis Tiigi --- src/test_helper.bash | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test_helper.bash b/src/test_helper.bash index f50f8b5..99227c9 100644 --- a/src/test_helper.bash +++ b/src/test_helper.bash @@ -78,15 +78,17 @@ supportRiscV() { return 0 } +versionGTE() { test "$(printf '%s\n' "$@" | sort -V | tail -n 1)" = "$1"; } + supportRiscVGo() { - go version | grep -E "1.14|1.15|1.16|1.17|1.18|1.19" >/dev/null 2>&1 + versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.14" } supportRiscVCGo() { if ! supportRiscV; then return 1 fi - go version | egrep -E "1.16|1.17|1.18|1.19" >/dev/null 2>&1 + versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.16" } supportRC() { From 5250a1b368939131d993c1aa635d9e50ec35edf0 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 4 Jan 2024 22:19:15 -0800 Subject: [PATCH 2/3] tests: fix go env parsing for newer versions Single/double quotes have changed in the output. Signed-off-by: Tonis Tiigi --- src/test-go.bats | 96 ++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/src/test-go.bats b/src/test-go.bats index 0aadce1..da318f3 100755 --- a/src/test-go.bats +++ b/src/test-go.bats @@ -3,40 +3,69 @@ load 'assert' load 'test_helper' -@test "nogo" { - del go 2>/dev/null || true - run xx-go env - assert_failure - assert_output --partial "go: not found" +ensureGo() { + if command -v apk >/dev/null 2>/dev/null; then + add go + else + add golang + fi + add clang lld +} + +setup_file() { + ensureGo +} + +teardown_file() { + for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64; do + TARGETPLATFORM=$p xxdel xx-c-essentials + root=/$(TARGETPLATFORM=$p xx-info triple) + if [ -d "$root" ] && [ "$root" != "/" ]; then + rm -rf "$root" + fi + done + del clang lld llvm + del pkgconfig || del pkg-config + if command -v apk >/dev/null 2>/dev/null; then + del go + else + del golang + fi + rm /tmp/a.out + rm -rf /var/cache/apt/*.bin || true } testEnv() { - run xx-go env + # single/double quotes changed in between go versions + run sh -c "xx-go env | sed 's/[\"'\'']//g'" assert_success - assert_output --partial 'GOARCH="'"$(xx-info arch)"'"' - assert_output --partial 'GOOS="'"$(xx-info os)"'"' - assert_output --partial 'GOHOSTOS="'"$(TARGETOS= TARGETARCH= xx-info os)"'"' - assert_output --partial 'GOHOSTARCH="'"$(TARGETOS= TARGETARCH= xx-info arch)"'"' + assert_output --partial "GOARCH=$(xx-info arch)" + assert_output --partial "GOOS=$(xx-info os)" + assert_output --partial "GOHOSTOS=$(TARGETOS= TARGETARCH= xx-info os)" + assert_output --partial "GOHOSTARCH=$(TARGETOS= TARGETARCH= xx-info arch)" case "$(xx-info arch)" in "arm") - assert_output --partial 'GOARM="'"$expArm"'"' + assert_output --partial "GOARM=$expArm" ;; "mips64"*) - assert_output --partial 'GOMIPS64="'"$expMips"'"' + assert_output --partial "GOMIPS64=$expMips" ;; "mips"*) - assert_output --partial 'GOMIPS="'"$expMips"'"' + assert_output --partial "GOMIPS=$expMips" ;; esac } +@test "nogo" { + del go 2>/dev/null || true + run xx-go env + assert_failure + assert_output --partial "go: not found" + ensureGo +} + @test "native-env" { - if command -v apk >/dev/null 2>/dev/null; then - add go - else - add golang - fi testEnv } @@ -270,7 +299,6 @@ testHelloCGO() { } @test "native-hellocgo" { - add clang lld unset TARGETARCH testHelloCGO } @@ -319,12 +347,13 @@ testHelloCGO() { add pkgconf || add pkg-config xxadd xx-c-essentials xxadd pkgconf || add pkg-config - run xx-go env + # single/double quotes changed in between go versions + run sh -c "xx-go env | sed 's/[\"'\'']//g'" assert_success - assert_output --partial 'CC="'"$(xx-info triple)-clang"'"' - assert_output --partial 'CXX="'"$(xx-info triple)-clang++"'"' - assert_output --partial 'AR="'"$(xx-info triple)-ar"'"' - assert_output --partial 'PKG_CONFIG="'"$(xx-info triple)-pkg-config"'"' + assert_output --partial "CC=$(xx-info triple)-clang" + assert_output --partial "CXX=$(xx-info triple)-clang++" + assert_output --partial "AR=$(xx-info triple)-ar" + assert_output --partial "PKG_CONFIG=$(xx-info triple)-pkg-config" } @test "wrap-unwrap" { @@ -351,22 +380,3 @@ testHelloCGO() { assert_success assert_output "$nativeArch" } - -@test "clean-packages" { - for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6; do - TARGETPLATFORM=$p xxdel xx-c-essentials - root=/$(TARGETPLATFORM=$p xx-info triple) - if [ -d "$root" ] && [ "$root" != "/" ]; then - rm -rf "$root" - fi - done - del clang lld llvm - del pkgconfig || del pkg-config - if command -v apk >/dev/null 2>/dev/null; then - del go - else - del golang - fi - rm /tmp/a.out - rm -rf /var/cache/apt/*.bin || true -} From 2a4d47b318e8c2a82cdf7ecebee1abaf7bb2de95 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 4 Jan 2024 23:07:08 -0800 Subject: [PATCH 3/3] tests: fixes for debian cleanup routines Signed-off-by: Tonis Tiigi --- src/test-go.bats | 8 ++++++-- src/test_helper.bash | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/test-go.bats b/src/test-go.bats index da318f3..92d56bd 100755 --- a/src/test-go.bats +++ b/src/test-go.bats @@ -31,7 +31,7 @@ teardown_file() { else del golang fi - rm /tmp/a.out + rm /tmp/a.out || true rm -rf /var/cache/apt/*.bin || true } @@ -58,7 +58,11 @@ testEnv() { } @test "nogo" { - del go 2>/dev/null || true + if command -v apk >/dev/null 2>/dev/null; then + del go + else + del golang + fi run xx-go env assert_failure assert_output --partial "go: not found" diff --git a/src/test_helper.bash b/src/test_helper.bash index 99227c9..21c18f9 100644 --- a/src/test_helper.bash +++ b/src/test_helper.bash @@ -26,9 +26,9 @@ xxadd() { xxdel() { if [ -f /etc/alpine-release ]; then - xx-apk add "$@" 2>/dev/null || true + xx-apk del "$@" 2>/dev/null || true else - xxrun xx-apt install -y --autoremove "$@" 2>/dev/null || true + xxrun xx-apt remove -y --autoremove "$@" 2>/dev/null || true fi }