예제 #1
0
def output_to_json(test: str, output: RunnerOutput,
                   benchmark: bool) -> Dict[str, str]:
    result = {
        'name': test,
        'test': open(test, 'r').read(),
        'success': output.is_success(),
    }
    if output.is_success():
        result['time'] = output.time
        result['errors'] = output.errors
        if output.errors:
            result['input'] = output.input_data
            result['output'] = output.output_data
            result['output_errors'] = output.output_errors
        if benchmark:
            result['statistics'] = output.statistics
    else:
        result['timed_out'] = output.is_timed_out()
    if isinstance(output, AsanRunnerOutput):
        result['asanoutput'] = output.asanoutput
    if isinstance(output, MemcheckRunnerOutput):
        result['memcheckoutput'] = output.memcheckoutput
    if isinstance(output, NvprofRunnerOutput):
        result['nvprof'] = output.nvprof
    return result
예제 #2
0
        def test(self, test: str, output: RunnerOutput):
            if not self.header_printed:
                self.header_printed = True
                self.reporter.log(
                    f'{"test":<{self.test_name_width}}  {"time":>9}  {"result":6}',
                    'heading')
            if output.is_success():
                msg = "errors" if output.errors else "pass"
                self.reporter.log(
                    f'{self._simplify_name(test):<{self.test_name_width}}  {output.time:>8.3f}s  {msg:6}',
                    'error' if output.errors else 'pass')
            else:
                self.reporter.log(
                    f'{self._simplify_name(test):<{self.test_name_width}}  [failed]',
                    'error')

            if output.stdout:
                self.reporter.log_sep()
                self.reporter.log('Standard output:')
                self.reporter.log(output.stdout, 'output')
                self.reporter.log_sep()

            if output.stderr:
                self.reporter.log_sep()
                self.reporter.log('Standard error:')
                self.reporter.log(output.stderr, 'output')
                self.reporter.log_sep()

            if not output.is_success():
                self.reporter.log_sep()
                if output.is_timed_out():
                    self.reporter.log('It seems that your program timed out.')
                    self.reporter.log(
                        f'The test should have ran in less than {output.timeout} seconds.'
                    )
                    self.reporter.log(
                        'You can override allowed running time with --timeout [timeout in seconds]'
                    )
                else:
                    self.reporter.log(
                        'It seems that your program crashed unexpectedly.')
                self.reporter.log_sep()

            if isinstance(output, AsanRunnerOutput) and output.asanoutput:
                self.reporter.log_sep()
                self.reporter.log(
                    'AddressSanitizer reported the following errors:')
                self.reporter.log(output.asanoutput, 'output')
                self.reporter.log_sep()

            if isinstance(output,
                          MemcheckRunnerOutput) and output.memcheckoutput:
                self.reporter.log_sep()
                self.reporter.log('Memcheck reported the following errors:')
                self.reporter.log(output.memcheckoutput, 'output')
                self.reporter.log_sep()

            if output.errors and not self.reporter.config.ignore_errors:
                human_readable = self.reporter.config.explain_terminal(
                    output, self.reporter.color)
                if human_readable is not None:
                    self.reporter.log_sep()
                    self.reporter.log(human_readable, 'preformatted')
                    self.reporter.log_sep()