def run(self): cmd = self.get_cmd() ret, out, err = ucmd.run_cmd(cmd) valid = ret == 0 output = FMT_OUTPUT.format(ret, out.decode('ascii'), err.decode('ascii')) expected = 'Status code: 0' err_short = '' err_long = '' if not valid: err_short = 'Command with non-0 status code' err_long = 'Expected status code of 0, got {}'.format(ret) ut = UTResult(name=self.name, cmd=' '.join(cmd), valid=valid, status=ret, output=output, expected=expected, err_short=err_short, err_long=err_long) self.ts.add_test(ut)
def _build_py(self, in_path, out_path): _, out, _ = ucmd.run_cmd(['python', in_path], stdin_path=self.stdin_path, exp0=True) return out
def _build_bin(self, in_path, out_path): _, out, _ = ucmd.run_cmd([in_path], stdin_path=self.stdin_path, exp0=True) return out
def build(self, in_path, out_path): cxx = conf.get('filebuilder-cxx') cxx_flags = conf.get('filebuilder-cxx-flags') ucmd.run_cmd([cxx, in_path, '-o', out_path] + cxx_flags, exp0=True)
def build(self, in_path, out_path): cc = conf.get('filebuilder-cc') cc_flags = conf.get('filebuilder-cc-flags') ucmd.run_cmd([cc, in_path, '-o', out_path] + cc_flags, exp0=True)
def run_one(self, input_name): dir_path = self.dir_path input_path = None if input_name is None else os.path.join( dir_path, input_name + '.input') self.conf['data_builder_stdin_path'] = input_path name = os.path.basename(dir_path)[6:] out_dir = os.path.join(self.out_dir, 'tmp', name) builder = FileBuilder(out_dir, [dir_path] + self.search_dirs, conf=self.conf) test_basename = 'test_{}'.format(name) ref_basename = 'ref_{}'.format( name) if input_name is None else 'ref_{}__in_{}'.format( name, input_name) name = name if input_name is None else '{}_in:{}'.format( name, input_name) test_bin = builder.build_type(test_basename, 'app') if test_bin is None: self._ts_err( "Failed to setup UnitTest: couldn't build binary for {}". format(name)) ref_out = builder.build_type(ref_basename, 'data') if ref_out is None: print(ref_basename) self._ts_err( "Failed to setup UnitTest: couldn't build ref output for {}". format(name)) test_ret, test_out, test_err = ucmd.run_cmd([test_bin], stdin_path=input_path) test_out_ca = test_out.decode('ascii', 'ignore') test_err_ca = test_err.decode('ascii', 'ignore') ref_out = ioutils.read_file_bin(ref_out) ref_out_ca = ref_out.decode('ascii', 'ignore') valid_out = test_out == ref_out valid = test_ret == 0 and valid_out output = FMT_OUTPUT.format(test_ret, test_out_ca, test_err_ca) expected = 'stdout:\n{}'.format(ref_out_ca) err_short = '' err_long = '' if not valid: if test_ret != 0: err_short = 'Expected status code 0, got {}'.format(ret) err_long += err_short + '\n' if not valid_out: err_short = 'Invalid stdout, differs from ref file.' err_long += 'Invalid stdout, differs from ref file:\n' + ( ' Ref: {} bytes\nTest: {} bytes'.format( len(ref_out), len(test_out))) ut = UTResult(name=name, cmd=(test_bin if input_path is None else '{} < {}'.format(test_bin, input_path)), valid=valid, status=test_ret, output=output, expected=expected, err_short=err_short, err_long=err_long) self.ts.add_test(ut)