# This code is in the public domain
#-------------------------------------------------------------------------------
import argparse
-import os
-import sys
-import re
from difflib import SequenceMatcher
import logging
+from multiprocessing import Pool
+import os
import platform
+import re
+import sys
import time
+
from utils import run_exe, is_in_rootdir, dump_output_to_temp_files
# Make it possible to run this file from the root dir of pyelftools without
if not os.path.exists(READELF_PATH):
READELF_PATH = 'readelf'
+
def discover_testfiles(rootdir):
""" Discover test files in the given directory. Yield them one by one.
"""
exe_path, ' '.join(args)))
t1 = time.time()
rc, stdout = run_exe(exe_path, args)
- testlog.info("....elapsed: %s" % (time.time() - t1,))
+ if verbose: testlog.info("....elapsed: %s" % (time.time() - t1,))
if rc != 0:
testlog.error("@@ aborting - '%s' returned '%s'" % (exe_path, rc))
return False
if verbose: testlog.info('....comparing output...')
t1 = time.time()
rc, errmsg = compare_output(*stdouts)
- testlog.info("....elapsed: %s" % (time.time() - t1,))
+ if verbose: testlog.info("....elapsed: %s" % (time.time() - t1,))
if rc:
if verbose: testlog.info('.......................SUCCESS')
else:
usage='usage: %(prog)s [options] [file] [file] ...',
prog='run_readelf_tests.py')
argparser.add_argument('files', nargs='*', help='files to run tests on')
+ argparser.add_argument(
+ '--parallel', action='store_true',
+ help='run tests in parallel; always runs all tests w/o verbose')
argparser.add_argument('-V', '--verbose',
action='store_true', dest='verbose',
- help='Verbose output')
+ help='verbose output')
argparser.add_argument(
'-k', '--keep-going',
action='store_true', dest='keep_going',
help="Run all tests, don't stop at the first failure")
args = argparser.parse_args()
+ if args.parallel:
+ if args.verbose or args.keep_going == False:
+ print('WARNING: parallel mode disables verbosity and always keeps going')
+
if args.verbose:
testlog.info('Running in verbose mode')
testlog.info('Python executable = %s' % sys.executable)
else:
filenames = sorted(discover_testfiles('test/testfiles_for_readelf'))
- failures = 0
- for filename in filenames:
- if not run_test_on_file(filename, verbose=args.verbose):
- failures += 1
- if not args.keep_going:
- break
+ if len(filenames) > 1 and args.parallel:
+ pool = Pool()
+ results = pool.map(
+ run_test_on_file,
+ filenames)
+ failures = results.count(False)
+ else:
+ failures = 0
+ for filename in filenames:
+ if not run_test_on_file(filename, verbose=args.verbose):
+ failures += 1
+ if not args.keep_going:
+ break
if failures == 0:
testlog.info('\nConclusion: SUCCESS')