1# 2# SPDX-License-Identifier: MIT 3# 4 5import tempfile 6import shutil 7import os 8import glob 9import time 10from oeqa.selftest.case import OESelftestTestCase 11from oeqa.utils.commands import runCmd, bitbake, get_bb_vars 12 13class 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 20 @staticmethod 21 def get_esdk_environment(env_eSDK, tmpdir_eSDKQA): 22 # XXX: at this time use the first env need to investigate 23 # what environment load oe-selftest, i586, x86_64 24 pattern = os.path.join(tmpdir_eSDKQA, 'environment-setup-*') 25 return glob.glob(pattern)[0] 26 27 @staticmethod 28 def run_esdk_cmd(env_eSDK, tmpdir_eSDKQA, cmd, postconfig=None, **options): 29 if postconfig: 30 esdk_conf_file = os.path.join(tmpdir_eSDKQA, 'conf', 'local.conf') 31 with open(esdk_conf_file, 'a+') as f: 32 f.write(postconfig) 33 if not options: 34 options = {} 35 if not 'shell' in options: 36 options['shell'] = True 37 38 runCmd("cd %s; unset BBPATH; unset BUILDDIR; . %s; %s" % (tmpdir_eSDKQA, env_eSDK, cmd), **options) 39 40 @staticmethod 41 def generate_eSDK(image): 42 pn_task = '%s -c populate_sdk_ext' % image 43 bitbake(pn_task) 44 45 @staticmethod 46 def get_eSDK_toolchain(image): 47 pn_task = '%s -c populate_sdk_ext' % image 48 49 bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAINEXT_OUTPUTNAME'], pn_task) 50 sdk_deploy = bb_vars['SDK_DEPLOY'] 51 toolchain_name = bb_vars['TOOLCHAINEXT_OUTPUTNAME'] 52 return os.path.join(sdk_deploy, toolchain_name + '.sh') 53 54 @staticmethod 55 def update_configuration(cls, image, tmpdir_eSDKQA, env_eSDK, ext_sdk_path): 56 sstate_dir = os.path.join(os.environ['BUILDDIR'], 'sstate-cache') 57 58 oeSDKExtSelfTest.generate_eSDK(cls.image) 59 60 cls.ext_sdk_path = oeSDKExtSelfTest.get_eSDK_toolchain(cls.image) 61 runCmd("%s -y -d \"%s\"" % (cls.ext_sdk_path, cls.tmpdir_eSDKQA)) 62 63 cls.env_eSDK = oeSDKExtSelfTest.get_esdk_environment('', cls.tmpdir_eSDKQA) 64 65 sstate_config=""" 66ESDK_LOCALCONF_ALLOW = "SSTATE_MIRRORS" 67SSTATE_MIRRORS = "file://.* file://%s/PATH" 68CORE_IMAGE_EXTRA_INSTALL = "perl" 69 """ % sstate_dir 70 71 with open(os.path.join(cls.tmpdir_eSDKQA, 'conf', 'local.conf'), 'a+') as f: 72 f.write(sstate_config) 73 74 @classmethod 75 def setUpClass(cls): 76 super(oeSDKExtSelfTest, cls).setUpClass() 77 cls.image = 'core-image-minimal' 78 79 bb_vars = get_bb_vars(['SSTATE_DIR', 'WORKDIR'], cls.image) 80 bb.utils.mkdirhier(bb_vars["WORKDIR"]) 81 cls.tmpdirobj = tempfile.TemporaryDirectory(prefix="selftest-esdk-", dir=bb_vars["WORKDIR"]) 82 cls.tmpdir_eSDKQA = cls.tmpdirobj.name 83 84 oeSDKExtSelfTest.generate_eSDK(cls.image) 85 86 # Install eSDK 87 cls.ext_sdk_path = oeSDKExtSelfTest.get_eSDK_toolchain(cls.image) 88 runCmd("%s -y -d \"%s\"" % (cls.ext_sdk_path, cls.tmpdir_eSDKQA)) 89 90 cls.env_eSDK = oeSDKExtSelfTest.get_esdk_environment('', cls.tmpdir_eSDKQA) 91 92 # Configure eSDK to use sstate mirror from poky 93 sstate_config=""" 94ESDK_LOCALCONF_ALLOW = "SSTATE_MIRRORS" 95SSTATE_MIRRORS = "file://.* file://%s/PATH" 96 """ % bb_vars["SSTATE_DIR"] 97 with open(os.path.join(cls.tmpdir_eSDKQA, 'conf', 'local.conf'), 'a+') as f: 98 f.write(sstate_config) 99 100 @classmethod 101 def tearDownClass(cls): 102 for i in range(0, 10): 103 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')): 104 time.sleep(1) 105 else: 106 break 107 cls.tmpdirobj.cleanup() 108 super().tearDownClass() 109 110 def test_install_libraries_headers(self): 111 pn_sstate = 'bc' 112 bitbake(pn_sstate) 113 cmd = "devtool sdk-install %s " % pn_sstate 114 oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd) 115 116 def test_image_generation_binary_feeds(self): 117 image = 'core-image-minimal' 118 cmd = "devtool build-image %s" % image 119 oeSDKExtSelfTest.run_esdk_cmd(self.env_eSDK, self.tmpdir_eSDKQA, cmd) 120 121