esdk.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. import tempfile
  7. import shutil
  8. import os
  9. import glob
  10. import time
  11. from oeqa.selftest.case import OESelftestTestCase
  12. from oeqa.utils.commands import runCmd, bitbake, get_bb_vars
  13. class oeSDKExtSelfTest(OESelftestTestCase):
  14. """
  15. # Bugzilla Test Plan: 6033
  16. # This code is planned to be part of the automation for eSDK containig
  17. # Install libraries and headers, image generation binary feeds, sdk-update.
  18. """
  19. @staticmethod
  20. def get_esdk_environment(env_eSDK, tmpdir_eSDKQA):
  21. # XXX: at this time use the first env need to investigate
  22. # what environment load oe-selftest, i586, x86_64
  23. pattern = os.path.join(tmpdir_eSDKQA, 'environment-setup-*')
  24. return glob.glob(pattern)[0]
  25. @staticmethod
  26. def run_esdk_cmd(env_eSDK, tmpdir_eSDKQA, cmd, postconfig=None, **options):
  27. if postconfig:
  28. esdk_conf_file = os.path.join(tmpdir_eSDKQA, 'conf', 'local.conf')
  29. with open(esdk_conf_file, 'a+') as f:
  30. f.write(postconfig)
  31. if not options:
  32. options = {}
  33. if not 'shell' in options:
  34. options['shell'] = True
  35. runCmd("cd %s; unset BBPATH; unset BUILDDIR; . %s; %s" % (tmpdir_eSDKQA, env_eSDK, cmd), **options)
  36. @staticmethod
  37. def generate_eSDK(image):
  38. pn_task = '%s -c populate_sdk_ext' % image
  39. bitbake(pn_task)
  40. @staticmethod
  41. def get_eSDK_toolchain(image):
  42. pn_task = '%s -c populate_sdk_ext' % image
  43. bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAINEXT_OUTPUTNAME'], pn_task)
  44. sdk_deploy = bb_vars['SDK_DEPLOY']
  45. toolchain_name = bb_vars['TOOLCHAINEXT_OUTPUTNAME']
  46. return os.path.join(sdk_deploy, toolchain_name + '.sh')
  47. @staticmethod
  48. def update_configuration(cls, image, tmpdir_eSDKQA, env_eSDK, ext_sdk_path):
  49. sstate_dir = os.path.join(os.environ['BUILDDIR'], 'sstate-cache')
  50. oeSDKExtSelfTest.generate_eSDK(cls.image)
  51. cls.ext_sdk_path = oeSDKExtSelfTest.get_eSDK_toolchain(cls.image)
  52. runCmd("%s -y -d \"%s\"" % (cls.ext_sdk_path, cls.tmpdir_eSDKQA))
  53. cls.env_eSDK = oeSDKExtSelfTest.get_esdk_environment('', cls.tmpdir_eSDKQA)
  54. sstate_config="""
  55. ESDK_LOCALCONF_ALLOW = "SSTATE_MIRRORS"
  56. SSTATE_MIRRORS = "file://.* file://%s/PATH"
  57. CORE_IMAGE_EXTRA_INSTALL = "perl"
  58. """ % sstate_dir
  59. with open(os.path.join(cls.tmpdir_eSDKQA, 'conf', 'local.conf'), 'a+') as f:
  60. f.write(sstate_config)
  61. @classmethod
  62. def setUpClass(cls):
  63. super(oeSDKExtSelfTest, cls).setUpClass()
  64. cls.image = 'core-image-minimal'
  65. bb_vars = get_bb_vars(['SSTATE_DIR', 'WORKDIR'], cls.image)
  66. bb.utils.mkdirhier(bb_vars["WORKDIR"])
  67. cls.tmpdirobj = tempfile.TemporaryDirectory(prefix="selftest-esdk-", dir=bb_vars["WORKDIR"])
  68. cls.tmpdir_eSDKQA = cls.tmpdirobj.name
  69. oeSDKExtSelfTest.generate_eSDK(cls.image)
  70. # Install eSDK
  71. cls.ext_sdk_path = oeSDKExtSelfTest.get_eSDK_toolchain(cls.image)
  72. runCmd("%s -y -d \"%s\"" % (cls.ext_sdk_path, cls.tmpdir_eSDKQA))
  73. cls.env_eSDK = oeSDKExtSelfTest.get_esdk_environment('', cls.tmpdir_eSDKQA)
  74. # Configure eSDK to use sstate mirror from poky
  75. sstate_config="""
  76. ESDK_LOCALCONF_ALLOW = "SSTATE_MIRRORS"
  77. SSTATE_MIRRORS = "file://.* file://%s/PATH"
  78. """ % bb_vars["SSTATE_DIR"]
  79. with open(os.path.join(cls.tmpdir_eSDKQA, 'conf', 'local.conf'), 'a+') as f:
  80. f.write(sstate_config)
  81. @classmethod
  82. def tearDownClass(cls):
  83. for i in range(0, 10):
  84. if os.path.exists(os.path.join(cls.tmpdir_eSDKQA, 'bitbake.lock')) or os.path.exists(os.path.join(cls.tmpdir_eSDKQA, 'cache/hashserv.db-wal')):
  85. time.sleep(1)
  86. else:
  87. break
  88. cls.tmpdirobj.cleanup()
  89. super().tearDownClass()
  90. def test_install_libraries_headers(self):
  91. pn_sstate = 'bc'
  92. bitbake(pn_sstate)
  93. cmd = "devtool sdk-install %s " % pn_sstate
  94. oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd)
  95. def test_image_generation_binary_feeds(self):
  96. image = 'core-image-minimal'
  97. cmd = "devtool build-image %s" % image
  98. oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd)