コード例 #1
0
 def __init__(self):
     """ ctor
     """
     # Setting Host Test Logger instance
     ht_loggers = {
         'BasePlugin' : HtrunLogger('PLGN'),
         'CopyMethod' : HtrunLogger('COPY'),
         'ResetMethod' : HtrunLogger('REST'),
     }
     self.plugin_logger = ht_loggers.get(self.type, ht_loggers['BasePlugin'])
コード例 #2
0
ファイル: conn_proxy.py プロジェクト: studavekar/htrun
    def append(self, payload):
        """! Append stream buffer with payload and process. Returns non-KV strings"""
        logger = HtrunLogger('CONN')
        try:
            self.buff += payload.decode('utf-8')
        except UnicodeDecodeError:
            logger.prn_wrn("UnicodeDecodeError encountered!")
            self.buff += payload.decode('utf-8','ignore')
        lines = self.buff.split('\n')
        self.buff = lines[-1]   # remaining
        lines.pop(-1)
        # List of line or strings that did not match K,V pair.
        discarded = []

        for line in lines:
            m = self.re_kv.search(line)
            if m:
                (key, value) = m.groups()
                self.kvl.append((key, value, time()))
                line = line.strip()
                match = m.group(0)
                pos = line.find(match)
                before = line[:pos]
                after = line[pos + len(match):]
                if len(before) > 0:
                    discarded.append(before)
                if len(after) > 0:
                    # not a K,V pair part
                    discarded.append(after)
            else:
                # not a K,V pair
                discarded.append(line)
        return discarded
コード例 #3
0
    def __init__(self, options):
        """ ctor
        """
        # For compatibility with old mbed. We can use command line options for Mbed object
        # or we can pass options directly from .
        self.options = options
        self.logger = HtrunLogger('MBED')
        # Options related to copy / reset mbed device
        self.port = self.options.port
        self.disk = self.options.disk
        self.target_id = self.options.target_id
        self.image_path = self.options.image_path.strip(
            '"') if self.options.image_path is not None else ''
        self.copy_method = self.options.copy_method
        self.retry_copy = self.options.retry_copy
        self.program_cycle_s = float(
            self.options.program_cycle_s if self.options.
            program_cycle_s is not None else 2.0)
        self.polling_timeout = self.options.polling_timeout

        # Serial port settings
        self.serial_baud = DEFAULT_BAUD_RATE
        self.serial_timeout = 1

        # Users can use command to pass port speeds together with port name. E.g. COM4:115200:1
        # Format if PORT:SPEED:TIMEOUT
        port_config = self.port.split(':') if self.port else ''
        if len(port_config) == 2:
            # -p COM4:115200
            self.port = port_config[0]
            self.serial_baud = int(port_config[1])
        elif len(port_config) == 3:
            # -p COM4:115200:0.5
            self.port = port_config[0]
            self.serial_baud = int(port_config[1])
            self.serial_timeout = float(port_config[2])

        # Overriding baud rate value with command line specified value
        self.serial_baud = self.options.baud_rate if self.options.baud_rate else self.serial_baud

        # Test configuration in JSON format
        self.test_cfg = None
        if self.options.json_test_configuration is not None:
            # We need to normalize path before we open file
            json_test_configuration_path = self.options.json_test_configuration.strip(
                "\"'")
            try:
                self.logger.prn_inf("Loading test configuration from '%s'..." %
                                    json_test_configuration_path)
                with open(json_test_configuration_path) as data_file:
                    self.test_cfg = json.load(data_file)
            except IOError as e:
                self.logger.prn_err(
                    "Test configuration JSON file '{0}' I/O error({1}): {2}".
                    format(json_test_configuration_path, e.errno, e.strerror))
            except:
                self.logger.prn_err(
                    "Test configuration JSON Unexpected error:", str(e))
                raise
コード例 #4
0
    def __init__(self, options):
        """! ctor
        """
        self.options = options

        self.logger = HtrunLogger('HTST')

        # Handle extra command from
        if options:
            if options.enum_host_tests:
                path = self.options.enum_host_tests
                enum_host_tests(path, verbose=options.verbose)

            if options.list_reg_hts:    # --list option
                print_ht_list(verbose=options.verbose)
                sys.exit(0)

            if options.list_plugins:    # --plugins option
                host_tests_plugins.print_plugin_info()
                sys.exit(0)

            if options.version:         # --version
                import pkg_resources    # part of setuptools
                version = pkg_resources.require("mbed-host-tests")[0].version
                print version
                sys.exit(0)

            if options.send_break_cmd:  # -b with -p PORT (and optional -r RESET_TYPE)
                handle_send_break_cmd(port=options.port,
                    disk=options.disk,
                    reset_type=options.forced_reset_type,
                    baudrate=options.baud_rate,
                    verbose=options.verbose)
                sys.exit(0)

            if options.global_resource_mgr:
                # If Global Resource Mgr is working it will handle reset/flashing workflow
                # So local plugins are offline
                self.options.skip_reset = True
                self.options.skip_flashing = True

        if options.compare_log:
            with open(options.compare_log, "r") as f:
                self.compare_log = f.read().splitlines()

        else:
            self.compare_log = None
        self.serial_output_file = options.serial_output_file
        self.compare_log_idx = 0
        DefaultTestSelectorBase.__init__(self, options)
