def setup_builddir(self, suffix, selftestdir, suite): builddir = os.environ['BUILDDIR'] if not selftestdir: selftestdir = get_test_layer() if self.newbuilddir: newbuilddir = os.path.join(self.newbuilddir, 'build' + suffix) else: 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]: os.environ[e] = os.environ[e].replace(builddir + "/", newbuilddir + "/") if 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) def patch_test(t): if not hasattr(t, "tc"): return 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) def patch_suite(s): for x in s: if isinstance(x, unittest.TestSuite): patch_suite(x) else: patch_test(x) patch_suite(suite) return (builddir, newbuilddir)
def __init__(self, methodName="runTest"): testlayer_path = get_test_layer() self._extra_tear_down_commands = [] self._track_for_cleanup = [ self.testinc_path, self.testinc_bblayers_path, self.machineinc_path, self.localconf_backup, self.local_bblayers_backup ] super(OESelftestTestCase, self).__init__(methodName)
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 _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 _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 remove_inc_files(cls): try: os.remove(os.path.join(cls.builddir, "conf/selftest.inc")) for root, _, files in os.walk(get_test_layer()): for f in files: if f == 'test_recipe.inc': os.remove(os.path.join(root, f)) except OSError as e: pass for incl_file in ['conf/bblayers.inc', 'conf/machine.inc']: try: os.remove(os.path.join(cls.builddir, incl_file)) except: pass
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
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_pseudo_pyc_creation(self): self.write_config("") metaselftestpath = get_test_layer() pycache_path = os.path.join(metaselftestpath, 'lib/__pycache__') if os.path.exists(pycache_path): shutil.rmtree(pycache_path) bitbake('pseudo-pyc-test -c install') test1_pyc_present = len( glob.glob(os.path.join(pycache_path, 'pseudo_pyc_test1.*.pyc'))) self.assertTrue( test1_pyc_present, 'test1 pyc file missing, should be created outside of pseudo context.' ) test2_pyc_present = len( glob.glob(os.path.join(pycache_path, 'pseudo_pyc_test2.*.pyc'))) self.assertFalse( test2_pyc_present, 'test2 pyc file present, should not be created in pseudo context.')
def fork_for_tests(concurrency_num, suite): result = [] if 'BUILDDIR' in os.environ: selftestdir = get_test_layer() test_blocks = partition_tests(suite, concurrency_num) # Clear the tests from the original suite so it doesn't keep them alive suite._tests[:] = [] totaltests = sum(len(x) for x in test_blocks) for process_tests in test_blocks: numtests = len(process_tests) process_suite = unittest.TestSuite(process_tests) # Also clear each split list so new suite has only reference process_tests[:] = [] c2pread, c2pwrite = os.pipe() # Clear buffers before fork to avoid duplicate output sys.stdout.flush() sys.stderr.flush() pid = os.fork() if pid == 0: ourpid = os.getpid() try: newbuilddir = None stream = os.fdopen(c2pwrite, 'wb', 1) os.close(c2pread) (builddir, newbuilddir) = suite.setupfunc("-st-" + str(ourpid), selftestdir, process_suite) # Leave stderr and stdout open so we can see test noise # Close stdin so that the child goes away if it decides to # read from stdin (otherwise its a roulette to see what # child actually gets keystrokes for pdb etc). newsi = os.open(os.devnull, os.O_RDWR) os.dup2(newsi, sys.stdin.fileno()) subunit_client = TestProtocolClient(stream) # Force buffering of stdout/stderr so the console doesn't get corrupted by test output # as per default in parent code subunit_client.buffer = True subunit_result = AutoTimingTestResultDecorator(subunit_client) process_suite.run( ExtraResultsEncoderTestResult(subunit_result)) if ourpid != os.getpid(): os._exit(0) if newbuilddir: removebuilddir(newbuilddir) except: # Don't do anything with process children if ourpid != os.getpid(): os._exit(1) # Try and report traceback on stream, but exit with error # even if stream couldn't be created or something else # goes wrong. The traceback is formatted to a string and # written in one go to avoid interleaving lines from # multiple failing children. try: stream.write(traceback.format_exc().encode('utf-8')) except: sys.stderr.write(traceback.format_exc()) finally: if newbuilddir: removebuilddir(newbuilddir) stream.flush() os._exit(1) stream.flush() os._exit(0) else: os.close(c2pwrite) stream = os.fdopen(c2pread, 'rb', 1) test = ProtocolTestCase(stream) result.append((test, numtests)) return result, totaltests
def setUpModule(): global tinfoil global metaselftestpath metaselftestpath = get_test_layer() tinfoil = bb.tinfoil.Tinfoil(tracking=True) tinfoil.prepare(config_only=False, quiet=2)
def fork_for_tests(concurrency_num, suite): result = [] if 'BUILDDIR' in os.environ: selftestdir = get_test_layer() test_blocks = partition_tests(suite, concurrency_num) # Clear the tests from the original suite so it doesn't keep them alive suite._tests[:] = [] totaltests = sum(len(x) for x in test_blocks) for process_tests in test_blocks: numtests = len(process_tests) process_suite = unittest.TestSuite(process_tests) # Also clear each split list so new suite has only reference process_tests[:] = [] c2pread, c2pwrite = os.pipe() # Clear buffers before fork to avoid duplicate output sys.stdout.flush() sys.stderr.flush() pid = os.fork() if pid == 0: ourpid = os.getpid() try: newbuilddir = None stream = os.fdopen(c2pwrite, 'wb', 1) os.close(c2pread) # Create a new separate BUILDDIR for each group of tests if 'BUILDDIR' in os.environ: builddir = os.environ['BUILDDIR'] newbuilddir = builddir + "-st-" + str(ourpid) newselftestdir = newbuilddir + "/meta-selftest" 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]: 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 process_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) # Leave stderr and stdout open so we can see test noise # Close stdin so that the child goes away if it decides to # read from stdin (otherwise its a roulette to see what # child actually gets keystrokes for pdb etc). newsi = os.open(os.devnull, os.O_RDWR) os.dup2(newsi, sys.stdin.fileno()) subunit_client = TestProtocolClient(stream) # Force buffering of stdout/stderr so the console doesn't get corrupted by test output # as per default in parent code subunit_client.buffer = True subunit_result = AutoTimingTestResultDecorator(subunit_client) process_suite.run(subunit_result) if ourpid != os.getpid(): os._exit(0) if newbuilddir: removebuilddir(newbuilddir) except: # Don't do anything with process children if ourpid != os.getpid(): os._exit(1) # Try and report traceback on stream, but exit with error # even if stream couldn't be created or something else # goes wrong. The traceback is formatted to a string and # written in one go to avoid interleaving lines from # multiple failing children. try: stream.write(traceback.format_exc().encode('utf-8')) except: sys.stderr.write(traceback.format_exc()) finally: if newbuilddir: removebuilddir(newbuilddir) stream.flush() os._exit(1) stream.flush() os._exit(0) else: os.close(c2pwrite) stream = os.fdopen(c2pread, 'rb', 1) test = ProtocolTestCase(stream) result.append((test, numtests)) return result, totaltests