report.py 12 KB

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