summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOsama Abdelkader <osama.abdelkader@gmail.com>2025-09-14 20:25:49 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-09-18 11:16:34 +0100
commitaf4a5882901610f9e09c3731469a7a065ace41a8 (patch)
treea4a5d8adad78713ca87eebf3c8e8cc6ef9530717
parentd8068d6c85c5e8e7f98ff6990c20897675f8b086 (diff)
downloadpoky-af4a5882901610f9e09c3731469a7a065ace41a8.tar.gz
go: extend runtime test
extend go runtime test with a simple test file, and simple go module test to validate go compilation and execution on target. (From OE-Core rev: e3b2b9170f76f4bbdc41ea6ba7bccffc17d01968) Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/files/test.go7
-rw-r--r--meta/lib/oeqa/runtime/cases/go.py68
2 files changed, 75 insertions, 0 deletions
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 @@
1package main
2
3import "fmt"
4
5func main() {
6 fmt.Println("Hello from Go!")
7}
diff --git a/meta/lib/oeqa/runtime/cases/go.py b/meta/lib/oeqa/runtime/cases/go.py
index 39a80f4dca..fc7959b5f4 100644
--- a/meta/lib/oeqa/runtime/cases/go.py
+++ b/meta/lib/oeqa/runtime/cases/go.py
@@ -4,10 +4,78 @@
4# SPDX-License-Identifier: MIT 4# SPDX-License-Identifier: MIT
5# 5#
6 6
7import os
7from oeqa.runtime.case import OERuntimeTestCase 8from oeqa.runtime.case import OERuntimeTestCase
8from oeqa.core.decorator.depends import OETestDepends 9from oeqa.core.decorator.depends import OETestDepends
9from oeqa.runtime.decorator.package import OEHasPackage 10from oeqa.runtime.decorator.package import OEHasPackage
10 11
12class GoCompileTest(OERuntimeTestCase):
13
14 @classmethod
15 def setUp(cls):
16 dst = '/tmp/'
17 src = os.path.join(cls.tc.files_dir, 'test.go')
18 cls.tc.target.copyTo(src, dst)
19
20 @classmethod
21 def tearDown(cls):
22 files = '/tmp/test.go /tmp/test'
23 cls.tc.target.run('rm %s' % files)
24 dirs = '/tmp/hello-go'
25 cls.tc.target.run('rm -r %s' % dirs)
26
27 @OETestDepends(['ssh.SSHTest.test_ssh'])
28 @OEHasPackage('go')
29 @OEHasPackage('go-runtime')
30 @OEHasPackage('go-runtime-dev')
31 @OEHasPackage('openssh-scp')
32 def test_go_compile(self):
33 # Check if go is available
34 status, output = self.target.run('which go')
35 if status != 0:
36 self.skipTest('go command not found, output: %s' % output)
37
38 # Compile the simple Go program
39 status, output = self.target.run('go build -o /tmp/test /tmp/test.go')
40 msg = 'go compile failed, output: %s' % output
41 self.assertEqual(status, 0, msg=msg)
42
43 # Run the compiled program
44 status, output = self.target.run('/tmp/test')
45 msg = 'running compiled file failed, output: %s' % output
46 self.assertEqual(status, 0, msg=msg)
47
48 @OETestDepends(['ssh.SSHTest.test_ssh'])
49 @OEHasPackage('go')
50 @OEHasPackage('go-runtime')
51 @OEHasPackage('go-runtime-dev')
52 @OEHasPackage('openssh-scp')
53 def test_go_module(self):
54 # Check if go is available
55 status, output = self.target.run('which go')
56 if status != 0:
57 self.skipTest('go command not found, output: %s' % output)
58
59 # Create a simple Go module
60 status, output = self.target.run('mkdir -p /tmp/hello-go')
61 msg = 'mkdir failed, output: %s' % output
62 self.assertEqual(status, 0, msg=msg)
63
64 # Copy the existing test.go file to the module
65 status, output = self.target.run('cp /tmp/test.go /tmp/hello-go/main.go')
66 msg = 'copying test.go failed, output: %s' % output
67 self.assertEqual(status, 0, msg=msg)
68
69 # Build the module
70 status, output = self.target.run('cd /tmp/hello-go && go build -o hello main.go')
71 msg = 'go build failed, output: %s' % output
72 self.assertEqual(status, 0, msg=msg)
73
74 # Run the module
75 status, output = self.target.run('cd /tmp/hello-go && ./hello')
76 msg = 'running go module failed, output: %s' % output
77 self.assertEqual(status, 0, msg=msg)
78
11class GoHelloworldTest(OERuntimeTestCase): 79class GoHelloworldTest(OERuntimeTestCase):
12 @OETestDepends(['ssh.SSHTest.test_ssh']) 80 @OETestDepends(['ssh.SSHTest.test_ssh'])
13 @OEHasPackage(['go-helloworld']) 81 @OEHasPackage(['go-helloworld'])