diff options
Diffstat (limited to 'poky/meta/lib/oeqa/selftest')
21 files changed, 821 insertions, 215 deletions
diff --git a/poky/meta/lib/oeqa/selftest/case.py b/poky/meta/lib/oeqa/selftest/case.py index ac3308d8a4..dcad4f76ec 100644 --- a/poky/meta/lib/oeqa/selftest/case.py +++ b/poky/meta/lib/oeqa/selftest/case.py @@ -6,7 +6,6 @@ import sys import os -import shutil import glob import errno from unittest.util import safe_repr @@ -30,9 +29,7 @@ class OESelftestTestCase(OETestCase): cls.builddir = cls.tc.config_paths['builddir'] cls.localconf_path = cls.tc.config_paths['localconf'] - cls.localconf_backup = cls.tc.config_paths['localconf_class_backup'] cls.local_bblayers_path = cls.tc.config_paths['bblayers'] - cls.local_bblayers_backup = cls.tc.config_paths['bblayers_class_backup'] cls.testinc_path = os.path.join(cls.tc.config_paths['builddir'], "conf/selftest.inc") @@ -43,8 +40,7 @@ class OESelftestTestCase(OETestCase): cls._track_for_cleanup = [ cls.testinc_path, cls.testinc_bblayers_path, - cls.machineinc_path, cls.localconf_backup, - cls.local_bblayers_backup] + cls.machineinc_path] cls.add_include() @@ -102,30 +98,6 @@ class OESelftestTestCase(OETestCase): def setUp(self): super(OESelftestTestCase, self).setUp() os.chdir(self.builddir) - # Check if local.conf or bblayers.conf files backup exists - # from a previous failed test and restore them - if os.path.isfile(self.localconf_backup) or os.path.isfile( - self.local_bblayers_backup): - self.logger.debug("\ -Found a local.conf and/or bblayers.conf backup from a previously aborted test.\ -Restoring these files now, but tests should be re-executed from a clean environment\ -to ensure accurate results.") - try: - shutil.copyfile(self.localconf_backup, self.localconf_path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - try: - shutil.copyfile(self.local_bblayers_backup, - self.local_bblayers_path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - else: - # backup local.conf and bblayers.conf - shutil.copyfile(self.localconf_path, self.localconf_backup) - shutil.copyfile(self.local_bblayers_path, self.local_bblayers_backup) - self.logger.debug("Creating local.conf and bblayers.conf backups.") # we don't know what the previous test left around in config or inc files # if it failed so we need a fresh start try: diff --git a/poky/meta/lib/oeqa/selftest/cases/archiver.py b/poky/meta/lib/oeqa/selftest/cases/archiver.py index f8672f8abb..606eaabcb0 100644 --- a/poky/meta/lib/oeqa/selftest/cases/archiver.py +++ b/poky/meta/lib/oeqa/selftest/cases/archiver.py @@ -129,3 +129,128 @@ class Archiver(OESelftestTestCase): self.write_config(features) bitbake('-n core-image-sato') + + def _test_archiver_mode(self, mode, target_file_name, extra_config=None): + target = "selftest-ed" + + features = 'INHERIT += "archiver"\n' + features += 'ARCHIVER_MODE[src] = "%s"\n' % (mode) + if extra_config: + features += extra_config + self.write_config(features) + + bitbake('-c clean %s' % (target)) + bitbake('-c deploy_archives %s' % (target)) + + bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS']) + glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'], '%s-*' % (target)) + glob_result = glob.glob(glob_str) + self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target)) + + archive_path = os.path.join(glob_result[0], target_file_name) + self.assertTrue(os.path.exists(archive_path), 'Missing archive file %s' % (target_file_name)) + + def test_archiver_mode_original(self): + """ + Test that the archiver works with `ARCHIVER_MODE[src] = "original"`. + """ + + self._test_archiver_mode('original', 'ed-1.14.1.tar.lz') + + def test_archiver_mode_patched(self): + """ + Test that the archiver works with `ARCHIVER_MODE[src] = "patched"`. + """ + + self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-patched.tar.gz') + + def test_archiver_mode_configured(self): + """ + Test that the archiver works with `ARCHIVER_MODE[src] = "configured"`. + """ + + self._test_archiver_mode('configured', 'selftest-ed-1.14.1-r0-configured.tar.gz') + + def test_archiver_mode_recipe(self): + """ + Test that the archiver works with `ARCHIVER_MODE[recipe] = "1"`. + """ + + self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-recipe.tar.gz', + 'ARCHIVER_MODE[recipe] = "1"\n') + + def test_archiver_mode_diff(self): + """ + Test that the archiver works with `ARCHIVER_MODE[diff] = "1"`. + Exclusions controlled by `ARCHIVER_MODE[diff-exclude]` are not yet tested. + """ + + self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-diff.gz', + 'ARCHIVER_MODE[diff] = "1"\n') + + def test_archiver_mode_dumpdata(self): + """ + Test that the archiver works with `ARCHIVER_MODE[dumpdata] = "1"`. + """ + + self._test_archiver_mode('patched', 'selftest-ed-1.14.1-r0-showdata.dump', + 'ARCHIVER_MODE[dumpdata] = "1"\n') + + def test_archiver_mode_mirror(self): + """ + Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`. + """ + + self._test_archiver_mode('mirror', 'ed-1.14.1.tar.lz', + 'BB_GENERATE_MIRROR_TARBALLS = "1"\n') + + def test_archiver_mode_mirror_excludes(self): + """ + Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"` and + correctly excludes an archive when its URL matches + `ARCHIVER_MIRROR_EXCLUDE`. + """ + + target='selftest-ed' + target_file_name = 'ed-1.14.1.tar.lz' + + features = 'INHERIT += "archiver"\n' + features += 'ARCHIVER_MODE[src] = "mirror"\n' + features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n' + features += 'ARCHIVER_MIRROR_EXCLUDE = "${GNU_MIRROR}"\n' + self.write_config(features) + + bitbake('-c clean %s' % (target)) + bitbake('-c deploy_archives %s' % (target)) + + bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS']) + glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'], '%s-*' % (target)) + glob_result = glob.glob(glob_str) + self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target)) + + archive_path = os.path.join(glob_result[0], target_file_name) + self.assertFalse(os.path.exists(archive_path), 'Failed to exclude archive file %s' % (target_file_name)) + + def test_archiver_mode_mirror_combined(self): + """ + Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"` + and `ARCHIVER_MODE[mirror] = "combined"`. Archives for multiple recipes + should all end up in the 'mirror' directory. + """ + + features = 'INHERIT += "archiver"\n' + features += 'ARCHIVER_MODE[src] = "mirror"\n' + features += 'ARCHIVER_MODE[mirror] = "combined"\n' + features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n' + features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n' + self.write_config(features) + + for target in ['selftest-ed', 'selftest-hardlink']: + bitbake('-c clean %s' % (target)) + bitbake('-c deploy_archives %s' % (target)) + + bb_vars = get_bb_vars(['DEPLOY_DIR_SRC']) + for target_file_name in ['ed-1.14.1.tar.lz', 'hello.c']: + glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name) + glob_result = glob.glob(glob_str) + self.assertTrue(glob_result, 'Missing archive file %s' % (target_file_name)) diff --git a/poky/meta/lib/oeqa/selftest/cases/devtool.py b/poky/meta/lib/oeqa/selftest/cases/devtool.py index 57e6662e4a..5886862d6c 100644 --- a/poky/meta/lib/oeqa/selftest/cases/devtool.py +++ b/poky/meta/lib/oeqa/selftest/cases/devtool.py @@ -511,6 +511,26 @@ class DevtoolAddTests(DevtoolBase): checkvars['SRC_URI'] = url.replace(testver, '${PV}') self._test_recipe_contents(recipefile, checkvars, []) + def test_devtool_add_npm(self): + pn = 'savoirfairelinux-node-server-example' + pv = '1.0.0' + url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=' + pv + # Test devtool add + self.track_for_cleanup(self.workspacedir) + self.add_command_to_tearDown('bitbake -c cleansstate %s' % pn) + self.add_command_to_tearDown('bitbake-layers remove-layer */workspace') + result = runCmd('devtool add \'%s\'' % url) + self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created') + self.assertExists(os.path.join(self.workspacedir, 'recipes', pn, '%s_%s.bb' % (pn, pv)), 'Recipe not created') + self.assertExists(os.path.join(self.workspacedir, 'recipes', pn, pn, 'npm-shrinkwrap.json'), 'Shrinkwrap not created') + # Test devtool status + result = runCmd('devtool status') + self.assertIn(pn, result.output) + # Clean up anything in the workdir/sysroot/sstate cache (have to do this *after* devtool add since the recipe only exists then) + bitbake('%s -c cleansstate' % pn) + # Test devtool build + result = runCmd('devtool build %s' % pn) + class DevtoolModifyTests(DevtoolBase): def test_devtool_modify(self): @@ -1721,7 +1741,7 @@ class DevtoolUpgradeTests(DevtoolBase): when building the kernel. """ kernel_provider = get_bb_var('PREFERRED_PROVIDER_virtual/kernel') - # Clean up the enviroment + # Clean up the environment bitbake('%s -c clean' % kernel_provider) tempdir = tempfile.mkdtemp(prefix='devtoolqa') tempdir_cfg = tempfile.mkdtemp(prefix='config_qa') diff --git a/poky/meta/lib/oeqa/selftest/cases/distrodata.py b/poky/meta/lib/oeqa/selftest/cases/distrodata.py index 68ba556485..e1cfc3b621 100644 --- a/poky/meta/lib/oeqa/selftest/cases/distrodata.py +++ b/poky/meta/lib/oeqa/selftest/cases/distrodata.py @@ -42,8 +42,9 @@ but their recipes claim otherwise by setting UPSTREAM_VERSION_UNKNOWN. Please re def test_maintainers(self): """ - Summary: Test that oe-core recipes have a maintainer + Summary: Test that oe-core recipes have a maintainer and entries in maintainers list have a recipe Expected: All oe-core recipes (except a few special static/testing ones) should have a maintainer listed in maintainers.inc file. + Expected: All entries in maintainers list should have a recipe file that matches them Product: oe-core Author: Alexander Kanavin <alex.kanavin@gmail.com> """ @@ -54,7 +55,15 @@ but their recipes claim otherwise by setting UPSTREAM_VERSION_UNKNOWN. Please re return True return False - feature = 'require conf/distro/include/maintainers.inc\n' + def is_maintainer_exception(entry): + exceptions = ["musl", "newlib", "linux-yocto", "linux-dummy", "mesa-gl", "libgfortran", + "cve-update-db-native"] + for i in exceptions: + if i in entry: + return True + return False + + feature = 'require conf/distro/include/maintainers.inc\nLICENSE_FLAGS_WHITELIST += " commercial"\nPARSE_ALL_RECIPES = "1"\n' self.write_config(feature) with bb.tinfoil.Tinfoil() as tinfoil: @@ -62,6 +71,11 @@ but their recipes claim otherwise by setting UPSTREAM_VERSION_UNKNOWN. Please re with_maintainer_list = [] no_maintainer_list = [] + + missing_recipes = [] + recipes = [] + prefix = "RECIPE_MAINTAINER_pn-" + # We could have used all_recipes() here, but this method will find # every recipe if we ever move to setting RECIPE_MAINTAINER in recipe files # instead of maintainers.inc @@ -71,6 +85,7 @@ but their recipes claim otherwise by setting UPSTREAM_VERSION_UNKNOWN. Please re continue rd = tinfoil.parse_recipe_file(fn, appends=False) pn = rd.getVar('PN') + recipes.append(pn) if is_exception(pn): continue if rd.getVar('RECIPE_MAINTAINER'): @@ -78,6 +93,15 @@ but their recipes claim otherwise by setting UPSTREAM_VERSION_UNKNOWN. Please re else: no_maintainer_list.append((pn, fn)) + maintainers = tinfoil.config_data.keys() + for key in maintainers: + if key.startswith(prefix): + recipe = tinfoil.config_data.expand(key[len(prefix):]) + if is_maintainer_exception(recipe): + continue + if recipe not in recipes: + missing_recipes.append(recipe) + if no_maintainer_list: self.fail(""" The following recipes do not have a maintainer assigned to them. Please add an entry to meta/conf/distro/include/maintainers.inc file. @@ -87,3 +111,8 @@ The following recipes do not have a maintainer assigned to them. Please add an e self.fail(""" The list of oe-core recipes with maintainers is empty. This may indicate that the test has regressed and needs fixing. """) + + if missing_recipes: + self.fail(""" +Unable to find recipes for the following entries in maintainers.inc: +""" + "\n".join(['%s' % i for i in missing_recipes])) diff --git a/poky/meta/lib/oeqa/selftest/cases/gcc.py b/poky/meta/lib/oeqa/selftest/cases/gcc.py index 5a917b9c44..3efe15228f 100644 --- a/poky/meta/lib/oeqa/selftest/cases/gcc.py +++ b/poky/meta/lib/oeqa/selftest/cases/gcc.py @@ -21,8 +21,10 @@ class GccSelfTestBase(OESelftestTestCase, OEPTestResultTestCase): def run_check(self, *suites, ssh = None): targets = set() for s in suites: - if s in ["gcc", "g++"]: - targets.add("check-gcc") + if s == "gcc": + targets.add("check-gcc-c") + elif s == "g++": + targets.add("check-gcc-c++") else: targets.add("check-target-{}".format(s)) @@ -77,7 +79,12 @@ class GccSelfTestBase(OESelftestTestCase, OEPTestResultTestCase): @OETestTag("toolchain-user") class GccCrossSelfTest(GccSelfTestBase): def test_cross_gcc(self): - self.run_check("gcc", "g++") + self.run_check("gcc") + +@OETestTag("toolchain-user") +class GxxCrossSelfTest(GccSelfTestBase): + def test_cross_gxx(self): + self.run_check("g++") @OETestTag("toolchain-user") class GccLibAtomicSelfTest(GccSelfTestBase): @@ -109,7 +116,12 @@ class GccLibItmSelfTest(GccSelfTestBase): @OETestTag("toolchain-system") class GccCrossSelfTestSystemEmulated(GccSelfTestBase): def test_cross_gcc(self): - self.run_check_emulated("gcc", "g++") + self.run_check_emulated("gcc") + +@OETestTag("toolchain-system") +class GxxCrossSelfTestSystemEmulated(GccSelfTestBase): + def test_cross_gxx(self): + self.run_check_emulated("g++") @OETestTag("toolchain-system") class GccLibAtomicSelfTestSystemEmulated(GccSelfTestBase): diff --git a/poky/meta/lib/oeqa/selftest/cases/imagefeatures.py b/poky/meta/lib/oeqa/selftest/cases/imagefeatures.py index ef2eefa860..5c519ac3d6 100644 --- a/poky/meta/lib/oeqa/selftest/cases/imagefeatures.py +++ b/poky/meta/lib/oeqa/selftest/cases/imagefeatures.py @@ -208,13 +208,13 @@ class ImageFeatures(OESelftestTestCase): """ image_name = 'core-image-minimal' - img_types = [itype for itype in get_bb_var("IMAGE_TYPES", image_name).split() \ - if itype not in ('container', 'elf', 'f2fs', 'multiubi')] + all_image_types = set(get_bb_var("IMAGE_TYPES", image_name).split()) + blacklist = set(('container', 'elf', 'f2fs', 'multiubi', 'tar.zst')) + img_types = all_image_types - blacklist config = 'IMAGE_FSTYPES += "%s"\n'\ 'MKUBIFS_ARGS ?= "-m 2048 -e 129024 -c 2047"\n'\ 'UBINIZE_ARGS ?= "-m 2048 -p 128KiB -s 512"' % ' '.join(img_types) - self.write_config(config) bitbake(image_name) diff --git a/poky/meta/lib/oeqa/selftest/cases/incompatible_lic.py b/poky/meta/lib/oeqa/selftest/cases/incompatible_lic.py index 904b5b4094..3eabd79097 100644 --- a/poky/meta/lib/oeqa/selftest/cases/incompatible_lic.py +++ b/poky/meta/lib/oeqa/selftest/cases/incompatible_lic.py @@ -4,7 +4,7 @@ from oeqa.utils.commands import bitbake class IncompatibleLicenseTests(OESelftestTestCase): def lic_test(self, pn, pn_lic, lic): - error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has an incompatible license: %s' % (pn, pn, pn_lic) + error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic) self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic)) @@ -12,30 +12,72 @@ class IncompatibleLicenseTests(OESelftestTestCase): if error_msg not in result.output: raise AssertionError(result.output) - # Verify that a package with an SPDX license (from SRC_DISTRIBUTE_LICENSES) + # Verify that a package with an SPDX license (from AVAILABLE_LICENSES) # cannot be built when INCOMPATIBLE_LICENSE contains this SPDX license def test_incompatible_spdx_license(self): self.lic_test('incompatible-license', 'GPL-3.0', 'GPL-3.0') - # Verify that a package with an SPDX license (from SRC_DISTRIBUTE_LICENSES) + # Verify that a package with an SPDX license (from AVAILABLE_LICENSES) # cannot be built when INCOMPATIBLE_LICENSE contains an alias (in # SPDXLICENSEMAP) of this SPDX license def test_incompatible_alias_spdx_license(self): self.lic_test('incompatible-license', 'GPL-3.0', 'GPLv3') + # Verify that a package with an SPDX license (from AVAILABLE_LICENSES) + # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded license + # matching this SPDX license + def test_incompatible_spdx_license_wildcard(self): + self.lic_test('incompatible-license', 'GPL-3.0', '*GPL-3.0') + + # Verify that a package with an SPDX license (from AVAILABLE_LICENSES) + # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded alias + # license matching this SPDX license + def test_incompatible_alias_spdx_license_wildcard(self): + self.lic_test('incompatible-license', 'GPL-3.0', '*GPLv3') + # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX # license def test_incompatible_spdx_license_alias(self): - self.lic_test('incompatible-license-alias', 'GPLv3', 'GPL-3.0') + self.lic_test('incompatible-license-alias', 'GPL-3.0', 'GPL-3.0') # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX # license cannot be built when INCOMPATIBLE_LICENSE contains this alias def test_incompatible_alias_spdx_license_alias(self): - self.lic_test('incompatible-license-alias', 'GPLv3', 'GPLv3') + self.lic_test('incompatible-license-alias', 'GPL-3.0', 'GPLv3') + + # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX + # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded + # license matching this SPDX license + def test_incompatible_spdx_license_alias_wildcard(self): + self.lic_test('incompatible-license-alias', 'GPL-3.0', '*GPL-3.0') + + # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX + # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded + # alias license matching the SPDX license + def test_incompatible_alias_spdx_license_alias_wildcard(self): + self.lic_test('incompatible-license-alias', 'GPL-3.0', '*GPLv3') + + # Verify that a package with multiple SPDX licenses (from + # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains + # some of them + def test_incompatible_spdx_licenses(self): + self.lic_test('incompatible-licenses', 'GPL-3.0 LGPL-3.0', 'GPL-3.0 LGPL-3.0') + + # Verify that a package with multiple SPDX licenses (from + # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a + # wildcard to some of them + def test_incompatible_spdx_licenses_wildcard(self): + self.lic_test('incompatible-licenses', 'GPL-3.0 LGPL-3.0', '*GPL-3.0') + + # Verify that a package with multiple SPDX licenses (from + # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a + # wildcard matching all licenses + def test_incompatible_all_licenses_wildcard(self): + self.lic_test('incompatible-licenses', 'GPL-2.0 GPL-3.0 LGPL-3.0', '*') # Verify that a package with a non-SPDX license (neither in - # SRC_DISTRIBUTE_LICENSES nor in SPDXLICENSEMAP) cannot be built when + # AVAILABLE_LICENSES nor in SPDXLICENSEMAP) cannot be built when # INCOMPATIBLE_LICENSE contains this license def test_incompatible_nonspdx_license(self): self.lic_test('incompatible-nonspdx-license', 'FooLicense', 'FooLicense') @@ -49,7 +91,7 @@ INCOMPATIBLE_LICENSE_pn-core-image-minimal = "GPL-3.0 LGPL-3.0" def test_bash_default(self): self.write_config(self.default_config()) - error_msg = "ERROR: core-image-minimal-1.0-r0 do_rootfs: Package bash has an incompatible license GPLv3+ and cannot be installed into the image." + error_msg = "ERROR: core-image-minimal-1.0-r0 do_rootfs: Package bash cannot be installed into the image because it has incompatible license(s): GPL-3.0+" result = bitbake('core-image-minimal', ignore_status=True) if error_msg not in result.output: @@ -57,7 +99,7 @@ INCOMPATIBLE_LICENSE_pn-core-image-minimal = "GPL-3.0 LGPL-3.0" def test_bash_and_license(self): self.write_config(self.default_config() + '\nLICENSE_append_pn-bash = " & SomeLicense"') - error_msg = "ERROR: core-image-minimal-1.0-r0 do_rootfs: Package bash has an incompatible license GPLv3+ & SomeLicense and cannot be installed into the image." + error_msg = "ERROR: core-image-minimal-1.0-r0 do_rootfs: Package bash cannot be installed into the image because it has incompatible license(s): GPL-3.0+" result = bitbake('core-image-minimal', ignore_status=True) if error_msg not in result.output: diff --git a/poky/meta/lib/oeqa/selftest/cases/meta_ide.py b/poky/meta/lib/oeqa/selftest/cases/meta_ide.py index 03901a2f32..809142559a 100644 --- a/poky/meta/lib/oeqa/selftest/cases/meta_ide.py +++ b/poky/meta/lib/oeqa/selftest/cases/meta_ide.py @@ -40,7 +40,7 @@ class MetaIDE(OESelftestTestCase): def test_meta_ide_can_build_cpio_project(self): dl_dir = self.td.get('DL_DIR', None) self.project = SDKBuildProject(self.tmpdir_metaideQA + "/cpio/", self.environment_script_path, - "https://ftp.gnu.org/gnu/cpio/cpio-2.12.tar.gz", + "https://ftp.gnu.org/gnu/cpio/cpio-2.13.tar.gz", self.tmpdir_metaideQA, self.td['DATETIME'], dl_dir=dl_dir) self.project.download_archive() self.assertEqual(self.project.run_configure(), 0, diff --git a/poky/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py b/poky/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py index 6d80827652..d4664bd0df 100644 --- a/poky/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py +++ b/poky/meta/lib/oeqa/selftest/cases/oelib/buildhistory.py @@ -45,7 +45,7 @@ class TestBlobParsing(OESelftestTestCase): def test_blob_to_dict(self): """ - Test convertion of git blobs to dictionary + Test conversion of git blobs to dictionary """ from oe.buildhistory_analysis import blob_to_dict valuesmap = { "foo" : "1", "bar" : "2" } diff --git a/poky/meta/lib/oeqa/selftest/cases/oescripts.py b/poky/meta/lib/oeqa/selftest/cases/oescripts.py index 41cbe04808..2f18d8f29c 100644 --- a/poky/meta/lib/oeqa/selftest/cases/oescripts.py +++ b/poky/meta/lib/oeqa/selftest/cases/oescripts.py @@ -4,6 +4,7 @@ import os import shutil +import importlib import unittest from oeqa.selftest.case import OESelftestTestCase from oeqa.selftest.cases.buildhistory import BuildhistoryBase @@ -33,15 +34,13 @@ class BuildhistoryDiffTests(BuildhistoryBase): if expected_endlines: self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines)) +@unittest.skipUnless(importlib.util.find_spec("cairo"), "Python cairo module is not present") class OEScriptTests(OESelftestTestCase): @classmethod def setUpClass(cls): super(OEScriptTests, cls).setUpClass() - try: - import cairo - except ImportError: - raise unittest.SkipTest('Python module cairo is not present') + import cairo bitbake("core-image-minimal -c rootfs -f") cls.tmpdir = get_bb_var('TMPDIR') cls.buildstats = cls.tmpdir + "/buildstats/" + sorted(os.listdir(cls.tmpdir + "/buildstats"))[-1] diff --git a/poky/meta/lib/oeqa/selftest/cases/package.py b/poky/meta/lib/oeqa/selftest/cases/package.py index 291627877e..3010b1af49 100644 --- a/poky/meta/lib/oeqa/selftest/cases/package.py +++ b/poky/meta/lib/oeqa/selftest/cases/package.py @@ -135,7 +135,7 @@ class PackageTests(OESelftestTestCase): return False # Check debugging symbols works correctly - elif re.match("Breakpoint 1.*hello\.c.*4", l): + elif re.match(r"Breakpoint 1.*hello\.c.*4", l): return True self.logger.error("GDB result:\n%d: %s", status, output) @@ -148,3 +148,26 @@ class PackageTests(OESelftestTestCase): '/usr/libexec/hello4']: if not gdbtest(qemu, binary): self.fail('GDB %s failed' % binary) + + def test_preserve_ownership(self): + import os, stat, oe.cachedpath + features = 'IMAGE_INSTALL_append = " selftest-chown"\n' + self.write_config(features) + bitbake("core-image-minimal") + + sysconfdir = get_bb_var('sysconfdir', 'selftest-chown') + def check_ownership(qemu, gid, uid, path): + self.logger.info("Check ownership of %s", path) + status, output = qemu.run_serial(r'/bin/stat -c "%U %G" ' + path, timeout=60) + output = output.split(" ") + if output[0] != uid or output[1] != gid : + self.logger.error("Incrrect ownership %s [%s:%s]", path, output[0], output[1]) + return False + return True + + with runqemu('core-image-minimal') as qemu: + for path in [ sysconfdir + "/selftest-chown/file", + sysconfdir + "/selftest-chown/dir", + sysconfdir + "/selftest-chown/symlink"]: + if not check_ownership(qemu, "test", "test", path): + self.fail('Test ownership %s failed' % path) diff --git a/poky/meta/lib/oeqa/selftest/cases/recipetool.py b/poky/meta/lib/oeqa/selftest/cases/recipetool.py index c1562c63b2..6bfe8f177f 100644 --- a/poky/meta/lib/oeqa/selftest/cases/recipetool.py +++ b/poky/meta/lib/oeqa/selftest/cases/recipetool.py @@ -421,6 +421,31 @@ class RecipetoolTests(RecipetoolBase): inherits = ['cmake'] self._test_recipe_contents(recipefile, checkvars, inherits) + def test_recipetool_create_npm(self): + temprecipe = os.path.join(self.tempdir, 'recipe') + os.makedirs(temprecipe) + recipefile = os.path.join(temprecipe, 'savoirfairelinux-node-server-example_1.0.0.bb') + shrinkwrap = os.path.join(temprecipe, 'savoirfairelinux-node-server-example', 'npm-shrinkwrap.json') + srcuri = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' + result = runCmd('recipetool create -o %s \'%s\'' % (temprecipe, srcuri)) + self.assertTrue(os.path.isfile(recipefile)) + self.assertTrue(os.path.isfile(shrinkwrap)) + checkvars = {} + checkvars['SUMMARY'] = 'Node Server Example' + checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme' + checkvars['LICENSE'] = set(['MIT', 'ISC', 'Unknown']) + urls = [] + urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}') + urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json') + checkvars['SRC_URI'] = set(urls) + checkvars['S'] = '${WORKDIR}/npm' + checkvars['LICENSE_${PN}'] = 'MIT' + checkvars['LICENSE_${PN}-base64'] = 'Unknown' + checkvars['LICENSE_${PN}-accepts'] = 'MIT' + checkvars['LICENSE_${PN}-inherits'] = 'ISC' + inherits = ['npm'] + self._test_recipe_contents(recipefile, checkvars, inherits) + def test_recipetool_create_github(self): # Basic test to see if github URL mangling works temprecipe = os.path.join(self.tempdir, 'recipe') diff --git a/poky/meta/lib/oeqa/selftest/cases/reproducible.py b/poky/meta/lib/oeqa/selftest/cases/reproducible.py index a9110565a9..5d3959be77 100644 --- a/poky/meta/lib/oeqa/selftest/cases/reproducible.py +++ b/poky/meta/lib/oeqa/selftest/cases/reproducible.py @@ -1,7 +1,7 @@ # # SPDX-License-Identifier: MIT # -# Copyright 2019 by Garmin Ltd. or its subsidiaries +# Copyright 2019-2020 by Garmin Ltd. or its subsidiaries from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars @@ -15,6 +15,7 @@ import tempfile import shutil import stat import os +import datetime MISSING = 'MISSING' DIFFERENT = 'DIFFERENT' @@ -78,8 +79,18 @@ def compare_file(reference, test, diffutils_sysroot): class ReproducibleTests(OESelftestTestCase): package_classes = ['deb', 'ipk'] - images = ['core-image-minimal'] + images = ['core-image-minimal', 'core-image-sato', 'core-image-full-cmdline'] save_results = False + if 'OEQA_DEBUGGING_SAVED_OUTPUT' in os.environ: + save_results = os.environ['OEQA_DEBUGGING_SAVED_OUTPUT'] + + # This variable controls if one of the test builds is allowed to pull from + # an sstate cache/mirror. The other build is always done clean as a point of + # comparison. + # If you know that your sstate archives are reproducible, enabling this + # will test that and also make the test run faster. If your sstate is not + # reproducible, disable this in your derived test class + build_from_sstate = True def setUpLocal(self): super().setUpLocal() @@ -88,12 +99,12 @@ class ReproducibleTests(OESelftestTestCase): for v in needed_vars: setattr(self, v.lower(), bb_vars[v]) - self.extrasresults = {} - self.extrasresults.setdefault('reproducible.rawlogs', {})['log'] = '' - self.extrasresults.setdefault('reproducible', {}).setdefault('files', {}) + self.extraresults = {} + self.extraresults.setdefault('reproducible.rawlogs', {})['log'] = '' + self.extraresults.setdefault('reproducible', {}).setdefault('files', {}) def append_to_log(self, msg): - self.extrasresults['reproducible.rawlogs']['log'] += msg + self.extraresults['reproducible.rawlogs']['log'] += msg def compare_packages(self, reference_dir, test_dir, diffutils_sysroot): result = PackageCompareResults() @@ -120,60 +131,69 @@ class ReproducibleTests(OESelftestTestCase): return result def write_package_list(self, package_class, name, packages): - self.extrasresults['reproducible']['files'].setdefault(package_class, {})[name] = [ + self.extraresults['reproducible']['files'].setdefault(package_class, {})[name] = [ {'reference': p.reference, 'test': p.test} for p in packages] def copy_file(self, source, dest): bb.utils.mkdirhier(os.path.dirname(dest)) shutil.copyfile(source, dest) - def test_reproducible_builds(self): + def do_test_build(self, name, use_sstate): capture_vars = ['DEPLOY_DIR_' + c.upper() for c in self.package_classes] - if self.save_results: - save_dir = tempfile.mkdtemp(prefix='oe-reproducible-') - os.chmod(save_dir, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) - self.logger.info('Non-reproducible packages will be copied to %s', save_dir) + tmpdir = os.path.join(self.topdir, name, 'tmp') + if os.path.exists(tmpdir): + bb.utils.remove(tmpdir, recurse=True) + + config = textwrap.dedent('''\ + INHERIT += "reproducible_build" + PACKAGE_CLASSES = "{package_classes}" + INHIBIT_PACKAGE_STRIP = "1" + TMPDIR = "{tmpdir}" + ''').format(package_classes=' '.join('package_%s' % c for c in self.package_classes), + tmpdir=tmpdir) + + if not use_sstate: + # This config fragment will disable using shared and the sstate + # mirror, forcing a complete build from scratch + config += textwrap.dedent('''\ + SSTATE_DIR = "${TMPDIR}/sstate" + SSTATE_MIRROR = "" + ''') + + self.write_config(config) + d = get_bb_vars(capture_vars) + bitbake(' '.join(self.images)) + return d + + def test_reproducible_builds(self): + def strip_topdir(s): + if s.startswith(self.topdir): + return s[len(self.topdir):] + return s # Build native utilities self.write_config('') - bitbake("diffutils-native -c addto_recipe_sysroot") + bitbake("diffoscope-native diffutils-native jquery-native -c addto_recipe_sysroot") diffutils_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "diffutils-native") + diffoscope_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "diffoscope-native") + jquery_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "jquery-native") - # Reproducible builds should not pull from sstate or mirrors, but - # sharing DL_DIR is fine - common_config = textwrap.dedent('''\ - INHERIT += "reproducible_build" - PACKAGE_CLASSES = "%s" - SSTATE_DIR = "${TMPDIR}/sstate" - ''') % (' '.join('package_%s' % c for c in self.package_classes)) - - # Perform a build. - reproducibleA_tmp = os.path.join(self.topdir, 'reproducibleA', 'tmp') - if os.path.exists(reproducibleA_tmp): - bb.utils.remove(reproducibleA_tmp, recurse=True) - - self.write_config((textwrap.dedent('''\ - TMPDIR = "%s" - ''') % reproducibleA_tmp) + common_config) - vars_A = get_bb_vars(capture_vars) - bitbake(' '.join(self.images)) - - # Perform another build. - reproducibleB_tmp = os.path.join(self.topdir, 'reproducibleB', 'tmp') - if os.path.exists(reproducibleB_tmp): - bb.utils.remove(reproducibleB_tmp, recurse=True) + if self.save_results: + os.makedirs(self.save_results, exist_ok=True) + datestr = datetime.datetime.now().strftime('%Y%m%d') + save_dir = tempfile.mkdtemp(prefix='oe-reproducible-%s-' % datestr, dir=self.save_results) + os.chmod(save_dir, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) + self.logger.info('Non-reproducible packages will be copied to %s', save_dir) - self.write_config((textwrap.dedent('''\ - SSTATE_MIRROR = "" - TMPDIR = "%s" - ''') % reproducibleB_tmp) + common_config) - vars_B = get_bb_vars(capture_vars) - bitbake(' '.join(self.images)) + vars_A = self.do_test_build('reproducibleA', self.build_from_sstate) + vars_B = self.do_test_build('reproducibleB', False) # NOTE: The temp directories from the reproducible build are purposely # kept after the build so it can be diffed for debugging. + fails = [] + for c in self.package_classes: with self.subTest(package_class=c): package_class = 'package_' + c @@ -193,10 +213,28 @@ class ReproducibleTests(OESelftestTestCase): if self.save_results: for d in result.different: - self.copy_file(d.reference, '/'.join([save_dir, d.reference])) - self.copy_file(d.test, '/'.join([save_dir, d.test])) + self.copy_file(d.reference, '/'.join([save_dir, 'packages', strip_topdir(d.reference)])) + self.copy_file(d.test, '/'.join([save_dir, 'packages', strip_topdir(d.test)])) if result.missing or result.different: - self.fail("The following %s packages are missing or different: %s" % - (c, ' '.join(r.test for r in (result.missing + result.different)))) + fails.append("The following %s packages are missing or different: %s" % + (c, '\n'.join(r.test for r in (result.missing + result.different)))) + + # Clean up empty directories + if self.save_results: + if not os.listdir(save_dir): + os.rmdir(save_dir) + else: + self.logger.info('Running diffoscope') + package_dir = os.path.join(save_dir, 'packages') + package_html_dir = os.path.join(package_dir, 'diff-html') + + # Copy jquery to improve the diffoscope output usability + self.copy_file(os.path.join(jquery_sysroot, 'usr/share/javascript/jquery/jquery.min.js'), os.path.join(package_html_dir, 'jquery.js')) + + runCmd(['diffoscope', '--no-default-limits', '--exclude-directory-metadata', '--html-dir', package_html_dir, 'reproducibleA', 'reproducibleB'], + native_sysroot=diffoscope_sysroot, ignore_status=True, cwd=package_dir) + + if fails: + self.fail('\n'.join(fails)) diff --git a/poky/meta/lib/oeqa/selftest/cases/runtime_test.py b/poky/meta/lib/oeqa/selftest/cases/runtime_test.py index 4b56e5beca..60cb2e01a6 100644 --- a/poky/meta/lib/oeqa/selftest/cases/runtime_test.py +++ b/poky/meta/lib/oeqa/selftest/cases/runtime_test.py @@ -10,6 +10,7 @@ import re import tempfile import shutil import oe.lsb +from oeqa.core.decorator.data import skipIfNotQemu class TestExport(OESelftestTestCase): @@ -166,9 +167,9 @@ class TestImage(OESelftestTestCase): bitbake('core-image-full-cmdline socat') bitbake('-c testimage core-image-full-cmdline') - def test_testimage_virgl_gtk(self): + def test_testimage_virgl_gtk_sdl(self): """ - Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk frontend + Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk and SDL frontends Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled 2. Check that kmscube demo runs without crashing. Product: oe-core @@ -181,20 +182,31 @@ class TestImage(OESelftestTestCase): self.skipTest('virgl isn\'t working with Debian 8') if distro and distro == 'centos-7': self.skipTest('virgl isn\'t working with Centos 7') + if distro and distro == 'opensuseleap-15.0': + self.skipTest('virgl isn\'t working with Opensuse 15.0') qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native') + sdl_packageconfig = get_bb_var('PACKAGECONFIG', 'libsdl2-native') features = 'INHERIT += "testimage"\n' if 'gtk+' not in qemu_packageconfig: features += 'PACKAGECONFIG_append_pn-qemu-system-native = " gtk+"\n' + if 'sdl' not in qemu_packageconfig: + features += 'PACKAGECONFIG_append_pn-qemu-system-native = " sdl"\n' if 'virglrenderer' not in qemu_packageconfig: features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n' if 'glx' not in qemu_packageconfig: features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n' + if 'opengl' not in sdl_packageconfig: + features += 'PACKAGECONFIG_append_pn-libsdl2-native = " opengl"\n' features += 'TEST_SUITES = "ping ssh virgl"\n' features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n' features += 'IMAGE_INSTALL_append = " kmscube"\n' - features += 'TEST_RUNQEMUPARAMS = "gtk gl"\n' - self.write_config(features) + features_gtk = features + 'TEST_RUNQEMUPARAMS = "gtk gl"\n' + self.write_config(features_gtk) + bitbake('core-image-minimal') + bitbake('-c testimage core-image-minimal') + features_sdl = features + 'TEST_RUNQEMUPARAMS = "sdl gl"\n' + self.write_config(features_sdl) bitbake('core-image-minimal') bitbake('-c testimage core-image-minimal') @@ -232,7 +244,47 @@ class TestImage(OESelftestTestCase): bitbake('-c testimage core-image-minimal') class Postinst(OESelftestTestCase): - def test_postinst_rootfs_and_boot(self): + + def init_manager_loop(self, init_manager): + import oe.path + + vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal") + rootfs = vars["IMAGE_ROOTFS"] + self.assertIsNotNone(rootfs) + sysconfdir = vars["sysconfdir"] + self.assertIsNotNone(sysconfdir) + # Need to use oe.path here as sysconfdir starts with / + hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test") + targettestdir = os.path.join(sysconfdir, "postinst-test") + + for classes in ("package_rpm", "package_deb", "package_ipk"): + with self.subTest(init_manager=init_manager, package_class=classes): + features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n' + features += 'IMAGE_FEATURES += "package-management empty-root-password"\n' + features += 'PACKAGE_CLASSES = "%s"\n' % classes + if init_manager == "systemd": + features += 'DISTRO_FEATURES_append = " systemd"\n' + features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n' + features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n' + features += 'VIRTUAL-RUNTIME_initscripts = ""\n' + self.write_config(features) + + bitbake('core-image-minimal') + + self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")), + "rootfs state file was not created") + + with runqemu('core-image-minimal') as qemu: + # Make the test echo a string and search for that as + # run_serial()'s status code is useless.' + for filename in ("rootfs", "delayed-a", "delayed-b"): + status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename)) + self.assertEqual(output, "found", "%s was not present on boot" % filename) + + + + @skipIfNotQemu('qemuall', 'Test only runs in qemu') + def test_postinst_rootfs_and_boot_sysvinit(self): """ Summary: The purpose of this test case is to verify Post-installation scripts are called when rootfs is created and also test @@ -246,46 +298,32 @@ class Postinst(OESelftestTestCase): created by postinst_boot recipe is present on image. Expected: The files are successfully created during rootfs and boot time for 3 different package managers: rpm,ipk,deb and - for initialization managers: sysvinit and systemd. + for initialization managers: sysvinit. """ + self.init_manager_loop("sysvinit") - import oe.path - vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal") - rootfs = vars["IMAGE_ROOTFS"] - self.assertIsNotNone(rootfs) - sysconfdir = vars["sysconfdir"] - self.assertIsNotNone(sysconfdir) - # Need to use oe.path here as sysconfdir starts with / - hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test") - targettestdir = os.path.join(sysconfdir, "postinst-test") + @skipIfNotQemu('qemuall', 'Test only runs in qemu') + def test_postinst_rootfs_and_boot_systemd(self): + """ + Summary: The purpose of this test case is to verify Post-installation + scripts are called when rootfs is created and also test + that script can be delayed to run at first boot. + Dependencies: NA + Steps: 1. Add proper configuration to local.conf file + 2. Build a "core-image-minimal" image + 3. Verify that file created by postinst_rootfs recipe is + present on rootfs dir. + 4. Boot the image created on qemu and verify that the file + created by postinst_boot recipe is present on image. + Expected: The files are successfully created during rootfs and boot + time for 3 different package managers: rpm,ipk,deb and + for initialization managers: systemd. - for init_manager in ("sysvinit", "systemd"): - for classes in ("package_rpm", "package_deb", "package_ipk"): - with self.subTest(init_manager=init_manager, package_class=classes): - features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n' - features += 'IMAGE_FEATURES += "package-management empty-root-password"\n' - features += 'PACKAGE_CLASSES = "%s"\n' % classes - if init_manager == "systemd": - features += 'DISTRO_FEATURES_append = " systemd"\n' - features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n' - features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n' - features += 'VIRTUAL-RUNTIME_initscripts = ""\n' - self.write_config(features) - - bitbake('core-image-minimal') - - self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")), - "rootfs state file was not created") - - with runqemu('core-image-minimal') as qemu: - # Make the test echo a string and search for that as - # run_serial()'s status code is useless.' - for filename in ("rootfs", "delayed-a", "delayed-b"): - status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename)) - self.assertEqual(output, "found", "%s was not present on boot" % filename) + """ + self.init_manager_loop("systemd") def test_failing_postinst(self): diff --git a/poky/meta/lib/oeqa/selftest/cases/signing.py b/poky/meta/lib/oeqa/selftest/cases/signing.py index 93b15ae681..202d54994b 100644 --- a/poky/meta/lib/oeqa/selftest/cases/signing.py +++ b/poky/meta/lib/oeqa/selftest/cases/signing.py @@ -157,8 +157,8 @@ class Signing(OESelftestTestCase): bitbake('-c clean %s' % test_recipe) bitbake('-c populate_lic %s' % test_recipe) - recipe_sig = glob.glob(sstatedir + '/*/*:ed:*_populate_lic.tgz.sig') - recipe_tgz = glob.glob(sstatedir + '/*/*:ed:*_populate_lic.tgz') + recipe_sig = glob.glob(sstatedir + '/*/*/*:ed:*_populate_lic.tgz.sig') + recipe_tgz = glob.glob(sstatedir + '/*/*/*:ed:*_populate_lic.tgz') self.assertEqual(len(recipe_sig), 1, 'Failed to find .sig file.') self.assertEqual(len(recipe_tgz), 1, 'Failed to find .tgz file.') diff --git a/poky/meta/lib/oeqa/selftest/cases/sstate.py b/poky/meta/lib/oeqa/selftest/cases/sstate.py index 410dec64fc..80ce9e353c 100644 --- a/poky/meta/lib/oeqa/selftest/cases/sstate.py +++ b/poky/meta/lib/oeqa/selftest/cases/sstate.py @@ -56,11 +56,11 @@ class SStateBase(OESelftestTestCase): def search_sstate(self, filename_regex, distro_specific=True, distro_nonspecific=True): result = [] for root, dirs, files in os.walk(self.sstate_path): - if distro_specific and re.search("%s/[a-z0-9]{2}$" % self.hostdistro, root): + if distro_specific and re.search(r"%s/%s/[a-z0-9]{2}/[a-z0-9]{2}$" % (self.sstate_path, self.hostdistro), root): for f in files: if re.search(filename_regex, f): result.append(f) - if distro_nonspecific and re.search("%s/[a-z0-9]{2}$" % self.sstate_path, root): + if distro_nonspecific and re.search(r"%s/[a-z0-9]{2}/[a-z0-9]{2}$" % self.sstate_path, root): for f in files: if re.search(filename_regex, f): result.append(f) diff --git a/poky/meta/lib/oeqa/selftest/cases/sstatetests.py b/poky/meta/lib/oeqa/selftest/cases/sstatetests.py index 6757a0ec68..9adb511960 100644 --- a/poky/meta/lib/oeqa/selftest/cases/sstatetests.py +++ b/poky/meta/lib/oeqa/selftest/cases/sstatetests.py @@ -446,6 +446,46 @@ BB_SIGNATURE_HANDLER = "OEBasicHash" self.assertCountEqual(files1, files2) + def test_sstate_multilib_or_not_native_samesigs(self): + """The sstate checksums of two native recipes (and their dependencies) + where the target is using multilib in one but not the other + should be the same. We use the qemux86copy machine to test + this. + """ + + self.write_config(""" +TMPDIR = \"${TOPDIR}/tmp-sstatesamehash\" +TCLIBCAPPEND = \"\" +MACHINE = \"qemux86\" +require conf/multilib.conf +MULTILIBS = "multilib:lib32" +DEFAULTTUNE_virtclass-multilib-lib32 = "x86" +BB_SIGNATURE_HANDLER = "OEBasicHash" +""") + self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash") + bitbake("binutils-native -S none") + self.write_config(""" +TMPDIR = \"${TOPDIR}/tmp-sstatesamehash2\" +TCLIBCAPPEND = \"\" +MACHINE = \"qemux86copy\" +BB_SIGNATURE_HANDLER = "OEBasicHash" +""") + self.track_for_cleanup(self.topdir + "/tmp-sstatesamehash2") + bitbake("binutils-native -S none") + + def get_files(d): + f = [] + for root, dirs, files in os.walk(d): + for name in files: + f.append(os.path.join(root, name)) + return f + files1 = get_files(self.topdir + "/tmp-sstatesamehash/stamps") + files2 = get_files(self.topdir + "/tmp-sstatesamehash2/stamps") + files2 = [x.replace("tmp-sstatesamehash2", "tmp-sstatesamehash") for x in files2] + self.maxDiff = None + self.assertCountEqual(files1, files2) + + def test_sstate_noop_samesigs(self): """ The sstate checksums of two builds with these variables changed or diff --git a/poky/meta/lib/oeqa/selftest/cases/sysroot.py b/poky/meta/lib/oeqa/selftest/cases/sysroot.py new file mode 100644 index 0000000000..6e34927c90 --- /dev/null +++ b/poky/meta/lib/oeqa/selftest/cases/sysroot.py @@ -0,0 +1,37 @@ +# +# SPDX-License-Identifier: MIT +# + +import uuid + +from oeqa.selftest.case import OESelftestTestCase +from oeqa.utils.commands import bitbake + +class SysrootTests(OESelftestTestCase): + def test_sysroot_cleanup(self): + """ + Build sysroot test which depends on virtual/sysroot-test for one machine, + switch machine, switch provider of virtual/sysroot-test and check that the + sysroot is correctly cleaned up. The files in the two providers overlap + so can cause errors if the sysroot code doesn't function correctly. + Yes, sysroot-test should be machine specific really to avoid this, however + the sysroot cleanup should also work [YOCTO #13702]. + """ + + uuid1 = uuid.uuid4() + uuid2 = uuid.uuid4() + + self.write_config(""" +PREFERRED_PROVIDER_virtual/sysroot-test = "sysroot-test-arch1" +MACHINE = "qemux86" +TESTSTRING_pn-sysroot-test-arch1 = "%s" +TESTSTRING_pn-sysroot-test-arch2 = "%s" +""" % (uuid1, uuid2)) + bitbake("sysroot-test") + self.write_config(""" +PREFERRED_PROVIDER_virtual/sysroot-test = "sysroot-test-arch2" +MACHINE = "qemux86copy" +TESTSTRING_pn-sysroot-test-arch1 = "%s" +TESTSTRING_pn-sysroot-test-arch2 = "%s" +""" % (uuid1, uuid2)) + bitbake("sysroot-test") diff --git a/poky/meta/lib/oeqa/selftest/cases/tinfoil.py b/poky/meta/lib/oeqa/selftest/cases/tinfoil.py index 42a1b6b4f4..d1aa7b9afd 100644 --- a/poky/meta/lib/oeqa/selftest/cases/tinfoil.py +++ b/poky/meta/lib/oeqa/selftest/cases/tinfoil.py @@ -65,19 +65,6 @@ class TinfoilTests(OESelftestTestCase): localdata.setVar('PN', 'hello') self.assertEqual('hello', localdata.getVar('BPN')) - def test_parse_recipe_initial_datastore(self): - with bb.tinfoil.Tinfoil() as tinfoil: - tinfoil.prepare(config_only=False, quiet=2) - testrecipe = 'mdadm' - best = tinfoil.find_best_provider(testrecipe) - if not best: - self.fail('Unable to find recipe providing %s' % testrecipe) - dcopy = bb.data.createCopy(tinfoil.config_data) - dcopy.setVar('MYVARIABLE', 'somevalue') - rd = tinfoil.parse_recipe_file(best[3], config_data=dcopy) - # Check we can get variable values - self.assertEqual('somevalue', rd.getVar('MYVARIABLE')) - def test_list_recipes(self): with bb.tinfoil.Tinfoil() as tinfoil: tinfoil.prepare(config_only=False, quiet=2) diff --git a/poky/meta/lib/oeqa/selftest/cases/wic.py b/poky/meta/lib/oeqa/selftest/cases/wic.py index 0c03b4b02d..c8765e5330 100644 --- a/poky/meta/lib/oeqa/selftest/cases/wic.py +++ b/poky/meta/lib/oeqa/selftest/cases/wic.py @@ -44,6 +44,30 @@ def only_for_arch(archs, image='core-image-minimal'): return wrapped_f return wrapper +def extract_files(debugfs_output): + """ + extract file names from the output of debugfs -R 'ls -p', + which looks like this: + + /2/040755/0/0/.//\n + /2/040755/0/0/..//\n + /11/040700/0/0/lost+found^M//\n + /12/040755/1002/1002/run//\n + /13/040755/1002/1002/sys//\n + /14/040755/1002/1002/bin//\n + /80/040755/1002/1002/var//\n + /92/040755/1002/1002/tmp//\n + """ + # NOTE the occasional ^M in file names + return [line.split('/')[5].strip() for line in \ + debugfs_output.strip().split('/\n')] + +def files_own_by_root(debugfs_output): + for line in debugfs_output.strip().split('/\n'): + if line.split('/')[3:5] != ['0', '0']: + print(debugfs_output) + return False + return True class WicTestCase(OESelftestTestCase): """Wic test class.""" @@ -66,6 +90,7 @@ class WicTestCase(OESelftestTestCase): self.skipTest('wic-tools cannot be built due its (intltool|gettext)-native dependency and NLS disable') bitbake('core-image-minimal') + bitbake('core-image-minimal-mtdutils') WicTestCase.image_is_ready = True rmtree(self.resultdir, ignore_errors=True) @@ -393,24 +418,6 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r runCmd("dd if=%s of=%s skip=%d count=%d" % (wicimg, part_file, start, length)) - def extract_files(debugfs_output): - """ - extract file names from the output of debugfs -R 'ls -p', - which looks like this: - - /2/040755/0/0/.//\n - /2/040755/0/0/..//\n - /11/040700/0/0/lost+found^M//\n - /12/040755/1002/1002/run//\n - /13/040755/1002/1002/sys//\n - /14/040755/1002/1002/bin//\n - /80/040755/1002/1002/var//\n - /92/040755/1002/1002/tmp//\n - """ - # NOTE the occasional ^M in file names - return [line.split('/')[5].strip() for line in \ - debugfs_output.strip().split('/\n')] - # Test partition 1, should contain the normal root directories, except # /usr. res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ @@ -451,6 +458,104 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r finally: os.environ['PATH'] = oldpath + def test_include_path(self): + """Test --include-path wks option.""" + + oldpath = os.environ['PATH'] + os.environ['PATH'] = get_bb_var("PATH", "wic-tools") + + try: + include_path = os.path.join(self.resultdir, 'test-include') + os.makedirs(include_path) + with open(os.path.join(include_path, 'test-file'), 'w') as t: + t.write("test\n") + wks_file = os.path.join(include_path, 'temp.wks') + with open(wks_file, 'w') as wks: + rootfs_dir = get_bb_var('IMAGE_ROOTFS', 'core-image-minimal') + wks.write(""" +part /part1 --source rootfs --ondisk mmcblk0 --fstype=ext4 +part /part2 --source rootfs --ondisk mmcblk0 --fstype=ext4 --include-path %s""" + % (include_path)) + runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir)) + + part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] + part2 = glob(os.path.join(self.resultdir, 'temp-*.direct.p2'))[0] + + # Test partition 1, should not contain 'test-file' + res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) + files = extract_files(res.output) + self.assertNotIn('test-file', files) + self.assertEqual(True, files_own_by_root(res.output)) + + # Test partition 2, should contain 'test-file' + res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part2)) + files = extract_files(res.output) + self.assertIn('test-file', files) + self.assertEqual(True, files_own_by_root(res.output)) + + finally: + os.environ['PATH'] = oldpath + + def test_include_path_embeded(self): + """Test --include-path wks option.""" + + oldpath = os.environ['PATH'] + os.environ['PATH'] = get_bb_var("PATH", "wic-tools") + + try: + include_path = os.path.join(self.resultdir, 'test-include') + os.makedirs(include_path) + with open(os.path.join(include_path, 'test-file'), 'w') as t: + t.write("test\n") + wks_file = os.path.join(include_path, 'temp.wks') + with open(wks_file, 'w') as wks: + wks.write(""" +part / --source rootfs --fstype=ext4 --include-path %s --include-path core-image-minimal-mtdutils export/""" + % (include_path)) + runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir)) + + part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] + + res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) + files = extract_files(res.output) + self.assertIn('test-file', files) + self.assertEqual(True, files_own_by_root(res.output)) + + res = runCmd("debugfs -R 'ls -p /export/etc/' %s 2>/dev/null" % (part1)) + files = extract_files(res.output) + self.assertIn('passwd', files) + self.assertEqual(True, files_own_by_root(res.output)) + + finally: + os.environ['PATH'] = oldpath + + def test_include_path_errors(self): + """Test --include-path wks option error handling.""" + wks_file = 'temp.wks' + + # Absolute argument. + with open(wks_file, 'w') as wks: + wks.write("part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils /export") + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir), ignore_status=True).status) + os.remove(wks_file) + + # Argument pointing to parent directory. + with open(wks_file, 'w') as wks: + wks.write("part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils ././..") + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir), ignore_status=True).status) + os.remove(wks_file) + + # 3 Argument pointing to parent directory. + with open(wks_file, 'w') as wks: + wks.write("part / --source rootfs --fstype=ext4 --include-path core-image-minimal-mtdutils export/ dummy") + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir), ignore_status=True).status) + os.remove(wks_file) + def test_exclude_path_errors(self): """Test --exclude-path wks option error handling.""" wks_file = 'temp.wks' @@ -469,6 +574,89 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r % (wks_file, self.resultdir), ignore_status=True).status) os.remove(wks_file) + def test_permissions(self): + """Test permissions are respected""" + + oldpath = os.environ['PATH'] + os.environ['PATH'] = get_bb_var("PATH", "wic-tools") + + t_normal = """ +part / --source rootfs --fstype=ext4 +""" + t_exclude = """ +part / --source rootfs --fstype=ext4 --exclude-path=home +""" + t_multi = """ +part / --source rootfs --ondisk sda --fstype=ext4 +part /export --source rootfs --rootfs=core-image-minimal-mtdutils --fstype=ext4 +""" + t_change = """ +part / --source rootfs --ondisk sda --fstype=ext4 --exclude-path=etc/ +part /etc --source rootfs --fstype=ext4 --change-directory=etc +""" + tests = [t_normal, t_exclude, t_multi, t_change] + + try: + for test in tests: + include_path = os.path.join(self.resultdir, 'test-include') + os.makedirs(include_path) + wks_file = os.path.join(include_path, 'temp.wks') + with open(wks_file, 'w') as wks: + wks.write(test) + runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir)) + + for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')): + res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) + self.assertEqual(True, files_own_by_root(res.output)) + + rmtree(self.resultdir, ignore_errors=True) + + finally: + os.environ['PATH'] = oldpath + + def test_change_directory(self): + """Test --change-directory wks option.""" + + oldpath = os.environ['PATH'] + os.environ['PATH'] = get_bb_var("PATH", "wic-tools") + + try: + include_path = os.path.join(self.resultdir, 'test-include') + os.makedirs(include_path) + wks_file = os.path.join(include_path, 'temp.wks') + with open(wks_file, 'w') as wks: + wks.write("part /etc --source rootfs --fstype=ext4 --change-directory=etc") + runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir)) + + part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] + + res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) + files = extract_files(res.output) + self.assertIn('passwd', files) + + finally: + os.environ['PATH'] = oldpath + + def test_change_directory_errors(self): + """Test --change-directory wks option error handling.""" + wks_file = 'temp.wks' + + # Absolute argument. + with open(wks_file, 'w') as wks: + wks.write("part / --source rootfs --fstype=ext4 --change-directory /usr") + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir), ignore_status=True).status) + os.remove(wks_file) + + # Argument pointing to parent directory. + with open(wks_file, 'w') as wks: + wks.write("part / --source rootfs --fstype=ext4 --change-directory ././..") + self.assertNotEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ + % (wks_file, self.resultdir), ignore_status=True).status) + os.remove(wks_file) + class Wic2(WicTestCase): def test_bmap_short(self): @@ -500,7 +688,8 @@ class Wic2(WicTestCase): # filter out optional variables wicvars = wicvars.difference(('DEPLOY_DIR_IMAGE', 'IMAGE_BOOT_FILES', 'INITRD', 'INITRD_LIVE', 'ISODIR','INITRAMFS_IMAGE', - 'INITRAMFS_IMAGE_BUNDLE', 'INITRAMFS_LINK_NAME')) + 'INITRAMFS_IMAGE_BUNDLE', 'INITRAMFS_LINK_NAME', + 'APPEND')) with open(path) as envfile: content = dict(line.split("=", 1) for line in envfile) # test if variables used by wic present in the .env file @@ -866,6 +1055,13 @@ class Wic2(WicTestCase): self.assertEqual(8, len(result.output.split('\n'))) self.assertTrue(os.path.basename(testdir) in result.output) + # copy the file from the partition and check if it success + dest = '%s-cp' % testfile.name + runCmd("wic cp %s:1/%s %s -n %s" % (images[0], + os.path.basename(testfile.name), dest, sysroot)) + self.assertTrue(os.path.exists(dest)) + + def test_wic_rm(self): """Test removing files and directories from the the wic image.""" runCmd("wic create mkefidisk " @@ -1005,6 +1201,16 @@ class Wic2(WicTestCase): newdirs = set(line.split()[-1] for line in result.output.split('\n') if line) self.assertEqual(newdirs.difference(dirs), set([os.path.basename(testfile.name)])) + # check if the file to copy is in the partition + result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot)) + self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line]) + + # copy file from the partition, replace the temporary file content with it and + # check for the file size to validate the copy + runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot)) + self.assertTrue(os.stat(testfile.name).st_size > 0) + + def test_wic_rm_ext(self): """Test removing files from the ext partition.""" runCmd("wic create mkefidisk " diff --git a/poky/meta/lib/oeqa/selftest/context.py b/poky/meta/lib/oeqa/selftest/context.py index c4eb5d614e..48ec5d419c 100644 --- a/poky/meta/lib/oeqa/selftest/context.py +++ b/poky/meta/lib/oeqa/selftest/context.py @@ -9,12 +9,12 @@ import time import glob import sys import importlib -import signal -from shutil import copyfile +import subprocess from random import choice import oeqa import oe +import bb.utils from oeqa.core.context import OETestContext, OETestContextExecutor from oeqa.core.exception import OEQAPreRun, OEQATestNotFound @@ -29,6 +29,54 @@ class OESelftestTestContext(OETestContext): self.custommachine = None self.config_paths = config_paths + def setup_builddir(self, suffix, selftestdir, suite): + builddir = os.environ['BUILDDIR'] + if not selftestdir: + selftestdir = get_test_layer() + newbuilddir = builddir + suffix + newselftestdir = newbuilddir + "/meta-selftest" + + if os.path.exists(newbuilddir): + self.logger.error("Build directory %s already exists, aborting" % newbuilddir) + sys.exit(1) + + bb.utils.mkdirhier(newbuilddir) + oe.path.copytree(builddir + "/conf", newbuilddir + "/conf") + oe.path.copytree(builddir + "/cache", newbuilddir + "/cache") + oe.path.copytree(selftestdir, newselftestdir) + + for e in os.environ: + if builddir + "/" in os.environ[e] or os.environ[e].endswith(builddir): + os.environ[e] = os.environ[e].replace(builddir, newbuilddir) + + subprocess.check_output("git init; git add *; git commit -a -m 'initial'", cwd=newselftestdir, shell=True) + + # Tried to used bitbake-layers add/remove but it requires recipe parsing and hence is too slow + subprocess.check_output("sed %s/conf/bblayers.conf -i -e 's#%s#%s#g'" % (newbuilddir, selftestdir, newselftestdir), cwd=newbuilddir, shell=True) + + os.chdir(newbuilddir) + + for t in suite: + if not hasattr(t, "tc"): + continue + cp = t.tc.config_paths + for p in cp: + if selftestdir in cp[p] and newselftestdir not in cp[p]: + cp[p] = cp[p].replace(selftestdir, newselftestdir) + if builddir in cp[p] and newbuilddir not in cp[p]: + cp[p] = cp[p].replace(builddir, newbuilddir) + + return (builddir, newbuilddir) + + def prepareSuite(self, suites, processes): + if processes: + from oeqa.core.utils.concurrencytest import ConcurrentTestSuite + + return ConcurrentTestSuite(suites, processes, self.setup_builddir) + else: + self.setup_builddir("-st", None, suites) + return suites + def runTests(self, processes=None, machine=None, skips=[]): if machine: self.custommachine = machine @@ -135,26 +183,10 @@ class OESelftestTestContextExecutor(OETestContextExecutor): builddir = os.environ.get("BUILDDIR") self.tc_kwargs['init']['config_paths'] = {} - self.tc_kwargs['init']['config_paths']['testlayer_path'] = \ - get_test_layer() + self.tc_kwargs['init']['config_paths']['testlayer_path'] = get_test_layer() self.tc_kwargs['init']['config_paths']['builddir'] = builddir - self.tc_kwargs['init']['config_paths']['localconf'] = \ - os.path.join(builddir, "conf/local.conf") - self.tc_kwargs['init']['config_paths']['localconf_backup'] = \ - os.path.join(builddir, "conf/local.conf.orig") - self.tc_kwargs['init']['config_paths']['localconf_class_backup'] = \ - os.path.join(builddir, "conf/local.conf.bk") - self.tc_kwargs['init']['config_paths']['bblayers'] = \ - os.path.join(builddir, "conf/bblayers.conf") - self.tc_kwargs['init']['config_paths']['bblayers_backup'] = \ - os.path.join(builddir, "conf/bblayers.conf.orig") - self.tc_kwargs['init']['config_paths']['bblayers_class_backup'] = \ - os.path.join(builddir, "conf/bblayers.conf.bk") - - copyfile(self.tc_kwargs['init']['config_paths']['localconf'], - self.tc_kwargs['init']['config_paths']['localconf_backup']) - copyfile(self.tc_kwargs['init']['config_paths']['bblayers'], - self.tc_kwargs['init']['config_paths']['bblayers_backup']) + self.tc_kwargs['init']['config_paths']['localconf'] = os.path.join(builddir, "conf/local.conf") + self.tc_kwargs['init']['config_paths']['bblayers'] = os.path.join(builddir, "conf/bblayers.conf") def tag_filter(tags): if args.exclude_tags: @@ -279,14 +311,9 @@ class OESelftestTestContextExecutor(OETestContextExecutor): return rc - def _signal_clean_handler(self, signum, frame): - sys.exit(1) - def run(self, logger, args): self._process_args(logger, args) - signal.signal(signal.SIGTERM, self._signal_clean_handler) - rc = None try: if args.machine: @@ -315,20 +342,6 @@ class OESelftestTestContextExecutor(OETestContextExecutor): rc = self._internal_run(logger, args) finally: config_paths = self.tc_kwargs['init']['config_paths'] - if os.path.exists(config_paths['localconf_backup']): - copyfile(config_paths['localconf_backup'], - config_paths['localconf']) - os.remove(config_paths['localconf_backup']) - - if os.path.exists(config_paths['bblayers_backup']): - copyfile(config_paths['bblayers_backup'], - config_paths['bblayers']) - os.remove(config_paths['bblayers_backup']) - - if os.path.exists(config_paths['localconf_class_backup']): - os.remove(config_paths['localconf_class_backup']) - if os.path.exists(config_paths['bblayers_class_backup']): - os.remove(config_paths['bblayers_class_backup']) output_link = os.path.join(os.path.dirname(args.output_log), "%s-results.log" % self.name) |