def CheckGoldenOutput(stdout, stderr): for (stream, getter) in [ ('stdout', lambda: stdout), ('stderr', lambda: stderr), ('log', lambda: open(GlobalSettings['log_file']).read()), ]: golden = stream + '_golden' if GlobalSettings[golden]: golden_data = open(GlobalSettings[golden]).read() actual = getter() if GlobalSettings['filter_regex']: actual = test_lib.RegexpFilterLines( GlobalSettings['filter_regex'], GlobalSettings['filter_inverse'], GlobalSettings['filter_group_only'], actual) if DifferentFromGolden(actual, golden_data, stream): return False return True
def main(argv): global GlobalReportStream command = ProcessOptions(argv) if GlobalSettings['report']: GlobalReportStream.append(open(GlobalSettings['report'], 'w')) if not GlobalSettings['name']: GlobalSettings['name'] = command[0] if GlobalSettings['osenv']: Banner('setting environment') # BUG(robertm): , is a legitimate character for an environment variable # value. env = GlobalSettings['osenv'].split(',') for e in env: # = is valid in val of an env eq_pos = e.find('=') key = e[:eq_pos] val = e[eq_pos + 1:] Print('[%s] = [%s]' % (key, val)) os.putenv(key, val) if GlobalSettings['logout']: try: os.unlink(GlobalSettings['logout']) # might not pre-exist except OSError: pass stdin_data = '' if GlobalSettings['stdin']: stdin_data = open(GlobalSettings['stdin']) run_under = GlobalSettings['run_under'] if run_under: command = run_under.split(',') + command start_time = time.time() Banner('running %s' % str(command)) # print the command in copy-and-pastable fashion print " ".join(command) _, exit_status, failed, stdout, stderr = test_lib.RunTestWithInputOutput( command, stdin_data) total_time = time.time() - start_time if not ExitStatusIsOK(GlobalSettings['exit_status'], exit_status) or failed: if failed: Print('command failed') else: Print('command returned unexpected exit status %d' % exit_status) Banner('Stdout') Print(stdout) Banner('Stderr') Print(stderr) Print(FailureMessage()) return -1 if GlobalSettings['filter_validator']: stdout = test_lib.RegexpFilterLines(r'^(?!VALIDATOR)', stdout) for (stream, getter) in [ ('stdout', lambda: stdout), ('stderr', lambda: stderr), ('log', lambda: open(GlobalSettings['logout']).read()), ]: golden = stream + '_golden' if GlobalSettings[golden]: golden_data = open(GlobalSettings[golden]).read() filt = stream + '_filter' actual = getter() if GlobalSettings[filt]: actual = test_lib.RegexpFilterLines(GlobalSettings[filt], actual) if DifferentFromGolden(actual, golden_data, stream, FailureMessage()): return -1 Print('Test %s took %f secs' % (GlobalSettings['name'], total_time)) if GlobalSettings['time_error']: if total_time > GlobalSettings['time_error']: Print('ERROR: should have taken less than %f secs' % (GlobalSettings['time_error'])) Print(FailureMessage()) return -1 if GlobalSettings['time_warning']: if total_time > GlobalSettings['time_warning']: Print('WARNING: should have taken less than %f secs' % (GlobalSettings['time_warning'])) Print(SuccessMessage()) return 0