diff mbox series

[meta-lts-mixins,scarthgap/go,4/7] go: ptest: improvements and multiple fixes in golang ptest

Message ID 20260513170902.2468061-4-peter.marko@siemens.com
State New
Headers show
Series [meta-lts-mixins,scarthgap/go,1/7] go-helloworld: upgrade to latest revision | expand

Commit Message

Peter Marko May 13, 2026, 5:08 p.m. UTC
From: Pratik Farkase <pratik.farkase@est.tech>

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 <pratik.farkase@est.tech>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(From OE-Core rev: a359aed2a8b94ad395a259a2009347e97185cbbc)
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
 recipes-devtools/go/go-1.26.2.inc |  1 -
 recipes-devtools/go/go/run-ptest  | 47 +++++++++++++++++++++++++------
 recipes-devtools/go/go_1.26.2.bb  |  8 ++++--
 3 files changed, 45 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/recipes-devtools/go/go-1.26.2.inc b/recipes-devtools/go/go-1.26.2.inc
index c53e828..8bb10bc 100644
--- a/recipes-devtools/go/go-1.26.2.inc
+++ b/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/recipes-devtools/go/go/run-ptest b/recipes-devtools/go/go/run-ptest
index ac020de..b8a0805 100755
--- a/recipes-devtools/go/go/run-ptest
+++ b/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
+# 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"
 
-cd $GOROOT
+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/recipes-devtools/go/go_1.26.2.bb b/recipes-devtools/go/go_1.26.2.bb
index 35a14b8..2e18ce0 100644
--- a/recipes-devtools/go/go_1.26.2.bb
+++ b/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"