[d69b677] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | # This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
| 4 | # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
| 5 | # |
---|
| 6 | # Leopold Haimberger, Dec 2015 |
---|
| 7 | # |
---|
| 8 | # Functionality provided: This script triggers the ECMWFDATA test suite. Call with |
---|
| 9 | # testsuite.py [test group] |
---|
| 10 | # |
---|
| 11 | # |
---|
| 12 | # Further documentation may be obtained from www.flexpart.eu |
---|
| 13 | # |
---|
| 14 | # Test groups are specified in testsuite.json |
---|
| 15 | # in addition to a standard python 2.6 or 2.7 installation the following packages need to be installed |
---|
| 16 | # ECMWF WebMARS, gribAPI with python enabled, emoslib, ecaccess web toolkit, all available from https://software.ecmwf.int/ |
---|
| 17 | # dateutils |
---|
| 18 | # matplotlib (optional, for debugging) |
---|
| 19 | |
---|
| 20 | import os,sys |
---|
| 21 | import json |
---|
| 22 | import subprocess |
---|
| 23 | try: |
---|
| 24 | taskfile=open('testsuite.json') |
---|
| 25 | except: |
---|
| 26 | print 'could not open suite definition file testsuite.json' |
---|
| 27 | exit() |
---|
| 28 | |
---|
| 29 | if not os.path.isfile('../src/CONVERT2'): |
---|
| 30 | print '../src/CONVERT2 could not be found' |
---|
| 31 | print 'please run "install.py --target=local" first' |
---|
| 32 | exit() |
---|
| 33 | |
---|
| 34 | fprs=os.getenv('FLEXPART_ROOT_SCRIPTS') |
---|
| 35 | if fprs is None: |
---|
| 36 | print 'FLEXPART_ROOT_SCRIPTS not set .. some test jobs may fail' |
---|
| 37 | |
---|
| 38 | tasks=json.load(taskfile,encoding='latin-1') |
---|
| 39 | taskfile.close() |
---|
| 40 | if not os.path.exists('../test'): |
---|
| 41 | os.makedirs('../test') |
---|
| 42 | if len(sys.argv)>1: |
---|
| 43 | groups=sys.argv[1:] |
---|
| 44 | else: |
---|
| 45 | groups=['xinstall','default','ops','work','cv','fc']#,'hires'] |
---|
| 46 | jobcounter=0 |
---|
| 47 | jobfailed=0 |
---|
| 48 | for g in groups: |
---|
| 49 | try: |
---|
| 50 | tk,tv=g,tasks[g] |
---|
| 51 | except: |
---|
| 52 | continue |
---|
| 53 | garglist=[] |
---|
| 54 | for ttk,ttv in tv.iteritems(): |
---|
| 55 | if isinstance(ttv,basestring): |
---|
| 56 | if ttk!='script': |
---|
| 57 | garglist.append('--'+ttk) |
---|
| 58 | if '$'==ttv[0]: |
---|
| 59 | garglist.append(os.path.expandvars(ttv)) |
---|
| 60 | else: |
---|
| 61 | garglist.append(ttv) |
---|
| 62 | for ttk,ttv in tv.iteritems(): |
---|
| 63 | if isinstance(ttv,dict): |
---|
| 64 | arglist=[] |
---|
| 65 | for tttk,tttv in ttv.iteritems(): |
---|
| 66 | if isinstance(tttv,basestring): |
---|
| 67 | arglist.append('--'+tttk) |
---|
| 68 | if '$' in tttv[0]: |
---|
| 69 | arglist.append(os.path.expandvars(tttv)) |
---|
| 70 | else: |
---|
| 71 | arglist.append(tttv) |
---|
| 72 | print 'Command: ',' '.join([tv['script']]+garglist+arglist) |
---|
| 73 | o='../test/'+tk+'_'+ttk+'_'+'_'.join(ttv.keys()) |
---|
| 74 | print 'Output will be sent to ',o |
---|
| 75 | f=open(o,'w') |
---|
| 76 | try: |
---|
| 77 | p=subprocess.check_call([tv['script']]+garglist+arglist,stdout=f,stderr=f) |
---|
| 78 | except: |
---|
| 79 | f.write('\nFAILED\n') |
---|
| 80 | print 'FAILED' |
---|
| 81 | jobfailed+=1 |
---|
| 82 | jobcounter+=1 |
---|
| 83 | f.close() |
---|
| 84 | |
---|
| 85 | print 'Test suite tasks completed' |
---|
| 86 | print str(jobcounter-jobfailed)+' successful, '+str(jobfailed)+' failed' |
---|
| 87 | print 'If tasks have been submitted via ECACCESS please check emails' |
---|
| 88 | |
---|
| 89 | #print tasks |
---|