123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #! /usr/bin/env python
- # ------------------------------------------------
- # help
- # ------------------------------------------------
- """
- TTB - TM Test Bench
- Description
- Test bench to pevent ttb's (ticking time bombs) in the model.
- History
- 2010, Arjo Segers
- """
- # ------------------------------------------------
- # main
- # ------------------------------------------------
- if __name__ == "__main__" :
- # -----------------------------------------------
- # external
- # -----------------------------------------------
- # standard modules:
- import sys
- import os
- import logging
- import optparse
- import traceback
- import numpy
- # -----------------------------------------------
- # toolboxes
- # -----------------------------------------------
- import rc
- import ttb_restart
- import ttb_change
-
- # -----------------------------------------------
- # arguments
- # -----------------------------------------------
- # set text for 'usage' help line:
- usage = "%prog [OPTIONS] <rcfile>"
- # initialise the option parser:
- parser = optparse.OptionParser(usage=usage)
- # define options:
- parser.add_option( "-v", "--verbose",
- help="print extra logging messages to standard output",
- dest="verbose", action="store_true", default=False )
- parser.add_option( "-t", "--test-only",
- help="do not run model, only apply tests to output",
- dest="test_only", action="store_true", default=False )
- parser.add_option( "-n", "--new",
- help="new build",
- dest="build_new", action="store_true", default=False )
- parser.add_option( "-j", "--jobs",
- help="number of processes that could be used by make",
- dest="build_jobs", action="store", default='' )
- # now parse the actual arguments;
- # return an object 'opts' with fields 'verbose' etc,
- # and the unnamed arguments in the list 'args' :
- opts,args = parser.parse_args()
- # only one command ...
- if len(args) != 1 :
- if opts.verbose : logger.error( 'single argument rcfile should be specified, found : %i' % len(args) )
- parser.print_usage()
- sys.exit(1)
- #endif
- # extract ...
- rcfile = args[0]
- # -----------------------------------------------
- # logging
- # -----------------------------------------------
- # create logger
- logger = logging.getLogger('ttb')
- # log everything:
- logger.setLevel(logging.DEBUG)
-
- # standard format:
- #logformat = '%(filename)s:%(lineno)s - %(levelname)s - %(message)s'
- logformat = '[%(levelname)-8s] %(message)s'
- # create standard output handler:
- stdout_handler = logging.StreamHandler(sys.stdout)
- # set level to debug or info:
- logging_level = logging.INFO
- if opts.verbose : logging_level = logging.DEBUG
- stdout_handler.setLevel(logging_level)
- # set format:
- stdout_handler.setFormatter(logging.Formatter(logformat))
- # add:
- logger.addHandler(stdout_handler)
- # -----------------------------------------------
- # begin
- # -----------------------------------------------
- # info ...
- logger.info( '' )
- logger.info( 'TTB - TM Test Bench' )
- logger.info( '' )
-
- # open rcfile:
- rcf = rc.RcFile( rcfile )
-
- # replace options:
- if opts.test_only : rcf.replace( 'ttb.no-run', 'True' )
-
- # tests to be performed:
- tests = rcf.get( 'ttb.tests' ).split()
-
- # no failures yet ...
- failure = False
-
- # loop over tests:
- for test in tests :
-
- # call proper routine:
- if test == 'restart' :
-
- # restart test:
- try :
- ttb_restart.Test( rcf )
- except ValueError :
- sys.exit(1)
- except :
- for line in traceback.format_exc().split('\n') : logger.error(line)
- logger.error( 'received exception from test "%s" ...' % test )
- failure = True
- #endif
-
- elif test == 'change' :
-
- # restart test:
- try :
- ttb_change.Test( rcf, build_jobs=opts.build_jobs, build_new=opts.build_new )
- except ValueError :
- sys.exit(1)
- except :
- for line in traceback.format_exc().split('\n') : logger.error(line)
- logger.error( 'received exception from test "%s" ...' % test )
- failure = True
- #endif
-
- else :
-
- # unknown ...
- logger.error( 'unsupported test : %s' % test )
- sys.exit(1)
-
- #endif
-
- #endif
-
- # failed ?
- if failure :
- logger.error( 'Tests failed.' )
- sys.exit(1)
- #endif
- # info ...
- logger.info( '' )
- logger.info( 'end' )
- logger.info( '' )
-
- # ok:
- #sys.exit(0)
- #endif
- # ------------------------------------------------
- # end
- # ------------------------------------------------
|