blob: 978898b86f17a77aea3501420271bc4968f2caa8 [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):
46 shutil.rmtree(cls.tmpdir_SDKQA, ignore_errors=True)
47 super(oeGoToolchainSelfTest, cls).tearDownClass()
48
Andrew Geissler90fd73c2021-03-05 15:25:55 -060049 def run_sdk_go_command(self, gocmd, proj, name):
50 cmd = "cd %s/src/%s/%s; " % (self.go_path, proj, name)
Brad Bishop316dfdd2018-06-25 12:45:53 -040051 cmd = cmd + ". %s; " % self.env_SDK
52 cmd = cmd + "export GOPATH=%s; " % self.go_path
Patrick Williamsdb4c27e2022-08-05 08:10:29 -050053 cmd = cmd + "export GOFLAGS=-modcacherw; "
54 cmd = cmd + "export CGO_ENABLED=1; "
Brad Bishop316dfdd2018-06-25 12:45:53 -040055 cmd = cmd + "${CROSS_COMPILE}go %s" % gocmd
56 return runCmd(cmd).status
57
58 def test_go_dep_build(self):
Andrew Geissler90fd73c2021-03-05 15:25:55 -060059 proj = "github.com/direnv"
60 name = "direnv"
61 ver = "v2.27.0"
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 archive = ".tar.gz"
63 url = "https://%s/%s/archive/%s%s" % (proj, name, ver, archive)
64
65 runCmd("cd %s; wget %s" % (self.tmpdir_SDKQA, url))
66 runCmd("cd %s; tar -xf %s" % (self.tmpdir_SDKQA, ver+archive))
67 runCmd("mkdir -p %s/src/%s" % (self.go_path, proj))
Andrew Geissler90fd73c2021-03-05 15:25:55 -060068 runCmd("mv %s/direnv-2.27.0 %s/src/%s/%s"
Brad Bishop316dfdd2018-06-25 12:45:53 -040069 % (self.tmpdir_SDKQA, self.go_path, proj, name))
Andrew Geissler90fd73c2021-03-05 15:25:55 -060070 retv = self.run_sdk_go_command('build', proj, name)
Brad Bishop316dfdd2018-06-25 12:45:53 -040071 self.assertEqual(retv, 0,
72 msg="Running go build failed for %s" % name)