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 __init__(self, name=None, original=None, rtdir='.'): self.files = [] self.macro_filter = re.compile(r'%{[^}]+}') if original is None: self.macros = {} self.read_maps = [] self.read_map_locked = False self.write_map = 'global' self.rtpath = path.abspath(path.dirname(inspect.getfile(macros))) if path.dirname(self.rtpath).endswith('/share/rtems'): self.prefix = path.dirname(self.rtpath)[:-len('/share/rtems')] else: self.prefix = '.' self.macros['global'] = {} self.macros['global']['nil'] = ('none', 'none', '') self.macros['global']['_cwd'] = ('dir', 'required', path.abspath(os.getcwd())) self.macros['global']['_prefix'] = ('dir', 'required', self.prefix) self.macros['global']['_rtdir'] = ('dir', 'required', path.abspath( self.expand(rtdir))) self.macros['global']['_rttop'] = ('dir', 'required', self.prefix) else: self.macros = {} for m in original.macros: if m not in self.macros: self.macros[m] = {} for k in original.macros[m]: self.macros[m][k] = copy.copy(original.macros[m][k]) self.read_maps = sorted(copy.copy(original.read_maps)) self.read_map_locked = copy.copy(original.read_map_locked) self.write_map = copy.copy(original.write_map) if name is not None: self.load(name)
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 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 __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 install_text(self, text, dst): dst_base = path.basename(dst) log.notice('Install: %s' % (dst_base)) adst = path.abspath(dst) log.output('Copy: text[%d] -> %s' % (len(text), adst)) log.output([' ] ' + l for l in text]) with open(adst, "w") as o: o.write(os.linesep.join(text))
def kernel_convert(self, image, kernel): dst = path.join(path.abspath(self['build']), path.basename(kernel)) self['kernel_build'] = dst log.output('Copy (into build): %s -> %s' % (kernel, dst)) image.clean_path(dst) path.copy(kernel, dst) cmds = self.filter_text(self.comma_split(self['kernel_converter'])) for cmd in cmds: _command(cmd, self['build']) return self['kernel_image'].replace('@KERNEL@', dst)
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 _link_executables(self): log.notice("Linking executables to " + self.traces_dir) for exe in self.executables: dst = path.join(self.traces_dir, path.basename(exe)) try: os.link(exe, dst) except OSError, e: log.stderr("creating hardlink from " + path.abspath(exe) + " to " + dst + " failed!") raise
def load_config(self, bootloader, config): super(uboot_bootloader, self).load_config(bootloader, config) if not self.convert_kernel: paths_count = len(self.uboot['paths']) if paths_count == 1: self.macros['ubootdir'] = path.abspath(self.uboot['paths'][0]) elif paths_count == 2: self.macros['first_stage'] = self.uboot['paths'][0] self.macros['second_stage'] = self.uboot['paths'][1] else: raise error.general('u-boot: invalid number of paths') self.macros['mkimage'] = 'mkimage'
def _command(cmd, cwd): e = execute.capture_execution() cwd = path.abspath(cwd) log.output('>> cwd: %s' % (cwd)) log.output('> %s' % (cmd)) exit_code, proc, output = e.shell(cmd, cwd=path.host(cwd)) output_split = output.split(os.linesep) if len(output_split) >= 1 and len(output_split[0]) > 0: log.output(['> ' + l for l in output_split]) log.output('> exit: %d' % (exit_code)) if exit_code != 0: err = 'executing failure: (exit:%d) %s' % (exit_code, cmd) raise error.general(err) return output
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 output(self, text): for l in text.splitlines(): if ' warning:' in l: self.count += 1 ws = l.split(' ') if len(ws) > 0: ws = ws[0].split(':') w = path.abspath(ws[0]) w = w.replace(self.rtems, '') if path.isabspath(w): w = w[1:] w = '%s:%s:%s' % (w, ws[1], ws[2]) if w not in self.warnings: self.warnings[w] = 0 self.warnings[w] += 1 log.output(text)
def _line_split(line, source_base): if line.count(':') < 2: return None ls = line.split(' ', 1) fname = ls[0].strip().split(':', 2) if len(fname) != 3: return None p = path.abspath(fname[0]) p = p.replace(source_base, '') if path.isabspath(p): p = p[1:] if len(fname[2]) == 0: pos = None else: pos = fname[2] return p, fname[1], pos, ls[1]
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 output(self, text): for l in text.splitlines(): if ' warning:' in l: self.count += 1 ws = l.split(' ') if len(ws) > 0: ws = ws[0].split(':') w = path.abspath(ws[0]) w = w.replace(self.rtems, '') if path.isabspath(w): w = w[1:] # # Ignore compiler option warnings. # if len(ws) >= 3: w = '%s:%s:%s' % (w, ws[1], ws[2]) if w not in self.warnings: self.warnings[w] = 0 self.warnings[w] += 1 log.output(text)
def __init__(self, p_macros, path_to_builddir): ''' Constructor ''' self.macros = p_macros self.target_dir = self.macros['_cwd'] self.test_dir = path.join(self.target_dir, 'test') 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.cfg') self.traces_dir = path.join(self.target_dir, 'coverage') self.config_map = self.macros.macros['coverage'] self.executables = None self.symbol_sets = [] self.path_to_builddir = path_to_builddir self.symbol_config = symbols_configuration() self.no_clean = int(self.macros['_no_clean']) self.report_format = self.config_map['report_format'][2]
def __init__(self, p_macros, path_to_builddir): ''' Constructor ''' self.macros = p_macros self.target_dir = self.macros['_cwd'] self.test_dir = path.join(self.target_dir, "test") 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.config") self.traces_dir = path.join(self.target_dir, 'coverage') self.config_map = self.macros.macros['coverage'] self.executables = None self.symbol_sets = [] self.path_to_builddir = path_to_builddir self.gcnos_file_path = path.join(self.coverage_config_path, "rtems.gcnos") self.no_clean = int(self.macros['_no_clean'])
def build(self): # # Cleanup if any goes wrong. # try: # # Ge the absolute paths to fixed locations. # output = path.abspath(self.loader['output']) build = path.abspath(self.loader['build']) mountpoint = path.join(build, 'mnt') # # Create any paths we need. They are removed when this object is # deleted. # self.create_path(build) # # If only coverting a kernel no need to create an image. # if not self.loader.convert_kernel: self.create_path(mountpoint) # # Create the blank image file. This is attached as a device, # partitioned, formatted and the files written to it. # log.notice('Create image: %s size %s' % (self.loader['output'], self.loader['image_size'])) self.image_create(output, self.loader['image_size']) # # Attach the image so it is a device. # log.notice('Attach image to device: %s' % (self.loader['output'])) device = self.image_attach(output) # # Partition the image. The device may change. # log.notice('Partition device: %s as %s' % (device, self.loader['part_type'])) device = self.partition(output, device, self.loader['part_type'], self.loader['part_label'], self.loader['fs_format'], self.loader['fs_size'], self.loader['fs_alignment']) part = self.device_partition(device, 1) # # Format the first partition. # log.notice('Format: %s as %s' % (part, self.loader['fs_format'])) self.format_partition(part, self.loader['fs_format'], self.loader['part_label']) # # Mount the file system. # log.notice('Mount: %s' % (part)) self.mount(self.loader['fs_format'], part, mountpoint) # # Install the first stage and second stage boot loaders. # self.install(self.loader['first_stage'], mountpoint) self.install(self.loader['second_stage'], mountpoint) # # Install the bootload files. # self.loader.install_files(self, mountpoint) if not self.loader.convert_kernel: # # Install the bootloader configuration. # self.loader.install_configuration(self, mountpoint) # # Install any user files if present. # for f in self.loader.files(): self.install(f, mountpoint) # # Done. # log.notice('Finished') finally: self.cleanup()
def abspath(self, rpath): return path.abspath(self.define(rpath))
def _lo_path(self, opt, macro, value): if value is None: raise error.general('option requires a path: %s' % (opt)) value = path.abspath(value) self.opts[opt[2:]] = value self.defaults[macro] = value
def load(self, name): def common_end(left, right): end = '' while len(left) and len(right): if left[-1] != right[-1]: return end end = left[-1] + end left = left[:-1] right = right[:-1] return end if self.load_depth == 0: self.in_error = False self.lc = 0 self.name = name self.conditionals = {} self.load_depth += 1 save_name = self.name save_lc = self.lc self.name = name self.lc = 0 # # Locate the config file. Expand any macros then add the # extension. Check if the file exists, therefore directly # referenced. If not see if the file contains ':' or the path # separator. If it does split the path else use the standard config dir # path in the defaults. # exname = self.expand(name) # # Macro could add an extension. # if exname.endswith('.cfg'): configname = exname else: configname = '%s.cfg' % (exname) name = '%s.cfg' % (name) if ':' in configname: cfgname = path.basename(configname) else: cfgname = common_end(configname, name) if not path.exists(configname): if ':' in configname: configdirs = path.dirname(configname).split(':') else: configdirs = self.define('_configdir').split(':') for cp in configdirs: configname = path.join(path.abspath(cp), cfgname) if path.exists(configname): break configname = None if configname is None: raise error.general('no config file found: %s' % (cfgname)) try: log.trace('config: %s: _open: %s' % (self.init_name, path.host(configname))) config = open(path.host(configname), 'r') except IOError as err: raise error.general('error opening config file: %s' % (path.host(configname))) self.configpath += [configname] self._includes += [configname] try: dir = None info = None data = [] while True: r = self._parse(config, dir, info) if r[0] == 'control': if r[1] == '%end': break log.warning("unexpected '%s'" % (r[1])) elif r[0] == 'directive': if r[1] == '%include': self.load(r[2][0]) continue dir, info, data = self._process_directive(r, dir, info, data) elif r[0] == 'data': dir, info, data = self._process_data(r, dir, info, data) else: self._error("%d: invalid parse state: '%s" % (self.lc, r[0])) if dir is not None: self._directive_extend(dir, data) except: config.close() raise config.close() self.name = save_name self.lc = save_lc self.load_depth -= 1