Ejemplo n.º 1
0
def register_apps():
    reg = ComponentRegistry()
    reg.clear_extensions('iotile.app')
    reg.register_extension('iotile.app', 'app', FakeApp)

    yield

    reg.clear_extensions('iotile.app')
Ejemplo n.º 2
0
def test_recording_rpcs(tmpdir):
    """Make sure we can record RPCs."""

    record_path = tmpdir.join('recording.csv')
    conf_file = os.path.join(os.path.dirname(__file__), 'tile_config.json')

    if '@' in conf_file or ',' in conf_file or ';' in conf_file:
        pytest.skip('Cannot pass device config because path has [@,;] in it')

    reg = ComponentRegistry()
    reg.register_extension('iotile.proxy', 'virtual_tile',
                           'test/test_hw/virtual_tile.py')

    try:
        with HardwareManager('virtual:tile_based@%s' % conf_file,
                             record=str(record_path)) as hw:
            hw.connect(1)

            con = hw.get(9)
            tile1 = hw.get(11)

            con.count()
            tile1.add(3, 5)
            tile1.count()
    finally:
        reg.clear_extensions()

    assert record_path.exists()

    rpcs = record_path.readlines(cr=False)
    assert len(rpcs) == 12
    assert rpcs[:3] == ['# IOTile RPC Recording', '# Format: 1.0', '']

    # Patch out the timestamps and run times for better comparison
    rpc_lines = [x.split(',') for x in rpcs[4:-1]]

    for rpc in rpc_lines:
        assert len(rpc) == 9
        rpc[1] = ""
        rpc[5] = ""

    rpc_lines = [",".join(x) for x in rpc_lines]

    print(rpc_lines[4])
    assert rpc_lines == [
        '1,, 9,0x0004,0xc0,,                                        ,ffff74657374303101000003                ,',
        '1,, 9,0x0004,0xc0,,                                        ,ffff74657374303101000003                ,',
        '1,,11,0x0004,0xc0,,                                        ,ffff74657374303101000003                ,',
        '1,,11,0x0004,0xc0,,                                        ,ffff74657374303101000003                ,',
        '1,, 9,0x8001,0xc0,,                                        ,00000000                                ,',
        '1,,11,0x8000,0xc0,,0300000005000000                        ,08000000                                ,',
        '1,,11,0x8001,0xc0,,                                        ,00000000                                ,'
    ]
def linked_tile(rpc_agent, tmpdir):
    """Create a connected HardwareManager instance with a proxy pointed at an RPCDispatcher."""

    visor, _client1, _client2 = rpc_agent

    # Create a config file that we can use to initialize a virtual device that will point at our
    # BasicRPCDispatch via a running IOTileSupervisor.  Currently, HardwareManager can only
    # load configurations for virtual devices from actual files, so we need to save this to a
    # temp file.
    config = {
        "device": {
            "iotile_id":
            1,
            "tiles": [{
                "name": "service_delegate",
                "address": 11,
                "args": {
                    "url": "ws://127.0.0.1:%d/services" % visor.
                    port,  # This has to match the port of the supervisor instance that we want to connect to
                    "service":
                    "service_1",  # This has to match the service name that the RPCDispatcher is registered as an agent for
                    "name":
                    "bsctst"  # This is the 6 character string that must match the ModuleName() of the proxy and is used to find the right proxy
                }
            }]
        }
    }

    # This is a special py.path.local object from pytest
    # https://docs.pytest.org/en/latest/tmpdir.html
    config_path_obj = tmpdir.join('config.json')
    config_path_obj.write(json.dumps(config))

    config_path = str(config_path_obj)

    reg = ComponentRegistry()
    reg.register_extension('iotile.proxy', 'test_proxy',
                           BasicRPCDispatcherProxy)

    # This will create a HardwareManager pointed at a virtual tile based device
    # where the tiles that are added to the virtual device are found using the config
    # file specified after the @ symbol.
    hw = HardwareManager(port="virtual:tile_based@%s" % config_path)  # pylint:disable=invalid-name; We use hw throughout CoreTools to denote a HardwareManager instance

    # We specified that the virtual device should be at uuid 1 (using iotile_id above)
    # so we know how to connect to it.  We also know that we specified a single tile
    # at address 11 inside that virtual device so we will be able to get its proxy
    # object by calling hw.get(11) once we are connected.
    hw.connect(1)
    yield hw

    hw.disconnect()
    reg.clear_extensions('iotile.proxy')
Ejemplo n.º 4
0
def tile_based():
    conf_file = os.path.join(os.path.dirname(__file__), 'tile_config.json')

    if '@' in conf_file or ',' in conf_file or ';' in conf_file:
        pytest.skip('Cannot pass device config because path has [@,;] in it')

    reg = ComponentRegistry()
    reg.register_extension('iotile.proxy', 'vitual_tile',
                           'test/test_hw/virtual_tile.py')

    hw = HardwareManager('virtual:tile_based@%s' % conf_file)
    yield hw

    reg.clear_extensions()
    hw.disconnect()
Ejemplo n.º 5
0
def proxy_variants_4():
    conf_file = os.path.join(os.path.dirname(__file__),
                             'proxy_match_tile_config.json')

    if '@' in conf_file or ',' in conf_file or ';' in conf_file:
        pytest.skip('Cannot pass device config because path has [@,;] in it')

    reg = ComponentRegistry()
    # None, None
    reg.register_extension('iotile.proxy', 'proxy_match_tile', ProxyMatchTest1)
    reg.register_extension('iotile.proxy', 'proxy_match_tile', ProxyMatchTest2)

    hw = HardwareManager('virtual:tile_based@%s' % conf_file)
    yield hw

    reg.clear_extensions()
    hw.close()