def main(): options, args = parse_args() # Measure the total wall-time timer = Timer() # Load the configuration (from config.py file). config = Config(args) # Optionally import tests from the source tree. if options.do_import: import_main(config) # Parse the command line after the import to check the presence of the # selected inputs config.parse_args() # Initialize the working directory. work = Work(config) # Update the source code update_source(config) # Try to compile the program compile_program(config) # Create a test runner. It will produce a Makefile based on the #CPQA # directives in the test inputs. It runs the make file, logs some screen # output and collects all the test results in the attributes of the runner # object. runner = Runner(work) # Stop timer timer.stop() # Print a summary on screen log_txt(runner, timer, sys.stdout) # Create a text log file log_txt(runner, timer) # Create a html log file log_html(runner, timer)
def run_test(bin, mpi_prefix, test_input): dirname, fn_inp = os.path.split(test_input.path_inp) fn_out = os.path.basename(test_input.path_out) fn_stdout = os.path.basename(test_input.path_stdout) fn_stderr = os.path.basename(test_input.path_stderr) command = 'cd ./%s; %s %s -i %s -o %s > %s 2> %s' % ( dirname, mpi_prefix, bin, fn_inp, fn_out, fn_stdout, fn_stderr ) timer_bin = Timer() retcode = os.system(command) timer_bin.stop() return retcode, timer_bin
def main(): timer_all = Timer() # Get command line arguments bin, path_inp, refdir, mpi_prefix = parse_args() test_input = TestInput('./', path_inp) refdir = os.path.join('..', refdir) # Flags to display the status of the test. flags = {} # To record error messages of this script: messages = [] # Run test job retcode, timer_bin = run_test(bin, mpi_prefix, test_input) flags['failed'] = (retcode != 0) # Get the last 20 lines last_out_lines = tail(test_input.path_out) last_stdout_lines = tail(test_input.path_stdout) last_stderr_lines = tail(test_input.path_stderr) flags['verbose'] = len(last_stderr_lines) > 0 or len(last_stdout_lines) > 0 # Detect memory leaks in teh stderr flags['leak'] = find_mem_leaks(test_input.path_stderr) # Check on refdir flags['new'] = not os.path.isfile(os.path.join(refdir, test_input.path_pp)) # Extract the tests and count the number of resets if flags['new']: num_resets_ref = test_input.num_resets else: test_input_ref = TestInput(refdir, path_inp) num_resets_ref = test_input_ref.num_resets flags['reset'] = (test_input.num_resets > num_resets_ref) flags['error'] = False if test_input.num_resets < num_resets_ref: flags['error'] = True messages.append('Error: The number of reset directives decreased.') # Collect fragments from output for tests. flags['missing'] = False harvest_test(test_input, refdir, flags['new'], messages) # Do the actual tests. flags['wrong'] = False flags['different'] = False for test in test_input.tests: if not test.complete(flags['new']): flags['missing'] = True else: try: test.run(flags['new']) except Exception: messages.append(traceback.format_exc()) if test.wrong is True: flags['wrong'] = True if test.different is True: flags['different'] = True # Determine error flag flags['error'] = len(messages) > 0 # Determine the OK flag flags['ok'] = not (flags['wrong'] or (flags['different'] and not flags['reset']) or flags['missing'] or flags['failed'] or flags['error'] or flags['leak']) # Write the TestResult to a pickle file timer_all.stop() test_result = TestResult( path_inp, flags, timer_bin.seconds, timer_all.seconds, test_input.tests, messages, last_out_lines, last_stdout_lines, last_stderr_lines ) f = open(test_input.path_pp, 'w') cPickle.dump(test_result, f, -1) f.close() # Copy the tests to the reference directory if needed. if (flags['new'] or flags['reset']) and flags['ok']: dstdir = os.path.join(refdir, os.path.dirname(test_input.path_pp)) if not os.path.isdir(dstdir): os.makedirs(dstdir) shutil.copy(path_inp, dstdir) shutil.copy(test_input.path_out, dstdir) shutil.copy(test_input.path_pp, dstdir) shutil.copy(test_input.path_stderr, dstdir) shutil.copy(test_input.path_stdout, dstdir) # Print some screen output. print_log_line(path_inp, flags, timer_bin.seconds, timer_all.seconds)