source: flexpart.git/flexpart-testing/check/check-v3.py @ 496c607

FPv9.3.1FPv9.3.1b_testingFPv9.3.2fp9.3.1-20161214-nc4grib2nc4_repair
Last change on this file since 496c607 was 496c607, checked in by Don Morton <Don.Morton@…>, 8 years ago

Initial commit of FPv9.3.1

Currently, this is a clone of snapshot FPv9.3.0

  • Property mode set to 100755
File size: 10.5 KB
Line 
1#!/usr/bin/env python
2
3"""
4@author: morton
5
6Don Morton
7Boreal Scientific Computing LLC, Fairbanks, Alaska, USA
8Don.Morton@borealscicomp.com
9http://www.borealscicomp.com/
10
11
12@contributors
13
14Christian Maurer
15ZAMG, Vienna, Austria
16christian.maurer@zamg.ac.at
17Delia Arnold
18ZAMG, Vienna, Austria
19delia.arnold-arias@zamg.ac.at
20
21"""
22
23
24
25#import tempfile
26import argparse
27import os
28import uuid
29import sys
30import shutil
31
32import distrotest.TestSuite as TS
33
34import flextest.FlexpartCase as FlexpartCase
35import flextest.FlexpartExecutable as Fexec
36import flextest.FlexpartErrors as FlexpartErrors
37import flextest.flexread.FlexpartOutput as FlexpartOutput
38import flextest.OutputCompare as OutputCompare
39
40# Set up for argument parsing
41
42# This used for checking presence of any files listed in arguments
43def is_valid_file(parser, arg):
44    if not os.path.exists(arg):
45        parser.error("File %s not found" % arg)
46    else:
47        return arg
48
49
50cmdline_makefile_path = None   # Initial value for the makefile from command line
51
52parser = argparse.ArgumentParser()
53
54parser.add_argument("xml_file", help="Full path to XML spec file",
55                    action="store")
56
57parser.add_argument("-m", "--makefile",
58                    help="Full path to makefile",
59                    action="store", dest="cmdline_makefile_path")
60
61parser.add_argument("-k", "--keeptemp",
62                    help="Keep temporary directories",
63                    action="store_true")
64
65args = parser.parse_args()
66
67#print 'args.xml_file: ', args.xml_file
68#print 'args.cmdline_makefile_path: ', args.cmdline_makefile_path
69
70# Get the command line arguments after parsing.  Some might be "None"
71xml_file = args.xml_file
72cmdline_makefile_path = args.cmdline_makefile_path
73
74# By default, temp directories will be cleaned up unless test fails.  We can choose
75# to keep these with the appropriate command-line flag -k or --keeptemp
76if args.keeptemp:
77    clean_up = False
78    print 'Will retain temporary directories'
79else:
80    clean_up = True
81    print 'Will delete temporary directories if test is successful'
82#sys.exit()
83
84# Bring in the XML filename from the command line
85
86XML_FILE = [xml_file]
87
88
89
90# This is where lots of temporary directories are going to be created.
91# User needs to make sure it is OK to put them in here.  Note that there
92# is currently no clean up of these directories if a test fails. 
93# The logic is that users
94# might want to go back and look at the test directories, so auto-cleanup
95# prevents that.
96SCRATCH_DIR = '/tmp'
97
98
99t = TS.TestSuite(xml_files=XML_FILE)
100
101distro_list = t.get_distribution_list()
102
103the_distro = distro_list[0]
104
105'''
106print the_distro.get_descr()
107print the_distro.get_distro_path()
108print the_distro.get_makefile_path()
109print the_distro.get_parmod_path()
110'''
111
112# Create a temporary directory for compiling the distribution
113distro_destdir_name = SCRATCH_DIR + '/distrotest_' + str(uuid.uuid4()) 
114print 'distro_destdir_name: ' + distro_destdir_name
115
116
117good_init = False
118compile_success = False
119all_success = False
120try:
121    srcdir = os.path.realpath(the_distro.get_distro_path())
122   
123    # The makefile path will come from command line, if available,
124    if cmdline_makefile_path:
125        makefile = cmdline_makefile_path
126    else:
127        print 'WARNING... makefile path not specified'
128
129    print 'using makefile: ' + str(makefile)
130   
131    parmodfile = os.path.realpath(the_distro.get_parmod_path())
132    exec_name = the_distro.get_exec_name()
133    exec_obj = Fexec.FlexpartExecutable(srcdir=srcdir,
134                                        destdir=distro_destdir_name,
135                                        makefile=makefile,
136                                        parmodfile=parmodfile,
137                                        executable_name=exec_name)
138    good_init = True
139except Exception as e:
140    print 'Bad instantiation: ' + str(e)
141    pass
142
143if good_init:
144    print 'Executable exists: ' + str(exec_obj.executable_exists())
145
146
147
148    # Try to compile it
149    print; print '============================'; print
150    print 'compile test...'
151    print 'Compile directory: ' + distro_destdir_name
152    compile_success = exec_obj.compile_it()
153   
154    print 'compile_success: ' + str(compile_success)
155    print 'Executable exists: ' + str(exec_obj.executable_exists())   
156   
157    if compile_success:
158        flexpart_executable = distro_destdir_name + '/' + exec_name       
159    else:
160        print
161        print '*** COMPILE TEST FAILED ***'
162        print
163        print 'If Executable exists is True, it is probably finding an old executable'
164        print 'The test distribution is located in: ' + distro_destdir_name
165        print 'The makefile being used is: ' + makefile
166        print 'You should try to go there and see if you can find error by compiling by hand'
167   
168    print; print '============================'; print
169
170# Next, get the met cases for this distro list and iterate through them
171
172if compile_success:
173
174#   We add a logical variable that will indicate us whether any
175#      of the tests failed and, if so, prevent the erasing of 
176#      the temporal directories
177    all_success = True   
178    list_all_cases = []
179   
180    met_case_list = the_distro.get_met_case_list()
181    print met_case_list
182    for the_met_case in met_case_list:
183       
184
185        print; print '****************************'
186        the_descr = the_met_case.get_descr()
187        print 'Running MetCase: ' + the_descr
188        the_metfile_dir = os.path.realpath(the_met_case.get_metfile_dir())
189        print 'Met file dir: ' + the_metfile_dir
190        try:
191            the_metnestfile_dir = os.path.realpath(the_met_case.get_metnestfile_dir())
192            print 'Met Nest file dir: ' + the_metnestfile_dir
193        except:
194            #print ' ... no nested met input used'
195            the_metnestfile_dir = None
196
197        print '****************************'; print
198       
199        # Iterate through each of the run cases in the met_case
200        run_case_list = the_met_case.get_run_case_list()
201       
202        for the_run_case in run_case_list:
203            the_descr = the_run_case.get_descr()
204            print 'Running RunCase: ' + the_descr
205           
206            case_dir = os.path.realpath(the_run_case.get_case_dir())
207            print 'Case dir: ' + case_dir
208            case_rundir = SCRATCH_DIR + '/caserun_' + str(uuid.uuid4())             
209            list_all_cases.append(case_rundir) # add the case_dir into a list for cleaning
210            control_data_dir = os.path.realpath(the_run_case.get_control_data_dir())
211           
212            basic_test_list = the_run_case.get_test_list()
213            run_success = False
214           
215            print; print '============================'
216            print 'Case Test ' + str(the_descr) + '...'
217            print 'Case template directory: ' + case_dir
218            print 'Case run directory: ' + case_rundir
219            print 'Control data directory: ' + control_data_dir
220            print 'Met file dir: ' + the_metfile_dir
221            if the_metnestfile_dir:
222                print 'Met Nest file dir: ' + the_metnestfile_dir
223            print 'Executable: ' + flexpart_executable
224            print 'Number of basic tests: ' + str(len(basic_test_list))
225            print '============================'; print
226           
227           
228            # Create the case object
229            case_obj = FlexpartCase.FlexpartCase(
230                             src_dir=case_dir,
231                             dest_dir=case_rundir,
232                             met_dir=the_metfile_dir,
233                             met_nest_dir=the_metnestfile_dir,
234                             flexpart_exe=flexpart_executable
235                                                 )
236       
237            # Run the case
238            run_val = case_obj.run()
239       
240            # Test for success
241            run_success = case_obj.success()
242            print 'run_success: ' + str(run_success)
243            print 'Execution time: %7.2E seconds' % \
244                  (case_obj.execution_time_seconds()) 
245            if not run_success:
246                all_success = False # to know wheter any of the tests failed
247                print 'run test failed'
248                print 'The test distribution is located in: ' + case_rundir
249                print 'The FLEXPART executable being used is: ' + flexpart_executable
250                print 'You should try to go there and see if you can find error by running by hand'
251                print 'There is a file named stdout.txt in there which might give a clue'
252       
253            print; print '============================'; print
254                   
255           
256       
257            if run_success:
258           
259           
260                output_compare = OutputCompare.OutputCompare(output_dir=case_rundir + '/output',
261                                                control_output_dir=control_data_dir)
262                                               
263                #print output_compare.query_test_types()
264
265
266                for the_basic_test in basic_test_list:
267                   
268                    the_descr = the_basic_test.get_descr()
269                    test_type = the_basic_test.get_test_type()
270                    threshold = the_basic_test.get_threshold()
271                   
272
273                    print; print '-----------------------'
274                    print 'Basic Test'
275                    print 'Description: ' + the_descr
276                    print 'Test type: ' + test_type
277                    print 'Threshold: %7.1E' % (threshold)
278
279                   
280                    the_error = output_compare.calculate_test_minus_control(test_type=test_type)
281                   
282                    print 'Test performed.  Error = %7.1E' % (the_error)
283                    if the_error > threshold:
284                        all_success = False
285                        print 'Test failed...'
286                        print '    Test data is in: ' + case_rundir + '/output'
287                        print '    Control data is in: ' + control_data_dir
288                    else:
289                        print 'Test passed'
290
291                    print '-----------------------'; print
292
293if clean_up:
294    if all_success:
295        print 'All tests passed, erasing temporary directories'
296        print distro_destdir_name
297        shutil.rmtree(distro_destdir_name)
298        for item in list_all_cases:
299            print item
300            shutil.rmtree(item)
301    else:
302        print 'Some of the tests failed, temp dirs not erased'
303        print ' WARNING: remember to remove directories manually'
304        print '          when you have finished checking them'           
305       
306       
307       
308       
309       
310   
311   
312   
313
314
315
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG