test_tm6.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /usr/bin/env python
  2. import sys
  3. import re
  4. import subprocess
  5. import optparse
  6. import tm5_test
  7. import pdb
  8. def main():
  9. """
  10. TM6 testing suite
  11. (1) create a tm5.rc from tm6.rc
  12. (2) compare TM6 with TM5
  13. (3) compare TM6 with 1, 4, and 10 processors [commented]
  14. (4) compare TM6 with extra restart [commented]
  15. Call:
  16. > test_tm6.py [-n] [-q]
  17. then tear the test down :
  18. > test_tm6.py -t
  19. There is two steps, because you may want to look at the models outputs
  20. before cleaning up (eg when a test is not successful).
  21. """
  22. p = optparse.OptionParser()
  23. p.add_option("-t", "--teardown", action="store_true", dest="teardown",
  24. help="cleanup test: remove restart and files in rundir")
  25. p.add_option("-n", "--new", action="store_true", dest="new",
  26. help="recompile everything fresh (a la realclean)")
  27. p.add_option("-q", "--queue", action="store_true", dest="queue",
  28. help="submit jobs to queue instead of foreground")
  29. options, args = p.parse_args()
  30. # 1st create a tm5.rc from tm6.rc
  31. #---------------------------------
  32. # to replace:
  33. tm6str=('my.source.CHEM : proj/chem/base/${my.tm6branch}',
  34. 'my.source.BASE : base/${my.branch} base/${my.tm6branch}',
  35. 'my.project.dir : ${my.scratch}/TM5/tm6',
  36. 'my.defs_chem : ')
  37. # with:
  38. tm5str=('my.source.CHEM : proj/chem/base/${my.branch}',
  39. 'my.source.BASE : base/${my.branch}',
  40. 'my.project.dir : ${my.scratch}/TM5/standard',
  41. 'my.defs_chem : with_tracerorder')
  42. # simply use:
  43. regex = ( r"^my\.source\.CHEM", r"^my\.source\.BASE", r"^my.project.dir" )
  44. infile=open('tm6.rc', 'r')
  45. outfile=open('tm5.rc', 'w')
  46. for line in infile:
  47. seded=False
  48. for (klm,r) in enumerate(regex):
  49. match = re.search(r, line)
  50. if match:
  51. outfile.write( tm5str[klm]+'\n' )
  52. seded=True
  53. if not seded: outfile.write( line )
  54. infile.close()
  55. outfile.close()
  56. # compare TM6 and TM5
  57. #---------------------------------
  58. try:
  59. tm5_test.testtm(['tm6.rc', 'tm5.rc'], teardown=options.teardown,
  60. new=options.new, queue=options.queue)
  61. except:
  62. print "FAIL : tm6 & tm5 are different"
  63. return 1
  64. # # compare results with different number of processors
  65. # #---------------------------------
  66. # try:
  67. # tm5_test.testtm(['tm6.rc'], teardown=options.teardown,
  68. # new=options.new, queue=options.queue, tm6=True, mpi=True)
  69. # except:
  70. # print "FAIL : tm6 gives different results on different number of processors"
  71. # return 1
  72. #
  73. # # compare results with extra restart
  74. # #---------------------------------
  75. # try:
  76. # tm5_test.testtm(['tm6.rc'], teardown=options.teardown, new=options.new,
  77. # queue=options.queue, restart=True)
  78. # except:
  79. # print "FAIL : tm6 gives different results with extra restart"
  80. # return 1
  81. return 0
  82. if __name__ == '__main__':
  83. sys.exit(main())