예제 #1
0
    def __init__(self, tfiles_list_path):
        '''
        This class holds all of the information from the test suite.
        This constructor, analyzes the test suite files (classes) create a TestInfo instance for each test method,
        together with its proper annotations (e.g. @Ignore)

        :param tfiles_list_path: path to mvn .lst file that contains a list of all test files
        example: "commons-math\target\maven-status\maven-compiler-plugin\testCompile\default-testCompile\inputFiles.lst"
        '''
        print_count = 0
        abstract_count = 0
        self.tinfos = []
        with open(tfiles_list_path, "r") as tfiles_paths:
            tfile_paths_list = list(tfiles_paths)
            for idx, tfile_path in enumerate(tfile_paths_list):
                tfile_path = tfile_path.rstrip('\n')
                tfile_name = Path(tfile_path).stem
                if tfile_name.endswith('AbstractTest'):
                    abstract_count += 1
                    continue
                tmethodnameTannotations = JavaTestClassFileParser.parse_and_return_methodnameTannotations(tfile_path)
                for (tmethod_name, annotations) in tmethodnameTannotations:
                    tinfo = TestInfo(tfile_path, tfile_name, tmethod_name, annotations)
                    if Config.SAMPLE_ONLY_ACTUAL_FAULTY_PACKAGES and tinfo.is_in_faulty_package:
                        self.tinfos.append(tinfo)
                if print_count == 20:
                    logger.debug(f"processed {idx +1} out of {len(tfile_paths_list)} test files information")
                    print_count = 0
                print_count += 1
        logger.debug(f"ignored {abstract_count} abstract test classes")
        logger.debug(f"added {len(self.tinfos)} test files information")
예제 #2
0
 def run(self):
     for retry_count in range(self.RETRY_COUNT):
         test_info = TestInfo(self.test_name)
         if retry_count > 0:
             test_info.info('Previous attempts %s' % retry_count)
         try:
             self._run(test_info)
         except IOError:
             time.sleep(self.DELAY_BEFORE_RETRY_S)
             continue
         self.parent_test.attach_subtest(test_info)
         break
     else:
         raise Exception("Flashing failed after %i retries" %
                         self.RETRY_COUNT)
예제 #3
0
    def run_tests(self, quick=False):
        """Run all configurations"""
        # Tests can only be run once per TestManager instance
        assert self._state is self._STATE.CONFIGURED
        self._state = self._STATE.COMPLETE

        all_tests_pass = True
        for test_configuration in self._test_configuration_list:
            board = test_configuration.board
            test_info = TestInfo(test_configuration.name)
            test_configuration.test_info = test_info

            test_info.info("Board: %s" % test_configuration.board)
            test_info.info("Application: %s" %
                           test_configuration.if_firmware)
            test_info.info("Bootloader: %s" %
                           test_configuration.bl_firmware)
            test_info.info("Target: %s" % test_configuration.target)


            if self._load_if:
                if_path = test_configuration.if_firmware.hex_path
                board.load_interface(if_path, test_info)

            valid_bl = test_configuration.bl_firmware is not None
            if self._load_bl and valid_bl:
                bl_path = test_configuration.bl_firmware.hex_path
                board.load_bootloader(bl_path, test_info)

            board.set_check_fs_on_remount(True)

            if self._test_daplink:
                daplink_test(test_configuration, test_info, quick)

            if self._test_ep:
                test_endpoints(test_configuration, test_info, quick)

            if test_info.get_failed():
                all_tests_pass = False

        self._all_tests_pass = all_tests_pass
