Changeset 5bf1f3e


Ignore:
Timestamp:
Mar 26, 2019, 10:36:58 AM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
1bb2488
Parents:
eb60b04
Message:

Code review of test.py and pybin

Location:
tests
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/settings.py

    reb60b04 r5bf1f3e  
    3737        def __init__(self, arch):
    3838                try:
    39                         canonical_host = Architecture.makeCanonical( config.HOSTARCH )
     39                        canonical_host = Architecture.make_canonical( config.HOSTARCH )
    4040                except KeyError:
    4141                        print("Unkown host architecture %s" % config.HOSTARCH, file=sys.stderr)
     
    4444                if arch:
    4545                        try:
    46                                 arch = Architecture.makeCanonical( arch )
     46                                arch = Architecture.make_canonical( arch )
    4747                        except KeyError:
    4848                                print("Unkown architecture %s" % arch, file=sys.stderr)
     
    7575
    7676        @classmethod
    77         def makeCanonical(_, arch):
     77        def make_canonical(_, arch):
    7878                return Architecture.KnownArchitectures[arch]
    7979
     
    110110        global install
    111111        global timeout
    112         global width
     112        global output_width
    113113
    114         dry_run    = options.dry_run
    115         generating = options.regenerate_expected
    116         make       = 'make'
    117         debug        = Debug(options.debug)
    118         install    = Install(options.install)
    119         arch       = Architecture(options.arch)
    120         timeout    = Timeouts(options.timeout, options.global_timeout)
    121         width      = 24
     114        dry_run      = options.dry_run
     115        generating   = options.regenerate_expected
     116        make         = 'make'
     117        debug        = Debug(options.debug)
     118        install      = Install(options.install)
     119        arch         = Architecture(options.arch)
     120        timeout      = Timeouts(options.timeout, options.global_timeout)
     121        output_width = 24
    122122
    123123
    124 def updateMakeCmd(force, jobs):
     124def update_make_cmd(force, jobs):
    125125        global make
    126126
     
    141141
    142142def prep_output(tests):
    143         global width
    144         width = max(map(lambda t: len(t.target()), tests))
     143        global output_width
     144        output_width = max(map(lambda t: len(t.target()), tests))
  • tests/pybin/test_run.py

    reb60b04 r5bf1f3e  
    44
    55import pybin.settings
    6 import datetime
    7 
    8 from string import Template
    9 
    10 class DeltaTemplate(Template):
    11     delimiter = "%"
    12 
    13 def strfdelta(tdelta, fmt):
    14     d["H"], rem = divmod(tdelta.seconds, 3600)
    15     d["M"], d["S"] = divmod(rem, 60)
    16     t = DeltaTemplate(fmt)
    17     return t.substitute(**d)
    186
    197# Test class that defines what a test is
  • tests/pybin/tools.py

    reb60b04 r5bf1f3e  
    5555        return match.group(1).startswith("ASCII text")
    5656
     57def is_exe(fname):
     58        return os.path.isfile(fname) and os.access(fname, os.X_OK)
     59
    5760# Remove 1 or more files silently
    5861def rm( files ):
     
    7982        # diff the output of the files
    8083        diff_cmd = ("diff --text "
    81 #                               "--ignore-all-space "
    82 #                               "--ignore-blank-lines "
    83                                 "--old-group-format='\t\tmissing lines :\n"
    84                                 "%%<' \\\n"
    85                                 "--new-group-format='\t\tnew lines :\n"
    86                                 "%%>' \\\n"
    87                                 "--unchanged-group-format='%%=' \\"
    88                                 "--changed-group-format='\t\texpected :\n"
    89                                 "%%<"
    90                                 "\t\tgot :\n"
    91                                 "%%>\n' \\\n"
    92                                 "--new-line-format='\t\t%%dn\t%%L' \\\n"
    93                                 "--old-line-format='\t\t%%dn\t%%L' \\\n"
    94                                 "--unchanged-line-format='' \\\n"
    95                                 "%s %s")
     84                        "--old-group-format='\t\tmissing lines :\n"
     85                        "%%<' \\\n"
     86                        "--new-group-format='\t\tnew lines :\n"
     87                        "%%>' \\\n"
     88                        "--unchanged-group-format='%%=' \\"
     89                        "--changed-group-format='\t\texpected :\n"
     90                        "%%<"
     91                        "\t\tgot :\n"
     92                        "%%>\n' \\\n"
     93                        "--new-line-format='\t\t%%dn\t%%L' \\\n"
     94                        "--old-line-format='\t\t%%dn\t%%L' \\\n"
     95                        "--unchanged-line-format='' \\\n"
     96                        "%s %s")
    9697
    9798        # fetch return code and error from the diff command
     
    115116
    116117def which(program):
    117     import os
    118     def is_exe(fpath):
    119         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    120 
    121118    fpath, fname = os.path.split(program)
    122119    if fpath:
     
    160157
    161158# helper function to check if a files contains only a specific string
    162 def fileContainsOnly(file, text) :
     159def file_contains_only(file, text) :
    163160        with open(file) as f:
    164161                ff = f.read().strip()
    165162                result = ff == text.strip()
    166163
    167                 return result;
    168 
    169 # check whether or not a file is executable
    170 def fileIsExecutable(file) :
    171         try :
    172                 fileinfo = os.stat(file)
    173                 return bool(fileinfo.st_mode & stat.S_IXUSR)
    174         except Exception as inst:
    175                 print(type(inst))    # the exception instance
    176                 print(inst.args)     # arguments stored in .args
    177                 print(inst)
    178                 return False
     164                return result
    179165
    180166# transform path to canonical form
    181 def canonicalPath(path):
     167def canonical_path(path):
    182168        abspath = os.path.abspath(__main__.__file__)
    183169        dname = os.path.dirname(abspath)
     
    185171
    186172# compare path even if form is different
    187 def pathCmp(lhs, rhs):
    188         return canonicalPath( lhs ) == canonicalPath( rhs )
     173def path_cmp(lhs, rhs):
     174        return canonical_path( lhs ) == canonical_path( rhs )
    189175
    190176# walk all files in a path
    191 def pathWalk( op ):
    192         def step(_, dirname, names):
    193                 for name in names:
    194                         path = os.path.join(dirname, name)
    195                         op( path )
    196 
    197         # Start the walk
     177def path_walk( op ):
    198178        dname = settings.SRCDIR
    199179        for dirname, _, names in os.walk(dname):
     
    206186################################################################################
    207187# count number of jobs to create
    208 def jobCount( options, tests ):
     188def job_count( options, tests ):
    209189        # check if the user already passed in a number of jobs for multi-threading
    210190        if not options.jobs:
     
    229209
    230210# setup a proper processor pool with correct signal handling
    231 def setupPool(jobs):
     211def setup_pool(jobs):
    232212        original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
    233213        pool = multiprocessing.Pool(jobs)
     
    261241                return False
    262242        raise argparse.ArgumentTypeError(msg)
    263         return False
    264243
    265244def fancy_print(text):
     
    273252
    274253
    275 def coreInfo(path):
     254def core_info(path):
    276255        cmd   = os.path.join(settings.SRCDIR, "pybin/print-core.gdb")
    277256        if not os.path.isfile(cmd):
  • tests/test.py

    reb60b04 r5bf1f3e  
    1414################################################################################
    1515
    16 def findTests():
     16def find_tests():
    1717        expected = []
    1818
    19         def matchTest(path):
     19        def match_test(path):
    2020                match = re.search("^%s\/([\w\/\-_]*).expect\/([\w\-_]+)(\.[\w\-_]+)?\.txt$" % settings.SRCDIR, path)
    2121                if match :
     
    2727                                expected.append(test)
    2828
    29         pathWalk( matchTest )
     29        path_walk( match_test )
    3030
    3131        return expected
    3232
    3333# reads the directory ./.expect and indentifies the tests
    34 def listTests( includes, excludes ):
     34def list_tests( includes, excludes ):
    3535        # tests directly in the .expect folder will always be processed
    36         test_list = findTests()
     36        test_list = find_tests()
    3737
    3838        # if we have a limited number of includes, filter by them
     
    5151
    5252# from the found tests, filter all the valid tests/desired tests
    53 def validTests( options ):
     53def valid_tests( options ):
    5454        tests = []
    5555
     
    5858        if options.regenerate_expected :
    5959                for testname in options.tests :
    60                         testname = canonicalPath( testname )
     60                        testname = canonical_path( testname )
    6161                        if Test.valid_name(testname):
    62                                 found = [test for test in allTests if canonicalPath( test.target() ) == testname]
     62                                found = [test for test in all_tests if canonical_path( test.target() ) == testname]
    6363                                tests.append( found[0] if len(found) == 1 else Test.from_target(testname) )
    6464                        else :
     
    6868                # otherwise we only need to validate that all tests are present in the complete list
    6969                for testname in options.tests:
    70                         test = [t for t in allTests if pathCmp( t.target(), testname )]
     70                        test = [t for t in all_tests if path_cmp( t.target(), testname )]
    7171
    7272                        if test :
     
    7878
    7979# parses the option
    80 def getOptions():
     80def parse_args():
    8181        # create a parser with the arguments for the tests script
    8282        parser = argparse.ArgumentParser(description='Script which runs cforall tests')
     
    123123        return val == 0 or settings.dry_run
    124124
    125 def isExe(file):
    126         return settings.dry_run or fileIsExecutable(file)
    127 
    128 def noRule(file, target):
    129         return not settings.dry_run and fileContainsOnly(file, "make: *** No rule to make target `%s'.  Stop." % target)
     125def no_rule(file, target):
     126        return not settings.dry_run and file_contains_only(file, "make: *** No rule to make target `%s'.  Stop." % target)
    130127
    131128# logic to run a single test and return the result (No handling of printing or other test framework logic)
     
    150147        if success(make_ret):
    151148                with Timed() as run_dur:
    152                         if isExe(exe_file):
     149                        if settings.dry_run or is_exe(exe_file):
    153150                                # run test
    154151                                retcode = run(exe_file, out_file, in_file)
     
    162159                if settings.generating :
    163160                        # if we are ounly generating the output we still need to check that the test actually exists
    164                         if noRule(out_file, test.target()) :
     161                        if no_rule(out_file, test.target()) :
    165162                                retcode = 1
    166163                                error = "\t\tNo make target for test %s!" % test.target()
     
    176173                        error = myfile.read()
    177174
    178                 ret, info = coreInfo(exe_file)
     175                ret, info = core_info(exe_file)
    179176                error = error + info
    180177
     
    190187        with SignalHandling():
    191188                # print formated name
    192                 name_txt = '{0:{width}}  '.format(t.target(), width=settings.width)
     189                name_txt = '{0:{width}}  '.format(t.target(), width=settings.output_width)
    193190
    194191                retcode, error, duration = run_single_test(t)
     
    216213
    217214        # create the executor for our jobs and handle the signal properly
    218         pool = setupPool(jobs)
     215        pool = setup_pool(jobs)
    219216
    220217        # for each test to run
     
    246243
    247244        # parse the command line arguments
    248         options = getOptions()
     245        options = parse_args()
    249246
    250247        # init global settings
     
    252249
    253250        # fetch the liest of all valid tests
    254         allTests = listTests( options.include, options.exclude )
     251        all_tests = list_tests( options.include, options.exclude )
    255252
    256253
    257254        # if user wants all tests than no other treatement of the test list is required
    258255        if options.all or options.list or options.list_comp or options.include :
    259                 tests = allTests
     256                tests = all_tests
    260257
    261258        #otherwise we need to validate that the test list that was entered is valid
    262259        else :
    263                 tests = validTests( options )
     260                tests = valid_tests( options )
    264261
    265262        # make sure we have at least some test to run
     
    286283                settings.validate()
    287284
    288                 options.jobs, forceJobs = jobCount( options, tests )
    289                 settings.updateMakeCmd(forceJobs, options.jobs)
     285                options.jobs, forceJobs = job_count( options, tests )
     286                settings.update_make_cmd(forceJobs, options.jobs)
    290287
    291288                print('%s (%s:%s) on %i cores' % (
Note: See TracChangeset for help on using the changeset viewer.