[d69b677] | 1 | #!/usr/bin/env python |
---|
[991df6a] | 2 | # -*- coding: utf-8 -*- |
---|
| 3 | #************************************************************************ |
---|
| 4 | # TODO AP |
---|
| 5 | # |
---|
| 6 | # - provide more tests |
---|
| 7 | # - provide more documentation |
---|
| 8 | # - |
---|
| 9 | #************************************************************************ |
---|
[d69b677] | 10 | |
---|
[991df6a] | 11 | #******************************************************************************* |
---|
| 12 | # @Author: Leopold Haimberger (University of Vienna) |
---|
| 13 | # |
---|
| 14 | # @Date: December 2015 |
---|
| 15 | # |
---|
| 16 | # @Change History: |
---|
| 17 | # |
---|
| 18 | # February 2018 - Anne Philipp (University of Vienna): |
---|
| 19 | # - applied PEP8 style guide |
---|
| 20 | # - added documentation |
---|
[64cf353] | 21 | # |
---|
[991df6a] | 22 | # @License: |
---|
| 23 | # (C) Copyright 2015-2018. |
---|
[d69b677] | 24 | # |
---|
[991df6a] | 25 | # This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
| 26 | # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
[64cf353] | 27 | # |
---|
[991df6a] | 28 | # @Program Functionality: |
---|
| 29 | # This script triggers the ECMWFDATA test suite. Call with |
---|
| 30 | # testsuite.py [test group] |
---|
[d69b677] | 31 | # |
---|
[991df6a] | 32 | # @Program Content: |
---|
[64cf353] | 33 | # |
---|
[991df6a] | 34 | #******************************************************************************* |
---|
[d69b677] | 35 | |
---|
[991df6a] | 36 | # ------------------------------------------------------------------------------ |
---|
| 37 | # MODULES |
---|
| 38 | # ------------------------------------------------------------------------------ |
---|
| 39 | import os |
---|
| 40 | import sys |
---|
[d69b677] | 41 | import json |
---|
| 42 | import subprocess |
---|
[64cf353] | 43 | |
---|
[991df6a] | 44 | # ------------------------------------------------------------------------------ |
---|
| 45 | # PROGRAM |
---|
| 46 | # ------------------------------------------------------------------------------ |
---|
[d69b677] | 47 | try: |
---|
[991df6a] | 48 | taskfile = open('testsuite.json') |
---|
[d69b677] | 49 | except: |
---|
| 50 | print 'could not open suite definition file testsuite.json' |
---|
| 51 | exit() |
---|
| 52 | |
---|
| 53 | if not os.path.isfile('../src/CONVERT2'): |
---|
| 54 | print '../src/CONVERT2 could not be found' |
---|
| 55 | print 'please run "install.py --target=local" first' |
---|
| 56 | exit() |
---|
| 57 | |
---|
[991df6a] | 58 | fprs = os.getenv('FLEXPART_ROOT_SCRIPTS') |
---|
[d69b677] | 59 | if fprs is None: |
---|
| 60 | print 'FLEXPART_ROOT_SCRIPTS not set .. some test jobs may fail' |
---|
| 61 | |
---|
[991df6a] | 62 | tasks = json.load(taskfile, encoding='latin-1') |
---|
[d69b677] | 63 | taskfile.close() |
---|
| 64 | if not os.path.exists('../test'): |
---|
| 65 | os.makedirs('../test') |
---|
[991df6a] | 66 | if len(sys.argv) > 1: |
---|
| 67 | groups = sys.argv[1:] |
---|
[d69b677] | 68 | else: |
---|
[991df6a] | 69 | groups = ['xinstall', 'default', 'ops', 'work', 'cv', 'fc']#,'hires'] |
---|
| 70 | jobcounter = 0 |
---|
| 71 | jobfailed = 0 |
---|
[d69b677] | 72 | for g in groups: |
---|
| 73 | try: |
---|
[991df6a] | 74 | tk, tv = g, tasks[g] |
---|
[d69b677] | 75 | except: |
---|
| 76 | continue |
---|
[991df6a] | 77 | garglist = [] |
---|
| 78 | for ttk, ttv in tv.iteritems(): |
---|
| 79 | if isinstance(ttv, basestring): |
---|
| 80 | if ttk != 'script': |
---|
| 81 | garglist.append('--' + ttk) |
---|
| 82 | if '$' == ttv[0]: |
---|
[d69b677] | 83 | garglist.append(os.path.expandvars(ttv)) |
---|
| 84 | else: |
---|
| 85 | garglist.append(ttv) |
---|
[991df6a] | 86 | for ttk, ttv in tv.iteritems(): |
---|
| 87 | if isinstance(ttv, dict): |
---|
| 88 | arglist = [] |
---|
| 89 | for tttk, tttv in ttv.iteritems(): |
---|
| 90 | if isinstance(tttv, basestring): |
---|
| 91 | arglist.append('--' + tttk) |
---|
[d69b677] | 92 | if '$' in tttv[0]: |
---|
[64cf353] | 93 | arglist.append(os.path.expandvars(tttv)) |
---|
[d69b677] | 94 | else: |
---|
| 95 | arglist.append(tttv) |
---|
[991df6a] | 96 | print 'Command: ', ' '.join([tv['script']] + garglist + arglist) |
---|
| 97 | o = '../test/' + tk + '_' + ttk + '_' + '_'.join(ttv.keys()) |
---|
| 98 | print 'Output will be sent to ', o |
---|
| 99 | f = open(o, 'w') |
---|
[d69b677] | 100 | try: |
---|
[991df6a] | 101 | p = subprocess.check_call([tv['script']] + garglist + arglist, |
---|
| 102 | stdout=f, stderr=f) |
---|
[d69b677] | 103 | except: |
---|
| 104 | f.write('\nFAILED\n') |
---|
| 105 | print 'FAILED' |
---|
[991df6a] | 106 | jobfailed += 1 |
---|
| 107 | jobcounter += 1 |
---|
[d69b677] | 108 | f.close() |
---|
| 109 | |
---|
| 110 | print 'Test suite tasks completed' |
---|
[991df6a] | 111 | print str(jobcounter-jobfailed) + ' successful, ' + str(jobfailed) + ' failed' |
---|
[d69b677] | 112 | print 'If tasks have been submitted via ECACCESS please check emails' |
---|
[64cf353] | 113 | |
---|
[d69b677] | 114 | #print tasks |
---|