source: flexpart.git/flexpart-testing/check/checknest.py.deprecated @ 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: 9.0 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 os
27import uuid
28import sys
29import shutil
30
31import distrotest.TestSuite as TS
32
33import flextest.FlexpartCase as FlexpartCase
34import flextest.FlexpartExecutable as Fexec
35import flextest.FlexpartErrors as FlexpartErrors
36import flextest.flexread.FlexpartOutput as FlexpartOutput
37import flextest.OutputCompare as OutputCompare
38
39
40# Bring in the XML filename from the command line
41if len(sys.argv) == 2:
42    xml_file = sys.argv[1]
43    XML_FILE = [xml_file]
44else:
45    print 'This program expects an XML filename as an argument...'
46    sys.exit()
47
48# Cleaning of temporary directories?
49clean_up = False
50
51
52# This is where lots of temporary directories are going to be created.
53# User needs to make sure it is OK to put them in here.  Note that there
54# is currently no clean up of these directories if a test fails. 
55# The logic is that users
56# might want to go back and look at the test directories, so auto-cleanup
57# prevents that.
58SCRATCH_DIR = '/tmp'
59
60
61t = TS.TestSuite(xml_files=XML_FILE)
62
63distro_list = t.get_distribution_list()
64
65the_distro = distro_list[0]
66
67print the_distro.get_descr()
68print the_distro.get_distro_path()
69print the_distro.get_makefile_path()
70print the_distro.get_parmod_path()
71
72# Create a temporary directory for compiling the distribution
73distro_destdir_name = SCRATCH_DIR + '/distrotest_' + str(uuid.uuid4()) 
74print 'distro_destdir_name: ' + distro_destdir_name
75
76
77good_init = False
78compile_success = False
79try:
80    srcdir = os.path.realpath(the_distro.get_distro_path())
81    makefile = os.path.realpath(the_distro.get_makefile_path())
82    parmodfile = os.path.realpath(the_distro.get_parmod_path())
83    exec_name = the_distro.get_exec_name()
84    exec_obj = Fexec.FlexpartExecutable(srcdir=srcdir,
85                                        destdir=distro_destdir_name,
86                                        makefile=makefile,
87                                        parmodfile=parmodfile,
88                                        executable_name=exec_name)
89    good_init = True
90except Exception as e:
91    print 'Bad instantiation: ' + str(e)
92    pass
93
94if good_init:
95    print 'Executable exists: ' + str(exec_obj.executable_exists())
96
97
98
99    # Try to compile it
100    print; print '============================'; print
101    print 'compile test...'
102    print 'Compile directory: ' + distro_destdir_name
103    compile_success = exec_obj.compile_it()
104   
105    print 'compile_success: ' + str(compile_success)
106    print 'Executable exists: ' + str(exec_obj.executable_exists())   
107   
108    if compile_success:
109        flexpart_executable = distro_destdir_name + '/' + exec_name       
110    else:
111        print 'compile test failed'
112        print 'The test distribution is located in: ' + distro_destdir_name
113        print 'The makefile being used is: ' + makefile
114        print 'You should try to go there and see if you can find error by compiling by hand'
115   
116    print; print '============================'; print
117
118# Next, get the met cases for this distro list and iterate through them
119
120if compile_success:
121
122#   We add a logical variable that will indicate us whether any
123#      of the tests failed and, if so, prevent the erasing of 
124#      the temporal directories
125    all_success = True   
126    list_all_cases = []
127   
128    met_case_list = the_distro.get_met_case_list()
129    print met_case_list
130    for the_met_case in met_case_list:
131       
132
133        print; print '****************************'
134        the_descr = the_met_case.get_descr()
135        print 'Running MetCase: ' + the_descr
136        the_metfile_dir = os.path.realpath(the_met_case.get_metfile_dir())
137        print 'Met file dir: ' + the_metfile_dir
138        try:                           
139            the_metnestfile_dir = os.path.realpath(the_met_case.get_metnestfile_dir())
140            print 'Met Nest file dir: ' + the_metnestfile_dir
141        except:
142            print ' ... no nested met input used'
143            the_metnestfile_dir = None 
144        print '****************************'; print
145       
146        # Iterate through each of the run cases in the met_case
147        run_case_list = the_met_case.get_run_case_list()
148       
149        for the_run_case in run_case_list:
150            the_descr = the_run_case.get_descr()
151            print 'Running RunCase: ' + the_descr
152           
153            case_dir = os.path.realpath(the_run_case.get_case_dir())
154            print 'Case dir: ' + case_dir
155            case_rundir = SCRATCH_DIR + '/caserun_' + str(uuid.uuid4())             
156            list_all_cases.append(case_rundir) # add the case_dir into a list for cleaning
157            control_data_dir = os.path.realpath(the_run_case.get_control_data_dir())
158           
159            basic_test_list = the_run_case.get_test_list()
160            run_success = False
161           
162            print; print '============================'
163            print 'Case Test ' + str(the_descr) + '...'
164            print 'Case template directory: ' + case_dir
165            print 'Case run directory: ' + case_rundir
166            print 'Control data directory: ' + control_data_dir
167            print 'Met file dir: ' + the_metfile_dir
168            if the_metnestfile_dir != None:
169                print 'Met Nest file dir: ' + the_metnestfile_dir
170            print 'Executable: ' + flexpart_executable
171            print 'Number of basic tests: ' + str(len(basic_test_list))
172            print '============================'; print
173           
174           
175            # Create the case object
176            case_obj = FlexpartCase.FlexpartCase(
177                             src_dir=case_dir,
178                             dest_dir=case_rundir,
179                             met_dir=the_metfile_dir,
180                             met_nest_dir=the_metnestfile_dir,
181                             flexpart_exe=flexpart_executable
182                                                 )
183       
184            # Run the case
185            run_val = case_obj.run()
186       
187            # Test for success
188            run_success = case_obj.success()
189            print 'run_success: ' + str(run_success)
190            print 'Execution time: %7.2E seconds' % \
191                  (case_obj.execution_time_seconds()) 
192            if not run_success:
193                all_success = False # to know wheter any of the tests failed
194                print 'run test failed'
195                print 'The test distribution is located in: ' + case_rundir
196                print 'The FLEXPART executable being used is: ' + flexpart_executable
197                print 'You should try to go there and see if you can find error by running by hand'
198                print 'There is a file named stdout.txt in there which might give a clue'
199       
200            print; print '============================'; print
201                   
202           
203       
204            if run_success:
205           
206           
207                output_compare = OutputCompare.OutputCompare(output_dir=case_rundir + '/output',
208                                                control_output_dir=control_data_dir)
209                                               
210                #print output_compare.query_test_types()
211
212
213                for the_basic_test in basic_test_list:
214                   
215                    the_descr = the_basic_test.get_descr()
216                    test_type = the_basic_test.get_test_type()
217                    threshold = the_basic_test.get_threshold()
218                   
219
220                    print; print '-----------------------'
221                    print 'Basic Test'
222                    print 'Description: ' + the_descr
223                    print 'Test type: ' + test_type
224                    print 'Threshold: %7.1E' % (threshold)
225
226                   
227                    the_error = output_compare.calculate_test_minus_control(test_type=test_type)
228                   
229                    print 'Test performed.  Error = %7.1E' % (the_error)
230                    if the_error > threshold:
231                        all_success = False
232                        print 'Test failed...'
233                        print '    Test data is in: ' + case_rundir + '/output'
234                        print '    Control data is in: ' + control_data_dir
235                    else:
236                        print 'Test passed'
237
238                    print '-----------------------'; print
239
240if clean_up:
241    if all_success:
242        print 'All tests passed, erasing temporary directories'
243        print distro_destdir_name
244        shutil.rmtree(distro_destdir_name)
245        for item in list_all_cases:
246            print item
247            shutil.rmtree(item)
248    else:
249        print 'Some of the tests failed, temp dirs not erased'
250        print ' WARNING: remember to remove directories manually'
251        print '          when you have finished checking them'           
252       
253       
254       
255       
256       
257   
258   
259   
260
261
262
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG