blob: c809d7c9b140434d6cd38ec3da15694e72c77b03 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop316dfdd2018-06-25 12:45:53 -04005import glob
6import os
7import shutil
8import tempfile
9from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import runCmd, bitbake, get_bb_vars
11
12
13class oeGoToolchainSelfTest(OESelftestTestCase):
14 """
15 Test cases for OE's Go toolchain
16 """
17
18 @staticmethod
19 def get_sdk_environment(tmpdir_SDKQA):
20 pattern = os.path.join(tmpdir_SDKQA, "environment-setup-*")
21 # FIXME: this is a very naive implementation
22 return glob.glob(pattern)[0]
23
24 @staticmethod
25 def get_sdk_toolchain():
26 bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAIN_OUTPUTNAME'],
27 "meta-go-toolchain")
28 sdk_deploy = bb_vars['SDK_DEPLOY']
29 toolchain_name = bb_vars['TOOLCHAIN_OUTPUTNAME']
30 return os.path.join(sdk_deploy, toolchain_name + ".sh")
31
32 @classmethod
33 def setUpClass(cls):
34 super(oeGoToolchainSelfTest, cls).setUpClass()
35 cls.tmpdir_SDKQA = tempfile.mkdtemp(prefix='SDKQA')
36 cls.go_path = os.path.join(cls.tmpdir_SDKQA, "go")
37 # Build the SDK and locate it in DEPLOYDIR
38 bitbake("meta-go-toolchain")
39 cls.sdk_path = oeGoToolchainSelfTest.get_sdk_toolchain()
40 # Install the SDK into the tmpdir
41 runCmd("sh %s -y -d \"%s\"" % (cls.sdk_path, cls.tmpdir_SDKQA))
42 cls.env_SDK = oeGoToolchainSelfTest.get_sdk_environment(cls.tmpdir_SDKQA)
43
44 @classmethod
45 def tearDownClass(cls):
Patrick Williams93c203f2021-10-06 16:15:23 -050046 # Go creates file which are readonly
47 for dirpath, dirnames, filenames in os.walk(cls.tmpdir_SDKQA):
48 for filename in filenames + dirnames:
49 f = os.path.join(dirpath, filename)
50 if not os.path.islink(f):
51 os.chmod(f, 0o775)
Brad Bishop316dfdd2018-06-25 12:45:53 -040052 shutil.rmtree(cls.tmpdir_SDKQA, ignore_errors=True)
53 super(oeGoToolchainSelfTest, cls).tearDownClass()
54
Andrew Geissler90fd73c2021-03-05 15:25:55 -060055 def run_sdk_go_command(self, gocmd, proj, name):
56 cmd = "cd %s/src/%s/%s; " % (self.go_path, proj, name)
Brad Bishop316dfdd2018-06-25 12:45:53 -040057 cmd = cmd + ". %s; " % self.env_SDK
58 cmd = cmd + "export GOPATH=%s; " % self.go_path
59 cmd = cmd + "${CROSS_COMPILE}go %s" % gocmd
60 return runCmd(cmd).status
61
62 def test_go_dep_build(self):
Andrew Geissler90fd73c2021-03-05 15:25:55 -060063 proj = "github.com/direnv"
64 name = "direnv"
65 ver = "v2.27.0"
Brad Bishop316dfdd2018-06-25 12:45:53 -040066 archive = ".tar.gz"
67 url = "https://%s/%s/archive/%s%s" % (proj, name, ver, archive)
68
69 runCmd("cd %s; wget %s" % (self.tmpdir_SDKQA, url))
70 runCmd("cd %s; tar -xf %s" % (self.tmpdir_SDKQA, ver+archive))
71 runCmd("mkdir -p %s/src/%s" % (self.go_path, proj))
Andrew Geissler90fd73c2021-03-05 15:25:55 -060072 runCmd("mv %s/direnv-2.27.0 %s/src/%s/%s"
Brad Bishop316dfdd2018-06-25 12:45:53 -040073 % (self.tmpdir_SDKQA, self.go_path, proj, name))
Andrew Geissler90fd73c2021-03-05 15:25:55 -060074 retv = self.run_sdk_go_command('build', proj, name)
Brad Bishop316dfdd2018-06-25 12:45:53 -040075 self.assertEqual(retv, 0,
76 msg="Running go build failed for %s" % name)