def configuration_path(prog=None): '''Return the path the configuration data path for RTEMS. The path is relative to the installed executable. Mangage the installed package and the in source tree when running from within the rtems-tools repo. Note: 1. This code assumes the executable is wrapped and not using 'env'. 2. Ok to directly call os.path. ''' if prog is None: if len(sys.argv) == 1: exec_name = sys.argv[0] else: exec_name = sys.argv[1] else: exec_name = prog exec_name = os.path.abspath(exec_name) for top in [ os.path.dirname(os.path.dirname(exec_name)), os.path.dirname(exec_name) ]: config_path = path.join(top, 'share', 'rtems', 'config') if path.exists(config_path): break config_path = path.join(top, 'config') if path.exists(config_path): break config_path = None return config_path
def add_covoar_css(self): table_js_path = path.join(self.covoar_src_path, 'table.js') covoar_css_path = path.join(self.covoar_src_path, 'covoar.css') coverage_directory = path.join(self.build_dir, self.bsp + '-coverage') path.copy_tree(covoar_css_path, coverage_directory) path.copy_tree(table_js_path, coverage_directory)
def run(self): if self.executables == None: log.stderr("ERROR: Executables for coverage analysis unspecified!") raise Exception('Executable for coverage analysis unspecified') if self.config_map == None: log.stderr("ERROR: Configuration map for coverage analysis unspecified!") raise Exception("ERROR: Configuration map for coverage analysis unspecified!") covoarConfigFile = path.join(self.tracesDir, 'config') self.writeCovoarConfig(covoarConfigFile) if(not path.exists(covoarConfigFile)): log.stderr("Covoar configuration file: " + path.abspath(covoarConfigFile) + " doesn't exists! Covoar can not be run! "); return -1 self._linkExecutables() symbolConfig = symbolsConfiguration() symbolConfig.load(self.symbolConfigPath) for sset in symbolConfig.symbolSets: if sset.isValid(): symbolSetFile = path.join(self.tracesDir, sset.name + ".symcfg") sset.writeSetFile(symbolSetFile) self.symbolSets.append(sset.name) covoar_run = covoar(self.testDir, self.symbolConfigPath, self.tracesDir, path.join(self.rtdir, 'covoar')) covoar_run.run(sset.name, covoarConfigFile, symbolSetFile) else: log.stderr("Invalid symbol set " + sset.name + ". Skipping covoar run.") self._generateReports(); self._cleanup(); self._summarize();
def __init__(self, config, version, prefix, tools, rtems, build_dir, options): self.config = config self.build_dir = build_dir self.rtems_version = version self.prefix = prefix self.tools = tools self.rtems = rtems self.options = options self.counts = {'h': 0, 'exes': 0, 'objs': 0, 'libs': 0} self.results = results( rtems, { 'groups': ['Shared', 'BSP', 'Network', 'Tests', 'LibCPU', 'CPU Kit'], 'exclude': '.*Makefile.*', 'CPU Kit': '.*cpukit/.*', 'Network': '.*libnetworking/.*|.*librpc/.*', 'Tests': '.*testsuites/.*', 'BSP': '.*libbsp/.*', 'LibCPU': '.*libcpu/.*', 'Shared': '.*shared/.*' }) if not path.exists(path.join(rtems, 'configure')) or \ not path.exists(path.join(rtems, 'Makefile.in')) or \ not path.exists(path.join(rtems, 'cpukit')): raise error.general('RTEMS source path does not look like RTEMS')
def __init__(self, macros_, executables, prefix, symbol_set=None, trace=False): ''' Constructor ''' self.trace = trace self.macros = macros_ self.build_dir = self.macros['_cwd'] self.explanations_txt = self.macros.expand( self.macros['cov_explanations']) self.test_dir = path.join(self.build_dir, self.macros['bsp'] + '-coverage') if not path.exists(self.test_dir): path.mkdir(self.test_dir) self.rtdir = path.abspath(self.macros['_rtdir']) self.rtscripts = self.macros.expand(self.macros['_rtscripts']) self.coverage_config_path = path.join(self.rtscripts, 'coverage') self.symbol_config_path = path.join(self.coverage_config_path, 'symbol-sets.ini') self.symbol_select_path = path.join( self.coverage_config_path, self.macros['bsp'] + '-symbols.ini') self.executables = executables self.symbol_sets = [] self.no_clean = int(self.macros['_no_clean']) self.report_format = self.macros['cov_report_format'] self.symbol_set = symbol_set self.target = self.macros['target'] self.bsp_name = self.macros['bsp'].split('-')[0] self.prefix = prefix
def run(self, setName, covoarConfigFile, symbolFile): covoarResultDir = path.join(self.baseResultDir, setName) if (not path.exists(covoarResultDir)): path.mkdir(covoarResultDir) if (not path.exists(symbolFile)): log.stderr("Symbol set file: " + symbolFile + " doesn't exists! Covoar can not be run!") log.stderr("Skipping " + setName) return command = "covoar -C" + covoarConfigFile + " -S " + symbolFile + " -O " + covoarResultDir + " " + path.join(self.tracesDir, "*.exe") log.notice("Running covoar for " + setName, stdout_only=True) log.notice(command, stdout_only=True) executor = execute.execute(verbose=True, output=output_handler) exit_code = executor.shell(command, cwd=os.getcwd()) shutil.copy2(path.join(self.covoarSrcDir, 'table.js'), path.join(covoarResultDir, 'table.js')) shutil.copy2(path.join(self.covoarSrcDir, 'covoar.css'), path.join(covoarResultDir, 'covoar.css')) log.notice("Coverage run for " + setName + " finished ") status = "success" if (exit_code[0] != 0): status = "failure. Error code: " + str(exit_code[0]) log.notice("Coverage run for " + setName + " finished " + status) log.notice("-----------------------------------------------")
def run(self, set_name, covoar_config_file, symbol_file, gcnos_file): covoar_result_dir = path.join(self.base_result_dir, set_name) if (not path.exists(covoar_result_dir)): path.mkdir(covoar_result_dir) if (not path.exists(symbol_file)): log.stderr("Symbol set file: " + symbol_file + " doesn't exists! Covoar can not be run!") log.stderr("Skipping " + set_name) return command = "covoar -v -C" + covoar_config_file + " -S " + symbol_file + " -O " + covoar_result_dir + " " + path.join( self.traces_dir, "*.exe") if (path.exists(gcnos_file)): command = command + " -g " + gcnos_file log.notice("Running covoar for " + set_name, stdout_only=True) log.notice(command, stdout_only=True) executor = execute.execute(verbose=True, output=output_handler) exit_code = executor.shell(command, cwd=os.getcwd()) shutil.copy2(path.join(self.covoar_src_dir, 'table.js'), path.join(covoar_result_dir, 'table.js')) shutil.copy2(path.join(self.covoar_src_dir, 'covoar.css'), path.join(covoar_result_dir, 'covoar.css')) log.notice("Coverage run for " + set_name + " finished ") status = "success" if (exit_code[0] != 0): status = "failure. Error code: " + str(exit_code[0]) log.notice("Coverage run for " + set_name + " finished " + status) log.notice("-----------------------------------------------")
def add_covoar_css(self): table_js_path = path.join(self.covoar_src_path, 'table.js') covoar_css_path = path.join(self.covoar_src_path, 'covoar.css') for symbol_set in self.symbol_sets: symbol_set_dir = path.join(self.build_dir, self.bsp + '-coverage', symbol_set) path.copy_tree(covoar_css_path, symbol_set_dir) path.copy_tree(table_js_path, symbol_set_dir)
def _find_covoar(self): covoar_exe = 'covoar' tester_dir = path.dirname(path.abspath(sys.argv[0])) base = path.dirname(tester_dir) exe = path.join(self.prefix, 'share', 'rtems', 'tester', 'bin', covoar_exe) if path.isfile(exe): return exe exe = path.join(base, 'build', 'tester', 'covoar', covoar_exe) if path.isfile(exe): return exe raise error.general('coverage: %s not found'% (covoar_exe))
def __init__(self, p_summaryDir): self.summaryFilePath = path.join(p_summaryDir, "summary.txt") self.indexFilePath = path.join(p_summaryDir, "index.html") self.bytes_analyzed = 0 self.bytes_notExecuted = 0 self.percentage_executed = 0.0 self.percentage_notExecuted = 100.0 self.ranges_uncovered = 0 self.branches_uncovered = 0 self.branches_total = 0 self.branches_alwaysTaken = 0 self.branches_neverTaken = 0 self.percentage_branchesCovered = 0.0 self.isFailure = False
def __init__(self, p_summary_dir): self.summary_file_path = path.join(p_summary_dir, 'summary.txt') self.index_file_path = path.join(p_summary_dir, 'index.html') self.bytes_analyzed = 0 self.bytes_not_executed = 0 self.percentage_executed = 0.0 self.percentage_not_executed = 100.0 self.ranges_uncovered = 0 self.branches_uncovered = 0 self.branches_total = 0 self.branches_always_taken = 0 self.branches_never_taken = 0 self.percentage_branches_covered = 0.0 self.is_failure = False
def load(bsp, opts): mandatory = ['bsp', 'arch', 'tester'] cfg = configuration.configuration() path_ = opts.defaults.expand('%%{_configdir}/bsps/%s.ini' % (bsp)) ini_name = path.basename(path_) for p in path.dirname(path_).split(':'): if path.exists(path.join(p, ini_name)): cfg.load(path.join(p, ini_name)) if not cfg.has_section(bsp): raise error.general('bsp section not found in ini: [%s]' % (bsp)) item_names = cfg.get_item_names(bsp, err=False) for m in mandatory: if m not in item_names: raise error.general( 'mandatory item not found in bsp section: %s' % (m)) opts.defaults.set_write_map(bsp, add=True) for i in cfg.get_items(bsp, flatten=False): opts.defaults[i[0]] = i[1] if not opts.defaults.set_read_map(bsp): raise error.general('cannot set BSP read map: %s' % (bsp)) # Get a copy of the required fields we need requires = cfg.comma_list(bsp, 'requires', err=False) del cfg user_config = opts.find_arg('--user-config') if user_config is not None: user_config = path.expanduser(user_config[1]) if not path.exists(user_config): raise error.general( 'cannot find user configuration file: %s' % (user_config)) else: if 'HOME' in os.environ: user_config = path.join(os.environ['HOME'], '.rtemstesterrc') if user_config: if path.exists(user_config): cfg = configuration.configuration() cfg.load(user_config) if cfg.has_section(bsp): for i in cfg.get_items(bsp, flatten=False): opts.defaults[i[0]] = i[1] # Check for the required values. for r in requires: if opts.defaults.get(r) is None: raise error.general('user value missing, BSP %s requires \'%s\': missing: %s' % \ (bsp, ', '.join(requires), r)) return opts.defaults['bsp'] raise error.general('cannot find bsp configuration file: %s.ini' % (bsp))
def __init__(self, p_macros): ''' Constructor ''' self.macros = p_macros self.targetDir = self.macros['_cwd'] self.testDir = path.join(self.targetDir, "test") self.rtdir = path.abspath(self.macros['_rtdir']) self.rtscripts = self.macros.expand(self.macros['_rtscripts']) self.coverageConfigPath = path.join(self.rtscripts, "coverage") self.symbolConfigPath = path.join(self.coverageConfigPath, "symbolSets.config") self.tracesDir = path.join(self.targetDir, 'coverage') self.config_map = self.macros.macros['coverage'] self.executables = None self.symbolSets = []
def add_dir_name(self): for symbol_set in self.symbol_sets: symbol_set_dir = path.join(self.build_dir, self.bsp + '-coverage', symbol_set) html_files = path.listdir(symbol_set_dir) for html_file in html_files: html_file = path.join(symbol_set_dir, html_file) if path.exists(html_file) and 'html' in html_file: with open(html_file, 'r') as f: file_data = f.read() text = file_data[file_data.find('<div class="heading-title">')\ +len('<div class="heading-title">') \ : file_data.find('</div')] file_data = file_data.replace(text, text + '<br>' + symbol_set) with open(html_file, 'w') as f: f.write(file_data)
def create_gcnos_file(self, gcnos_config_file_path, gcnos_file_path, path_to_builddir): with open(gcnos_file_path, 'w') as gcnos_file: with open(gcnos_config_file_path, 'r') as config_file: for line in config_file: if line.strip(): gcnos_file.write(path.join(path_to_builddir, line))
def _create_index_file(self, head_section, content): f = open(path.join(self.target_dir, "report.html"), "w") try: f.write(head_section) f.write(content) finally: f.close()
def _findPartialReports(self): partialReports = {} for symbolSet in self.symbolSetsList: setSummary = summary(path.join(self.targetDir, "test", symbolSet)) setSummary.parse() partialReports[symbolSet] = setSummary return partialReports
def run(self, set_name, symbol_file): covoar_result_dir = path.join(self.base_result_dir, set_name) if not path.exists(covoar_result_dir): path.mkdir(covoar_result_dir) if not path.exists(symbol_file): raise error.general('coverage: no symbol set file: %s' % (symbol_file)) exe = self._find_covoar() command = exe + ' -O ' + covoar_result_dir + \ ' -p ' + self.project_name + \ ' ' + self.executables + ' ' command += self.covoar_cmd log.notice() log.notice('Running coverage analysis: %s (%s)' % (set_name, covoar_result_dir)) start_time = datetime.datetime.now() executor = execute.execute(verbose=self.trace, output=self.output_handler) exit_code = executor.shell(command, cwd=os.getcwd()) if exit_code[0] != 0: raise error.general('coverage: covoar failure:: %d' % (exit_code[0])) end_time = datetime.datetime.now() log.notice('Coverage time: %s' % (str(end_time - start_time)))
def _createIndexFile(self, headSection, content): f = open(path.join(self.targetDir, "report.html"),"w") try: f.write(headSection) f.write(content) finally: f.close()
def load(args, optargs=None, command_path=None, defaults="%s" % (defaults_mc)): # # The path to this command if not supplied by the upper layers. # if command_path is None: command_path = path.dirname(args[0]) if len(command_path) == 0: command_path = "." # # Check if there is a defaults.mc file under the command path. If so this is # the tester being run from within the git repo. If not found assume the tools # have been installed and the defaults is in the install prefix. # if path.exists(path.join(command_path, defaults_mc)): rtdir = command_path else: rtdir = "%{_prefix}/share/rtems/tester" defaults = "%s/%s" % (rtdir, defaults_mc) # # The command line contains the base defaults object all build objects copy # and modify by loading a configuration. # opts = command_line(args, optargs, macros.macros(name=defaults, rtdir=rtdir), command_path) options.load(opts) return opts
def _linkExecutables(self): log.notice("Linking executables to " + self.tracesDir) for exe in self.executables: dst = path.join(self.tracesDir, path.basename(exe)) os.link(exe, dst) log.notice("Symlinks made")
def add_covoar_src_path(self): table_js_path = path.join(self.covoar_src_path, 'table.js') covoar_css_path = path.join(self.covoar_src_path, 'covoar.css') for symbol_set in self.symbol_sets_list: symbol_set_dir = path.join(self.target_dir, "test", symbol_set) html_files = os.listdir(symbol_set_dir) for html_file in html_files: html_file = path.join(symbol_set_dir, html_file) if path.exists(html_file) and 'html' in html_file: with open(html_file, 'r') as f: file_data = f.read() file_data = file_data.replace('table.js', table_js_path) file_data = file_data.replace('covoar.css', covoar_css_path) with open(html_file, 'w') as f: f.write(file_data)
def post_process(self): # Handle the log first. log.default = log.log(self.logfiles()) if self.trace(): log.tracing = True if self.quiet(): log.quiet = True # Handle the jobs for make if '_ncpus' not in self.defaults: raise error.general('host number of CPUs not set') ncpus = self.jobs(self.defaults['_ncpus']) if ncpus > 1: self.defaults['_smp_mflags'] = '-j %d' % (ncpus) else: self.defaults['_smp_mflags'] = self.defaults['nil'] # Load user macro files um = self.user_macros() if um: checked = path.exists(um) if False in checked: raise error.general('macro file not found: %s' % (um[checked.index(False)])) for m in um: self.defaults.load(m) # Check if the user has a private set of macros to load if 'RSB_MACROS' in os.environ: if path.exists(os.environ['RSB_MACROS']): self.defaults.load(os.environ['RSB_MACROS']) if 'HOME' in os.environ: rsb_macros = path.join(os.environ['HOME'], '.rsb_macros') if path.exists(rsb_macros): self.defaults.load(rsb_macros)
def configuration_file(config, prog=None): '''Return the path to a configuration file for RTEMS. The path is relative to the installed executable or we are testing and running from within the rtems-tools repo. ''' return path.join(configuration_path(prog=prog), config)
def install(self, src, dst): src_base = path.basename(src) log.notice('Install: %s' % (src_base)) asrc = path.abspath(src) adst = path.join(path.abspath(dst), src_base) log.output('Copy: %s -> %s' % (asrc, adst)) path.copy(asrc, adst)
def load(self, name): # # Load all the files. # self.ini = {'base': path.dirname(name), 'files': []} includes = [name] still_loading = True while still_loading: still_loading = False for include in includes: if not path.exists(include): rebased_inc = path.join(self.ini['base'], path.basename(include)) if not path.exists(rebased_inc): e = 'config: cannot find configuration: %s' % (include) raise error.general(e) include = rebased_inc if include not in self.ini['files']: try: self.config.read(include) except configparser.ParsingError as ce: raise error.general('config: %s' % (ce)) still_loading = True self.ini['files'] += [include] includes = [] if still_loading: for section in self.config.sections(): includes += self.comma_list(section, 'include', err=False)
def install_configuration(self, image, mountpoint): uenv_txt = self['uenv_txt'] if uenv_txt is not None: log.output('Uenv txt: %s' % (uenv_txt)) image.install(path.abspath(uenv_txt), mountpoint) else: template = None if self['net_dhcp'] or self['net_ip'] is not None: if self['net_dhcp']: template = 'uenv_net_dhcp' else: template = 'uenv_net_static' if self['net_server_ip']: template += '_sip' if self['net_fdt']: template += '_net_fdt' else: if self['kernel'] is not None: template = 'uenv_exe' elif self['fdt'] is not None: template = 'uenv' if self['fdt'] is not None: template += '_fdt' if template is not None: log.notice('Uenv template: %s' % (template)) uenv_start = self.comma_split(self['uenv_start']) uenv_body = self.comma_split(self[template]) uenv_end = self.comma_split(self['uenv_end']) uenv = uenv_start + uenv_body + uenv_end image.install_text(self.filter_text(uenv), path.join(mountpoint, self['boot_config']))
def fdt_convert(self, image, fdt): dst = path.join(path.abspath(self['build']), path.basename(fdt)) self['fdt_build'] = dst log.output('Copy (into build): %s -> %s' % (fdt, dst)) image.clean_path(dst) path.copy(fdt, dst) return self['fdt_image'].replace('@FDT@', dst)
def load(args, optargs=None, command_path=None, defaults='%s' % (defaults_mc)): # # The path to this command if not supplied by the upper layers. # if command_path is None: command_path = path.dirname(args[0]) if len(command_path) == 0: command_path = '.' # # Check if there is a defaults.mc file under the command path. If so this is # the tester being run from within the git repo. If not found assume the tools # have been installed and the defaults is in the install prefix. # if path.exists(path.join(command_path, defaults_mc)): rtdir = command_path else: rtdir = '%{_prefix}/share/rtems/tester' defaults = '%s/%s' % (rtdir, defaults_mc) # # The command line contains the base defaults object all build objects copy # and modify by loading a configuration. # opts = command_line(args, optargs, macros.macros(name=defaults, rtdir=rtdir), command_path) options.load(opts) return opts
def __init__(self, index, total, report, executable, rtems_tools, bsp, bsp_config, opts): self.index = index self.total = total self.report = report self.bsp = bsp self.bsp_config = bsp_config self.opts = copy.copy(opts) self.opts.defaults['test_index'] = str(index) self.opts.defaults['test_total'] = str(total) self.opts.defaults['bsp'] = bsp self.opts.defaults['bsp_arch'] = '%%{%s_arch}' % (bsp) self.opts.defaults['bsp_opts'] = '%%{%s_opts}' % (bsp) if not path.isfile(executable): raise error.general('cannot find executable: %s' % (executable)) self.opts.defaults['test_executable'] = executable self.opts.defaults['test_executable_name'] = path.basename(executable) if rtems_tools: rtems_tools_bin = path.join(self.opts.defaults.expand(rtems_tools), 'bin') if not path.isdir(rtems_tools_bin): raise error.general('cannot find RTEMS tools path: %s' % (rtems_tools_bin)) self.opts.defaults['rtems_tools'] = rtems_tools_bin self.config = config.file(self.report, self.bsp_config, self.opts)
def __init__(self, symbol_sets, build_dir, rtdir, bsp): self.symbol_sets = symbol_sets self.build_dir = build_dir self.partial_reports_files = list(['index.html', 'summary.txt']) self.number_of_columns = 1 self.covoar_src_path = path.join(rtdir, 'covoar') self.bsp = bsp
def _lo_triplets(self, opt, macro, value): # # This is a target triplet. Run it past config.sub to make make sure it # is ok. The target triplet is 'cpu-vendor-os'. # e = execute.capture_execution() config_sub = path.join(self.command_path, basepath, 'config.sub') exit_code, proc, output = e.shell(config_sub + ' ' + value) if exit_code == 0: value = output self.defaults[macro] = ('triplet', 'none', value) self.opts[opt[2:]] = value _cpu = macro + '_cpu' _arch = macro + '_arch' _vendor = macro + '_vendor' _os = macro + '_os' _arch_value = '' _vendor_value = '' _os_value = '' dash = value.find('-') if dash >= 0: _arch_value = value[:dash] value = value[dash + 1:] dash = value.find('-') if dash >= 0: _vendor_value = value[:dash] value = value[dash + 1:] if len(value): _os_value = value self.defaults[_cpu] = _arch_value self.defaults[_arch] = _arch_value self.defaults[_vendor] = _vendor_value self.defaults[_os] = _os_value
def _find_partial_reports(self): partial_reports = {} for symbol_set in self.symbol_sets_list: set_summary = summary( path.join(self.target_dir, "test", symbol_set)) set_summary.parse() partial_reports[symbol_set] = set_summary return partial_reports
def _find_partial_reports(self): partial_reports = {} for symbol_set in self.symbol_sets: set_summary = summary(path.join(self.bsp + "-coverage", symbol_set)) set_summary.parse() partial_reports[symbol_set] = set_summary return partial_reports
def __init__(self, config, version, prefix, tools, rtems, build_dir, options): self.config = config self.build_dir = build_dir self.rtems_version = version self.prefix = prefix self.tools = tools self.rtems = rtems self.options = options self.errors = {'configure': 0, 'build': 0, 'tests': 0} self.counts = {'h': 0, 'exes': 0, 'objs': 0, 'libs': 0} self.warnings = warnings_counter(rtems) self.results = results() if not path.exists(path.join(rtems, 'configure')) or \ not path.exists(path.join(rtems, 'Makefile.in')) or \ not path.exists(path.join(rtems, 'cpukit')): raise error.general('RTEMS source path does not look like RTEMS')
def run(self): if self.executables == None: log.stderr( "ERROR: _executables for coverage analysis unspecified!") raise Exception('Executable for coverage analysis unspecified') if self.config_map == None: log.stderr( "ERROR: _configuration map for coverage analysis unspecified!") raise Exception( "ERROR: _configuration map for coverage analysis unspecified!") covoar_config_file = path.join(self.traces_dir, 'config') self.write_covoar_config(covoar_config_file) if (not path.exists(covoar_config_file)): log.stderr("Covoar configuration file: " + path.abspath(covoar_config_file) + " doesn't exists! Covoar can not be run! ") return -1 self._link_executables() symbol_config = symbols_configuration() symbol_config.load(self.symbol_config_path, self.path_to_builddir) gcnos_file = path.join(self.traces_dir, "rtems.gcnos") gcnos().create_gcnos_file(self.gcnos_file_path, gcnos_file, self.path_to_builddir) for sset in symbol_config.symbol_sets: if sset.is_valid(): symbol_set_file = path.join(self.traces_dir, sset.name + ".symcfg") sset.write_set_file(symbol_set_file) self.symbol_sets.append(sset.name) covoar_run = covoar(self.test_dir, self.symbol_config_path, self.traces_dir, path.join(self.rtdir, 'covoar')) covoar_run.run(sset.name, covoar_config_file, symbol_set_file, gcnos_file) else: log.stderr("Invalid symbol set " + sset.name + ". Skipping covoar run.") self._generate_reports() self._cleanup() self._summarize()
def _check_paths(name, paths): for p in paths: exe = path.join(p, name) if path.isfile(exe): return True if os.name == 'nt': if path.isfile('%s.exe' % (exe)): return True return False
def run(self): build_path = '/' path_ = self.executables[0].split('/') for p in path_: if p == self.target: break else: build_path = path.join(build_path, p) return build_path
def _config_command(self, commands, arch, bsp): cmd = [path.join(self.rtems, 'configure')] commands += self.config.bspopts(arch, bsp) for c in commands: c = c.replace('@PREFIX@', self.prefix) c = c.replace('@RTEMS_VERSION@', self.rtems_version) c = c.replace('@ARCH@', arch) c = c.replace('@BSP@', bsp) cmd += [c] return ' '.join(cmd)
def __init__(self, config, version, prefix, tools, rtems, build_dir, options): self.config = config self.build_dir = build_dir self.rtems_version = version self.prefix = prefix self.tools = tools self.rtems = rtems self.options = options self.errors = { 'configure': 0, 'build': 0, 'tests': 0 } self.counts = { 'h' : 0, 'exes' : 0, 'objs' : 0, 'libs' : 0 } self.warnings = warnings_counter(rtems) if not path.exists(path.join(rtems, 'configure')) or \ not path.exists(path.join(rtems, 'Makefile.in')) or \ not path.exists(path.join(rtems, 'cpukit')): raise error.general('RTEMS source path does not look like RTEMS')
def find_executables(paths, glob): executables = [] for p in paths: if path.isfile(p): executables += [p] elif path.isdir(p): for root, dirs, files in os.walk(p, followlinks = True): for f in files: if fnmatch.fnmatch(f.lower(), glob): executables += [path.join(root, f)] return sorted(executables)
def find_executables(paths): executables = [] for p in paths: if path.isfile(p): executables += [p] elif path.isdir(p): for root, dirs, files in os.walk(p, followlinks = True): for f in files: if f.lower().endswith('.exe'): executables += [path.join(root, f)] return sorted(executables)
def __init__(self, index, total, report, executable, rtems_tools, bsp, bsp_config, opts): self.index = index self.total = total self.report = report self.bsp = bsp self.bsp_config = bsp_config self.opts = copy.copy(opts) self.opts.defaults['test_index'] = str(index) self.opts.defaults['test_total'] = str(total) self.opts.defaults['bsp'] = bsp self.opts.defaults['bsp_arch'] = '%%{%s_arch}' % (bsp) self.opts.defaults['bsp_opts'] = '%%{%s_opts}' % (bsp) if not path.isfile(executable): raise error.general('cannot find executable: %s' % (executable)) self.opts.defaults['test_executable'] = executable if rtems_tools: rtems_tools_bin = path.join(self.opts.defaults.expand(rtems_tools), 'bin') if not path.isdir(rtems_tools_bin): raise error.general('cannot find RTEMS tools path: %s' % (rtems_tools_bin)) self.opts.defaults['rtems_tools'] = rtems_tools_bin self.config = config.file(self.report, self.bsp_config, self.opts)
def run_args(args): b = None ec = 0 try: # # On Windows MSYS2 prepends a path to itself to the environment # path. This means the RTEMS specific automake is not found and which # breaks the bootstrap. We need to remove the prepended path. Also # remove any ACLOCAL paths from the environment. # if os.name == 'nt': cspath = os.environ['PATH'].split(os.pathsep) if 'msys' in cspath[0] and cspath[0].endswith('bin'): os.environ['PATH'] = os.pathsep.join(cspath[1:]) top = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) prefix = '/opt/rtems/%s' % (rtems_version()) tools = prefix build_dir = 'bsp-builds' logf = 'bsp-build-%s.txt' % (datetime.datetime.now().strftime('%Y%m%d-%H%M%S')) config_file = path.join(top, 'share', 'rtems', 'tester', 'rtems', 'rtems-bsps.ini') if not path.exists(config_file): config_file = path.join(top, 'tester', 'rtems', 'rtems-bsps.ini') argsp = argparse.ArgumentParser() argsp.add_argument('--prefix', help = 'Prefix to build the BSP.', type = str) argsp.add_argument('--rtems-tools', help = 'The RTEMS tools directory.', type = str) argsp.add_argument('--rtems', help = 'The RTEMS source tree.', type = str) argsp.add_argument('--build-path', help = 'Path to build in.', type = str) argsp.add_argument('--log', help = 'Log file.', type = str) argsp.add_argument('--stop-on-error', help = 'Stop on an error.', action = 'store_true') argsp.add_argument('--no-clean', help = 'Do not clean the build output.', action = 'store_true') argsp.add_argument('--profiles', help = 'Build the listed profiles.', type = str, default = 'tier-1') argsp.add_argument('--build', help = 'Build variation.', type = str) argsp.add_argument('--arch', help = 'Build the specific architecture.', type = str) argsp.add_argument('--bsp', help = 'Build the specific BSP.', type = str) argsp.add_argument('--dry-run', help = 'Do not run the actual builds.', action = 'store_true') opts = argsp.parse_args(args[1:]) if opts.log is not None: logf = opts.log log.default = log.log([logf]) log.notice('RTEMS Tools Project - RTEMS Kernel BSP Builder, %s' % (version.str())) if opts.rtems is None: raise error.general('No RTEMS source provided on the command line') if opts.prefix is not None: prefix = path.shell(opts.prefix) if opts.rtems_tools is not None: tools = path.shell(opts.rtems_tools) if opts.build_path is not None: build_dir = path.shell(opts.build_path) if opts.bsp is not None and opts.arch is None: raise error.general('BSP provided but no architecture') config = configuration() config.load(config_file, opts.build) options = { 'stop-on-error' : opts.stop_on_error, 'no-clean' : opts.no_clean, 'dry-run' : opts.dry_run, 'jobs' : 8 } b = build(config, rtems_version(), prefix, tools, path.shell(opts.rtems), build_dir, options) if opts.arch is not None: if opts.bsp is not None: b.build_arch_bsp(opts.arch, opts.bsp) else: b.build_arch(opts.arch) else: for profile in opts.profiles.split(','): b.build_profile(profile.strip()) except error.general as gerr: print(gerr) print('BSP Build FAILED', file = sys.stderr) ec = 1 except error.internal as ierr: print(ierr) print('BSP Build FAILED', file = sys.stderr) ec = 1 except error.exit as eerr: pass except KeyboardInterrupt: log.notice('abort: user terminated') ec = 1 if b is not None: b.results.report() sys.exit(ec)
def build_arch_bsp(self, arch, bsp): if not self.config.bsp_present(arch, bsp): raise error.general('BSP not found: %s/%s' % (arch, bsp)) log.output('-' * 70) log.notice('] BSP: %s/%s' % (arch, bsp)) log.notice('. Creating: %s' % (self._path(arch, bsp))) self._arch_bsp_dir_clean(arch, bsp) self._arch_bsp_dir_make(arch, bsp) variations = self._variations(arch, bsp) build_set = self._build_set(variations) bsp_start = datetime.datetime.now() bsp_warnings = warnings_counter(self.rtems) env_path = os.environ['PATH'] os.environ['PATH'] = path.host(path.join(self.tools, 'bin')) + \ os.pathsep + os.environ['PATH'] for bs in sorted(build_set.keys()): warnings = warnings_counter(self.rtems) start = datetime.datetime.now() log.output('- ' * 35) log.notice('. Configuring: %s' % (bs)) try: result = '+ Pass' bpath = self._build_dir(arch, bsp, bs) path.mkdir(bpath) config_cmd = self._config_command(build_set[bs], arch, bsp) cmd = config_cmd e = execute.capture_execution(log = warnings) log.output('run: ' + cmd) if self.options['dry-run']: exit_code = 0 else: exit_code, proc, output = e.shell(cmd, cwd = path.host(bpath)) if exit_code != 0: result = '- FAIL' self.errors['configure'] += 1 log.notice('- Configure failed: %s' % (bs)) log.output('cmd failed: %s' % (cmd)) if self.options['stop-on-error']: raise error.general('Configuring %s failed' % (bs)) else: log.notice('. Building: %s' % (bs)) cmd = 'make' if 'jobs' in self.options: cmd += ' -j %s' % (self.options['jobs']) log.output('run: ' + cmd) if self.options['dry-run']: exit_code = 0 else: exit_code, proc, output = e.shell(cmd, cwd = path.host(bpath)) if exit_code != 0: result = '- FAIL' self.errors['build'] += 1 log.notice('- FAIL: %s: %s' % (bs, self._error_str())) log.output('cmd failed: %s' % (cmd)) if self.options['stop-on-error']: raise error.general('Building %s failed' % (bs)) files = self._count_files(arch, bsp, bs) log.notice('%s: %s: warnings:%d exes:%d objs:%s libs:%d' % \ (result, bs, warnings.get(), files['exes'], files['objs'], files['libs'])) log.notice(' %s' % (self._error_str())) self.results.add(result[0] == '+', arch, bsp, config_cmd, warnings.get()) finally: end = datetime.datetime.now() if not self.options['no-clean']: log.notice('. Cleaning: %s' % (self._build_dir(arch, bsp, bs))) path.removeall(self._build_dir(arch, bsp, bs)) log.notice('^ Time %s' % (str(end - start))) log.output('Warnings Report:') log.output(warnings.report()) warnings.accumulate(bsp_warnings) warnings.accumulate(self.warnings) bsp_end = datetime.datetime.now() log.notice('^ BSP Time %s' % (str(bsp_end - bsp_start))) log.output('BSP Warnings Report:') log.output(bsp_warnings.report()) os.environ['PATH'] = env_path
def _build_dir(self, arch, bsp, build): return path.join(self._path(arch, bsp), build)
def _path(self, arch, bsp): return path.join(self.build_dir, arch, bsp)