Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] go: extend runtime test
@ 2025-09-12 23:21 Osama Abdelkader
  2025-09-12 23:21 ` [PATCH 2/2] go: add sdk test Osama Abdelkader
  2025-09-14  9:44 ` [OE-core] [PATCH 1/2] go: extend runtime test Mathieu Dubois-Briand
  0 siblings, 2 replies; 4+ messages in thread
From: Osama Abdelkader @ 2025-09-12 23:21 UTC (permalink / raw)
  To: openembedded-core, alex.kanavin; +Cc: Osama Abdelkader

extend go runtime test with a simple test file, and simple
go module test to validate go compilation and execution on
target.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 meta/lib/oeqa/files/test.go       |  7 ++++
 meta/lib/oeqa/runtime/cases/go.py | 61 ++++++++++++++++++++++++++++++-
 2 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 meta/lib/oeqa/files/test.go

diff --git a/meta/lib/oeqa/files/test.go b/meta/lib/oeqa/files/test.go
new file mode 100644
index 0000000000..9ca9302654
--- /dev/null
+++ b/meta/lib/oeqa/files/test.go
@@ -0,0 +1,7 @@
+package main
+
+import "fmt"
+
+func main() {
+	fmt.Println("Hello from Go!")
+}
diff --git a/meta/lib/oeqa/runtime/cases/go.py b/meta/lib/oeqa/runtime/cases/go.py
index 39a80f4dca..abcf9f231a 100644
--- a/meta/lib/oeqa/runtime/cases/go.py
+++ b/meta/lib/oeqa/runtime/cases/go.py
@@ -4,10 +4,69 @@
 # SPDX-License-Identifier: MIT
 #
 
+import os
 from oeqa.runtime.case import OERuntimeTestCase
 from oeqa.core.decorator.depends import OETestDepends
 from oeqa.runtime.decorator.package import OEHasPackage
 
+class GoCompileTest(OERuntimeTestCase):
+
+    @classmethod
+    def setUp(cls):
+        dst = '/tmp/'
+        src = os.path.join(cls.tc.files_dir, 'test.go')
+        cls.tc.target.copyTo(src, dst)
+
+    @classmethod
+    def tearDown(cls):
+        files = '/tmp/test.go /tmp/test'
+        cls.tc.target.run('rm %s' % files)
+        dirs = '/tmp/hello-go'
+        cls.tc.target.run('rm -r %s' % dirs)
+
+    @OETestDepends(['ssh.SSHTest.test_ssh'])
+    @OEHasPackage('go')
+    @OEHasPackage('openssh-scp')
+    def test_go_compile(self):
+        # Check if go is available
+        status, output = self.target.run('which go')
+        msg = 'go command not found, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+        
+        # Compile the simple Go program
+        status, output = self.target.run('go build -o /tmp/test /tmp/test.go')
+        msg = 'go compile failed, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+        # Run the compiled program
+        status, output = self.target.run('/tmp/test')
+        msg = 'running compiled file failed, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+    @OETestDepends(['ssh.SSHTest.test_ssh'])
+    @OEHasPackage('go')
+    @OEHasPackage('openssh-scp')
+    def test_go_module(self):
+        # Create a simple Go module
+        status, output = self.target.run('mkdir -p /tmp/hello-go')
+        msg = 'mkdir failed, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+        # Copy the existing test.go file to the module
+        status, output = self.target.run('cp /tmp/test.go /tmp/hello-go/main.go')
+        msg = 'copying test.go failed, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+        # Build the module
+        status, output = self.target.run('cd /tmp/hello-go && go build -o hello main.go')
+        msg = 'go build failed, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
+        # Run the module
+        status, output = self.target.run('cd /tmp/hello-go && ./hello')
+        msg = 'running go module failed, output: %s' % output
+        self.assertEqual(status, 0, msg=msg)
+
 class GoHelloworldTest(OERuntimeTestCase):
     @OETestDepends(['ssh.SSHTest.test_ssh'])
     @OEHasPackage(['go-helloworld'])
@@ -18,4 +77,4 @@ class GoHelloworldTest(OERuntimeTestCase):
         self.assertEqual(status, 0, msg=msg)
 
         msg = 'Incorrect output: %s' % output
-        self.assertEqual(output, "Hello, world!", msg=msg)
+        self.assertEqual(output, "Hello, world!", msg=msg)
\ No newline at end of file
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] go: add sdk test
  2025-09-12 23:21 [PATCH 1/2] go: extend runtime test Osama Abdelkader
@ 2025-09-12 23:21 ` Osama Abdelkader
  2025-09-14  9:44 ` [OE-core] [PATCH 1/2] go: extend runtime test Mathieu Dubois-Briand
  1 sibling, 0 replies; 4+ messages in thread
From: Osama Abdelkader @ 2025-09-12 23:21 UTC (permalink / raw)
  To: openembedded-core, alex.kanavin; +Cc: Osama Abdelkader

Add Go SDK tests for cross-compilation toolchain

