Browse Source

runner/regression.py initial checkin

[SVN r23776]
Aleksey Gurtovoy 22 years ago
parent
commit
f43498cff2

+ 7 - 3
tools/regression/xsl_reports/runner/collect_and_upload_logs.py

@@ -63,7 +63,7 @@ def copy_comments( results_xml, comment_file ):
 
 def collect_and_upload_logs( 
           locate_root_dir
-        , runner
+        , runner_id
         , tag
         , platform
         , comment_file
@@ -71,7 +71,11 @@ def collect_and_upload_logs(
         , user
         ):
     
-    test_results_file =  '%s.xml' % runner
+    test_results_file =  '%s.xml' % runner_id
+    if not os.path.exists( test_results_file ):
+        utils.log( 'No test results found (%s); did nothing.' % test_results_file )
+        return
+    
     test_results_writer = open( test_results_file, "w" )
     utils.log( 'Collecting test logs into "%s"...' % test_results_file )
     
@@ -82,7 +86,7 @@ def collect_and_upload_logs(
         , { 
               "tag":        tag
             , "platform":   platform
-            , "runner":     runner
+            , "runner":     runner_id
             , "timestamp":  timestamp 
             }
         )

+ 416 - 0
tools/regression/xsl_reports/runner/regression.py

@@ -0,0 +1,416 @@
+
+# Copyright (c) MetaCommunications, Inc. 2003-2004
+#
+# Distributed under the Boost Software License, Version 1.0. 
+# (See accompanying file LICENSE_1_0.txt or copy at 
+# http://www.boost.org/LICENSE_1_0.txt)
+
+import time
+import glob
+import shutil
+import os.path
+import os
+import traceback
+import string
+import sys
+
+boost_root = os.path.abspath( os.path.dirname( sys.argv[0] ) )
+while os.path.basename( boost_root ) != 'boost': 
+    boost_root = os.path.dirname( boost_root )
+
+regression_root = os.path.dirname( boost_root )
+regression_results = os.path.join( regression_root, 'results' )
+regression_log = os.path.join( regression_results, 'bjam.log' )
+
+timestamp = None
+
+if sys.platform == 'win32': 
+    bjam_name = 'bjam.exe'
+    bjam_build_compiler = 'vc7'
+    bjam_make_cmd = 'build.bat %s' % bjam_build_compiler
+    bjam_location = 'bin.ntx86'
+    process_jam_log_name = 'process_jam_log.exe'
+    process_jam_log_toolset = 'vc7.1'
+else:
+    bjam_name = 'bjam'
+    bjam_build_compiler = 'gcc'
+    bjam_make_cmd = 'build.sh' % bjam_build_compiler
+    bjam_location = ''
+    process_jam_log_name = "process_jam_log"
+    process_jam_log_toolset = 'gcc'
+
+bjam_path = os.path.join( regression_root, bjam_name )
+process_jam_log_path = os.path.join( regression_root, process_jam_log_name )
+
+
+def tool_path( name ):
+    return os.path.join( regression_results, name )
+
+
+def check_environment():
+    try:
+        utils.check_existance( 'gzip' )
+        utils.check_existance( 'tar' )
+    except Exception, msg:
+        raise '\nPrerequisites check failed: %s' % msg
+
+
+def cleanup( args ):
+    utils.log( 'Cleaning up "%s" directory ...' % boost_root )
+    utils.rmtree( boost_root )
+    
+    utils.log( 'Cleaning up "%s" directory ...' % regression_results )
+    utils.rmtree( regression_results )
+
+
+def download_boost_tarball( destination, tag ):
+    site = 'boost-consulting.com'
+    tarball_name = 'boost.tar.bz2'
+    tarball_path = os.path.join( destination, tarball_name )
+
+    utils.log( "Downloading '%s' for tag %s from %s "  % ( tarball_path, tag, site ) )
+    return tarball_path
+    if os.path.exists( tarball_path ):
+        os.unlink( tarball_path )
+
+    utils.http_get(
+          site
+        , '/%s' % tarball_name # ignore tag for now
+        , tarball_path
+        )
+        
+    return tarball_path
+
+
+def unpack_tarball( tarball_path, destination ):
+    utils.log( 'Looking for old unpacked archives...' )
+    old_boost_dirs =  glob.glob( os.path.join( destination, 'boost-*' ) )
+
+    for old_boost_dir in old_boost_dirs:
+        utils.log( 'Deleting old directory %s.' % old_boost_dir ) 
+        utils.rmtree( old_boost_dir )
+
+    utils.log( 'Unpacking boost tarball ("%s")' % tarball_path )
+    utils.untar( tarball_path )
+    boost_dir = glob.glob( os.path.join( destination, 'boost-*' ) )[0]
+    utils.log( '    Unpacked into directory "%s"' % boost_dir )
+    
+    if os.path.exists( boost_root ):
+        utils.log( 'Deleting "%s" directory...' % boost_root )
+        shutil.rmtree( boost_root )
+
+    utils.log( 'Renaming "%s" into "%s"' % ( boost_dir, boost_root ) )
+    os.rename( boost_dir, boost_root )
+
+
+def get_source( user, tag, args ):
+    __log__ = 1; utils.log( "Getting sources ..." )
+
+    global timestamp
+    timestamp = time.gmtime()
+    if user is not None:
+        boost_cvs_checkout( user, tag )
+    else:
+        tarball_path = download_boost_tarball( regression_root, tag )
+        unpack_tarball( tarball_path, regression_root )
+
+
+def update_source( args ):
+    __log__ = 1; log( "Getting sources ..." ) 
+    get_source_method = { "cvs": boost_cvs_update
+                          , "directory": get_source_directory
+                          }
+    log( "    Source type: %s" % config.source.source_type )
+    get_source_method[ config.source.source_type ]( args )
+
+
+
+def build_bjam_if_needed():    
+    global bjam_path
+    if os.path.exists( bjam_path ):
+        utils.log( 'Found preinstalled "%s"; will use it.' % bjam_path )
+        return
+    
+    utils.log( 'Preinstalled "%s" is not found; building one...' % bjam_path )
+
+    utils.log( 'Locating bjam source directory...' )
+    bjam_source_dir = os.path.join( boost_root, 'tools', 'build', 'jam_src' )
+    
+    if os.path.exists( bjam_source_dir ):
+        utils.log( 'Found bjam source directory "%s"' % bjam_source_dir )
+        utils.log( 'Building bjam using \"%s\"...' % bjam_build_compiler )
+            
+        utils.log( "Building bjam (%s)" % bjam_make_cmd )
+        utils.system( [ 
+              'cd %s' % bjam_source_dir
+            , bjam_make_cmd 
+            ] )
+    else:
+        raise 'Could not find bjam source directory \"%s\"' % bjam_source_dir
+
+    bjam_path = os.path.join( bjam_source_dir, bjam_location, bjam_name )
+    if not os.path.exists( bjam_path ):
+        raise 'Failed to find bjam (\"%s\") after build.' % bjam_path
+
+    utils.log( 'Bjam succesfully built in "%s" directory' % bjam_path )
+
+
+def build_process_jam_log_if_needed():
+    global process_jam_log_path
+    if os.path.exists( process_jam_log_path ):
+        utils.log( 'Found preinstalled "%s"; will use it.' % process_jam_log_path )
+        return
+    
+    utils.log( 'Preinstalled "%s" is not found; building one.' % process_jam_log_path )
+    
+    process_jam_log_source_dir = os.path.join( boost_root, 'tools', 'regression', 'build' )
+
+    utils.log( 'Locating proces_jam_log source directory...' )
+    if os.path.exists( process_jam_log_source_dir ):
+        utils.log( 'Found proces_jam_log source directory "%s"' % process_jam_log_source_dir )
+
+        utils.log( 'Building process_jam_log using toolset "%s"' % process_jam_log_toolset )
+        utils.system( [ 
+              'cd %s' % process_jam_log_source_dir
+            , '%s -sTOOLS=%s' % ( bjam_path, process_jam_log_toolset )
+            ] )
+
+    else:
+        raise 'Could not find process_jam_log source directory "%s"' % process_jam_log_source_dir
+
+    process_jam_log_path = os.path.join( 
+          boost_root, 'bin', 'boost', 'tools', 'regression', 'build'
+        , process_jam_log_name, process_jam_log_toolset, 'release', process_jam_log_name
+        )
+    
+    if not os.path.exists( process_jam_log_path ):
+        raise 'Failed to find process_jam_log ("%s") after build.' % process_jam_log_path
+    
+    utils.log( 'Process_jam_log succesfully built in "%s" directory' % process_jam_log_path )
+
+
+def setup( args ):
+    if not 'no-bjam' in args:
+        build_bjam_if_needed()
+    
+    if not 'no-process_jam_log' in args:
+        build_process_jam_log_if_needed()
+
+
+def start_build_monitor():
+    if sys.platform == 'win32':
+        build_monitor = tool_path( 'build_monitor.exe' )
+        if os.path.exists( build_monitor ):
+            utils.system( [ 'start "" %s bjam.exe %d' % ( build_monitor, 3*60 ) ] )
+
+
+def stop_build_monitor():
+    if sys.platform == 'win32':
+        build_monitor = tool_path( 'build_monitor.exe' )
+        if os.path.exists( build_monitor ):
+            utils.system( [ '%s build_monitor' %  tool_path( 'pskill.exe' ) ] )
+
+
+def process_bjam_log():
+    utils.log( 'Getting test case results out of "%s"...' % regression_log )
+    utils.checked_system( [ 
+        "%s %s <%s" % (  
+              process_jam_log_path
+            , regression_results
+            , regression_log
+            )
+        ] )
+    
+    os.rename( regression_log, '%s.processed' % regression_log )
+
+
+def test( 
+          toolsets
+        , args
+        ):
+    if args == []:
+        args = [ "test", "process" ]
+
+    try:
+        start_build_monitor()
+        cd = os.getcwd()
+        os.chdir( os.path.join( boost_root, 'status' ) )
+
+        utils.log( 'Making "%s" directory...' % regression_results )
+        utils.makedirs( regression_results )
+
+        results_libs = os.path.join( regression_results, 'libs' )
+        results_status = os.path.join( regression_results, 'status' )
+        
+        if "clean" in args:
+            utils.rmtree( results_libs )
+            utils.rmtree( results_status )
+                
+        if "test" in args:
+            test_cmd = []
+            if not toolsets is None:
+                test_cmd.append( 'set TOOLS=%s' % string.join( toolsets, ' ' ) )
+            test_cmd.append( 'set BOOST_ROOT=%s' % boost_root )
+            test_cmd.append( '"%s" -d2 --dump-tests "-sALL_LOCATE_TARGET=%s" >>%s 2>&1'
+                                      % (     bjam_path
+                                            , regression_results
+                                            , regression_log
+                                            )
+                                      )
+
+            utils.checked_system( test_cmd, [ 1 ] )
+
+        if "process" in args:
+            process_bjam_log()
+
+        os.chdir( cd )
+    finally:
+        stop_build_monitor()
+
+
+def upload( 
+          tag
+        , runner_id
+        , platform
+        , user
+        , comment_file
+        , args
+        ):
+    global timestamp
+    import runner
+
+    runner.collect_and_upload_logs( 
+          regression_results
+        , runner_id
+        , tag
+        , platform
+        , comment_file
+        , time.strftime("%a, %d %b %Y %H:%M:%S +0000", timestamp )
+        , user
+        )
+
+
+def regression( 
+          tag
+        , runner
+        , platform
+        , user
+        , comment_file
+        , toolsets
+        , incremental
+        , mail = None
+        , args = []
+        ):
+
+    check_environment()
+
+    try:
+        mail_subject = "Boost regression for %s on %s \n" % ( tag, os.environ[ "COMPUTERNAME" ] )
+        if incremental:
+            update_source( user )
+            setup( [ "bjam", "build" ] )
+        else:
+            cleanup( args )
+            get_source( user, tag, args )
+            setup( args )
+
+        test( toolsets, args )
+        upload( tag, runner, platform, user, comment_file, args )
+
+        if mail:
+            utils.log( 'Sending report to "%s"' % mail )
+            utils.send_mail( mail, mail_subject + ' completed successfully.' )
+    except:
+        if mail:
+            utils.log( 'Sending report to "%s"' % mail )
+            msg = regression_log + [ "" ] + apply( traceback.format_exception, sys.exc_info() ) 
+            utils.send_mail( mail, mail_subject + ' failed.', '\n'.join( msg ) )
+        raise
+
+
+def accept_args( args ):
+    args_spec = [ 
+          'tag='
+        , 'runner='
+        , 'platform='
+        , 'user='
+        , 'comment='
+        , 'toolsets='
+        , 'mail='
+        , 'incremental'
+        , 'help'
+        ]
+    
+    options = {
+          '--platform' :    sys.platform
+        , '--user' :        None
+        , '--comment' :     'comment.html'
+        , '--toolsets' :    None
+        , '--mail' :        None
+        }
+    
+    other_args = utils.accept_args( args_spec, args, options, usage )
+
+    return ( 
+          options[ '--tag' ]
+        , options[ '--runner' ]
+        , options[ '--platform']
+        , options[ '--user' ]
+        , options[ '--comment' ]
+        , options[ '--toolsets' ]
+        , options.has_key( '--incremental' )
+        , options[ '--mail' ]
+        , other_args
+        )
+
+
+commands = {
+      'cleanup'         : cleanup
+    , 'get-source'      : get_source
+    , 'update-source'   : update_source
+    , 'setup'           : setup
+    , 'test'            : test
+    , 'upload'          : upload
+    , 'regression'      : regression
+    }
+
+def usage():
+    print 'Usage: %s command [options|@response-file]' % os.path.basename( sys.argv[0] )
+    print    '''
+Commands:
+\t%s
+
+Options:
+
+\t--tag                 the tag for the results (e.g. 'CVS-HEAD')
+\t--runner              runner ID (e.g. 'Metacomm')
+\t--comment             an html comment file (will be inserted in the reports, 
+\t                      'comment.html' by default)
+\t--incremental         do incremental run (do not remove previous binaries)
+\t--user                SourceForge user name for a shell/CVS account (optional)
+\t--toolsets            comma-separated list of toolsets to test with (optional)
+\t--mail                email address to send run notification to (optional)
+''' % '\n\t'.join( commands.keys() )
+
+    print 'Example:\n\t%s regression --tag=CVS-HEAD --runner=Metacomm' \
+        % os.path.basename( sys.argv[0] )
+
+
+def main():
+    if len(sys.argv) < 2:
+        usage()
+        sys.exit( 1 )
+
+    command = sys.argv[1];
+    commands[ command ]( *accept_args( sys.argv[ 2: ] ) );
+
+
+if __name__ != '__main__':  import utils
+else:
+    # in absense of relative import...
+    xsl_path = os.path.abspath( os.path.dirname( sys.argv[ 0 ] ) )
+    while os.path.basename( xsl_path ) != 'xsl_reports': xsl_path = os.path.dirname( xsl_path )
+    sys.path.append( xsl_path )
+
+    import utils
+    main()

+ 3 - 0
tools/regression/xsl_reports/utils/__init__.py

@@ -1,10 +1,13 @@
 
 from accept_args import *
 from char_translation_table import *
+from check_existance import *
 from checked_system import *
+from http_get import *
 from libxslt import *
 from log import *
 from makedirs import *
+from rmtree import *
 from tar import *
 
 import sourceforge

+ 2 - 0
tools/regression/xsl_reports/utils/accept_args.py

@@ -26,3 +26,5 @@ def accept_args( args_spec, args, options, usage ):
                 options[ '--%s' % m.group( 'name' ) ] = m.group( 'value' )
             else:
                 raise 'Invalid format of config line "%s"' % l
+
+    return rest_args

+ 9 - 0
tools/regression/xsl_reports/utils/check_existance.py

@@ -0,0 +1,9 @@
+
+import os
+
+def check_existance( name ):
+    a = os.popen( '%s --version' % name )
+    output = a.read()
+    rc = a.close()
+    if rc is not None:
+        raise Exception( '"%s" is required' % name )

+ 2 - 2
tools/regression/xsl_reports/utils/checked_system.py

@@ -13,7 +13,7 @@ def system( commands ):
     rc = os.system( 'tmp.cmd' )
     return rc
 
-def checked_system( commands ):
+def checked_system( commands, valid_return_codes = [ 0 ] ):
     rc = system( commands ) 
-    if 0 != rc : raise failure_exception( rc )
+    if rc not in [ 0 ] + valid_return_codes: raise failure_exception( rc )
     return rc

+ 15 - 0
tools/regression/xsl_reports/utils/http_get.py

@@ -0,0 +1,15 @@
+
+import httplib
+
+def http_get( site, source, destination ):
+    h = httplib.HTTPConnection( site )
+    h.request( 'GET', source )
+    
+    response = h.getresponse()
+    f = open( destination, 'wb' )
+    while True:
+        data = response.read( 16*1024 )
+        if len( data ) == 0: break
+        f.write( data )
+
+    f.close()

+ 7 - 0
tools/regression/xsl_reports/utils/rmtree.py

@@ -0,0 +1,7 @@
+
+import utils.checked_system
+import os.path
+
+def rmtree( path ):
+    if os.path.exists( path ):
+        utils.checked_system( [ "rm -f -r \"%s\"" % path ] )

+ 13 - 0
tools/regression/xsl_reports/utils/send_mail.py

@@ -0,0 +1,13 @@
+
+import smtplib
+
+def send_mail( mail, subject, msg = '' ):
+    smtp_server = smtplib.SMTP( 'mail.%s' % mail.split( '@' )[-1] )
+    smtp_server.sendmail( 
+          mail
+        , [ mail ]
+        , 'Subject: %s\n' % subject
+            + 'To: %s\n' % mail
+            + '\n'
+            + msg 
+        )

+ 8 - 0
tools/regression/xsl_reports/utils/tar.py

@@ -1,8 +1,16 @@
 
 import utils.checked_system
+import os.path
 
 def tar( source_dir, archive_name ):
     utils.checked_system( [
           'cd %s' % source_dir
         , 'tar -c -f ../%s -z *' % archive_name
         ] )
+
+def untar( archive_path ):
+    #utils.checked_system( [ 'tar -xjf "%s"' % archive_path ] )
+    utils.checked_system( [ 
+          'cd %s' % os.path.dirname( archive_path )
+        , 'tar -xjf "%s"' % os.path.basename( archive_path )
+        ] )

粤ICP备19079148号