eSDK.py 4.2 KB

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