diff mbox series

[meta-lts-mixins,scarthgap/go,2/4] cgo-helloworld: init add

Message ID 20260607192934.156036-2-peter.marko@siemens.com
State New
Headers show
Series [meta-lts-mixins,scarthgap/go,1/4] go-helloworld: use bbappend for mixin modifications | expand

Commit Message

Peter Marko June 7, 2026, 7:29 p.m. UTC
From: Changqing Li <changqing.li@windriver.com>

* Add a go example recipe with cgo enabled, Flush the stdio buffer so
  that piped stdout can read the output before the program exits.

  This is for covering go reproducibility with cgo enabled. The test
  coverage is provided by the reproducibility world build.

  Related to the following commit [1]:
  [0642d23230 go.bbclass: change GOTMPDIR to improve reproducibility]

* cgo-helloworld is a complement for go-helloworld, also add it in
  runtime case for go and gotools

[1] https://git.openembedded.org/openembedded-core/commit/?id=0642d2323072f561a4d0eeb9266213387b2997fc

[YOCTO #16100]

Signed-off-by: Changqing Li <changqing.li@windriver.com>
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(From OE-Core rev: 204e4f7398ca0e8847a026c5b4f46685760af90a)
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
 lib/oeqa/runtime/cases/go_mixin.py            | 15 ++++++++++++
 .../packagegroup-core-tools-testapps.bbappend |  4 ++++
 .../cgo-helloworld/cgo-helloworld.go          |  9 ++++++++
 .../go-examples/cgo-helloworld_1.0.bb         | 23 +++++++++++++++++++
 .../go-examples/cgo-helloworld_1.0.bbappend   |  2 ++
 5 files changed, 53 insertions(+)
 create mode 100644 lib/oeqa/runtime/cases/go_mixin.py
 create mode 100644 recipes-core/packagegroups/packagegroup-core-tools-testapps.bbappend
 create mode 100644 recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go
 create mode 100644 recipes-extended/go-examples/cgo-helloworld_1.0.bb
 create mode 100644 recipes-extended/go-examples/cgo-helloworld_1.0.bbappend
diff mbox series

Patch

diff --git a/lib/oeqa/runtime/cases/go_mixin.py b/lib/oeqa/runtime/cases/go_mixin.py
new file mode 100644
index 0000000..9e94cfa
--- /dev/null
+++ b/lib/oeqa/runtime/cases/go_mixin.py
@@ -0,0 +1,15 @@ 
+from oeqa.runtime.case import OERuntimeTestCase
+from oeqa.core.decorator.depends import OETestDepends
+from oeqa.runtime.decorator.package import OEHasPackage
+
+class CgoHelloworldTest(OERuntimeTestCase):
+    @OETestDepends(['ssh.SSHTest.test_ssh'])
+    @OEHasPackage(['cgo-helloworld'])
+    def test_cgohelloworld(self):
+        cmd = "cgo-helloworld"
+        status, output = self.target.run(cmd)
+        msg = 'Exit status was not 0. Output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+        msg = 'Incorrect output: %s' % output
+        self.assertEqual(output, "Hello, world!", msg=msg)
diff --git a/recipes-core/packagegroups/packagegroup-core-tools-testapps.bbappend b/recipes-core/packagegroups/packagegroup-core-tools-testapps.bbappend
new file mode 100644
index 0000000..e5dca6f
--- /dev/null
+++ b/recipes-core/packagegroups/packagegroup-core-tools-testapps.bbappend
@@ -0,0 +1,4 @@ 
+GOTOOLS = "\
+    go-helloworld \
+    cgo-helloworld \
+    "
diff --git a/recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go b/recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go
new file mode 100644
index 0000000..0c1f9d4
--- /dev/null
+++ b/recipes-extended/go-examples/cgo-helloworld/cgo-helloworld.go
@@ -0,0 +1,9 @@ 
+package main
+
+// #include <stdio.h>
+// void hello() { printf("Hello, world!\n"); fflush(stdout);}
+import "C"
+
+func main() {
+	C.hello()
+}
diff --git a/recipes-extended/go-examples/cgo-helloworld_1.0.bb b/recipes-extended/go-examples/cgo-helloworld_1.0.bb
new file mode 100644
index 0000000..9ca1e16
--- /dev/null
+++ b/recipes-extended/go-examples/cgo-helloworld_1.0.bb
@@ -0,0 +1,23 @@ 
+SUMMARY = "A simple CGO example that calls C to print hello world"
+SECTION = "examples"
+HOMEPAGE = "https://golang.org/"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+SRC_URI = "file://cgo-helloworld.go"
+
+S = "${UNPACKDIR}"
+
+GO_IMPORT = "cgo-helloworld"
+GO_INSTALL = "${GO_IMPORT}"
+
+inherit go
+
+export GO111MODULE = "off"
+export CGO_ENABLED = "1"
+
+do_configure:prepend() {
+    mkdir -p ${S}/src/${GO_IMPORT}
+    cp ${UNPACKDIR}/cgo-helloworld.go ${S}/src/${GO_IMPORT}/main.go
+}
diff --git a/recipes-extended/go-examples/cgo-helloworld_1.0.bbappend b/recipes-extended/go-examples/cgo-helloworld_1.0.bbappend
new file mode 100644
index 0000000..6d8a9ee
--- /dev/null
+++ b/recipes-extended/go-examples/cgo-helloworld_1.0.bbappend
@@ -0,0 +1,2 @@ 
+# UNPACKDIR does not exist yet in scarthgap
+UNPACKDIR = "${WORKDIR}"