- Add meta/lib/oeqa/sdk/cases/go.py with GoCompileTest and GoHostCompileTest classes
- Test validates go-cross-canadian toolchain functionality
- Includes native compilation, module creation, and cross-compilation tests
- Supports dynamic architecture mapping (aarch64, x86_64, riscv64, etc.)
- Validates both simple Go builds and Go module workflows

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 meta/lib/oeqa/sdk/cases/go.py | 116 ++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 meta/lib/oeqa/sdk/cases/go.py

diff --git a/meta/lib/oeqa/sdk/cases/go.py b/meta/lib/oeqa/sdk/cases/go.py
new file mode 100644
index 0000000000..a6122841f5
--- /dev/null
+++ b/meta/lib/oeqa/sdk/cases/go.py
@@ -0,0 +1,116 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+import os
+import shutil
+import unittest
+
+from oeqa.core.utils.path import remove_safe
+from oeqa.sdk.case import OESDKTestCase
+
+from oeqa.utils.subprocesstweak import errors_have_output
+errors_have_output()
+
+class GoCompileTest(OESDKTestCase):
+    td_vars = ['MACHINE', 'TARGET_ARCH']
+
+    @classmethod
+    def setUpClass(self):
+        # Copy test.go file to SDK directory (same as GCC test uses files_dir)
+        shutil.copyfile(os.path.join(self.tc.files_dir, 'test.go'),
+                        os.path.join(self.tc.sdk_dir, 'test.go'))
+
+    def setUp(self):
+        target_arch = self.td.get("TARGET_ARCH")
+        # Check for go-cross-canadian package (uses target architecture)
+        if not self.tc.hasHostPackage("go-cross-canadian-%s" % target_arch):
+            raise unittest.SkipTest("GoCompileTest class: SDK doesn't contain a Go cross-canadian toolchain")
+
+    def test_go_build(self):
+        """Test Go build command (native compilation)"""
+        self._run('cd %s; go build -o test test.go' % self.tc.sdk_dir)
+
+    def test_go_module(self):
+        """Test Go module creation and building"""
+        # Create a simple Go module
+        self._run('cd %s; go mod init hello-go' % self.tc.sdk_dir)
+        self._run('cd %s; go build -o hello-go' % self.tc.sdk_dir)
+
+    @classmethod
+    def tearDownClass(self):
+        files = [os.path.join(self.tc.sdk_dir, f) \
+                for f in ['test.go', 'test', 'hello-go', 'go.mod', 'go.sum']]
+        for f in files:
+            remove_safe(f)
+
+class GoHostCompileTest(OESDKTestCase):
+    td_vars = ['MACHINE', 'SDK_SYS', 'TARGET_ARCH']
+
+    # Architecture mapping from Yocto/Poky to Go
+    ARCH_MAP = {
+        'aarch64': 'arm64',
+        'cortexa57': 'arm64',  # ARM Cortex-A57 is ARM64
+        'cortexa72': 'arm64',  # ARM Cortex-A72 is ARM64
+        'cortexa53': 'arm64',  # ARM Cortex-A53 is ARM64
+        'x86_64': 'amd64',
+        'i586': '386',
+        'i686': '386',
+        'mips': 'mips',
+        'mipsel': 'mipsle',
+        'powerpc64': 'ppc64',
+        'powerpc64le': 'ppc64le',
+        'riscv64': 'riscv64',
+    }
+
+    @classmethod
+    def setUpClass(self):
+        # Copy test.go file to SDK directory (same as GCC test uses files_dir)
+        shutil.copyfile(os.path.join(self.tc.files_dir, 'test.go'),
+                        os.path.join(self.tc.sdk_dir, 'test.go'))
+
+    def setUp(self):
+        target_arch = self.td.get("TARGET_ARCH")
+        # Check for go-cross-canadian package (uses target architecture)
+        if not self.tc.hasHostPackage("go-cross-canadian-%s" % target_arch):
+            raise unittest.SkipTest("GoHostCompileTest class: SDK doesn't contain a Go cross-canadian toolchain")
+
+    def _get_go_arch(self):
+        """Get Go architecture from SDK_SYS"""
+        sdksys = self.td.get("SDK_SYS")
+        arch = sdksys.split('-')[0]
+        
+        # Handle ARM variants
+        if arch.startswith('arm'):
+            return 'arm'
+        
+        # Use mapping for other architectures
+        return self.ARCH_MAP.get(arch, arch)
+
+    def test_go_cross_compile(self):
+        """Test Go cross-compilation for target"""
+        goarch = self._get_go_arch()
+        self._run('cd %s; GOOS=linux GOARCH=%s go build -o test-%s test.go' % (self.tc.sdk_dir, goarch, goarch))
+
+    def test_go_module_cross_compile(self):
+        """Test Go module cross-compilation"""
+        goarch = self._get_go_arch()
+        self._run('cd %s; go mod init hello-go' % self.tc.sdk_dir)
+        self._run('cd %s; GOOS=linux GOARCH=%s go build -o hello-go-%s' % (self.tc.sdk_dir, goarch, goarch))
+
+    @classmethod
+    def tearDownClass(self):
+        # Clean up files with dynamic architecture names
+        files = [os.path.join(self.tc.sdk_dir, f) \
+                for f in ['test.go', 'go.mod', 'go.sum']]
+        # Add architecture-specific files using the same mapping
+        for arch in self.ARCH_MAP.values():
+            files.extend([os.path.join(self.tc.sdk_dir, f) \
+                         for f in ['test-%s' % arch, 'hello-go-%s' % arch]])
+        # Add 'arm' for ARM variants
+        files.extend([os.path.join(self.tc.sdk_dir, f) \
+                     for f in ['test-arm', 'hello-go-arm']])
+        for f in files:
+            remove_safe(f)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [OE-core] [PATCH 1/2] go: extend runtime test
  2025-09-12 23:21 [PATCH 1/2] go: extend runtime test Osama Abdelkader
  2025-09-12 23:21 ` [PATCH 2/2] go: add sdk test Osama Abdelkader
@ 2025-09-14  9:44 ` Mathieu Dubois-Briand
  2025-09-14 18:39   ` Osama Abdelkader
  1 sibling, 1 reply; 4+ messages in thread
From: Mathieu Dubois-Briand @ 2025-09-14  9:44 UTC (permalink / raw)
  To: osama.abdelkader, openembedded-core, alex.kanavin

On Sat Sep 13, 2025 at 1:21 AM CEST, Osama Abdelkader via lists.openembedded.org wrote:
> extend go runtime test with a simple test file, and simple
> go module test to validate go compilation and execution on
> target.
>
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---

Hi Osama,

Thanks for your patches.

It looks like one of these is triggering this error:

oeqa.utils.subprocesstweak.OETestCalledProcessError: Command '. /srv/pokybuild/yocto-worker/beaglebone/build/build/tmp/work/beaglebone_yocto-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi > /dev/null; cd /srv/pokybuild/yocto-worker/beaglebone/build/build/tmp/work/beaglebone_yocto-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/; go build -o test test.go;' returned non-zero exit status 127.
Standard Output: /bin/bash: line 1: go: command not found

https://autobuilder.yoctoproject.org/valkyrie/#/builders/30/builds/2360
https://autobuilder.yoctoproject.org/valkyrie/#/builders/16/builds/2408
https://autobuilder.yoctoproject.org/valkyrie/#/builders/2/builds/2396

Can you have a look at this, please?

Thanks,
Mathieu

-- 
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [OE-core] [PATCH 1/2] go: extend runtime test
  2025-09-14  9:44 ` [OE-core] [PATCH 1/2] go: extend runtime test Mathieu Dubois-Briand
