<s> """<STR_LIT>""" <EOL> import os , sys <EOL> import Build , TaskGen , Utils , Options , Logs , Task <EOL> from TaskGen import before , after , feature <EOL> from Constants import * <EOL> class unit_test ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . returncode_ok = <NUM_LIT:0> <EOL> self . num_tests_ok = <NUM_LIT:0> <EOL> self . num_tests_failed = <NUM_LIT:0> <EOL> self . num_tests_err = <NUM_LIT:0> <EOL> self . total_num_tests = <NUM_LIT:0> <EOL> self . max_label_length = <NUM_LIT:0> <EOL> self . unit_tests = Utils . ordered_dict ( ) <EOL> self . unit_test_results = { } <EOL> self . unit_test_erroneous = { } <EOL> self . change_to_testfile_dir = False <EOL> self . want_to_see_test_output = False <EOL> self . want_to_see_test_error = False <EOL> self . run_if_waf_does = '<STR_LIT>' <EOL> def run ( self ) : <EOL> "<STR_LIT>" <EOL> self . num_tests_ok = <NUM_LIT:0> <EOL> self . num_tests_failed = <NUM_LIT:0> <EOL> self . num_tests_err = <NUM_LIT:0> <EOL> self . total_num_tests = <NUM_LIT:0> <EOL> self . max_label_length = <NUM_LIT:0> <EOL> self . unit_tests = Utils . ordered_dict ( ) <EOL> self . unit_test_results = { } <EOL> self . unit_test_erroneous = { } <EOL> ld_library_path = [ ] <EOL> if not Options . commands [ self . run_if_waf_does ] : return <EOL> for obj in Build . bld . all_task_gen : <EOL> try : <EOL> link_task = obj . link_task <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> lib_path = link_task . outputs [ <NUM_LIT:0> ] . parent . abspath ( obj . env ) <EOL> if lib_path not in ld_library_path : <EOL> ld_library_path . append ( lib_path ) <EOL> unit_test = getattr ( obj , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if unit_test and '<STR_LIT>' in obj . features : <EOL> try : <EOL> output = obj . path <EOL> filename = os . path . join ( output . abspath ( obj . env ) , obj . target ) <EOL> srcdir = output . abspath ( ) <EOL> label = os . path . join ( output . bldpath ( obj . env ) , obj . target ) <EOL> self . max_label_length = max ( self . max_label_length , len ( label ) ) <EOL> self . unit_tests [ label ] = ( filename , srcdir ) <EOL> except KeyError : <EOL> pass <EOL> self . total_num_tests = len ( self . unit_tests ) <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> count = <NUM_LIT:0> <EOL> result = <NUM_LIT:1> <EOL> for label in self . unit_tests . allkeys : <EOL> file_and_src = self . unit_tests [ label ] <EOL> filename = file_and_src [ <NUM_LIT:0> ] <EOL> srcdir = file_and_src [ <NUM_LIT:1> ] <EOL> count += <NUM_LIT:1> <EOL> line = Build . bld . progress_line ( count , self . total_num_tests , Logs . colors . GREEN , Logs . colors . NORMAL ) <EOL> if Options . options . progress_bar and line : <EOL> sys . stderr . write ( line ) <EOL> sys . stderr . flush ( ) <EOL> try : <EOL> kwargs = { } <EOL> kwargs [ '<STR_LIT>' ] = os . environ . copy ( ) <EOL> if self . change_to_testfile_dir : <EOL> kwargs [ '<STR_LIT>' ] = srcdir <EOL> if not self . want_to_see_test_output : <EOL> kwargs [ '<STR_LIT>' ] = Utils . pproc . PIPE <EOL> if not self . want_to_see_test_error : <EOL> kwargs [ '<STR_LIT>' ] = Utils . pproc . PIPE <EOL> if ld_library_path : <EOL> v = kwargs [ '<STR_LIT>' ] <EOL> def add_path ( dct , path , var ) : <EOL> dct [ var ] = os . pathsep . join ( Utils . to_list ( path ) + [ os . environ . get ( var , '<STR_LIT>' ) ] ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> add_path ( v , ld_library_path , '<STR_LIT>' ) <EOL> elif sys . platform == '<STR_LIT>' : <EOL> add_path ( v , ld_library_path , '<STR_LIT>' ) <EOL> add_path ( v , ld_library_path , '<STR_LIT>' ) <EOL> else : <EOL> add_path ( v , ld_library_path , '<STR_LIT>' ) <EOL> pp = Utils . pproc . Popen ( filename , ** kwargs ) <EOL> pp . wait ( ) <EOL> result = int ( pp . returncode == self . returncode_ok ) <EOL> if result : <EOL> self . num_tests_ok += <NUM_LIT:1> <EOL> else : <EOL> self . num_tests_failed += <NUM_LIT:1> <EOL> self . unit_test_results [ label ] = result <EOL> self . unit_test_erroneous [ label ] = <NUM_LIT:0> <EOL> except OSError : <EOL> self . unit_test_erroneous [ label ] = <NUM_LIT:1> <EOL> self . num_tests_err += <NUM_LIT:1> <EOL> except KeyboardInterrupt : <EOL> pass <EOL> if Options . options . progress_bar : sys . stdout . write ( Logs . colors . cursor_on ) <EOL> def print_results ( self ) : <EOL> "<STR_LIT>" <EOL> if not Options . commands [ self . run_if_waf_does ] : return <EOL> p = Utils . pprint <EOL> if self . total_num_tests == <NUM_LIT:0> : <EOL> p ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return <EOL> for label in self . unit_tests . allkeys : <EOL> filename = self . unit_tests [ label ] <EOL> err = <NUM_LIT:0> <EOL> result = <NUM_LIT:0> <EOL> try : err = self . unit_test_erroneous [ label ] <EOL> except KeyError : pass <EOL> try : result = self . unit_test_results [ label ] <EOL> except KeyError : pass <EOL> n = self . max_label_length - len ( label ) <EOL> if err : n += <NUM_LIT:4> <EOL> elif result : n += <NUM_LIT:7> <EOL> else : n += <NUM_LIT:3> <EOL> line = '<STR_LIT>' % ( label , '<STR_LIT:.>' * n ) <EOL> if err : p ( '<STR_LIT>' , '<STR_LIT>' % line ) <EOL> elif result : p ( '<STR_LIT>' , '<STR_LIT>' % line ) <EOL> else : p ( '<STR_LIT>' , '<STR_LIT>' % line ) <EOL> percentage_ok = float ( self . num_tests_ok ) / float ( self . total_num_tests ) * <NUM_LIT> <EOL> percentage_failed = float ( self . num_tests_failed ) / float ( self . total_num_tests ) * <NUM_LIT> <EOL> percentage_erroneous = float ( self . num_tests_err ) / float ( self . total_num_tests ) * <NUM_LIT> <EOL> p ( '<STR_LIT>' , '''<STR_LIT>''' % ( self . num_tests_ok , percentage_ok , self . num_tests_failed , percentage_failed , <EOL> self . num_tests_err , percentage_erroneous , self . total_num_tests ) ) <EOL> p ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> import threading <EOL> testlock = threading . Lock ( ) <EOL> def set_options ( opt ) : <EOL> opt . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = True , help = '<STR_LIT>' , dest = '<STR_LIT>' ) <EOL> @ feature ( '<STR_LIT:test>' ) <EOL> @ after ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def make_test ( self ) : <EOL> if not '<STR_LIT>' in self . features : <EOL> Logs . error ( '<STR_LIT>' % self ) <EOL> return <EOL> self . default_install_path = None <EOL> self . create_task ( '<STR_LIT>' , self . link_task . outputs ) <EOL> def exec_test ( self ) : <EOL> status = <NUM_LIT:0> <EOL> variant = self . env . variant ( ) <EOL> filename = self . inputs [ <NUM_LIT:0> ] . abspath ( self . env ) <EOL> try : <EOL> fu = getattr ( self . generator . bld , '<STR_LIT>' ) <EOL> except AttributeError : <EOL> fu = os . environ . copy ( ) <EOL> self . generator . bld . all_test_paths = fu <EOL> lst = [ ] <EOL> for obj in self . generator . bld . all_task_gen : <EOL> link_task = getattr ( obj , '<STR_LIT>' , None ) <EOL> if link_task and link_task . env . variant ( ) == variant : <EOL> lst . append ( link_task . outputs [ <NUM_LIT:0> ] . parent . abspath ( obj . env ) ) <EOL> def add_path ( dct , path , var ) : <EOL> dct [ var ] = os . pathsep . join ( Utils . to_list ( path ) + [ os . environ . get ( var , '<STR_LIT>' ) ] ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> add_path ( fu , lst , '<STR_LIT>' ) <EOL> elif sys . platform == '<STR_LIT>' : <EOL> add_path ( fu , lst , '<STR_LIT>' ) <EOL> add_path ( fu , lst , '<STR_LIT>' ) <EOL> else : <EOL> add_path ( fu , lst , '<STR_LIT>' ) <EOL> cwd = getattr ( self . generator , '<STR_LIT>' , '<STR_LIT>' ) or self . inputs [ <NUM_LIT:0> ] . parent . abspath ( self . env ) <EOL> proc = Utils . pproc . Popen ( filename , cwd = cwd , env = fu , stderr = Utils . pproc . PIPE , stdout = Utils . pproc . PIPE ) <EOL> ( stdout , stderr ) = proc . communicate ( ) <EOL> tup = ( filename , proc . returncode , stdout , stderr ) <EOL> self . generator . utest_result = tup <EOL> testlock . acquire ( ) <EOL> try : <EOL> bld = self . generator . bld <EOL> Logs . debug ( "<STR_LIT>" , tup ) <EOL> try : <EOL> bld . utest_results . append ( tup ) <EOL> except AttributeError : <EOL> bld . utest_results = [ tup ] <EOL> finally : <EOL> testlock . release ( ) <EOL> cls = Task . task_type_from_func ( '<STR_LIT>' , func = exec_test , color = '<STR_LIT>' , ext_in = '<STR_LIT>' ) <EOL> old = cls . runnable_status <EOL> def test_status ( self ) : <EOL> if getattr ( Options . options , '<STR_LIT>' , False ) : <EOL> return RUN_ME <EOL> return old ( self ) <EOL> cls . runnable_status = test_status <EOL> cls . quiet = <NUM_LIT:1> <EOL> def summary ( bld ) : <EOL> lst = getattr ( bld , '<STR_LIT>' , [ ] ) <EOL> if lst : <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> total = len ( lst ) <EOL> tfail = len ( [ x for x in lst if x [ <NUM_LIT:1> ] ] ) <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' % ( total - tfail , total ) ) <EOL> for ( f , code , out , err ) in lst : <EOL> if not code : <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' % f ) <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' % ( tfail , total ) ) <EOL> for ( f , code , out , err ) in lst : <EOL> if code : <EOL> Utils . pprint ( '<STR_LIT>' , '<STR_LIT>' % f ) </s>
