report.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. # Copyright (c) MetaCommunications, Inc. 2003-2004
  2. #
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE_1_0.txt or copy at
  5. # http://www.boost.org/LICENSE_1_0.txt)
  6. import shutil
  7. import os.path
  8. import os
  9. import string
  10. import time
  11. import sys
  12. import utils
  13. import runner
  14. report_types = [ 'us', 'ds', 'ud', 'dd', 'l', 'p', 'x', 'i', 'n', 'ddr', 'dsr' ]
  15. if __name__ == '__main__':
  16. run_dir = os.path.abspath( os.path.dirname( sys.argv[ 0 ] ) )
  17. else:
  18. run_dir = os.path.abspath( os.path.dirname( sys.modules[ __name__ ].__file__ ) )
  19. def map_path( path ):
  20. return os.path.join( run_dir, path )
  21. def xsl_path( xsl_file_name, v2 = 0 ):
  22. if v2:
  23. return map_path( os.path.join( 'xsl/v2', xsl_file_name ) )
  24. else:
  25. return map_path( os.path.join( 'xsl', xsl_file_name ) )
  26. def make_result_pages(
  27. test_results_file
  28. , expected_results_file
  29. , failures_markup_file
  30. , tag
  31. , run_date
  32. , comment_file
  33. , results_dir
  34. , result_prefix
  35. , reports
  36. , v2
  37. ):
  38. utils.log( 'Producing the reports...' )
  39. __log__ = 1
  40. output_dir = os.path.join( results_dir, result_prefix )
  41. utils.makedirs( output_dir )
  42. if comment_file != '':
  43. comment_file = os.path.abspath( comment_file )
  44. if expected_results_file != '':
  45. expected_results_file = os.path.abspath( expected_results_file )
  46. else:
  47. expected_results_file = os.path.abspath( map_path( 'empty_expected_results.xml' ) )
  48. extended_test_results = os.path.join( output_dir, 'extended_test_results.xml' )
  49. if 'x' in reports:
  50. utils.log( ' Merging with expected results...' )
  51. utils.libxslt(
  52. utils.log
  53. , test_results_file
  54. , xsl_path( 'add_expected_results.xsl', v2 )
  55. , extended_test_results
  56. , { 'expected_results_file': expected_results_file, 'failures_markup_file' : failures_markup_file }
  57. )
  58. links = os.path.join( output_dir, 'links.html' )
  59. utils.makedirs( os.path.join( output_dir, 'output' ) )
  60. for mode in ( 'developer', 'user' ):
  61. utils.makedirs( os.path.join( output_dir, mode , 'output' ) )
  62. if 'l' in reports:
  63. utils.log( ' Making test output files...' )
  64. utils.libxslt(
  65. utils.log
  66. , extended_test_results
  67. , xsl_path( 'links_page.xsl', v2 )
  68. , links
  69. , {
  70. 'source': tag
  71. , 'run_date': run_date
  72. , 'comment_file': comment_file
  73. , 'explicit_markup_file': failures_markup_file
  74. }
  75. )
  76. issues = os.path.join( output_dir, 'developer', 'issues.html' )
  77. if 'i' in reports:
  78. utils.log( ' Making issues list...' )
  79. utils.libxslt(
  80. utils.log
  81. , extended_test_results
  82. , xsl_path( 'issues_page.xsl', v2 )
  83. , issues
  84. , {
  85. 'source': tag
  86. , 'run_date': run_date
  87. , 'comment_file': comment_file
  88. , 'explicit_markup_file': failures_markup_file
  89. }
  90. )
  91. for mode in ( 'developer', 'user' ):
  92. if mode[0] + 'd' in reports:
  93. utils.log( ' Making detailed %s report...' % mode )
  94. utils.libxslt(
  95. utils.log
  96. , extended_test_results
  97. , xsl_path( 'result_page.xsl', v2 )
  98. , os.path.join( output_dir, mode, 'index.html' )
  99. , {
  100. 'links_file': 'links.html'
  101. , 'mode': mode
  102. , 'source': tag
  103. , 'run_date': run_date
  104. , 'comment_file': comment_file
  105. , 'expected_results_file': expected_results_file
  106. , 'explicit_markup_file' : failures_markup_file
  107. }
  108. )
  109. for mode in ( 'developer', 'user' ):
  110. if mode[0] + 's' in reports:
  111. utils.log( ' Making summary %s report...' % mode )
  112. utils.libxslt(
  113. utils.log
  114. , extended_test_results
  115. , xsl_path( 'summary_page.xsl', v2 )
  116. , os.path.join( output_dir, mode, 'summary.html' )
  117. , {
  118. 'mode' : mode
  119. , 'source': tag
  120. , 'run_date': run_date
  121. , 'comment_file': comment_file
  122. , 'explicit_markup_file' : failures_markup_file
  123. }
  124. )
  125. if v2 and "ddr" in reports:
  126. utils.log( ' Making detailed %s release report...' % mode )
  127. utils.libxslt(
  128. utils.log
  129. , extended_test_results
  130. , xsl_path( 'result_page.xsl', v2 )
  131. , os.path.join( output_dir, "developer", 'index_release.html' )
  132. , {
  133. 'links_file': 'links.html'
  134. , 'mode': "developer"
  135. , 'source': tag
  136. , 'run_date': run_date
  137. , 'comment_file': comment_file
  138. , 'expected_results_file': expected_results_file
  139. , 'explicit_markup_file' : failures_markup_file
  140. , 'release': "yes"
  141. }
  142. )
  143. if v2 and "dsr" in reports:
  144. utils.log( ' Making summary %s release report...' % mode )
  145. utils.libxslt(
  146. utils.log
  147. , extended_test_results
  148. , xsl_path( 'summary_page.xsl', v2 )
  149. , os.path.join( output_dir, "developer", 'summary_release.html' )
  150. , {
  151. 'mode' : "developer"
  152. , 'source': tag
  153. , 'run_date': run_date
  154. , 'comment_file': comment_file
  155. , 'explicit_markup_file' : failures_markup_file
  156. , 'release': 'yes'
  157. }
  158. )
  159. if 'e' in reports:
  160. utils.log( ' Generating expected_results ...' )
  161. utils.libxslt(
  162. utils.log
  163. , extended_test_results
  164. , xsl_path( 'produce_expected_results.xsl', v2 )
  165. , os.path.join( output_dir, 'expected_results.xml' )
  166. )
  167. if v2 and 'n' in reports:
  168. utils.log( ' Making runner comment files...' )
  169. utils.libxslt(
  170. utils.log
  171. , extended_test_results
  172. , xsl_path( 'runners.xsl', v2 )
  173. , os.path.join( output_dir, 'runners.html' )
  174. )
  175. shutil.copyfile(
  176. xsl_path( 'html/master.css', v2 )
  177. , os.path.join( output_dir, 'master.css' )
  178. )
  179. def build_xsl_reports(
  180. locate_root_dir
  181. , tag
  182. , expected_results_file
  183. , failures_markup_file
  184. , comment_file
  185. , results_dir
  186. , result_file_prefix
  187. , dont_collect_logs = 0
  188. , reports = report_types
  189. , v2 = 0
  190. , user = None
  191. , upload = False
  192. ):
  193. ( run_date ) = time.strftime('%a, %d %b %Y %H:%M:%S +0000', time.gmtime() )
  194. test_results_file = os.path.join( results_dir, 'test_results.xml' )
  195. bin_boost_dir = os.path.join( locate_root_dir, 'bin', 'boost' )
  196. if v2:
  197. import merger
  198. merger.merge_logs(
  199. tag
  200. , user
  201. , results_dir
  202. , test_results_file
  203. , dont_collect_logs
  204. )
  205. else:
  206. utils.log( ' dont_collect_logs: %s' % dont_collect_logs )
  207. if not dont_collect_logs:
  208. f = open( test_results_file, 'w+' )
  209. f.write( '<tests>\n' )
  210. runner.collect_test_logs( [ bin_boost_dir ], f )
  211. f.write( '</tests>\n' )
  212. f.close()
  213. make_result_pages(
  214. test_results_file
  215. , expected_results_file
  216. , failures_markup_file
  217. , tag
  218. , run_date
  219. , comment_file
  220. , results_dir
  221. , result_file_prefix
  222. , reports
  223. , v2
  224. )
  225. if v2 and upload:
  226. upload_dir = 'regression-logs/'
  227. utils.log( 'Uploading v2 results into "%s" [connecting as %s]...' % ( upload_dir, user ) )
  228. archive_name = '%s.tar.gz' % result_file_prefix
  229. utils.tar(
  230. os.path.join( results_dir, result_file_prefix )
  231. , archive_name
  232. )
  233. utils.sourceforge.upload( os.path.join( results_dir, archive_name ), upload_dir, user )
  234. utils.sourceforge.untar( os.path.join( upload_dir, archive_name ), user, background = True )
  235. def accept_args( args ):
  236. args_spec = [
  237. 'locate-root='
  238. , 'tag='
  239. , 'expected-results='
  240. , 'failures-markup='
  241. , 'comment='
  242. , 'results-dir='
  243. , 'results-prefix='
  244. , 'dont-collect-logs'
  245. , 'reports='
  246. , 'v2'
  247. , 'user='
  248. , 'upload'
  249. , 'help'
  250. ]
  251. options = {
  252. '--comment': ''
  253. , '--expected-results': ''
  254. , '--failures-markup': ''
  255. , '--reports': string.join( report_types, ',' )
  256. , '--tag': None
  257. , '--user': None
  258. , 'upload': False
  259. }
  260. utils.accept_args( args_spec, args, options, usage )
  261. if not options.has_key( '--results-dir' ):
  262. options[ '--results-dir' ] = options[ '--locate-root' ]
  263. if not options.has_key( '--results-prefix' ):
  264. if options.has_key( '--v2' ):
  265. options[ '--results-prefix' ] = 'all'
  266. else:
  267. options[ '--results-prefix' ] = ''
  268. return (
  269. options[ '--locate-root' ]
  270. , options[ '--tag' ]
  271. , options[ '--expected-results' ]
  272. , options[ '--failures-markup' ]
  273. , options[ '--comment' ]
  274. , options[ '--results-dir' ]
  275. , options[ '--results-prefix' ]
  276. , options.has_key( '--dont-collect-logs' )
  277. , options[ '--reports' ].split( ',' )
  278. , options.has_key( '--v2' )
  279. , options[ '--user' ]
  280. , options.has_key( '--upload' )
  281. )
  282. def usage():
  283. print 'Usage: %s [options]' % os.path.basename( sys.argv[0] )
  284. print '''
  285. \t--locate-root the same as --locate-root in compiler_status
  286. \t--tag the tag for the results (i.e. 'CVS-HEAD')
  287. \t--expected-results the file with the results to be compared with
  288. \t the current run
  289. \t--failures-markup the file with the failures markup
  290. \t--comment an html comment file (will be inserted in the reports)
  291. \t--results-dir the directory containing -links.html, -fail.html
  292. \t files produced by compiler_status (by default the
  293. \t same as specified in --locate-root)
  294. \t--results-prefix the prefix of -links.html, -fail.html
  295. \t files produced by compiler_status
  296. \t--v2 v2 reports (combine multiple runners results into a
  297. \t single set of reports)
  298. The following options are valid only for v2 reports:
  299. \t--user SourceForge user name for a shell account
  300. \t--upload upload v2 reports to SourceForge
  301. The following options are useful in debugging:
  302. \t--dont-collect-logs dont collect the test logs
  303. \t--reports produce only the specified reports
  304. \t us - user summary
  305. \t ds - developer summary
  306. \t ud - user detailed
  307. \t dd - developer detailed
  308. \t l - links
  309. \t p - patches
  310. \t x - extended results file
  311. \t i - issues
  312. '''
  313. def main():
  314. build_xsl_reports( *accept_args( sys.argv[ 1 : ] ) )
  315. if __name__ == '__main__':
  316. main()
粤ICP备19079148号