コード例 #5
0
ファイル: softap_basic.py プロジェクト: zhiyong80/mbed-os
    def __init__(self):
        super(SoftAPBasicHostTests, self).__init__()
        self.logger = HtrunLogger('TEST')
        self.log = self.logger.prn_inf

        self.__result = False
        self.wifi_dev = 'wlan0'

        # The SoftAP config must be consisten with client side
        self.softap_ssid = 'MBEDSoftAPTest'
        self.softap_password = '******'
        self.softap_ip_address = '192.168.10.1'

        self.softap_event_action_table = {'up': self.host_wifi_softap_up_test}
コード例 #6
0
ファイル: conn_primitive.py プロジェクト: zhanggyhz/htrun
 def __init__(self, name):
     self.LAST_ERROR = None
     self.logger = HtrunLogger(name)
     self.polling_timeout = 60
コード例 #7
0
ファイル: conn_proxy.py プロジェクト: u-blox/htrun
def conn_process(event_queue, dut_event_queue, config):

    logger = HtrunLogger('CONN')
    logger.prn_inf("starting connection process...")

    # Send connection process start event to host process
    # NOTE: Do not send any other Key-Value pairs before this!
    event_queue.put(('__conn_process_start', 1, time()))

    # Configuration of conn_opriocess behaviour
    sync_behavior = int(config.get('sync_behavior', 1))
    sync_timeout = config.get('sync_timeout', 1.0)
    conn_resource = config.get('conn_resource', 'serial')

    # Create connector instance with proper configuration
    connector = conn_primitive_factory(conn_resource, config, event_queue, logger)
    # Create simple buffer we will use for Key-Value protocol data
    kv_buffer = KiViBufferWalker()

    # List of all sent to target UUIDs (if multiple found)
    sync_uuid_list = []

    # We will ignore all kv pairs before we get sync back
    sync_uuid_discovered = False

    def __send_sync(timeout=None):
        sync_uuid = str(uuid.uuid4())
        # Handshake, we will send {{sync;UUID}} preamble and wait for mirrored reply
        if timeout:
            logger.prn_inf("resending new preamble '%s' after %0.2f sec"% (sync_uuid, timeout))
        else:
            logger.prn_inf("sending preamble '%s'"% sync_uuid)
        connector.write_kv('__sync', sync_uuid)
        return sync_uuid

    # Send simple string to device to 'wake up' greentea-client k-v parser
    connector.write("mbed" * 10, log=True)

    # Sync packet management allows us to manipulate the way htrun sends __sync packet(s)
    # With current settings we can force on htrun to send __sync packets in this manner:
    #
    # * --sync=0        - No sync packets will be sent to target platform
    # * --sync=-10      - __sync packets will be sent unless we will reach
    #                     timeout or proper response is sent from target platform
    # * --sync=N        - Send up to N __sync packets to target platform. Response
    #                     is sent unless we get response from target platform or
    #                     timeout occur

    if sync_behavior > 0:
        # Sending up to 'n' __sync packets
        logger.prn_inf("sending up to %s __sync packets (specified with --sync=%s)"% (sync_behavior, sync_behavior))
        sync_uuid_list.append(__send_sync())
        sync_behavior -= 1
    elif sync_behavior == 0:
        # No __sync packets
        logger.prn_wrn("skipping __sync packet (specified with --sync=%s)"% sync_behavior)
    else:
        # Send __sync until we go reply
        logger.prn_inf("sending multiple __sync packets (specified with --sync=%s)"% sync_behavior)
        sync_uuid_list.append(__send_sync())
        sync_behavior -= 1

    loop_timer = time()
    while True:

        # Check if connection is lost to serial
        if not connector.connected():
            error_msg = connector.error()
            connector.finish()
            event_queue.put(('__notify_conn_lost', error_msg, time()))
            break

        # Send data to DUT
        try:
            (key, value, _) = dut_event_queue.get(block=False)
        except QueueEmpty:
            pass # Check if target sent something
        else:
            # Return if state machine in host_test_default has finished to end process
            if key == '__host_test_finished' and value == True:
                logger.prn_inf("received special even '%s' value='%s', finishing"% (key, value))
                connector.finish()
                return 0
            connector.write_kv(key, value)

        # Since read is done every 0.2 sec, with maximum baud rate we can receive 2304 bytes in one read in worst case.
        data = connector.read(2304)
        if data:
            # Stream data stream KV parsing
            print_lines = kv_buffer.append(data)
            for line in print_lines:
                logger.prn_rxd(line)
                event_queue.put(('__rxd_line', line, time()))
            while kv_buffer.search():
                key, value, timestamp = kv_buffer.pop_kv()

                if sync_uuid_discovered:
                    event_queue.put((key, value, timestamp))
                    logger.prn_inf("found KV pair in stream: {{%s;%s}}, queued..."% (key, value))
                else:
                    if key == '__sync':
                        if value in sync_uuid_list:
                            sync_uuid_discovered = True
                            event_queue.put((key, value, time()))
                            idx = sync_uuid_list.index(value)
                            logger.prn_inf("found SYNC in stream: {{%s;%s}} it is #%d sent, queued..."% (key, value, idx))
                        else:
                            logger.prn_err("found faulty SYNC in stream: {{%s;%s}}, ignored..."% (key, value))
                    else:
                        logger.prn_wrn("found KV pair in stream: {{%s;%s}}, ignoring..."% (key, value))

        if not sync_uuid_discovered:
            # Resending __sync after 'sync_timeout' secs (default 1 sec)
            # to target platform. If 'sync_behavior' counter is != 0 we
            # will continue to send __sync packets to target platform.
            # If we specify 'sync_behavior' < 0 we will send 'forever'
            # (or until we get reply)

            if sync_behavior != 0:
                time_to_sync_again = time() - loop_timer
                if time_to_sync_again > sync_timeout:
                    sync_uuid_list.append(__send_sync(timeout=time_to_sync_again))
                    sync_behavior -= 1
                    loop_timer = time()

    return 0
