def run(self, previous_values, slot): # Check whether the test should be skipped skip = self.should_skip() if skip is not None: self.result.set_status(skip) self.push_result() return False # If there's a test.cmd, execute it with the shell; # otherwise execute test.py. wd = self.test_env['working_dir'] base = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) # In the development environment, run the development GPS, # otherwise use the GPS found on the PATH devel_gps = os.path.join(base, "gnatstudio", "obj", "gnatstudio") if os.path.exists(devel_gps): the_gps = devel_gps else: the_gps = "gnatstudio" test_cmd = os.path.join(wd, 'test.cmd') if os.path.exists(test_cmd): cmd_line = ['bash', test_cmd] else: cmd_line = [the_gps, "--load={}".format('test.py')] env = {'GNATSTUDIO_HOME': self.test_env['working_dir'], 'GNATINSPECT': shutil.which("gnatinspect") + " --exit", 'GNATSTUDIO': the_gps, 'GPS': the_gps} env.update(Xvfbs.get_env(slot)) # TODO: add support for valgrind process = Run( cmd_line, cwd=wd, timeout=None if 'GPS_PREVENT_EXIT' in os.environ else 120, env=env, ignore_environ=False) output = process.out if output: # If there's an output, capture it self.result.out = output is_error = False if process.status: # Nonzero status? if process.status == 100: # This one is an xfail self.result.set_status(TestStatus.XFAIL) elif process.status == 99: # This is intentionally deactivated in this configuration self.result.set_status(TestStatus.SKIP) else: # Unknown status! self.result.set_status(TestStatus.ERROR) is_error = True else: # Status is 0... if output: # ... and there is an output: compare it to test.out # if it exists test_out = os.path.join(wd, 'test.out') if os.path.exists(test_out): with open(test_out, 'r') as f: expected = f.read() res = "\n".join(difflib.unified_diff(expected.splitlines(), output.splitlines())) if res == '': self.result.set_status(TestStatus.PASS) else: self.result.out = res self.result.set_status(TestStatus.FAIL) is_error = True else: # ... if there's no test.out, that's a FAIL self.result.set_status(TestStatus.FAIL) is_error = True else: # ... and no output: that's a PASS self.result.set_status(TestStatus.PASS) if is_error: if self.result.out is None: self.result.out = self._capture_for_developers() else: self.result.out += self._capture_for_developers() self.push_result()
import os import sys from e3.os.process import Run from testsuite_support.builder_and_runner import BuilderAndRunner, GPRINSTALL bnr = BuilderAndRunner() p = Run(['gprbuild', '-p', 'mylib/mylib.gpr']) p = bnr.run([ GPRINSTALL, '-p', '--prefix=' + os.path.join(os.getcwd(), 'inst'), 'mylib/mylib.gpr' ]) p = Run(['gprbuild', '-p', '-f', '--src-subdirs=instr', 'mylib/mylib.gpr']) p = bnr.run([ GPRINSTALL, '-p', '--prefix=' + os.path.join(os.getcwd(), 'inst'), '--sources-subdir=include/mylib/instr', '--src-subdirs=instr', '--build-name=instr', 'mylib/mylib.gpr' ]) if os.path.exists('inst/include/mylib/counters.adb'): print("OK counters.adb") else: print("NOK counters.adb") if os.path.exists('inst/include/mylib/instr/counters.adb'): print("OK instrumented counters.adb") else:
def cleanup(self, project): """Cleanup possible remnants of previous builds.""" Run([GPRCLEAN, "-P%s" % project] + self.gprconfoptions + self.gprvaroptions) rm('*.xcov') rm('*.bin')
import os from e3.os.process import Run OK = True # build 'p' project Run(['gprbuild', '-p', '-q', '-aPmylib', '-Pmain/main.gpr'], output='run.out') for line in open("run.out"): OK = False print('1:' + line) Run(['gprbuild', '-p', '-q', '-Pmylib/mylib.gpr'], output='run.out') for line in open("run.out"): OK = False print('2:' + line) Run([ 'gpr2install', '-p', '-q', '-Pmylib/mylib.gpr', '--prefix=' + os.path.join(os.getcwd(), 'install') ], output='run.out') for line in open("run.out"): OK = False print('3:' + line) Run(['gprbuild', '-p', '-q', '-aPinstall/share/gpr', '-Pmain/main.gpr'], output='run.out')
def run(self, **kwargs): """Run GNAThub with the appropriate command line. :param kwargs: Keyword arguments that translate into command line switches :type kwargs: dict[str,*] | None """ argv = ['gnathub', '-P', self.project.name] if kwargs.get('quiet', True): argv.append('--quiet') if kwargs.get('verbose', False): argv.append('--verbose') if kwargs.get('incremental', False): argv.append('--incremental') if kwargs.get('gnatcheck_hide_exempted', False): argv.append('--gnatcheck-hide-exempted') if kwargs.get('dry_run', False): argv.append('--dry-run') if kwargs.get('runners_only', False): argv.append('--runners-only') if kwargs.get('reporters_only', False): argv.append('--reporters-only') if kwargs.get('scenario_vars', None): scenario = kwargs['scenario_vars'] assert isinstance(scenario, dict), 'invalid "scenario_vars" arg' argv.extend(['-X%s=%s' % (k, v) for k, v in scenario.items()]) if kwargs.get('plugins', None): assert isinstance(kwargs['plugins'], list), 'invalid "plugins" arg' argv.extend(['--plugins', ','.join(kwargs['plugins'])]) if kwargs.get('subdirs', None): argv.extend(['--subdirs', kwargs['subdirs']]) if kwargs.get('target', None): argv.extend(['--target', kwargs['target']]) if kwargs.get('runtime', None): argv.extend(['--RTS', kwargs['runtime']]) for tool_name, arguments in kwargs.get('tool_args', {}).items(): argv.append('--targs:%s' % tool_name) argv.extend(arguments) argv.append('--') if kwargs.get('script', None): argv.append('--exec') if isinstance(kwargs['script'], str): argv.append(os.path.abspath(kwargs['script'])) elif isinstance(kwargs['script'], Script): argv.append(kwargs['script'].path) else: raise TypeError('expected str or support.Script') # Add the local bin directory to the path to use mocks if any BaseEnv().add_path(self._bin) run_kwargs = { 'output': kwargs.get('output', PIPE), 'error': kwargs.get('error', STDOUT), 'timeout': kwargs.get('timeout', None), 'env': kwargs.get('env', None) } p = Run(argv, cwd=self.project.install_dir, **run_kwargs) if p.status != 0: raise GNAThubExecutionFailed(p.out) if kwargs.get('dry_run', False): # In dry-run mode, the gnathub.backlog file is not created return backlog = os.path.join( self.project.install_dir, 'obj', 'gnathub', 'gnathub.backlog') if not os.path.exists(backlog): # when the object directory is the same as the project dir backlog = os.path.join( self.project.install_dir, 'gnathub', 'gnathub.backlog') with open(backlog, 'r') as fd: plugins = json.loads(fd.read()) failed = [name for name, results in plugins if not results['success']] if failed: raise GNAThubExecutionFailed( 'plugin(s) failure: {}: {}'.format(failed, p.out))