Example #1
0
            LOG.error("Error reading test results: %s", err, exc_info=True)

    if result.passed:
        print("GDB TEST PASSED")
    else:
        print("GDB TEST FAILED")

    # Cleanup
    try:
        if temp_test_elf_name and os.path.exists(temp_test_elf_name):
            os.remove(temp_test_elf_name)
        os.remove(test_result_filename)
        os.remove(test_param_filename)
    except IOError as err:
        pass

    return result


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='pyOCD gdb test')
    parser.add_argument('-d',
                        '--debug',
                        action="store_true",
                        help='Enable debug logging')
    args = parser.parse_args()
    level = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=level)
    ensure_output_dir()
    test_gdb()
Example #2
0
def main():
    parser = argparse.ArgumentParser(description='pyOCD automated testing')
    parser.add_argument('-d',
                        '--debug',
                        action="store_true",
                        help='Enable debug logging')
    parser.add_argument('-q',
                        '--quiet',
                        action="store_true",
                        help='Hide test progress for 1 job')
    parser.add_argument(
        '-j',
        '--jobs',
        action="store",
        default=1,
        type=int,
        metavar="JOBS",
        help='Set number of concurrent board tests (default is 1)')
    parser.add_argument(
        '-b',
        '--board',
        action="append",
        metavar="ID",
        help=
        "Limit testing to boards with specified unique IDs. Multiple boards can be listed."
    )
    parser.add_argument('-l',
                        '--list-tests',
                        action="store_true",
                        help="Print a list of tests that will be run.")
    parser.add_argument('-x',
                        '--exclude-tests',
                        metavar="TESTS",
                        default="",
                        help="Comma-separated list of tests to exclude.")
    parser.add_argument('-i',
                        '--include-tests',
                        metavar="TESTS",
                        default="",
                        help="Comma-separated list of tests to include.")
    args = parser.parse_args()

    # Allow CI to override the number of concurrent jobs.
    if 'CI_JOBS' in os.environ:
        args.jobs = int(os.environ['CI_JOBS'])

    filter_tests(args)

    if args.list_tests:
        for test in test_list:
            print(test.name)
        return

    # Disable multiple jobs on macOS prior to Python 3.4. By default, multiprocessing uses
    # fork() on Unix, which doesn't work on the Mac because CoreFoundation requires exec()
    # to be used in order to init correctly (CoreFoundation is used in hidapi). Only on Python
    # version 3.4+ is the multiprocessing.set_start_method() API available that lets us
    # switch to the 'spawn' method, i.e. exec().
    if args.jobs > 1 and sys.platform.startswith(
            'darwin') and sys.version_info[0:2] < (3, 4):
        print(
            "WARNING: Cannot support multiple jobs on macOS prior to Python 3.4. Forcing 1 job."
        )
        args.jobs = 1

    ensure_output_dir()

    # Setup logging based on concurrency and quiet option.
    level = logging.DEBUG if args.debug else logging.INFO
    if args.jobs == 1 and not args.quiet:
        log_file = os.path.join(TEST_OUTPUT_DIR,
                                LOG_FILE_TEMPLATE.format(get_env_file_name()))
        # Create common log file.
        if os.path.exists(log_file):
            os.remove(log_file)
        logToConsole = True
        commonLogFile = open(log_file, "a")
    else:
        logToConsole = False
        commonLogFile = None

    board_list = []
    result_list = []

    # Put together list of boards to test
    board_list = ConnectHelper.get_all_connected_probes(blocking=False)
    board_id_list = sorted(b.unique_id for b in board_list)

    # Filter boards.
    if args.board:
        board_id_list = [
            b for b in board_id_list
            if any(c for c in args.board if c.lower() in b.lower())
        ]

    # If only 1 job was requested, don't bother spawning processes.
    start = time()
    if args.jobs == 1:
        for n, board_id in enumerate(board_id_list):
            result_list += test_board(board_id, n, level, logToConsole,
                                      commonLogFile)
    else:
        # Create a pool of processes to run tests.
        try:
            pool = mp.Pool(args.jobs)

            # Issue board test job to process pool.
            async_results = [
                pool.apply_async(
                    test_board,
                    (board_id, n, level, logToConsole, commonLogFile))
                for n, board_id in enumerate(board_id_list)
            ]

            # Gather results.
            for r in async_results:
                result_list += r.get(timeout=JOB_TIMEOUT)
        finally:
            pool.close()
            pool.join()
    stop = time()
    test_time = (stop - start)

    print_summary(test_list, result_list, test_time)
    summary_file = os.path.join(
        TEST_OUTPUT_DIR, SUMMARY_FILE_TEMPLATE.format(get_env_file_name()))
    with open(summary_file, "w") as output_file:
        print_summary(test_list, result_list, test_time, output_file)
    generate_xml_results(result_list)

    exit_val = 0 if Test.all_tests_pass(result_list) else -1
    exit(exit_val)