Changeset 256728f for tests


Ignore:
Timestamp:
Jun 26, 2019, 5:32:42 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
39156ed
Parents:
bd87a9ad (diff), b0ab7853 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/pybin/tools.py

    rbd87a9ad r256728f  
    179179                        os.chdir(cwd)
    180180
     181def killgroup():
     182        try:
     183                os.killpg(os.getpgrp(), signal.SIGINT)
     184        except KeyboardInterrupt:
     185                pass # expected
     186        except Exception as exc:
     187                print("Unexpected exception", file=sys.stderr)
     188                print(exc, file=sys.stderr)
     189                sys.stderr.flush()
     190                sys.exit(2)
     191
    181192################################################################################
    182193#               file handling
     
    301312        self.end = time.time()
    302313        self.duration = self.end - self.start
     314
     315def timed(src, timeout):
     316        expire = time.time() + timeout
     317        i = iter(src)
     318        while True:
     319                yield i.next(max(expire - time.time(), 0))
  • tests/test.py

    rbd87a9ad r256728f  
    202202                if error :
    203203                        text = text + '\n' + error
    204                         out = sys.stderr
    205 
    206                 print(text, file = out)
    207                 sys.stdout.flush()
     204
     205                return retcode == TestResult.SUCCESS, text
     206        except KeyboardInterrupt:
     207                return False, ""
     208        except:
     209                print("Unexpected error in worker thread", file=sys.stderr)
    208210                sys.stderr.flush()
    209 
    210                 return retcode != TestResult.SUCCESS
    211         except KeyboardInterrupt:
    212                 False
     211                return False, ""
     212
    213213
    214214# run the given list of tests with the given parameters
     
    220220        pool = multiprocessing.Pool(jobs)
    221221
     222        failed = False
     223
    222224        # for each test to run
    223225        try :
    224                 results = pool.map_async(
     226                num = len(tests)
     227                fancy = sys.stdout.isatty()
     228                results = pool.imap_unordered(
    225229                        run_test_worker,
    226230                        tests,
    227231                        chunksize = 1
    228                 ).get(settings.timeout.total)
     232                )
     233
     234                for i, (succ, txt) in enumerate(timed(results, timeout = settings.timeout.total), 1) :
     235                        if not succ :
     236                                failed = True
     237
     238                        print("       " + txt)
     239
     240                        if(fancy and i != num):
     241                                print("%d/%d" % (i, num), end='\r')
     242                                sys.stdout.flush()
     243
    229244        except KeyboardInterrupt:
     245                print("Tests interrupted by user", file=sys.stderr)
    230246                pool.terminate()
    231                 print("Tests interrupted by user")
    232                 sys.exit(1)
     247                pool.join()
     248                failed = True
     249        except multiprocessing.TimeoutError:
     250                print("ERROR: Test suite timed out", file=sys.stderr)
     251                pool.terminate()
     252                pool.join()
     253                failed = True
     254                killgroup() # needed to cleanly kill all children
     255
    233256
    234257        # clean the workspace
    235258        make('clean', output=subprocess.DEVNULL, error=subprocess.DEVNULL)
    236259
    237         for failed in results:
    238                 if failed :
    239                         return 1
    240 
    241         return 0
     260        return 1 if failed else 0
    242261
    243262
Note: See TracChangeset for help on using the changeset viewer.