[496c607] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | """ |
---|
| 4 | @author: arnold |
---|
| 5 | |
---|
| 6 | Delia Arnold |
---|
| 7 | Arnold Scientific Consulting, Manresa, Spain. |
---|
| 8 | delia.arnold.consulting@gmail.com |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | This routine will go over a set of selected cases |
---|
| 12 | to ensure many of the functionalities of FLEXPART are working |
---|
| 13 | under certain conditions. |
---|
| 14 | |
---|
| 15 | It may include multiple species, fwd - bwd, depositing species, |
---|
| 16 | VTABLES and fp format |
---|
| 17 | |
---|
| 18 | """ |
---|
| 19 | |
---|
| 20 | # --- import needed modules ---- |
---|
| 21 | import argparse |
---|
| 22 | import os |
---|
| 23 | import sys |
---|
| 24 | import subprocess |
---|
| 25 | import time |
---|
| 26 | # ------------------------------ |
---|
| 27 | |
---|
| 28 | #import ur_config as urcf |
---|
| 29 | __all__ = [] |
---|
| 30 | __version__ = 0.1 |
---|
| 31 | __date__ = '2016-02-10' |
---|
| 32 | __updated__ = '2016-02-10' |
---|
| 33 | |
---|
| 34 | DEBUG = 1 # [ 0: None, 1: all ] |
---|
| 35 | ERR = "[ERROR] " |
---|
| 36 | INFO = "[INFO] " |
---|
| 37 | WRN = "[WARNING] " |
---|
| 38 | SPACES = " " |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | #--------- start of the main program ------------ |
---|
| 42 | |
---|
| 43 | def main(): |
---|
| 44 | |
---|
| 45 | # To keep track of failures and exceptions |
---|
| 46 | list_failing_cases = [] |
---|
| 47 | any_fails = 0 |
---|
| 48 | list_exceptions_cases = [] |
---|
| 49 | any_exceptions = 0 |
---|
| 50 | list_compiling_errors = [] |
---|
| 51 | any_failed_compile = 0 |
---|
| 52 | list_running_errors = [] |
---|
| 53 | any_failed_run = 0 |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | # Get the information from the command line: |
---|
| 57 | name_makefile_path = None # Initial value for the makefile from command line |
---|
| 58 | parser = argparse.ArgumentParser() |
---|
| 59 | parser.add_argument("-m", "--makefile", |
---|
| 60 | help="Full path to makefile", |
---|
| 61 | action="store", dest="cmdline_makefile_path") |
---|
| 62 | parser.add_argument("-f", "--filelist", |
---|
| 63 | help="file list of a name of xml cases", |
---|
| 64 | action="store", dest="cases_filelist") |
---|
| 65 | |
---|
| 66 | args = parser.parse_args() |
---|
| 67 | |
---|
| 68 | # Get the command line arguments after parsing. Some might be "None" |
---|
| 69 | cmdline_makefile_path = args.cmdline_makefile_path |
---|
| 70 | cases_filelist = args.cases_filelist |
---|
| 71 | |
---|
| 72 | # following the concept of check.py, if the path is not given |
---|
| 73 | # the ones specified in the xml files may be used - not yet implemented |
---|
| 74 | if cmdline_makefile_path == None: |
---|
| 75 | if DEBUG == 1: |
---|
| 76 | print INFO, ' the makefile pathname was not specified and the tests cannot be performed' |
---|
| 77 | print SPACES, 'please specifiy a pathname use the -m <path> option' |
---|
| 78 | sys.exit() |
---|
| 79 | if cases_filelist == None: |
---|
| 80 | if DEBUG == 1: |
---|
| 81 | print INFO, ' the file with the list of cases was not specified and the tests cannot be performed' |
---|
| 82 | print SPACES, 'please specifiy a pathname use the -f <filename> option' |
---|
| 83 | sys.exit() |
---|
| 84 | |
---|
| 85 | # Get the list of cases LIST_OF_XML_FILES from argument file: |
---|
| 86 | LIST_OF_XML_FILES = [] |
---|
| 87 | with open(cases_filelist) as f: |
---|
| 88 | LIST_OF_XML_FILES = f.read().splitlines() |
---|
| 89 | |
---|
| 90 | # START EXECUTING THE CASES |
---|
| 91 | if DEBUG == 1: |
---|
| 92 | print ' ' |
---|
| 93 | print INFO, ' The following cases will be executed: ' |
---|
| 94 | for items in LIST_OF_XML_FILES: |
---|
| 95 | print SPACES, ' -)' , items |
---|
| 96 | print INFO, ' Start execution of the test cases' |
---|
| 97 | print SPACES, ' ... the time invested on running' |
---|
| 98 | print SPACES, ' these tests is variable, from 2' |
---|
| 99 | print SPACES, ' minutes to 30 with all cases' |
---|
| 100 | print ' ----------------------------------\n' |
---|
| 101 | |
---|
| 102 | # for the list of xml files, check.py is executed with the makefile provided (if provided) |
---|
| 103 | |
---|
| 104 | # to get the time: |
---|
| 105 | start_time = time.time() |
---|
| 106 | |
---|
| 107 | for xml_case in LIST_OF_XML_FILES: |
---|
| 108 | print '\n EXECUTING TEST : ', xml_case, '\n' |
---|
| 109 | if cmdline_makefile_path != None: |
---|
[ac8f03a] | 110 | process=subprocess.Popen(['./check.py','-m', cmdline_makefile_path, xml_case ], |
---|
[496c607] | 111 | stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
---|
| 112 | # print the output of the process |
---|
| 113 | for line in process.stdout: |
---|
| 114 | if "Exception" in line: |
---|
| 115 | any_exceptions = 1 |
---|
| 116 | if "failed" in line: |
---|
| 117 | any_fails = 1 |
---|
| 118 | if "compile_success: False" in line: |
---|
| 119 | any_failed_compile = 1 |
---|
| 120 | if "run_success: False" in line: |
---|
| 121 | any_failed_run = 1 |
---|
| 122 | sys.stdout.write(line) |
---|
| 123 | for line in process.stderr: |
---|
| 124 | if "Exception" in line: |
---|
| 125 | any_exceptions = 1 |
---|
| 126 | if "failed" in line: |
---|
| 127 | any_fails = 1 |
---|
| 128 | if "compile_success: False" in line: |
---|
| 129 | any_failed_compile = 1 |
---|
| 130 | if "run_success: False" in line: |
---|
| 131 | any_failed_run = 1 |
---|
| 132 | sys.stderr.write(line) |
---|
| 133 | |
---|
| 134 | # using os.system it works and the stfout and stderr is output on the fly. |
---|
[ac8f03a] | 135 | #os.system('./check.py -m '+cmdline_makefile_path+' '+xml_case) |
---|
[496c607] | 136 | |
---|
[ac8f03a] | 137 | else: # I leave this ready in case check.py ever supports back to use a default makefile |
---|
[496c607] | 138 | print INFO, ' No path to makefile was specified, run again the script' |
---|
| 139 | print SPACES, ' with -m path/makefile option' |
---|
| 140 | |
---|
| 141 | if any_exceptions == 1: |
---|
| 142 | list_exceptions_cases.append(xml_case) |
---|
| 143 | if any_fails == 1: |
---|
| 144 | list_failing_cases.append(xml_case) |
---|
| 145 | if any_failed_run == 1: |
---|
| 146 | list_running_errors.append(xml_case) |
---|
| 147 | if any_failed_compile == 1: |
---|
| 148 | list_compiling_errors.append(xml_case) |
---|
| 149 | |
---|
| 150 | any_exceptions = 0 |
---|
| 151 | any_fails = 0 |
---|
| 152 | any_failed_compile = 0 |
---|
| 153 | any_failed_run = 0 |
---|
| 154 | |
---|
| 155 | print '\n ******************************************** \n' |
---|
| 156 | |
---|
| 157 | # to get the time |
---|
| 158 | stop_time = time.time() |
---|
| 159 | total_time = stop_time - start_time |
---|
| 160 | if DEBUG == 1: |
---|
| 161 | print INFO, ' -------------- SUMMARY-----------------' |
---|
| 162 | print INFO, ' Failing compilations: ', list_compiling_errors |
---|
| 163 | print INFO, ' Failing runs: ', list_running_errors |
---|
| 164 | print INFO, ' Failing cases: ', list_failing_cases |
---|
| 165 | print INFO, ' Cases raising exceptions: ', list_exceptions_cases |
---|
| 166 | |
---|
| 167 | if DEBUG == 1: |
---|
| 168 | print '\n' |
---|
| 169 | |
---|
| 170 | print INFO, ' Time invested in running the tests: ' |
---|
| 171 | print SPACES, total_time, ' seconds' |
---|
| 172 | |
---|
| 173 | #----------------------------------------------------------- |
---|
| 174 | |
---|
| 175 | if __name__ == "__main__": |
---|
| 176 | |
---|
| 177 | main() |
---|