コード例 #8
0
ファイル: conn_primitive.py プロジェクト: u-blox/htrun
 def __init__(self, name):
     self.LAST_ERROR = None
     self.logger = HtrunLogger(name)
コード例 #9
0
 def __init__(self):
     super(SDKTests, self).__init__()
     self.logger = HtrunLogger('TEST')
コード例 #10
0
    def __init__(self, options):
        """! ctor
        """
        self.options = options

        self.logger = HtrunLogger('HTST')

        self.registry = HostRegistry()
        self.registry.register_host_test("echo", EchoTest())
        self.registry.register_host_test("default", DefaultAuto())
        self.registry.register_host_test("rtc_auto", RTCTest())
        self.registry.register_host_test("hello_auto", HelloTest())
        self.registry.register_host_test("detect_auto", DetectPlatformTest())
        self.registry.register_host_test("default_auto", DefaultAuto())
        self.registry.register_host_test("wait_us_auto", WaitusTest())
        self.registry.register_host_test("dev_null_auto", DevNullTest())

        # Handle extra command from
        if options:
            if options.enum_host_tests:
                for path in options.enum_host_tests:
                    self.registry.register_from_path(path,
                                                     verbose=options.verbose)

            if options.list_reg_hts:  # --list option
                print(self.registry.table(options.verbose))
                sys.exit(0)

            if options.list_plugins:  # --plugins option
                host_tests_plugins.print_plugin_info()
                sys.exit(0)

            if options.version:  # --version
                import pkg_resources  # part of setuptools
                version = pkg_resources.require("mbed-host-tests")[0].version
                print(version)
                sys.exit(0)

            if options.send_break_cmd:  # -b with -p PORT (and optional -r RESET_TYPE)
                handle_send_break_cmd(port=options.port,
                                      disk=options.disk,
                                      reset_type=options.forced_reset_type,
                                      baudrate=options.baud_rate,
                                      verbose=options.verbose)
                sys.exit(0)

            if options.global_resource_mgr or options.fast_model_connection:
                # If Global/Simulator Resource Mgr is working it will handle reset/flashing workflow
                # So local plugins are offline
                self.options.skip_reset = True
                self.options.skip_flashing = True

        if options.compare_log:
            with open(options.compare_log, "r") as f:
                self.compare_log = f.read().splitlines()

        else:
            self.compare_log = None
        self.serial_output_file = options.serial_output_file
        self.compare_log_idx = 0
        DefaultTestSelectorBase.__init__(self, options)
コード例 #11
0
    def __init__(self):
        super(HTTPHostTests, self).__init__()

        self.logger = HtrunLogger('TEST')