blob: 3119520f0de3ddaf009008e5ef4b1c46d19f107c [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
49 def run_sdk_go_command(self, gocmd):
50 cmd = "cd %s; " % self.tmpdir_SDKQA
51 cmd = cmd + ". %s; " % self.env_SDK
52 cmd = cmd + "export GOPATH=%s; " % self.go_path
53 cmd = cmd + "${CROSS_COMPILE}go %s" % gocmd
54 return runCmd(cmd).status
55
56 def test_go_dep_build(self):
57 proj = "github.com/golang"
58 name = "dep"
59 ver = "v0.3.1"
60 archive = ".tar.gz"
61 url = "https://%s/%s/archive/%s%s" % (proj, name, ver, archive)
62
63 runCmd("cd %s; wget %s" % (self.tmpdir_SDKQA, url))
64 runCmd("cd %s; tar -xf %s" % (self.tmpdir_SDKQA, ver+archive))
65 runCmd("mkdir -p %s/src/%s" % (self.go_path, proj))
66 runCmd("mv %s/dep-0.3.1 %s/src/%s/%s"
67 % (self.tmpdir_SDKQA, self.go_path, proj, name))
68 retv = self.run_sdk_go_command('build %s/%s/cmd/dep'
69 % (proj, name))
70 self.assertEqual(retv, 0,
71 msg="Running go build failed for %s" % name)