Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | import tempfile |
| 6 | import shutil |
| 7 | import os |
| 8 | import glob |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 9 | import time |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | from oeqa.selftest.case import OESelftestTestCase |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame^] | 11 | from oeqa.utils.commands import runCmd, bitbake, get_bb_vars |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 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 | |
| 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 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 38 | runCmd("cd %s; unset BBPATH; unset BUILDDIR; . %s; %s" % (tmpdir_eSDKQA, env_eSDK, cmd), **options) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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=""" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 66 | ESDK_LOCALCONF_ALLOW = "SSTATE_MIRRORS" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 67 | SSTATE_MIRRORS = "file://.* file://%s/PATH" |
| 68 | CORE_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() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 77 | cls.image = 'core-image-minimal' |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 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 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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=""" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 94 | ESDK_LOCALCONF_ALLOW = "SSTATE_MIRRORS" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | SSTATE_MIRRORS = "file://.* file://%s/PATH" |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 96 | """ % bb_vars["SSTATE_DIR"] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 102 | for i in range(0, 10): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 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')): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 104 | time.sleep(1) |
| 105 | else: |
| 106 | break |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 107 | cls.tmpdirobj.cleanup() |
| 108 | super().tearDownClass() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 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 | |