diff options
-rw-r--r-- | meta/lib/oeqa/selftest/cases/gotoolchain.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/gotoolchain.py b/meta/lib/oeqa/selftest/cases/gotoolchain.py new file mode 100644 index 0000000000..1e23257f4d --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/gotoolchain.py | |||
@@ -0,0 +1,67 @@ | |||
1 | import glob | ||
2 | import os | ||
3 | import shutil | ||
4 | import tempfile | ||
5 | from oeqa.selftest.case import OESelftestTestCase | ||
6 | from oeqa.utils.commands import runCmd, bitbake, get_bb_vars | ||
7 | |||
8 | |||
9 | class oeGoToolchainSelfTest(OESelftestTestCase): | ||
10 | """ | ||
11 | Test cases for OE's Go toolchain | ||
12 | """ | ||
13 | |||
14 | @staticmethod | ||
15 | def get_sdk_environment(tmpdir_SDKQA): | ||
16 | pattern = os.path.join(tmpdir_SDKQA, "environment-setup-*") | ||
17 | # FIXME: this is a very naive implementation | ||
18 | return glob.glob(pattern)[0] | ||
19 | |||
20 | @staticmethod | ||
21 | def get_sdk_toolchain(): | ||
22 | bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAIN_OUTPUTNAME'], | ||
23 | "meta-go-toolchain") | ||
24 | sdk_deploy = bb_vars['SDK_DEPLOY'] | ||
25 | toolchain_name = bb_vars['TOOLCHAIN_OUTPUTNAME'] | ||
26 | return os.path.join(sdk_deploy, toolchain_name + ".sh") | ||
27 | |||
28 | @classmethod | ||
29 | def setUpClass(cls): | ||
30 | super(oeGoToolchainSelfTest, cls).setUpClass() | ||
31 | cls.tmpdir_SDKQA = tempfile.mkdtemp(prefix='SDKQA') | ||
32 | cls.go_path = os.path.join(cls.tmpdir_SDKQA, "go") | ||
33 | # Build the SDK and locate it in DEPLOYDIR | ||
34 | bitbake("meta-go-toolchain") | ||
35 | cls.sdk_path = oeGoToolchainSelfTest.get_sdk_toolchain() | ||
36 | # Install the SDK into the tmpdir | ||
37 | runCmd("sh %s -y -d \"%s\"" % (cls.sdk_path, cls.tmpdir_SDKQA)) | ||
38 | cls.env_SDK = oeGoToolchainSelfTest.get_sdk_environment(cls.tmpdir_SDKQA) | ||
39 | |||
40 | @classmethod | ||
41 | def tearDownClass(cls): | ||
42 | shutil.rmtree(cls.tmpdir_SDKQA, ignore_errors=True) | ||
43 | super(oeGoToolchainSelfTest, cls).tearDownClass() | ||
44 | |||
45 | def run_sdk_go_command(self, gocmd): | ||
46 | cmd = "cd %s; " % self.tmpdir_SDKQA | ||
47 | cmd = cmd + ". %s; " % self.env_SDK | ||
48 | cmd = cmd + "export GOPATH=%s; " % self.go_path | ||
49 | cmd = cmd + "${CROSS_COMPILE}go %s" % gocmd | ||
50 | return runCmd(cmd).status | ||
51 | |||
52 | def test_go_dep_build(self): | ||
53 | proj = "github.com/golang" | ||
54 | name = "dep" | ||
55 | ver = "v0.3.1" | ||
56 | archive = ".tar.gz" | ||
57 | url = "https://%s/%s/archive/%s%s" % (proj, name, ver, archive) | ||
58 | |||
59 | runCmd("cd %s; wget %s" % (self.tmpdir_SDKQA, url)) | ||
60 | runCmd("cd %s; tar -xf %s" % (self.tmpdir_SDKQA, ver+archive)) | ||
61 | runCmd("mkdir -p %s/src/%s" % (self.go_path, proj)) | ||
62 | runCmd("mv %s/dep-0.3.1 %s/src/%s/%s" | ||
63 | % (self.tmpdir_SDKQA, self.go_path, proj, name)) | ||
64 | retv = self.run_sdk_go_command('build %s/%s/cmd/dep' | ||
65 | % (proj, name)) | ||
66 | self.assertEqual(retv, 0, | ||
67 | msg="Running go build failed for %s" % name) | ||