(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=None, combined_logs_len=0, failfast=False, runs_ci)
| 328 | ) |
| 329 | |
| 330 | def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=None, combined_logs_len=0, failfast=False, runs_ci): |
| 331 | args = args or [] |
| 332 | |
| 333 | # Warn if bitcoind is already running (unix only) |
| 334 | try: |
| 335 | if subprocess.check_output(["pidof", "bitcoind"]) is not None: |
| 336 | print("%sWARNING!%s There is already a bitcoind process running on this system. Tests may fail unexpectedly due to resource contention!" % (BOLD[1], BOLD[0])) |
| 337 | except (OSError, subprocess.SubprocessError): |
| 338 | pass |
| 339 | |
| 340 | # Warn if there is a cache directory |
| 341 | cache_dir = "%s/test/cache" % build_dir |
| 342 | if os.path.isdir(cache_dir): |
| 343 | print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % (BOLD[1], BOLD[0], cache_dir)) |
| 344 | |
| 345 | # ELEMENTS: |
| 346 | tests_dir = src_dir + '/test/bitcoin_functional/functional/' |
| 347 | |
| 348 | flags = ['--cachedir={}'.format(cache_dir)] + args |
| 349 | |
| 350 | if enable_coverage: |
| 351 | coverage = RPCCoverage() |
| 352 | flags.append(coverage.flag) |
| 353 | logging.debug("Initializing coverage directory at %s" % coverage.dir) |
| 354 | else: |
| 355 | coverage = None |
| 356 | |
| 357 | if len(test_list) > 1 and jobs > 1: |
| 358 | # Populate cache |
| 359 | try: |
| 360 | subprocess.check_output([sys.executable, tests_dir + 'create_cache.py'] + flags + ["--tmpdir=%s/cache" % tmpdir]) |
| 361 | except subprocess.CalledProcessError as e: |
| 362 | sys.stdout.buffer.write(e.output) |
| 363 | raise |
| 364 | |
| 365 | #Run Tests |
| 366 | job_queue = TestHandler( |
| 367 | num_tests_parallel=jobs, |
| 368 | tests_dir=tests_dir, |
| 369 | tmpdir=tmpdir, |
| 370 | test_list=test_list, |
| 371 | flags=flags, |
| 372 | timeout_duration=40 * 60 if runs_ci else float('inf'), # in seconds |
| 373 | ) |
| 374 | start_time = time.time() |
| 375 | test_results = [] |
| 376 | |
| 377 | max_len_name = len(max(test_list, key=len)) |
| 378 | test_count = len(test_list) |
| 379 | for i in range(test_count): |
| 380 | test_result, testdir, stdout, stderr = job_queue.get_next() |
| 381 | test_results.append(test_result) |
| 382 | done_str = "{}/{} - {}{}{}".format(i + 1, test_count, BOLD[1], test_result.name, BOLD[0]) |
| 383 | if test_result.status == "Passed": |
| 384 | logging.debug("%s passed, Duration: %s s" % (done_str, test_result.time)) |
| 385 | elif test_result.status == "Skipped": |
| 386 | logging.debug("%s skipped" % (done_str)) |
| 387 | else: |
no test coverage detected