Example #1
0
def cmd_parser_setup():
    """! Creates simple command line parser
    """
    parser = optparse.OptionParser()

    parser.add_option('-f',
                      '--file',
                      dest='filename',
                      help='File to flash onto mbed device')

    parser.add_option(
        "-d",
        "--disk",
        dest="disk",
        help="Target disk (mount point) path. Example: F:, /mnt/MBED",
        metavar="DISK_PATH")

    copy_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('CopyMethod'))

    parser.add_option("-c",
                      "--copy",
                      dest="copy_method",
                      default='shell',
                      help="Copy (flash the target) method selector. " +
                      copy_methods_str,
                      metavar="COPY_METHOD")

    parser.add_option('',
                      '--plugins',
                      dest='list_plugins',
                      default=False,
                      action="store_true",
                      help='Prints registered plugins and exits')

    parser.add_option('',
                      '--version',
                      dest='version',
                      default=False,
                      action="store_true",
                      help='Prints package version and exits')

    parser.description = """Flash mbed devices from command line.""" \
        """This module is using build in to mbed-host-tests plugins used for flashing mbed devices"""
    parser.epilog = """Example: mbedflsh -d E: -f /path/to/file.bin"""

    (opts, args) = parser.parse_args()
    return (opts, args)
Example #2
0
def main():
    """ Closure for main_cli() function """
    parser = optparse.OptionParser()

    parser.add_option(
        '-t',
        '--target',
        dest='list_of_targets',
        help=
        'You can specify list of yotta targets you want to build. Use comma to separate them.'
        +
        'Note: If --test-spec switch is defined this list becomes optional list of builds you want to filter in your test:'
        +
        'Comma separated list of builds from test specification. Applicable if --test-spec switch is specified'
    )

    parser.add_option(
        '-n',
        '--test-by-names',
        dest='test_by_names',
        help=
        'Runs only test enumerated it this switch. Use comma to separate test case names.'
    )

    parser.add_option(
        '-i',
        '--skip-test',
        dest='skip_test',
        help=
        'Skip tests enumerated it this switch. Use comma to separate test case names.'
    )

    parser.add_option(
        "-O",
        "--only-build",
        action="store_true",
        dest="only_build_tests",
        default=False,
        help=
        "Only build repository and tests, skips actual test procedures (flashing etc.)"
    )

    parser.add_option("-S",
                      "--skip-build",
                      action="store_true",
                      dest="skip_yotta_build",
                      default=True,
                      help="Skip calling 'yotta build' on this module")

    copy_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('CopyMethod'))
    parser.add_option("-c",
                      "--copy",
                      dest="copy_method",
                      help="Copy (flash the target) method selector. " +
                      copy_methods_str,
                      metavar="COPY_METHOD")

    reset_methods_str = "Plugin support: " + ', '.join(
        host_tests_plugins.get_plugin_caps('ResetMethod'))
    parser.add_option("-r",
                      "--reset",
                      dest="reset_method",
                      help="Reset method selector. " + reset_methods_str,
                      metavar="RESET_METHOD")

    parser.add_option(
        '',
        '--parallel',
        dest='parallel_test_exec',
        default=1,
        help=
        'Experimental, you execute test runners for connected to your host MUTs in parallel (speeds up test result collection)'
    )

    parser.add_option(
        "-e",
        "--enum-host-tests",
        dest="enum_host_tests",
        help=
        "Define directory with yotta module local host tests. Default: ./test/host_tests"
    )

    parser.add_option(
        '',
        '--config',
        dest='verbose_test_configuration_only',
        default=False,
        action="store_true",
        help='Displays connected boards and detected targets and exits.')

    parser.add_option(
        '',
        '--release',
        dest='build_to_release',
        default=False,
        action="store_true",
        help='If possible force build in release mode (yotta -r).')

    parser.add_option('',
                      '--debug',
                      dest='build_to_debug',
                      default=False,
                      action="store_true",
                      help='If possible force build in debug mode (yotta -d).')

    parser.add_option('-l',
                      '--list',
                      dest='list_binaries',
                      default=False,
                      action="store_true",
                      help='List available binaries')

    parser.add_option(
        '-g',
        '--grm',
        dest='global_resource_mgr',
        help=('Global resource manager: "<platform name>:'
              '<remote mgr module>:<host url or IP address>[:<port>]", '
              'Ex. "K64F:module_name:10.2.123.43:3334", '
              '"K64F:module_name:https://example.com"'))

    # Show --fm option only if "fm_agent" module installed
    try:
        imp.find_module('fm_agent')
    except ImportError:
        fm_help = optparse.SUPPRESS_HELP
    else:
        fm_help = 'Fast Model Connection: fastmodel name, config name, example FVP_MPS2_M3:DEFAULT'
    parser.add_option('', '--fm', dest='fast_model_connection', help=fm_help)

    parser.add_option(
        '-m',
        '--map-target',
        dest='map_platform_to_yt_target',
        help=
        'List of custom mapping between platform name and yotta target. Comma separated list of YOTTA_TARGET:PLATFORM tuples'
    )

    parser.add_option(
        '',
        '--use-tids',
        dest='use_target_ids',
        help=
        'Specify explicitly which devices can be used by Greentea for testing by creating list of allowed Target IDs (use comma separated list)'
    )

    parser.add_option('-u',
                      '--shuffle',
                      dest='shuffle_test_order',
                      default=False,
                      action="store_true",
                      help='Shuffles test execution order')

    parser.add_option(
        '',
        '--shuffle-seed',
        dest='shuffle_test_seed',
        default=None,
        help=
        'Shuffle seed (If you want to reproduce your shuffle order please use seed provided in test summary)'
    )

    parser.add_option(
        '',
        '--sync',
        dest='num_sync_packtes',
        default=5,
        help=
        'Define how many times __sync packet will be sent to device: 0: none; -1: forever; 1,2,3... - number of  times (the default is 5 packets)'
    )

    parser.add_option(
        '-P',
        '--polling-timeout',
        dest='polling_timeout',
        default=60,
        metavar="NUMBER",
        type="int",
        help=
        'Timeout in sec for readiness of mount point and serial port of local or remote device. Default 60 sec'
    )

    parser.add_option(
        '',
        '--tag-filters',
        dest='tags',
        default=None,
        help=
        'Filter list of available devices under test to only run on devices with the provided list of tags  [tag-filters tag1,tag]'
    )

    parser.add_option(
        '',
        '--lock',
        dest='lock_by_target',
        default=False,
        action="store_true",
        help=
        'Use simple resource locking mechanism to run multiple application instances'
    )

    parser.add_option(
        '',
        '--digest',
        dest='digest_source',
        help=
        'Redirect input from where test suite should take console input. You can use stdin or file name to get test case console output'
    )

    parser.add_option('-H',
                      '--hooks',
                      dest='hooks_json',
                      help='Load hooks used drive extra functionality')

    parser.add_option('',
                      '--test-spec',
                      dest='test_spec',
                      help='Test specification generated by build system.')

    parser.add_option(
        '',
        '--test-cfg',
        dest='json_test_configuration',
        help='Pass to host test data with host test configuration')

    parser.add_option(
        '',
        '--run',
        dest='run_app',
        help='Flash, reset and dump serial from selected binary application')

    parser.add_option(
        '',
        '--report-junit',
        dest='report_junit_file_name',
        help=
        'You can log test suite results in form of JUnit compliant XML report')

    parser.add_option('',
                      '--report-text',
                      dest='report_text_file_name',
                      help='You can log test suite results to text file')

    parser.add_option(
        '',
        '--report-json',
        dest='report_json_file_name',
        help='You can log test suite results to JSON formatted file')

    parser.add_option(
        '',
        '--report-html',
        dest='report_html_file_name',
        help='You can log test suite results in the form of a HTML page')

    parser.add_option('',
                      '--report-fails',
                      dest='report_fails',
                      default=False,
                      action="store_true",
                      help='Prints console outputs for failed tests')

    parser.add_option(
        '',
        '--retry-count',
        dest='retry_count',
        default=1,
        type=int,
        help=
        'retry count for individual test failure. By default, there is no retry'
    )

    parser.add_option(
        '',
        '--report-memory-metrics-csv',
        dest='report_memory_metrics_csv_file_name',
        help='You can log test suite memory metrics in the form of a CSV file')

    parser.add_option(
        '',
        '--yotta-registry',
        dest='yotta_search_for_mbed_target',
        default=False,
        action="store_true",
        help=
        'Use on-line yotta registry to search for compatible with connected mbed devices yotta targets. Default: search is done in yotta_targets directory'
    )

    parser.add_option('-V',
                      '--verbose-test-result',
                      dest='verbose_test_result_only',
                      default=False,
                      action="store_true",
                      help='Prints test serial output')

    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      default=False,
                      action="store_true",
                      help='Verbose mode (prints some extra information)')

    parser.add_option('',
                      '--plain',
                      dest='plain',
                      default=False,
                      action="store_true",
                      help='Do not use colours while logging')

    parser.add_option('',
                      '--version',
                      dest='version',
                      default=False,
                      action="store_true",
                      help='Prints package version and exits')

    parser.description = """This automated test script is used to test mbed SDK 3.0 on mbed-enabled devices with support from yotta build tool"""
    parser.epilog = """Example: mbedgt --target frdm-k64f-gcc"""

    (opts, args) = parser.parse_args()

    cli_ret = 0

    if not opts.version:
        # This string should not appear when fetching plain version string
        gt_logger.gt_log(get_hello_string())

    start = time()
    if opts.lock_by_target:
        # We are using Greentea proprietary locking mechanism to lock between platforms and targets
        gt_logger.gt_log("using (experimental) simple locking mechanism")
        gt_logger.gt_log_tab("kettle: %s" % GREENTEA_KETTLE_PATH)
        gt_file_sem, gt_file_sem_name, gt_instance_uuid = greentea_get_app_sem(
        )
        with gt_file_sem:
            greentea_update_kettle(gt_instance_uuid)
            try:
                cli_ret = main_cli(opts, args, gt_instance_uuid)
            except KeyboardInterrupt:
                greentea_clean_kettle(gt_instance_uuid)
                gt_logger.gt_log_err("ctrl+c keyboard interrupt!")
                return 1  # Keyboard interrupt
            except:
                greentea_clean_kettle(gt_instance_uuid)
                gt_logger.gt_log_err("unexpected error:")
                gt_logger.gt_log_tab(sys.exc_info()[0])
                raise
            greentea_clean_kettle(gt_instance_uuid)
    else:
        # Standard mode of operation
        # Other instance must provide mutually exclusive access control to platforms and targets
        try:
            cli_ret = main_cli(opts, args)
        except KeyboardInterrupt:
            gt_logger.gt_log_err("ctrl+c keyboard interrupt!")
            return 1  # Keyboard interrupt
        except Exception as e:
            gt_logger.gt_log_err("unexpected error:")
            gt_logger.gt_log_tab(str(e))
            raise

    if not any([opts.list_binaries, opts.version]):
        delta = time() - start  # Test execution time delta
        gt_logger.gt_log("completed in %.2f sec" % delta)

    if cli_ret:
        if cli_ret < 0 or cli_ret > 255:
            cli_ret = 1
        gt_logger.gt_log_err("exited with code %d" % cli_ret)

    return (cli_ret)