From: Pratik Farkase Date: Wed, 6 May 2026 12:43:29 +0000 (+0200) Subject: go: ptest: improvements and multiple fixes in golang ptest X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a359aed2a8b94ad395a259a2009347e97185cbbc;p=thirdparty%2Fopenembedded%2Fopenembedded-core.git go: ptest: improvements and multiple fixes in golang ptest Summary of Changelog: - run-ptest permanently modified the installed GOROOT by symlinking src/ and copying files without cleanup, corrupting the Go installation - Sub-package skip regex used exact match (^pkg$) so subpackages like net/http/httptest and runtime/debug were not skipped and would fail - Test output was completely suppressed (>/dev/null 2>&1), making failures impossible to diagnose - go was missing from RDEPENDS, allowing ptest to be installed without the toolchain it needs - bash was in RDEPENDS despite the script using #!/bin/sh with no bash-isms - file://run-ptest was in the shared .inc, affecting go-cross and go-native which don't inherit ptest - cp pkg/include/* would fail if the directory was empty Fix by saving/restoring GOROOT/src, using (/|$) in the skip regex, printing output on failure, correcting RDEPENDS, moving run-ptest to the target .bb, and guarding the glob. Tested on qemux86-64: all tests pass, 0 failures (~63 min). Signed-off-by: Pratik Farkase Signed-off-by: Richard Purdie --- diff --git a/meta/recipes-devtools/go/go-1.26.2.inc b/meta/recipes-devtools/go/go-1.26.2.inc index c53e8284a6..8bb10bc89f 100644 --- a/meta/recipes-devtools/go/go-1.26.2.inc +++ b/meta/recipes-devtools/go/go-1.26.2.inc @@ -16,6 +16,5 @@ SRC_URI += "\ file://0009-go-Filter-build-paths-on-staticly-linked-arches.patch \ file://0010-cmd-go-clear-GOROOT-for-func-ldShared-when-trimpath-.patch \ file://0011-cmd-link-stop-forcing-binutils-gold-dependency-on-aa.patch \ - file://run-ptest \ " SRC_URI[main.sha256sum] = "2e91ebb6947a96e9436fb2b3926a8802efe63a6d375dffec4f82aa9dbd6fd43b" diff --git a/meta/recipes-devtools/go/go/run-ptest b/meta/recipes-devtools/go/go/run-ptest index ac020de025..b8a080526d 100755 --- a/meta/recipes-devtools/go/go/run-ptest +++ b/meta/recipes-devtools/go/go/run-ptest @@ -1,32 +1,63 @@ #!/bin/sh +# SPDX-License-Identifier: MIT -PTEST_DIR=/usr/lib/go/ptest +PTEST_DIR=$(cd "$(dirname "$0")" && pwd) GOROOT=/usr/lib/go export GOROOT export PATH=$GOROOT/bin:$PATH +export GOCACHE=$(mktemp -d) export ZONEINFO=/usr/share/zoneinfo -ln -sf $PTEST_DIR/src $GOROOT/src -mkdir -p $GOROOT/pkg/include -cp $PTEST_DIR/pkg/include/* $GOROOT/pkg/include/ -cp $PTEST_DIR/VERSION $GOROOT/VERSION - -cd $GOROOT - +# Link ptest source tree into GOROOT for testing. +# Save and restore any existing src directory. +if [ -d "$GOROOT/src" ] && [ ! -L "$GOROOT/src" ]; then + mv "$GOROOT/src" "$GOROOT/src.orig" +fi +ln -sf "$PTEST_DIR/src" "$GOROOT/src" + +if [ -f "$PTEST_DIR/VERSION" ]; then + cp "$PTEST_DIR/VERSION" "$GOROOT/VERSION" +fi +if ls "$PTEST_DIR/pkg/include/"* >/dev/null 2>&1; then + mkdir -p "$GOROOT/pkg/include" + cp "$PTEST_DIR/pkg/include/"* "$GOROOT/pkg/include/" +fi + +cd "$GOROOT" || exit 1 + +# Packages skipped due to known issues in the ptest environment: +# debug/dwarf, debug/elf, debug/pe, debug/plan9obj, internal/xcoff: +# require binary testdata files excluded to avoid QA errors +# go/types: extremely slow, exceeds ptest timeout +# net/http: requires network access unavailable in qemu +# runtime: requires cgo rebuild and race detector setup +# testing: circular dependency when testing the test framework +# time: requires writable GOROOT for timezone data SKIP_PKGS="debug/dwarf debug/elf debug/pe debug/plan9obj go/types internal/xcoff net/http runtime testing time" SKIP_REGEX=$(echo "$SKIP_PKGS" | sed 's/ /|/g') for pkg in $(go list std); do - if echo "$pkg" | grep -qE "^($SKIP_REGEX)$"; then + # Skip package and all its subpackages + if echo "$pkg" | grep -qE "^($SKIP_REGEX)(/|$)"; then echo "SKIP: $pkg" continue fi - if go test -short "$pkg" >/dev/null 2>&1; then + output=$(go test -short "$pkg" 2>&1) + ret=$? + if [ $ret -eq 0 ]; then echo "PASS: $pkg" else echo "FAIL: $pkg" + echo "$output" fi done + +# Cleanup: restore original src directory +rm -f "$GOROOT/src" +if [ -d "$GOROOT/src.orig" ]; then + mv "$GOROOT/src.orig" "$GOROOT/src" +fi +rm -rf "$GOCACHE" diff --git a/meta/recipes-devtools/go/go_1.26.2.bb b/meta/recipes-devtools/go/go_1.26.2.bb index 35a14b8e8b..2e18ce05a8 100644 --- a/meta/recipes-devtools/go/go_1.26.2.bb +++ b/meta/recipes-devtools/go/go_1.26.2.bb @@ -3,6 +3,8 @@ require go-target.inc inherit linuxloader ptest +SRC_URI += "file://run-ptest" + CGO_LDFLAGS:append = " -no-pie" export GO_LDSO = "${@get_linuxloader(d)}" @@ -20,7 +22,9 @@ do_install_ptest() { install -d ${D}${PTEST_PATH}/src install -d ${D}${PTEST_PATH}/pkg/include - cp ${S}/pkg/include/* ${D}${PTEST_PATH}/pkg/include/ + if ls ${S}/pkg/include/* >/dev/null 2>&1; then + cp ${S}/pkg/include/* ${D}${PTEST_PATH}/pkg/include/ + fi echo "go${PV}" > ${D}${PTEST_PATH}/VERSION cd ${S}/src @@ -40,4 +44,4 @@ do_install_ptest() { -exec install -m 0644 {} ${D}${PTEST_PATH}/src/{} \; } -RDEPENDS:${PN}-ptest += "bash tzdata git packagegroup-core-buildessential" +RDEPENDS:${PN}-ptest += "go tzdata git packagegroup-core-buildessential"