def test_build_artifacts(self): """Test wic create directdisk providing all artifacts.""" bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], 'wic-tools') bb_vars.update(get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'], 'core-image-minimal')) bbvars = {key.lower(): value for key, value in bb_vars.items()} bbvars['resultdir'] = self.resultdir runCmd("wic create directdisk " "-b %(staging_datadir)s " "-k %(deploy_dir_image)s " "-n %(recipe_sysroot_native)s " "-r %(image_rootfs)s " "-o %(resultdir)s" % bbvars) self.assertEqual(1, len(glob(self.resultdir + "directdisk-*.direct")))
def test_archiver_allows_to_filter_on_recipe_name(self): """ Summary: The archiver should offer the possibility to filter on the recipe. (#6929) Expected: 1. Included recipe (busybox) should be included 2. Excluded recipe (zlib) should be excluded Product: oe-core Author: Daniel Istrate <*****@*****.**> AutomatedBy: Daniel Istrate <*****@*****.**> """ include_recipe = 'busybox' exclude_recipe = 'zlib' features = 'INHERIT += "archiver"\n' features += 'ARCHIVER_MODE[src] = "original"\n' features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % include_recipe features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % exclude_recipe self.write_config(features) bitbake('-c clean %s %s' % (include_recipe, exclude_recipe)) bitbake("-c deploy_archives %s %s" % (include_recipe, exclude_recipe)) bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS']) src_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS']) # Check that include_recipe was included included_present = len(glob.glob(src_path + '/%s-*' % include_recipe)) self.assertTrue(included_present, 'Recipe %s was not included.' % include_recipe) # Check that exclude_recipe was excluded excluded_present = len(glob.glob(src_path + '/%s-*' % exclude_recipe)) self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % exclude_recipe)
def metadata_from_bb(): """ Returns test's metadata as OrderedDict. Data will be gathered using bitbake -e thanks to get_bb_vars. """ metadata_config_vars = ('MACHINE', 'BB_NUMBER_THREADS', 'PARALLEL_MAKE') info_dict = OrderedDict() hostname = runCmd('hostname') info_dict['hostname'] = hostname.output data_dict = get_bb_vars() # Distro information info_dict['distro'] = {'id': data_dict['DISTRO'], 'version_id': data_dict['DISTRO_VERSION'], 'pretty_name': '%s %s' % (data_dict['DISTRO'], data_dict['DISTRO_VERSION'])} # Host distro information os_release = get_os_release() if os_release: info_dict['host_distro'] = OrderedDict() for key in ('ID', 'VERSION_ID', 'PRETTY_NAME'): if key in os_release: info_dict['host_distro'][key.lower()] = os_release[key] info_dict['layers'] = get_layers(data_dict['BBLAYERS']) info_dict['bitbake'] = git_rev_info(os.path.dirname(bb.__file__)) info_dict['config'] = OrderedDict() for var in sorted(metadata_config_vars): info_dict['config'][var] = data_dict[var] return info_dict
def test_signing_packages(self): """ Summary: Test that packages can be signed in the package feed Expected: Package should be signed with the correct key Expected: Images can be created from signed packages Product: oe-core Author: Daniel Istrate <*****@*****.**> Author: Alexander Kanavin <*****@*****.**> AutomatedBy: Daniel Istrate <*****@*****.**> """ import oe.packagedata package_classes = get_bb_var('PACKAGE_CLASSES') if 'package_rpm' not in package_classes: self.skipTest('This test requires RPM Packaging.') test_recipe = 'ed' feature = 'INHERIT += "sign_rpm"\n' feature += 'RPM_GPG_PASSPHRASE = "test123"\n' feature += 'RPM_GPG_NAME = "testuser"\n' feature += 'GPG_PATH = "%s"\n' % self.gpg_dir self.write_config(feature) bitbake('-c clean %s' % test_recipe) bitbake('-f -c package_write_rpm %s' % test_recipe) self.add_command_to_tearDown('bitbake -c clean %s' % test_recipe) needed_vars = ['PKGDATA_DIR', 'DEPLOY_DIR_RPM', 'PACKAGE_ARCH', 'STAGING_BINDIR_NATIVE'] bb_vars = get_bb_vars(needed_vars, test_recipe) pkgdatadir = bb_vars['PKGDATA_DIR'] pkgdata = oe.packagedata.read_pkgdatafile(pkgdatadir + "/runtime/ed") if 'PKGE' in pkgdata: pf = pkgdata['PN'] + "-" + pkgdata['PKGE'] + pkgdata['PKGV'] + '-' + pkgdata['PKGR'] else: pf = pkgdata['PN'] + "-" + pkgdata['PKGV'] + '-' + pkgdata['PKGR'] deploy_dir_rpm = bb_vars['DEPLOY_DIR_RPM'] package_arch = bb_vars['PACKAGE_ARCH'].replace('-', '_') staging_bindir_native = bb_vars['STAGING_BINDIR_NATIVE'] pkg_deploy = os.path.join(deploy_dir_rpm, package_arch, '.'.join((pf, package_arch, 'rpm'))) # Use a temporary rpmdb rpmdb = tempfile.mkdtemp(prefix='oeqa-rpmdb') runCmd('%s/rpmkeys --define "_dbpath %s" --import %s' % (staging_bindir_native, rpmdb, self.pub_key_path)) ret = runCmd('%s/rpmkeys --define "_dbpath %s" --checksig %s' % (staging_bindir_native, rpmdb, pkg_deploy)) # tmp/deploy/rpm/i586/ed-1.9-r0.i586.rpm: rsa sha1 md5 OK self.assertIn('rsa sha1 (md5) pgp md5 OK', ret.output, 'Package signed incorrectly.') shutil.rmtree(rpmdb) #Check that an image can be built from signed packages self.add_command_to_tearDown('bitbake -c clean core-image-minimal') bitbake('-c clean core-image-minimal') bitbake('core-image-minimal')
def test_archiver_filters_by_type(self): """ Summary: The archiver is documented to filter on the recipe type. Expected: 1. included recipe type (target) should be included 2. other types should be excluded Product: oe-core Author: André Draszik <*****@*****.**> """ target_recipe = 'initscripts' native_recipe = 'zlib-native' features = 'INHERIT += "archiver"\n' features += 'ARCHIVER_MODE[src] = "original"\n' features += 'COPYLEFT_RECIPE_TYPES = "target"\n' self.write_config(features) bitbake('-c clean %s %s' % (target_recipe, native_recipe)) bitbake("%s -c deploy_archives %s" % (target_recipe, native_recipe)) bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS']) src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS']) src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS']) # Check that target_recipe was included included_present = len(glob.glob(src_path_target + '/%s-*' % target_recipe)) self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipe) # Check that native_recipe was excluded excluded_present = len(glob.glob(src_path_native + '/%s-*' % native_recipe)) self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipe)
def test_image_manifest(self): bitbake('core-image-minimal') bb_vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "IMAGE_LINK_NAME"], "core-image-minimal") deploydir = bb_vars["DEPLOY_DIR_IMAGE"] imagename = bb_vars["IMAGE_LINK_NAME"] manifest = os.path.join(deploydir, imagename + ".manifest") self.assertTrue(os.path.islink(manifest), msg="No manifest file created for image. It should have been created in %s" % manifest)
def test_copy_tree_xattr(self): """ Summary: oe.path.copytree() should preserve xattr on copied files Expected: testxattr file in destination should have user.oetest extended attribute Product: OE-Core Author: Joshua Lock <*****@*****.**> """ testloc = oe.path.join(self.tmp_dir, 'liboetests') src = oe.path.join(testloc, 'src') dst = oe.path.join(testloc, 'dst') bb.utils.mkdirhier(testloc) bb.utils.mkdirhier(src) testfilename = 'testxattr' # ensure we have setfattr available bitbake("attr-native") bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'attr-native') destdir = bb_vars['SYSROOT_DESTDIR'] bindir = bb_vars['bindir'] bindir = destdir + bindir # create a file with xattr and copy it open(oe.path.join(src, testfilename), 'w+b').close() runCmd('%s/setfattr -n user.oetest -v "testing liboe" %s' % (bindir, oe.path.join(src, testfilename))) oe.path.copytree(src, dst) # ensure file in dest has user.oetest xattr result = runCmd('%s/getfattr -n user.oetest %s' % (bindir, oe.path.join(dst, testfilename))) self.assertIn('user.oetest="testing liboe"', result.output, 'Extended attribute not sert in dst') oe.path.remove(testloc)
def get_eSDK_toolchain(image): pn_task = '%s -c populate_sdk_ext' % image bb_vars = get_bb_vars(['SDK_DEPLOY', 'TOOLCHAINEXT_OUTPUTNAME'], pn_task) sdk_deploy = bb_vars['SDK_DEPLOY'] toolchain_name = bb_vars['TOOLCHAINEXT_OUTPUTNAME'] return os.path.join(sdk_deploy, toolchain_name + '.sh')
def test_recipetool_appendsrcfile_srcdir_basic(self): testrecipe = 'bash' bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) srcdir = bb_vars['S'] workdir = bb_vars['WORKDIR'] subdir = os.path.relpath(srcdir, workdir) self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
def test_failing_postinst(self): """ Summary: The purpose of this test case is to verify that post-installation scripts that contain errors are properly reported. Expected: The scriptlet failure is properly reported. The file that is created after the error in the scriptlet is not present. Product: oe-core Author: Alexander Kanavin <*****@*****.**> """ 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") for classes in ("package_rpm", "package_deb", "package_ipk"): with self.subTest(package_class=classes): features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n' features += 'PACKAGE_CLASSES = "%s"\n' % classes self.write_config(features) bb_result = bitbake('core-image-minimal') self.assertGreaterEqual(bb_result.output.find("Intentionally failing postinstall scriptlets of ['postinst-rootfs-failing'] to defer them to first boot is deprecated."), 0, "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output)) self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")), "rootfs-before-failure file was not created") self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")), "rootfs-after-failure file was created")
def setUpClass(cls): super(RecipetoolTests, cls).setUpClass() # Ensure we have the right data in shlibs/pkgdata cls.logger.info('Running bitbake to generate pkgdata') bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile') bb_vars = get_bb_vars(['COREBASE', 'BBPATH']) cls.corebase = bb_vars['COREBASE'] cls.bbpath = bb_vars['BBPATH']
def test_rootfs_artifacts(self): """Test usage of rootfs plugin with rootfs paths""" bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], 'wic-tools') bb_vars.update(get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'], 'core-image-minimal')) bbvars = {key.lower(): value for key, value in bb_vars.items()} bbvars['wks'] = "directdisk-multi-rootfs" bbvars['resultdir'] = self.resultdir runCmd("wic create %(wks)s " "--bootimg-dir=%(staging_datadir)s " "--kernel-dir=%(deploy_dir_image)s " "--native-sysroot=%(recipe_sysroot_native)s " "--rootfs-dir rootfs1=%(image_rootfs)s " "--rootfs-dir rootfs2=%(image_rootfs)s " "--outdir %(resultdir)s" % bbvars) self.assertEqual(1, len(glob(self.resultdir + "%(wks)s-*.direct" % bbvars)))
def setUpClass(cls): super(MetaIDE, cls).setUpClass() bitbake('meta-ide-support') bb_vars = get_bb_vars(['MULTIMACH_TARGET_SYS', 'TMPDIR', 'COREBASE']) cls.environment_script = 'environment-setup-%s' % bb_vars['MULTIMACH_TARGET_SYS'] cls.tmpdir = bb_vars['TMPDIR'] cls.environment_script_path = '%s/%s' % (cls.tmpdir, cls.environment_script) cls.corebasedir = bb_vars['COREBASE'] cls.tmpdir_metaideQA = tempfile.mkdtemp(prefix='metaide')
def _get_image_env_path(self, image): """Generate and obtain the path to <image>.env""" if image not in self.wicenv_cache: self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % image).status) bb_vars = get_bb_vars(['STAGING_DIR', 'MACHINE'], image) stdir = bb_vars['STAGING_DIR'] machine = bb_vars['MACHINE'] self.wicenv_cache[image] = os.path.join(stdir, machine, 'imgdata') return self.wicenv_cache[image]
def setUpClass(cls): # Build the tools we need and populate a sysroot bitbake("dpkg-native opkg-native rpm-native python3-native") bitbake("build-sysroots -c build_native_sysroot") # Get the paths so we can point into the sysroot correctly vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"]) cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"]) cls.bindir = oe.path.join(cls.staging, vars["bindir_native"]) cls.libdir = oe.path.join(cls.staging, vars["libdir_native"])
def _get_image_env_path(self, image): """Generate and obtain the path to <image>.env""" if image not in WicTestCase.wicenv_cache: self.assertEqual(0, bitbake('%s -c do_rootfs_wicenv' % image).status) bb_vars = get_bb_vars(['STAGING_DIR', 'MACHINE'], image) stdir = bb_vars['STAGING_DIR'] machine = bb_vars['MACHINE'] WicTestCase.wicenv_cache[image] = os.path.join( stdir, machine, 'imgdata') return WicTestCase.wicenv_cache[image]
def setUpLocal(self): super().setUpLocal() needed_vars = ['TOPDIR', 'TARGET_PREFIX', 'BB_NUMBER_THREADS'] bb_vars = get_bb_vars(needed_vars) 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', {})
def test_testexport_sdk(self): """ Summary: Check sdk functionality for testexport. Expected: 1. testexport directory must be created. 2. SDK tarball must exists. 3. Uncompressing of tarball must succeed. 4. Check if the SDK directory is added to PATH. 5. Run tar from the SDK directory. Product: oe-core Author: Mariano Lopez <*****@*****.**> """ features = 'INHERIT += "testexport"\n' # These aren't the actual IP addresses but testexport class needs something defined features += 'TEST_SERVER_IP = "192.168.7.1"\n' features += 'TEST_TARGET_IP = "192.168.7.1"\n' features += 'TEST_SUITES = "ping"\n' features += 'TEST_EXPORT_SDK_ENABLED = "1"\n' features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n' self.write_config(features) # Build tesexport for core-image-minimal bitbake('core-image-minimal') bitbake('-c testexport core-image-minimal') needed_vars = [ 'TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME' ] bb_vars = get_bb_vars(needed_vars, 'core-image-minimal') testexport_dir = bb_vars['TEST_EXPORT_DIR'] sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR'] sdk_name = bb_vars['TEST_EXPORT_SDK_NAME'] # Check for SDK tarball_name = "%s.sh" % sdk_name tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name) msg = "Couldn't find SDK tarball: %s" % tarball_path self.assertEqual(os.path.isfile(tarball_path), True, msg) with tempfile.TemporaryDirectory() as tmpdirname: # Extract SDK and run tar from SDK result = runCmd("%s -y -d %s" % (tarball_path, tmpdirname)) self.assertEqual(0, result.status, "Couldn't extract SDK") env_script = result.output.split()[-1] result = runCmd(". %s; which tar" % env_script, shell=True) self.assertEqual(0, result.status, "Couldn't setup SDK environment") is_sdk_tar = True if tmpdirname in result.output else False self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment") tar_sdk = result.output result = runCmd("%s --version" % tar_sdk) self.assertEqual(0, result.status, "Couldn't run tar from SDK")
def test_rootfs_artifacts(self): """Test usage of rootfs plugin with rootfs paths""" bb_vars = get_bb_vars(['STAGING_DATADIR', 'RECIPE_SYSROOT_NATIVE'], 'wic-tools') bb_vars.update( get_bb_vars(['DEPLOY_DIR_IMAGE', 'IMAGE_ROOTFS'], 'core-image-minimal')) bbvars = {key.lower(): value for key, value in bb_vars.items()} bbvars['wks'] = "directdisk-multi-rootfs" bbvars['resultdir'] = self.resultdir status = runCmd("wic create %(wks)s " "--bootimg-dir=%(staging_datadir)s " "--kernel-dir=%(deploy_dir_image)s " "--native-sysroot=%(recipe_sysroot_native)s " "--rootfs-dir rootfs1=%(image_rootfs)s " "--rootfs-dir rootfs2=%(image_rootfs)s " "--outdir %(resultdir)s" % bbvars).status self.assertEqual(0, status) self.assertEqual( 1, len(glob(self.resultdir + "%(wks)s-*.direct" % bbvars)))
def test_ccache_tool(self): bitbake("ccache-native") bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native') p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache" self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p) self.write_config('INHERIT += "ccache"') self.add_command_to_tearDown('bitbake -c clean m4') bitbake("m4 -f -c compile") log_compile = os.path.join(get_bb_var("WORKDIR","m4"), "temp/log.do_compile") res = runCmd("grep ccache %s" % log_compile, ignore_status=True) self.assertEqual(0, res.status, msg="No match for ccache in m4 log.do_compile. For further details: %s" % log_compile)
def test_archiver_filters_by_type_and_name(self): """ Summary: Test that the archiver archives by recipe type, taking the recipe name into account. Expected: 1. included recipe type (target) should be included 2. other types should be excluded 3. recipe by name should be included / excluded, overriding previous decision by type Product: oe-core Author: André Draszik <*****@*****.**> """ target_recipes = ['initscripts', 'selftest-ed'] native_recipes = ['update-rc.d-native', 'selftest-ed-native'] features = 'INHERIT += "archiver"\n' features += 'ARCHIVER_MODE[src] = "original"\n' features += 'COPYLEFT_RECIPE_TYPES = "target"\n' features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % native_recipes[1] features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % target_recipes[1] self.write_config(features) bitbake('-c clean %s %s' % (' '.join(target_recipes), ' '.join(native_recipes))) bitbake('-c deploy_archives %s %s' % (' '.join(target_recipes), ' '.join(native_recipes))) bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS']) src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS']) src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS']) # Check that target_recipe[0] and native_recipes[1] were included included_present = len( glob.glob(src_path_target + '/%s-*/*' % target_recipes[0])) self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipes[0]) included_present = len( glob.glob(src_path_native + '/%s-*/*' % native_recipes[1])) self.assertTrue(included_present, 'Recipe %s was not included.' % native_recipes[1]) # Check that native_recipes[0] and target_recipes[1] were excluded excluded_present = len( glob.glob(src_path_native + '/%s-*/*' % native_recipes[0])) self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipes[0]) excluded_present = len( glob.glob(src_path_target + '/%s-*/*' % target_recipes[1])) self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % target_recipes[1])
def test_recipetool_appendsrcfile_replace_file_srcdir(self): testrecipe = 'bash' filepath = 'Makefile.in' bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) srcdir = bb_vars['S'] workdir = bb_vars['WORKDIR'] subdir = os.path.relpath(srcdir, workdir) self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir) bitbake('%s:do_unpack' % testrecipe) self.assertEqual(open(self.testfile, 'r').read(), open(os.path.join(srcdir, filepath), 'r').read())
def test_provisioning(self): print('Checking machine name (hostname) of device:') stdout, stderr, retcode = self.qemu_command('hostname') self.assertEqual(retcode, 0, "Unable to check hostname. " + "Is an ssh daemon (such as dropbear or openssh) installed on the device?") machine = get_bb_var('MACHINE', 'core-image-minimal') self.assertEqual(stderr, b'', 'Error: ' + stderr.decode()) # Strip off line ending. value = stdout.decode()[:-1] self.assertEqual(value, machine, 'MACHINE does not match hostname: ' + machine + ', ' + value) print(value) print('Checking output of aktualizr-info:') ran_ok = False for delay in [1, 2, 5, 10, 15]: stdout, stderr, retcode = self.qemu_command('aktualizr-info') if retcode == 0 and stderr == b'': ran_ok = True break sleep(delay) self.assertTrue(ran_ok, 'aktualizr-info failed: ' + stderr.decode() + stdout.decode()) # Verify that device has NOT yet provisioned. self.assertIn(b'Couldn\'t load device ID', stdout, 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) self.assertIn(b'Couldn\'t load ECU serials', stdout, 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) self.assertIn(b'Provisioned on server: no', stdout, 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) self.assertIn(b'Fetched metadata: no', stdout, 'Device already provisioned!? ' + stderr.decode() + stdout.decode()) # Run cert_provider. bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS'], 'aktualizr-native') creds = bb_vars['SOTA_PACKED_CREDENTIALS'] bb_vars_prov = get_bb_vars(['STAGING_DIR_HOST', 'libdir'], 'aktualizr-implicit-prov') config = bb_vars_prov['STAGING_DIR_HOST'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov.toml' akt_native_run(self, 'aktualizr_cert_provider -c {creds} -t root@localhost -p {port} -s -g {config}' .format(creds=creds, port=self.qemu.ssh_port, config=config)) verifyProvisioned(self, machine)
def config_buildhistory(self, tmp_bh_location=False): bb_vars = get_bb_vars(['USER_CLASSES', 'INHERIT']) if (not 'buildhistory' in bb_vars['USER_CLASSES']) and (not 'buildhistory' in bb_vars['INHERIT']): add_buildhistory_config = 'INHERIT += "buildhistory"\nBUILDHISTORY_COMMIT = "1"' self.append_config(add_buildhistory_config) if tmp_bh_location: # Using a temporary buildhistory location for testing tmp_bh_dir = os.path.join(self.builddir, "tmp_buildhistory_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')) buildhistory_dir_config = "BUILDHISTORY_DIR = \"%s\"" % tmp_bh_dir self.append_config(buildhistory_dir_config) self.track_for_cleanup(tmp_bh_dir)
def __init__(self, *args, **kwargs): super(BuildPerfTestCase, self).__init__(*args, **kwargs) self.name = self._testMethodName self.base_dir = None self.start_time = None self.elapsed_time = None self.measurements = [] self.bb_vars = get_bb_vars() # TODO: remove 'times' and 'sizes' arrays when globalres support is # removed self.times = [] self.sizes = []
def test_image_manifest(self): bitbake('core-image-minimal') bb_vars = get_bb_vars(["DEPLOY_DIR_IMAGE", "IMAGE_LINK_NAME"], "core-image-minimal") deploydir = bb_vars["DEPLOY_DIR_IMAGE"] imagename = bb_vars["IMAGE_LINK_NAME"] manifest = os.path.join(deploydir, imagename + ".manifest") self.assertTrue( os.path.islink(manifest), msg= "No manifest file created for image. It should have been created in %s" % manifest)
def setUpClass(cls): super().setUpClass() # Build the tools we need and populate a sysroot bitbake("dpkg-native opkg-native rpm-native python3-native") bitbake("build-sysroots -c build_native_sysroot") # Get the paths so we can point into the sysroot correctly vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"]) cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"]) cls.bindir = oe.path.join(cls.staging, vars["bindir_native"]) cls.libdir = oe.path.join(cls.staging, vars["libdir_native"])
def test_postinst_rootfs_and_boot(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: sysvinit and systemd. """ 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 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)
def _process_args(self, logger, args): args.test_start_time = time.strftime("%Y%m%d%H%M%S") args.test_data_file = None args.CASES_PATHS = None bbvars = get_bb_vars() logdir = os.environ.get("BUILDDIR") if 'LOG_DIR' in bbvars: logdir = bbvars['LOG_DIR'] bb.utils.mkdirhier(logdir) args.output_log = logdir + '/%s-results-%s.log' % ( self.name, args.test_start_time) super(OESelftestTestContextExecutor, self)._process_args(logger, args) if args.list_modules: args.list_tests = 'module' elif args.list_classes: args.list_tests = 'class' elif args.list_tests: args.list_tests = 'name' self.tc_kwargs['init']['td'] = bbvars self.tc_kwargs['init']['machines'] = self._get_available_machines() 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']['builddir'] = builddir 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") self.tc_kwargs['init']['newbuilddir'] = args.newbuilddir self.tc_kwargs['init']['keep_builddir'] = args.keep_builddir def tag_filter(tags): if args.exclude_tags: if any(tag in args.exclude_tags for tag in tags): return True if args.select_tags: if not tags or not any(tag in args.select_tags for tag in tags): return True return False if args.select_tags or args.exclude_tags: self.tc_kwargs['load']['tags_filter'] = tag_filter self.tc_kwargs['run']['skips'] = args.skips self.tc_kwargs['run']['processes'] = args.processes
def test_expand_mbr_image(self): """Test wic write --expand command for mbr image""" # build an image config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n' self.append_config(config) self.assertEqual(0, bitbake('core-image-minimal').status) # get path to the image bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] machine = bb_vars['MACHINE'] image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine) self.remove_config(config) try: # expand image to 1G new_image_path = None with NamedTemporaryFile(mode='wb', suffix='.wic.exp', dir=deploy_dir, delete=False) as sparse: sparse.truncate(1024 ** 3) new_image_path = sparse.name sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path) self.assertEqual(0, runCmd(cmd).status) # check if partitions are expanded orig = runCmd("wic ls %s -n %s" % (image_path, sysroot)) exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot)) orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]] exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]] self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized self.assertTrue(orig_sizes[1] < exp_sizes[1]) # Check if all free space is partitioned result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output) os.rename(image_path, image_path + '.bak') os.rename(new_image_path, image_path) # Check if it boots in qemu with runqemu('core-image-minimal', ssh=False) as qemu: cmd = "ls /etc/" status, output = qemu.run_serial('true') self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) finally: if os.path.exists(new_image_path): os.unlink(new_image_path) if os.path.exists(image_path + '.bak'): os.rename(image_path + '.bak', image_path)
def test_expand_mbr_image(self): """Test wic write --expand command for mbr image""" # build an image config = 'IMAGE_FSTYPES = "wic"\nWKS_FILE = "directdisk.wks"\n' self.append_config(config) self.assertEqual(0, bitbake('core-image-minimal').status) # get path to the image bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] machine = bb_vars['MACHINE'] image_path = os.path.join(deploy_dir, 'core-image-minimal-%s.wic' % machine) self.remove_config(config) try: # expand image to 1G new_image_path = None with NamedTemporaryFile(mode='wb', suffix='.wic.exp', dir=deploy_dir, delete=False) as sparse: sparse.truncate(1024 ** 3) new_image_path = sparse.name sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') cmd = "wic write -n %s --expand 1:0 %s %s" % (sysroot, image_path, new_image_path) runCmd(cmd) # check if partitions are expanded orig = runCmd("wic ls %s -n %s" % (image_path, sysroot)) exp = runCmd("wic ls %s -n %s" % (new_image_path, sysroot)) orig_sizes = [int(line.split()[3]) for line in orig.output.split('\n')[1:]] exp_sizes = [int(line.split()[3]) for line in exp.output.split('\n')[1:]] self.assertEqual(orig_sizes[0], exp_sizes[0]) # first partition is not resized self.assertTrue(orig_sizes[1] < exp_sizes[1]) # Check if all free space is partitioned result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output) os.rename(image_path, image_path + '.bak') os.rename(new_image_path, image_path) # Check if it boots in qemu with runqemu('core-image-minimal', ssh=False) as qemu: cmd = "ls /etc/" status, output = qemu.run_serial('true') self.assertEqual(1, status, 'Failed to run command "%s": %s' % (cmd, output)) finally: if os.path.exists(new_image_path): os.unlink(new_image_path) if os.path.exists(image_path + '.bak'): os.rename(image_path + '.bak', image_path)
def test_ccache_tool(self): bitbake("ccache-native") bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native') p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache" self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p) self.write_config('INHERIT += "ccache"') self.add_command_to_tearDown('bitbake -c clean m4-native') bitbake("m4-native -c clean") bitbake("m4-native -f -c compile") log_compile = os.path.join(get_bb_var("WORKDIR","m4-native"), "temp/log.do_compile") with open(log_compile, "r") as f: loglines = "".join(f.readlines()) self.assertIn("ccache", loglines, msg="No match for ccache in m4-native log.do_compile. For further details: %s" % log_compile)
def test_ccache_tool(self): bitbake("ccache-native") bb_vars = get_bb_vars(['SYSROOT_DESTDIR', 'bindir'], 'ccache-native') p = bb_vars['SYSROOT_DESTDIR'] + bb_vars['bindir'] + "/" + "ccache" self.assertTrue(os.path.isfile(p), msg = "No ccache found (%s)" % p) self.write_config('INHERIT += "ccache"') self.add_command_to_tearDown('bitbake -c clean m4') bitbake("m4 -c clean") bitbake("m4 -f -c compile") log_compile = os.path.join(get_bb_var("WORKDIR","m4"), "temp/log.do_compile") with open(log_compile, "r") as f: loglines = "".join(f.readlines()) self.assertIn("ccache", loglines, msg="No match for ccache in m4 log.do_compile. For further details: %s" % log_compile)
def setUpLocal(self): self.temp_sstate_location = None needed_vars = ['SSTATE_DIR', 'NATIVELSBSTRING', 'TCLIBC', 'TUNE_ARCH', 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS'] bb_vars = get_bb_vars(needed_vars) self.sstate_path = bb_vars['SSTATE_DIR'] self.hostdistro = bb_vars['NATIVELSBSTRING'] self.tclibc = bb_vars['TCLIBC'] self.tune_arch = bb_vars['TUNE_ARCH'] self.topdir = bb_vars['TOPDIR'] self.target_vendor = bb_vars['TARGET_VENDOR'] self.target_os = bb_vars['TARGET_OS'] self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro)
def setUpClass(cls): super(MetaIDE, cls).setUpClass() bitbake('meta-ide-support') bitbake('build-sysroots') bb_vars = get_bb_vars( ['MULTIMACH_TARGET_SYS', 'DEPLOY_DIR_IMAGE', 'COREBASE']) cls.environment_script = 'environment-setup-%s' % bb_vars[ 'MULTIMACH_TARGET_SYS'] cls.deploydir = bb_vars['DEPLOY_DIR_IMAGE'] cls.environment_script_path = '%s/%s' % (cls.deploydir, cls.environment_script) cls.corebasedir = bb_vars['COREBASE'] cls.tmpdir_metaideQA = tempfile.mkdtemp(prefix='metaide')
def test_recipe_report_json_ignored(self): config = """ INHERIT += "cve-check" CVE_CHECK_FORMAT_JSON = "1" CVE_CHECK_REPORT_PATCHED = "1" """ self.write_config(config) vars = get_bb_vars( ["CVE_CHECK_SUMMARY_DIR", "CVE_CHECK_SUMMARY_FILE_NAME_JSON"]) summary_json = os.path.join(vars["CVE_CHECK_SUMMARY_DIR"], vars["CVE_CHECK_SUMMARY_FILE_NAME_JSON"]) recipe_json = os.path.join(vars["CVE_CHECK_SUMMARY_DIR"], "logrotate_cve.json") try: os.remove(summary_json) os.remove(recipe_json) except FileNotFoundError: pass bitbake("logrotate -c cve_check") def check_m4_json(filename): with open(filename) as f: report = json.load(f) self.assertEqual(report["version"], "1") self.assertEqual(len(report["package"]), 1) package = report["package"][0] self.assertEqual(package["name"], "logrotate") found_cves = { issue["id"]: issue["status"] for issue in package["issue"] } # m4 CVE should not be in logrotate self.assertNotIn("CVE-2008-1687", found_cves) # logrotate has both Patched and Ignored CVEs self.assertIn("CVE-2011-1098", found_cves) self.assertEqual(found_cves["CVE-2011-1098"], "Patched") self.assertIn("CVE-2011-1548", found_cves) self.assertEqual(found_cves["CVE-2011-1548"], "Ignored") self.assertIn("CVE-2011-1549", found_cves) self.assertEqual(found_cves["CVE-2011-1549"], "Ignored") self.assertIn("CVE-2011-1550", found_cves) self.assertEqual(found_cves["CVE-2011-1550"], "Ignored") self.assertExists(summary_json) check_m4_json(summary_json) self.assertExists(recipe_json) check_m4_json(recipe_json)
def setUpLocal(self): super(SStateBase, self).setUpLocal() self.temp_sstate_location = None needed_vars = ['SSTATE_DIR', 'NATIVELSBSTRING', 'TCLIBC', 'TUNE_ARCH', 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS'] bb_vars = get_bb_vars(needed_vars) self.sstate_path = bb_vars['SSTATE_DIR'] self.hostdistro = bb_vars['NATIVELSBSTRING'] self.tclibc = bb_vars['TCLIBC'] self.tune_arch = bb_vars['TUNE_ARCH'] self.topdir = bb_vars['TOPDIR'] self.target_vendor = bb_vars['TARGET_VENDOR'] self.target_os = bb_vars['TARGET_OS'] self.distro_specific_sstate = os.path.join(self.sstate_path, self.hostdistro)
def _process_args(self, logger, args): args.test_start_time = time.strftime("%Y%m%d%H%M%S") args.test_data_file = None args.CASES_PATHS = None bbvars = get_bb_vars() logdir = os.environ.get("BUILDDIR") if 'LOG_DIR' in bbvars: logdir = bbvars['LOG_DIR'] bb.utils.mkdirhier(logdir) args.output_log = logdir + '/%s-results-%s.log' % ( self.name, args.test_start_time) super(OESelftestTestContextExecutor, self)._process_args(logger, args) if args.list_modules: args.list_tests = 'module' elif args.list_classes: args.list_tests = 'class' elif args.list_tests: args.list_tests = 'name' self.tc_kwargs['init']['td'] = bbvars self.tc_kwargs['init']['machines'] = self._get_available_machines() 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']['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['run']['skips'] = args.skips self.tc_kwargs['run']['processes'] = args.processes
def test_testexport_sdk(self): """ Summary: Check sdk functionality for testexport. Expected: 1. testexport directory must be created. 2. SDK tarball must exists. 3. Uncompressing of tarball must succeed. 4. Check if the SDK directory is added to PATH. 5. Run tar from the SDK directory. Product: oe-core Author: Mariano Lopez <*****@*****.**> """ features = 'INHERIT += "testexport"\n' # These aren't the actual IP addresses but testexport class needs something defined features += 'TEST_SERVER_IP = "192.168.7.1"\n' features += 'TEST_TARGET_IP = "192.168.7.1"\n' features += 'TEST_SUITES = "ping"\n' features += 'TEST_EXPORT_SDK_ENABLED = "1"\n' features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n' self.write_config(features) # Build tesexport for core-image-minimal bitbake('core-image-minimal') bitbake('-c testexport core-image-minimal') needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME'] bb_vars = get_bb_vars(needed_vars, 'core-image-minimal') testexport_dir = bb_vars['TEST_EXPORT_DIR'] sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR'] sdk_name = bb_vars['TEST_EXPORT_SDK_NAME'] # Check for SDK tarball_name = "%s.sh" % sdk_name tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name) msg = "Couldn't find SDK tarball: %s" % tarball_path self.assertEqual(os.path.isfile(tarball_path), True, msg) # Extract SDK and run tar from SDK result = runCmd("%s -y -d /tmp/sdk" % tarball_path) self.assertEqual(0, result.status, "Couldn't extract SDK") env_script = result.output.split()[-1] result = runCmd(". %s; which tar" % env_script, shell=True) self.assertEqual(0, result.status, "Couldn't setup SDK environment") is_sdk_tar = True if "/tmp/sdk" in result.output else False self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment") tar_sdk = result.output result = runCmd("%s --version" % tar_sdk) self.assertEqual(0, result.status, "Couldn't run tar from SDK")
def test_cert_provider_local_output(self): logger = logging.getLogger("selftest") logger.info('Running bitbake to build aktualizr-ca-implicit-prov') bitbake('aktualizr-ca-implicit-prov') bb_vars = get_bb_vars(['SOTA_PACKED_CREDENTIALS', 'T'], 'aktualizr-native') creds = bb_vars['SOTA_PACKED_CREDENTIALS'] temp_dir = bb_vars['T'] bb_vars_prov = get_bb_vars(['STAGING_DIR_HOST', 'libdir'], 'aktualizr-ca-implicit-prov') config = bb_vars_prov['STAGING_DIR_HOST'] + bb_vars_prov['libdir'] + '/sota/sota_implicit_prov_ca.toml' akt_native_run(self, 'aktualizr-cert-provider -c {creds} -r -l {temp} -g {config}' .format(creds=creds, temp=temp_dir, config=config)) # Might be nice if these names weren't hardcoded. cert_path = temp_dir + '/var/sota/import/client.pem' self.assertTrue(os.path.isfile(cert_path), "Client certificate not found at %s." % cert_path) self.assertTrue(os.path.getsize(cert_path) > 0, "Client certificate at %s is empty." % cert_path) pkey_path = temp_dir + '/var/sota/import/pkey.pem' self.assertTrue(os.path.isfile(pkey_path), "Private key not found at %s." % pkey_path) self.assertTrue(os.path.getsize(pkey_path) > 0, "Private key at %s is empty." % pkey_path) ca_path = temp_dir + '/var/sota/import/root.crt' self.assertTrue(os.path.isfile(ca_path), "Client certificate not found at %s." % ca_path) self.assertTrue(os.path.getsize(ca_path) > 0, "Client certificate at %s is empty." % ca_path)
def _process_args(self, logger, args): args.test_start_time = time.strftime("%Y%m%d%H%M%S") args.test_data_file = None args.CASES_PATHS = None bbvars = get_bb_vars() logdir = os.environ.get("BUILDDIR") if 'LOG_DIR' in bbvars: logdir = bbvars['LOG_DIR'] bb.utils.mkdirhier(logdir) args.output_log = logdir + '/%s-results-%s.log' % (self.name, args.test_start_time) super(OESelftestTestContextExecutor, self)._process_args(logger, args) if args.list_modules: args.list_tests = 'module' elif args.list_classes: args.list_tests = 'class' elif args.list_tests: args.list_tests = 'name' self.tc_kwargs['init']['td'] = bbvars self.tc_kwargs['init']['machines'] = self._get_available_machines() 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']['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['run']['skips'] = args.skips self.tc_kwargs['run']['processes'] = args.processes
def akt_native_run(testInst, cmd, **kwargs): # run a command supplied by aktualizr-native and checks that: # - the executable exists # - the command runs without error # # Requirements in base test class (setUpClass for example): # bitbake aktualizr-native # bitbake build-sysroots -c build_native_sysroot # # (technique found in poky/meta/lib/oeqa/selftest/cases/package.py) bb_vars = get_bb_vars(['STAGING_DIR', 'BUILD_ARCH']) sysroot = oe.path.join(bb_vars['STAGING_DIR'], bb_vars['BUILD_ARCH']) result = runCmd(cmd, native_sysroot=sysroot, ignore_status=True, **kwargs) testInst.assertEqual(result.status, 0, "Status not equal to 0. output: %s" % result.output)
def __init__(self, *args, **kwargs): super(BuildPerfTestCase, self).__init__(*args, **kwargs) self.name = self._testMethodName self.base_dir = None self.start_time = None self.elapsed_time = None self.measurements = OrderedDict() self.buildstats = OrderedDict() # self.err is supposed to be a tuple from sys.exc_info() self.err = None self.bb_vars = get_bb_vars() # TODO: remove 'times' and 'sizes' arrays when globalres support is # removed self.times = [] self.sizes = []
def config_buildhistory(self, tmp_bh_location=False): bb_vars = get_bb_vars(['USER_CLASSES', 'INHERIT']) if (not 'buildhistory' in bb_vars['USER_CLASSES']) and ( not 'buildhistory' in bb_vars['INHERIT']): add_buildhistory_config = 'INHERIT += "buildhistory"\nBUILDHISTORY_COMMIT = "1"' self.append_config(add_buildhistory_config) if tmp_bh_location: # Using a temporary buildhistory location for testing tmp_bh_dir = os.path.join( self.builddir, "tmp_buildhistory_%s" % datetime.datetime.now().strftime('%Y%m%d%H%M%S')) buildhistory_dir_config = "BUILDHISTORY_DIR = \"%s\"" % tmp_bh_dir self.append_config(buildhistory_dir_config) self.track_for_cleanup(tmp_bh_dir)
def __init__(self, out_dir): self.out_dir = out_dir self.results = {'name':self.name, 'description': self.description, 'status': 'NOTRUN', 'start_time': None, 'elapsed_time': None, 'measurements': []} if not os.path.exists(self.out_dir): os.makedirs(self.out_dir) if not self.name: self.name = self.__class__.__name__ self.bb_vars = get_bb_vars() # TODO: remove the _failed flag when globalres.log is ditched as all # failures should raise an exception self._failed = False self.cmd_log = os.path.join(self.out_dir, 'commands.log')
def run_check(self, *suites, ssh=None): targets = set() for s in suites: if s in ["gcc", "g++"]: targets.add("check-gcc") else: targets.add("check-target-{}".format(s)) # configure ssh target features = [] features.append('MAKE_CHECK_TARGETS = "{0}"'.format(" ".join(targets))) if ssh is not None: features.append('TOOLCHAIN_TEST_TARGET = "ssh"') features.append('TOOLCHAIN_TEST_HOST = "{0}"'.format(ssh)) features.append('TOOLCHAIN_TEST_HOST_USER = "******"') features.append('TOOLCHAIN_TEST_HOST_PORT = "22"') self.write_config("\n".join(features)) recipe = "gcc-runtime" bitbake("{} -c check".format(recipe)) bb_vars = get_bb_vars(["B", "TARGET_SYS"], recipe) builddir, target_sys = bb_vars["B"], bb_vars["TARGET_SYS"] self.extraresults = {"ptestresult.sections": {}} for suite in suites: sumspath = os.path.join(builddir, "gcc", "testsuite", suite, "{0}.sum".format(suite)) if not os.path.exists(sumspath): # check in target dirs sumspath = os.path.join(builddir, target_sys, suite, "testsuite", "{0}.sum".format(suite)) if not os.path.exists( sumspath): # handle libstdc++-v3 -> libstdc++ sumspath = os.path.join(builddir, target_sys, suite, "testsuite", "{0}.sum".format(suite.split("-")[0])) ptestsuite = "gcc-{}".format(suite) if suite != "gcc" else suite ptestsuite = ptestsuite + "-user" if ssh is None else ptestsuite self.extraresults["ptestresult.sections"][ptestsuite] = {} with open(sumspath, "r") as f: for test, result in parse_values(f): self.extraresults["ptestresult.{}.{}".format( ptestsuite, test)] = { "status": result }
def do_test_build(self, name, use_sstate): capture_vars = [ 'DEPLOY_DIR_' + c.upper() for c in self.package_classes ] 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}" LICENSE_FLAGS_WHITELIST = "commercial" DISTRO_FEATURES:append = ' systemd pam' USERADDEXTENSION = "useradd-staticids" USERADD_ERROR_DYNAMIC = "skip" USERADD_UID_TABLES += "files/static-passwd" USERADD_GID_TABLES += "files/static-group" ''').format(package_classes=' '.join( 'package_%s' % c for c in self.package_classes), tmpdir=tmpdir) if not use_sstate: if self.sstate_targets: self.logger.info( "Building prebuild for %s (sstate allowed)..." % (name)) self.write_config(config) bitbake(' '.join(self.sstate_targets)) # 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_MIRRORS = "" ''') self.logger.info("Building %s (sstate%s allowed)..." % (name, '' if use_sstate else ' NOT')) self.write_config(config) d = get_bb_vars(capture_vars) # targets used to be called images bitbake(' '.join(getattr(self, 'images', self.targets))) return d
def _run(self): self.log_cmd_output("bitbake {} -c do_populate_sdk_ext".format( self.build_target)) self.bb_vars = get_bb_vars(None, self.build_target) tmp_dir = self.bb_vars['TMPDIR'] installer = os.path.join( self.bb_vars['SDK_DEPLOY'], self.bb_vars['TOOLCHAINEXT_OUTPUTNAME'] + '.sh') # Measure installer size self.measure_disk_usage(installer, 'installer_bin', 'eSDK installer') # Measure deployment time and deployed size deploy_dir = os.path.join(tmp_dir, 'esdk-deploy') if os.path.exists(deploy_dir): shutil.rmtree(deploy_dir) self.sync() self.measure_cmd_resources([installer, '-y', '-d', deploy_dir], 'deploy', 'eSDK deploy') self.measure_disk_usage(deploy_dir, 'deploy_dir', 'deploy dir')
def _check_presence_meta_selftest(): builddir = os.environ.get("BUILDDIR") if os.getcwd() != builddir: self.tc.logger.info("Changing cwd to %s" % builddir) os.chdir(builddir) if not "meta-selftest" in self.tc.td["BBLAYERS"]: self.tc.logger.warning("meta-selftest layer not found in BBLAYERS, adding it") meta_selftestdir = os.path.join( self.tc.td["BBLAYERS_FETCH_DIR"], 'meta-selftest') if os.path.isdir(meta_selftestdir): runCmd("bitbake-layers add-layer %s" %meta_selftestdir) # reload data is needed because a meta-selftest layer was add self.tc.td = get_bb_vars() self.tc.config_paths['testlayer_path'] = get_test_layer() else: self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir) raise OEQAPreRun
def test_wic_image_type(self): """Test building wic images by bitbake""" config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "wic-image-minimal"\n'\ 'MACHINE_FEATURES_append = " efi"\n' self.append_config(config) self.assertEqual(0, bitbake('wic-image-minimal').status) self.remove_config(config) bb_vars = get_bb_vars(['DEPLOY_DIR_IMAGE', 'MACHINE']) deploy_dir = bb_vars['DEPLOY_DIR_IMAGE'] machine = bb_vars['MACHINE'] prefix = os.path.join(deploy_dir, 'wic-image-minimal-%s.' % machine) # check if we have result image and manifests symlinks # pointing to existing files for suffix in ('wic', 'manifest'): path = prefix + suffix self.assertTrue(os.path.islink(path)) self.assertTrue(os.path.isfile(os.path.realpath(path)))
def _process_args(self, logger, args): args.output_log = '%s-results-%s.log' % (self.name, time.strftime("%Y%m%d%H%M%S")) args.test_data_file = None args.CASES_PATHS = None super(OESelftestTestContextExecutor, self)._process_args(logger, args) if args.list_modules: args.list_tests = 'module' elif args.list_classes: args.list_tests = 'class' elif args.list_tests: args.list_tests = 'name' self.tc_kwargs['init']['td'] = get_bb_vars() self.tc_kwargs['init']['machines'] = self._get_available_machines() self.tc_kwargs['init']['testlayer_path'] = get_test_layer()
def _check_presence_meta_selftest(): builddir = os.environ.get("BUILDDIR") if os.getcwd() != builddir: self.tc.logger.info("Changing cwd to %s" % builddir) os.chdir(builddir) if not "meta-selftest" in self.tc.td["BBLAYERS"]: self.tc.logger.warn("meta-selftest layer not found in BBLAYERS, adding it") meta_selftestdir = os.path.join( self.tc.td["BBLAYERS_FETCH_DIR"], 'meta-selftest') if os.path.isdir(meta_selftestdir): runCmd("bitbake-layers add-layer %s" %meta_selftestdir) # reload data is needed because a meta-selftest layer was add self.tc.td = get_bb_vars() self.tc.testlayer_path = get_test_layer() else: self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir) raise OEQAPreRun