예제 #4
0
def main():
    self_path = os.path.abspath(__file__)
    test_dir = os.path.dirname(self_path)
    daplink_dir = os.path.dirname(test_dir)

    # We make assumptions that break if user copies script file outside the test dir
    if os.path.basename(test_dir) != "test":
        print("Error - this script must reside in the test directory")
        exit(-1)

    git_sha, local_changes = get_git_info(daplink_dir)
    firmware_list = get_firmware_names(daplink_dir)
    firmware_choices = [
        firmware for firmware in firmware_list if firmware.endswith('_if')
    ]

    description = 'DAPLink validation and testing tool'
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument('--targetdir',
                        help='Directory with pre-built target test images.',
                        default=None)
    parser.add_argument('--user',
                        type=str,
                        default=None,
                        help='MBED username (required for compile-api)')
    parser.add_argument('--password',
                        type=str,
                        default=None,
                        help='MBED password (required for compile-api)')
    parser.add_argument('--firmwaredir',
                        help='Directory with firmware images to test',
                        default=None)
    parser.add_argument('--firmware',
                        help='Firmware to test',
                        action='append',
                        choices=firmware_choices,
                        default=[],
                        required=False)
    parser.add_argument('--logdir',
                        help='Directory to log test results to',
                        default=DEFAULT_TEST_DIR)
    parser.add_argument('--noloadif',
                        help='Skip load step for interface.',
                        default=False,
                        action='store_true')
    parser.add_argument('--notestendpt',
                        help='Dont test the interface '
                        'USB endpoints.',
                        default=False,
                        action='store_true')
    parser.add_argument('--loadbl',
                        help='Load bootloader before test.',
                        default=False,
                        action='store_true')
    parser.add_argument('--testdl',
                        help='Run DAPLink specific tests. '
                        'The DAPLink test tests bootloader updates so use'
                        'with caution',
                        default=False,
                        action='store_true')
    parser.add_argument('--testfirst',
                        help='If multiple boards of the same '
                        'type are found only test the first one.',
                        default=False,
                        action='store_true')
    parser.add_argument('--verbose',
                        help='Verbose output',
                        choices=VERB_LEVELS,
                        default=VERB_NORMAL)
    parser.add_argument('--dryrun',
                        default=False,
                        action='store_true',
                        help='Print info on configurations but dont '
                        'actually run tests.')
    parser.add_argument(
        '--force',
        action='store_true',
        default=False,
        help=
        'Try to run tests even if there are problems. Delete logs from previous run.'
    )
    args = parser.parse_args()

    use_prebuilt = args.targetdir is not None
    use_compile_api = args.user is not None and args.password is not None

    test_info = TestInfo('DAPLink')

    # Validate args

    # See if user wants to test endpoints. If yes and he didn't provide
    # target test binaries, use the Compile API to build them
    all_targets = None
    if not args.notestendpt:
        if not use_prebuilt and not use_compile_api:
            print("Endpoint test requires target test images.")
            print("  Directory with pre-built target test images")
            print("  must be specified with '--targetdir'")
            print("OR")
            print("  developer.mbed.org login credentials must be ")
            print("  specified with '--user' and '--password' so test ")
            print("  images can be built with the RESTful Compile API.")
            print("NOTE: you can skip the endpoint tests altogether ")
            print("with --notestendpt")

            exit(-1)

        if args.targetdir is not None:
            target_dir = args.targetdir
        else:
            target_dir = daplink_dir + os.sep + 'tmp'
            build_target_bundle(target_dir, args.user, args.password,
                                test_info)

        target_bundle = load_target_bundle(target_dir)
        all_targets = target_bundle.get_target_list()

    if os.path.exists(args.logdir):
        if args.force:
            shutil.rmtree(args.logdir)
        else:
            print('Error - test results directory "%s" already exists' %
                  args.logdir)
            exit(-1)

    # Get all relevant info
    if args.firmwaredir is None:
        firmware_bundle = load_bundle_from_project()
    else:
        firmware_bundle = load_bundle_from_release(args.firmwaredir)

    all_firmware = firmware_bundle.get_firmware_list()
    all_boards = get_all_attached_daplink_boards()

    for board in all_boards:
        if board.get_mode() == board.MODE_BL:
            print('Switching to APP mode on board: %s' % board.unique_id)
            try:
                board.set_mode(board.MODE_IF)
            except Exception:
                print('Unable to switch mode on board: %s' % board.unique_id)

    # Make sure firmware is present
    firmware_explicitly_specified = len(args.firmware) != 0
    if firmware_explicitly_specified:
        all_firmware_names = set(fw.name for fw in all_firmware)
        firmware_missing = False
        for firmware_name in args.firmware:
            if firmware_name not in all_firmware_names:
                firmware_missing = True
                test_info.failure('Cannot find firmware %s' % firmware_name)
        if firmware_missing:
            test_info.failure('Firmware missing - aborting test')
            exit(-1)

    # Create manager and add resources
    tester = TestManager()
    tester.add_firmware(all_firmware)
    tester.add_boards(all_boards)
    if all_targets is not None:
        tester.add_targets(all_targets)
    if firmware_explicitly_specified:
        tester.set_firmware_filter(args.firmware)

    # Configure test manager
    tester.set_test_first_board_only(args.testfirst)
    tester.set_load_if(not args.noloadif)
    tester.set_test_ep(not args.notestendpt)
    tester.set_load_bl(args.loadbl)
    tester.set_test_daplink(args.testdl)

    # Build test configurations
    tester.build_test_configurations(test_info)

    test_config_list = tester.get_test_configurations()
    if len(test_config_list) == 0:
        test_info.failure("Nothing that can be tested")
        exit(-1)
    else:
        test_info.info('Test configurations to be run:')
        index = 0
        for test_config in test_config_list:
            test_info.info('    %i: %s' % (index, test_config))
            index += 1
    test_info.info('')

    untested_list = tester.get_untested_firmware()
    if len(untested_list) == 0:
        test_info.info("All firmware can be tested")
    else:
        test_info.info('Fimrware that will not be tested:')
        for untested_firmware in untested_list:
            test_info.info('    %s' % untested_firmware.name)
    test_info.info('')

    if firmware_explicitly_specified and len(untested_list) != 0:
        test_info.failure("Exiting because not all firmware could be tested")
        exit(-1)

    # If this is a dryrun don't run tests, just print info
    if args.dryrun:
        exit(0)

    # Run tests
    tester.run_tests()

    # Print test results
    tester.print_results(args.verbose)
    tester.write_test_results(args.logdir,
                              git_sha=git_sha,
                              local_changes=local_changes)

    # Warn about untested boards
    print('')
    for firmware in tester.get_untested_firmware():
        print('Warning - configuration %s is untested' % firmware.name)

    if tester.all_tests_pass:
        print("All boards passed")
        exit(0)
    else:
        print("Test Failed")
        exit(-1)
예제 #5
0
 def __str__(self):
     from common import exc_info_to_string
     from test_info import TestInfo
     return exc_info_to_string(self.exc_info, TestInfo(self.test))