ttb 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #! /usr/bin/env python
  2. # ------------------------------------------------
  3. # help
  4. # ------------------------------------------------
  5. """
  6. TTB - TM Test Bench
  7. Description
  8. Test bench to pevent ttb's (ticking time bombs) in the model.
  9. History
  10. 2010, Arjo Segers
  11. """
  12. # ------------------------------------------------
  13. # main
  14. # ------------------------------------------------
  15. if __name__ == "__main__" :
  16. # -----------------------------------------------
  17. # external
  18. # -----------------------------------------------
  19. # standard modules:
  20. import sys
  21. import os
  22. import logging
  23. import optparse
  24. import traceback
  25. import numpy
  26. # -----------------------------------------------
  27. # toolboxes
  28. # -----------------------------------------------
  29. import rc
  30. import ttb_restart
  31. import ttb_change
  32. # -----------------------------------------------
  33. # arguments
  34. # -----------------------------------------------
  35. # set text for 'usage' help line:
  36. usage = "%prog [OPTIONS] <rcfile>"
  37. # initialise the option parser:
  38. parser = optparse.OptionParser(usage=usage)
  39. # define options:
  40. parser.add_option( "-v", "--verbose",
  41. help="print extra logging messages to standard output",
  42. dest="verbose", action="store_true", default=False )
  43. parser.add_option( "-t", "--test-only",
  44. help="do not run model, only apply tests to output",
  45. dest="test_only", action="store_true", default=False )
  46. parser.add_option( "-n", "--new",
  47. help="new build",
  48. dest="build_new", action="store_true", default=False )
  49. parser.add_option( "-j", "--jobs",
  50. help="number of processes that could be used by make",
  51. dest="build_jobs", action="store", default='' )
  52. # now parse the actual arguments;
  53. # return an object 'opts' with fields 'verbose' etc,
  54. # and the unnamed arguments in the list 'args' :
  55. opts,args = parser.parse_args()
  56. # only one command ...
  57. if len(args) != 1 :
  58. if opts.verbose : logger.error( 'single argument rcfile should be specified, found : %i' % len(args) )
  59. parser.print_usage()
  60. sys.exit(1)
  61. #endif
  62. # extract ...
  63. rcfile = args[0]
  64. # -----------------------------------------------
  65. # logging
  66. # -----------------------------------------------
  67. # create logger
  68. logger = logging.getLogger('ttb')
  69. # log everything:
  70. logger.setLevel(logging.DEBUG)
  71. # standard format:
  72. #logformat = '%(filename)s:%(lineno)s - %(levelname)s - %(message)s'
  73. logformat = '[%(levelname)-8s] %(message)s'
  74. # create standard output handler:
  75. stdout_handler = logging.StreamHandler(sys.stdout)
  76. # set level to debug or info:
  77. logging_level = logging.INFO
  78. if opts.verbose : logging_level = logging.DEBUG
  79. stdout_handler.setLevel(logging_level)
  80. # set format:
  81. stdout_handler.setFormatter(logging.Formatter(logformat))
  82. # add:
  83. logger.addHandler(stdout_handler)
  84. # -----------------------------------------------
  85. # begin
  86. # -----------------------------------------------
  87. # info ...
  88. logger.info( '' )
  89. logger.info( 'TTB - TM Test Bench' )
  90. logger.info( '' )
  91. # open rcfile:
  92. rcf = rc.RcFile( rcfile )
  93. # replace options:
  94. if opts.test_only : rcf.replace( 'ttb.no-run', 'True' )
  95. # tests to be performed:
  96. tests = rcf.get( 'ttb.tests' ).split()
  97. # no failures yet ...
  98. failure = False
  99. # loop over tests:
  100. for test in tests :
  101. # call proper routine:
  102. if test == 'restart' :
  103. # restart test:
  104. try :
  105. ttb_restart.Test( rcf )
  106. except ValueError :
  107. sys.exit(1)
  108. except :
  109. for line in traceback.format_exc().split('\n') : logger.error(line)
  110. logger.error( 'received exception from test "%s" ...' % test )
  111. failure = True
  112. #endif
  113. elif test == 'change' :
  114. # restart test:
  115. try :
  116. ttb_change.Test( rcf, build_jobs=opts.build_jobs, build_new=opts.build_new )
  117. except ValueError :
  118. sys.exit(1)
  119. except :
  120. for line in traceback.format_exc().split('\n') : logger.error(line)
  121. logger.error( 'received exception from test "%s" ...' % test )
  122. failure = True
  123. #endif
  124. else :
  125. # unknown ...
  126. logger.error( 'unsupported test : %s' % test )
  127. sys.exit(1)
  128. #endif
  129. #endif
  130. # failed ?
  131. if failure :
  132. logger.error( 'Tests failed.' )
  133. sys.exit(1)
  134. #endif
  135. # info ...
  136. logger.info( '' )
  137. logger.info( 'end' )
  138. logger.info( '' )
  139. # ok:
  140. #sys.exit(0)
  141. #endif
  142. # ------------------------------------------------
  143. # end
  144. # ------------------------------------------------