diff mbox series

[1/2] go: extend runtime test

Message ID 20250912232110.1794088-1-osama.abdelkader@gmail.com
State Accepted, archived
Commit e3b2b9170f76f4bbdc41ea6ba7bccffc17d01968
Headers show
Series [1/2] go: extend runtime test | expand

Commit Message

Osama Abdelkader Sept. 12, 2025, 11:21 p.m. UTC
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

Comments

Mathieu Dubois-Briand Sept. 14, 2025, 9:44 a.m. UTC | #1
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
Osama Abdelkader Sept. 14, 2025, 6:39 p.m. UTC | #2
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
diff mbox series

Patch

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