@ 2025-09-14 18:39   ` Osama Abdelkader
  0 siblings, 0 replies; 4+ messages in thread
From: Osama Abdelkader @ 2025-09-14 18:39 UTC (permalink / raw)
  To: Mathieu Dubois-Briand; +Cc: openembedded-core, alex.kanavin

On Sun, Sep 14, 2025 at 11:44:25AM +0200, Mathieu Dubois-Briand wrote:
> On Sat Sep 13, 2025 at 1:21 AM CEST, Osama Abdelkader via lists.openembedded.org wrote:
> > extend go runtime test with a simple test file, and simple
> > go module test to validate go compilation and execution on
> > target.
> >
> > Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> > ---
> 
> Hi Osama,
> 
> Thanks for your patches.
> 
> It looks like one of these is triggering this error:
> 
> oeqa.utils.subprocesstweak.OETestCalledProcessError: Command '. /srv/pokybuild/yocto-worker/beaglebone/build/build/tmp/work/beaglebone_yocto-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/environment-setup-cortexa8hf-neon-poky-linux-gnueabi > /dev/null; cd /srv/pokybuild/yocto-worker/beaglebone/build/build/tmp/work/beaglebone_yocto-poky-linux-gnueabi/core-image-sato/1.0/testimage-sdk/; go build -o test test.go;' returned non-zero exit status 127.
> Standard Output: /bin/bash: line 1: go: command not found
> 
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/30/builds/2360
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/16/builds/2408
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/2/builds/2396
> 
> Can you have a look at this, please?
> 
> Thanks,
> Mathieu
> 
> -- 
> Mathieu Dubois-Briand, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
> 

Thanks Mathieu. It looks "go" & "go-runtime" are missing in the image
I just sent v3 which skip those tests if "go & go-runtime" are missing.

Thanks,
Osama


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-14 18:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-12 23:21 [PATCH 1/2] go: extend runtime test Osama Abdelkader
2025-09-12 23:21 ` [PATCH 2/2] go: add sdk test Osama Abdelkader
2025-09-14  9:44 ` [OE-core] [PATCH 1/2] go: extend runtime test Mathieu Dubois-Briand
2025-09-14 18:39   ` Osama Abdelkader

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox