/poky/meta/lib/oeqa/selftest/cases/gotoolchain.py

https://github.com/openbmc/openbmc
Python | 71 lines | 60 code | 3 blank | 8 comment | 1 complexity | 215f1458c72478cf5d5c95dd22e448eb MD5 | raw file
  1. #
  2. # SPDX-License-Identifier: MIT
  3. #
  4. import glob
  5. import os
  6. import shutil
  7. import tempfile
  8. from oeqa.selftest.case import OESelftestTestCase
  9. from oeqa.utils.commands import runCmd, bitbake, get_bb_vars
  10. class oeGoToolchainSelfTest(OESelftestTestCase):
  11. """
  12. Test cases for OE's Go toolchain
  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. @staticmethod
  20. def get_sdk_toolchain():
  21. bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAIN_OUTPUTNAME'],
  22. "meta-go-toolchain")
  23. sdk_deploy = bb_vars['SDK_DEPLOY']
  24. toolchain_name = bb_vars['TOOLCHAIN_OUTPUTNAME']
  25. return os.path.join(sdk_deploy, toolchain_name + ".sh")
  26. @classmethod
  27. def setUpClass(cls):
  28. super(oeGoToolchainSelfTest, cls).setUpClass()
  29. cls.tmpdir_SDKQA = tempfile.mkdtemp(prefix='SDKQA')
  30. cls.go_path = os.path.join(cls.tmpdir_SDKQA, "go")
  31. # Build the SDK and locate it in DEPLOYDIR
  32. bitbake("meta-go-toolchain")
  33. cls.sdk_path = oeGoToolchainSelfTest.get_sdk_toolchain()
  34. # Install the SDK into the tmpdir
  35. runCmd("sh %s -y -d \"%s\"" % (cls.sdk_path, cls.tmpdir_SDKQA))
  36. cls.env_SDK = oeGoToolchainSelfTest.get_sdk_environment(cls.tmpdir_SDKQA)
  37. @classmethod
  38. def tearDownClass(cls):
  39. shutil.rmtree(cls.tmpdir_SDKQA, ignore_errors=True)
  40. super(oeGoToolchainSelfTest, cls).tearDownClass()
  41. def run_sdk_go_command(self, gocmd):
  42. cmd = "cd %s; " % self.tmpdir_SDKQA
  43. cmd = cmd + ". %s; " % self.env_SDK
  44. cmd = cmd + "export GOPATH=%s; " % self.go_path
  45. cmd = cmd + "${CROSS_COMPILE}go %s" % gocmd
  46. return runCmd(cmd).status
  47. def test_go_dep_build(self):
  48. proj = "github.com/golang"
  49. name = "dep"
  50. ver = "v0.3.1"
  51. archive = ".tar.gz"
  52. url = "https://%s/%s/archive/%s%s" % (proj, name, ver, archive)
  53. runCmd("cd %s; wget %s" % (self.tmpdir_SDKQA, url))
  54. runCmd("cd %s; tar -xf %s" % (self.tmpdir_SDKQA, ver+archive))
  55. runCmd("mkdir -p %s/src/%s" % (self.go_path, proj))
  56. runCmd("mv %s/dep-0.3.1 %s/src/%s/%s"
  57. % (self.tmpdir_SDKQA, self.go_path, proj, name))
  58. retv = self.run_sdk_go_command('build %s/%s/cmd/dep'
  59. % (proj, name))
  60. self.assertEqual(retv, 0,
  61. msg="Running go build failed for %s" % name)