Ejemplo n.º 1
0
def test_rsl_reset_config(reference_hw):
    """Make sure we properly load config variables into the sensor_log."""

    hw, _device, _peripheral = reference_hw

    con = hw.get(8, basic=True)
    sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller',
                                     'SensorGraphPlugin')(con)
    config = find_proxy_plugin('iotile_standard_library/lib_controller',
                               'ConfigDatabasePlugin')(con)

    config.set_variable('controller', 0x2004, 'uint8_t', 1)
    con.reset(wait=0)

    with pytest.raises(HardwareError):
        sensor_graph.push_many('buffered 1', 15, 20000)

    assert sensor_graph.count_readings() == {'streaming': 0, 'storage': 16128}

    config.set_variable('controller', 0x2005, 'uint8_t', 1)
    con.reset(wait=0)

    with pytest.raises(HardwareError):
        sensor_graph.push_many('output 1', 15, 50000)

    assert sensor_graph.count_readings() == {
        'streaming': 48896,
        'storage': 16128
    }
def streaming_sg():
    """A preprogrammed basic sensorgraph for testing streaming."""

    device = ReferenceDevice({'simulate_time': False})

    adapter = EmulatedDeviceAdapter(None, devices=[device])

    nodes = [
        "(input 1 when count >= 1) => output 1 using copy_latest_a",
        "(input 2 when count >= 1) => output 2 using copy_latest_a",
        "(input 3 when count >= 1 && constant 1 always) => unbuffered 1 using trigger_streamer"
    ]

    with HardwareManager(adapter=adapter) as hw:
        hw.connect(1)

        con = hw.get(8, basic=True)
        sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller', 'SensorGraphPlugin')(con)

        for node in nodes:
            sensor_graph.add_node(node)

        sensor_graph.push_reading('constant 1', 0)

        sensor_graph.add_streamer('output 1', 'controller', False, 'individual', 'telegram')
        sensor_graph.add_streamer('output 2', 'controller', False, 'hashedlist', 'telegram', withother=0)

        yield sensor_graph, hw, device
def basic_sg():
    """A preprogrammed basic sensorgraph for testing."""

    device = ReferenceDevice({'simulate_time': False})
    peripheral = EmulatedPeripheralTile(11, device)
    peripheral.declare_config_variable("test 1", 0x8000, 'uint16_t')
    peripheral.declare_config_variable('test 2', 0x8001, 'uint32_t[5]')

    device.add_tile(11, peripheral)

    adapter = EmulatedDeviceAdapter(None, devices=[device])

    nodes = [
        "(input 1 always) => counter 1024 using copy_latest_a",
        "(counter 1024 when count >= 1 && constant 1030 when value == 1) => counter 1030 using copy_latest_a",
        "(counter 1030 when count >= 4) => output 1 using copy_all_a"
    ]

    with HardwareManager(adapter=adapter) as hw:
        hw.connect(1)

        con = hw.get(8, basic=True)
        sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller', 'SensorGraphPlugin')(con)

        for node in nodes:
            sensor_graph.add_node(node)

        sensor_graph.add_streamer('output 10', 'controller', True, 'individual', 'telegram')

        yield sensor_graph, hw, device
Ejemplo n.º 4
0
def basic_device():
    """A preprogrammed basic sensorgraph for testing."""

    device = ReferenceDevice({})
    adapter = EmulatedDeviceAdapter(None, devices=[device])

    nodes = [
        "(system input 2 always) => output 1 using copy_latest_a",
        "(system input 3 always) => output 2 using copy_latest_a",
        "(system input 5 always) => output 3 using copy_latest_a",
        "(system input 6 always) => output 4 using copy_latest_a"
    ]

    with HardwareManager(adapter=adapter) as hw:
        hw.connect(1)

        con = hw.get(8, basic=True)
        sensor_graph = find_proxy_plugin(
            'iotile_standard_library/lib_controller', 'SensorGraphPlugin')(con)

        for node in nodes:
            sensor_graph.add_node(node)

        sensor_graph.add_streamer('output 10', 'controller', True,
                                  'individual', 'telegram')

        yield hw, device
Ejemplo n.º 5
0
def test_raw_sensor_log(reference_hw):
    """Test to ensure that the raw sensor log works."""

    hw, _device, _peripheral = reference_hw

    con = hw.get(8, basic=True)
    sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller',
                                     'SensorGraphPlugin')(con)

    assert sensor_graph.count_readings() == {'streaming': 0, 'storage': 0}

    assert sensor_graph.highest_id() == 0

    sensor_graph.push_many('output 1', 10, 20)
    sensor_graph.push_many('buffered 1', 15, 25)

    assert sensor_graph.highest_id() == 45

    readings = sensor_graph.download_stream('output 1')
    assert len(readings) == 20

    readings = sensor_graph.download_stream('buffered 1')
    assert len(readings) == 25

    readings = sensor_graph.download_stream('buffered 1', reading_id=44)
    assert len(readings) == 2

    sensor_graph.clear()
    assert sensor_graph.count_readings() == {'streaming': 1, 'storage': 0}

    assert sensor_graph.highest_id() == 46
Ejemplo n.º 6
0
def test_utc_time(basic_device):
    """Make sure we can get and set utc time."""

    hw, device = basic_device

    con = hw.get(8, basic=True)
    test_interface = find_proxy_plugin(
        'iotile_standard_library/lib_controller', 'ControllerTestPlugin')(con)

    test_time = datetime.datetime(2018, 11, 11, 16, 0, 0)
    zero = datetime.datetime(1970, 1, 1)
    y2k_zero = datetime.datetime(2000, 1, 1)

    device.controller.clock_manager.handle_tick()

    delta = (test_time - zero).total_seconds()
    y2k_delta = (test_time - y2k_zero).total_seconds()

    test_interface.synchronize_clock(delta)
    device_time = test_interface.current_time()
    device_uptime = test_interface.get_uptime()
    info = test_interface.get_timeoffset()

    assert device_time & (1 << 31)
    assert (device_time & ~(1 << 31)) == int(y2k_delta)
    assert device_uptime == 1
    assert info == {'is_utc': True, 'offset': int(y2k_delta) - 1}
Ejemplo n.º 7
0
def test_user_ticks(basic_device):
    """Make sure that we can control user ticks."""

    hw, device = basic_device

    con = hw.get(8, basic=True)
    sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller',
                                     'SensorGraphPlugin')(con)
    config = find_proxy_plugin('iotile_standard_library/lib_controller',
                               'ConfigDatabasePlugin')(con)

    assert sensor_graph.user_tick(0) == 0
    assert sensor_graph.user_tick(1) == 0
    assert sensor_graph.user_tick(2) == 0

    with pytest.raises(HardwareError):
        sensor_graph.user_tick(3)

    sensor_graph.set_user_tick(0, 1)
    sensor_graph.set_user_tick(1, 5)
    sensor_graph.set_user_tick(2, 6)

    with pytest.raises(HardwareError):
        sensor_graph.set_user_tick(3, 1)

    assert sensor_graph.user_tick(0) == 1
    assert sensor_graph.user_tick(1) == 5
    assert sensor_graph.user_tick(2) == 6

    # Make sure set on reset works
    config.set_variable('controller', 0x2000, 'uint32_t', 2)
    config.set_variable('controller', 0x2002, 'uint32_t', 4)
    config.set_variable('controller', 0x2003, 'uint32_t', 7)

    con.reset(wait=0)
    device.wait_idle()

    assert sensor_graph.user_tick(0) == 2
    assert sensor_graph.user_tick(1) == 4
    assert sensor_graph.user_tick(2) == 7
def sg_device():
    """Get a reference device and connected HardwareManager."""

    device = ReferenceDevice({'simulate_time': False})
    peripheral = EmulatedPeripheralTile(11, device)
    peripheral.declare_config_variable("test 1", 0x8000, 'uint16_t')
    peripheral.declare_config_variable('test 2', 0x8001, 'uint32_t[5]')

    device.add_tile(11, peripheral)

    adapter = EmulatedDeviceAdapter(None, devices=[device])

    with HardwareManager(adapter=adapter) as hw:
        hw.connect(1)

        con = hw.get(8, basic=True)
        sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller', 'SensorGraphPlugin')(con)

        yield sensor_graph, hw
Ejemplo n.º 9
0
def test_tick_inputs(basic_device):
    """Test to make sure that ticks are sent to sensor_graph."""

    hw, device = basic_device

    con = hw.get(8, basic=True)
    sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller',
                                     'SensorGraphPlugin')(con)
    clock_man = device.controller.clock_manager

    sensor_graph.enable()

    assert clock_man.uptime == 0

    sensor_graph.set_user_tick(0, 1)
    sensor_graph.set_user_tick(1, 2)
    sensor_graph.set_user_tick(2, 5)

    for i in range(1, 11):
        device.controller.clock_manager.handle_tick()
        assert clock_man.uptime == i

    dump1 = sensor_graph.download_stream('output 1')
    assert len(dump1) == 1
    key_parts_1 = [(x.raw_time, x.value) for x in dump1]
    assert key_parts_1 == [(10, 10)]

    dump2 = sensor_graph.download_stream('output 2')
    assert len(dump2) == 10
    key_parts_2 = [(x.raw_time, x.value) for x in dump2]
    assert key_parts_2 == list(zip(range(1, 11), range(1, 11)))

    dump3 = sensor_graph.download_stream('output 3')
    assert len(dump3) == 5
    key_parts_3 = [(x.raw_time, x.value) for x in dump3]
    assert key_parts_3 == list(zip(range(2, 11, 2), range(2, 11, 2)))

    dump4 = sensor_graph.download_stream('output 4')
    assert len(dump4) == 2
    key_parts_4 = [(x.raw_time, x.value) for x in dump4]
    assert key_parts_4 == list(zip(range(5, 11, 5), range(5, 11, 5)))
Ejemplo n.º 10
0
def test_rsl_dump_restore(reference_hw):
    """Make sure the rsl state is properly saved and restored."""

    hw, device, _peripheral = reference_hw
    refcon = device.controller

    con = hw.get(8, basic=True)
    sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller',
                                     'SensorGraphPlugin')(con)

    # Verify that we properly restore data and our download walker
    for i in range(0, 10):
        sensor_graph.push_reading('output 1', i)

    con.rpc(0x20, 0x08, 0x5001, result_format="LLLL")
    err, _timestamp, reading, unique_id, _act_stream = con.rpc(
        0x20, 0x09, 1, arg_format='B', result_format="LLLLH2x")
    assert err == 0
    assert reading == 0
    assert unique_id == 1

    state = device.dump_state()
    device.restore_state(state)

    # Make sure we keep our same place in the dump stream line
    err, _timestamp, reading, unique_id, _act_stream = con.rpc(
        0x20, 0x09, 1, arg_format='B', result_format="LLLLH2x")

    assert err == 0
    assert reading == 1
    assert unique_id == 2

    # Make sure we have all of our data
    assert refcon.sensor_log.engine.count() == (0, 10)

    readings = sensor_graph.download_stream('output 1')
    assert len(readings) == 10
    for i, reading in enumerate(readings):
        assert reading.value == i
        assert reading.reading_id == i + 1
Ejemplo n.º 11
0
def test_tile_manager(reference_hw):
    """Test the controller tile_manager RPCs using the canonical proxy plugin."""

    # Work around inconsistency in output of iotile-support-lib-controller-3 on python 2 and 3
    if sys.version_info.major < 3:
        con_str = 'refcn1, version 1.0.0 at slot 0'
        peri_str = 'abcdef, version 1.0.0 at slot 1'
    else:
        con_str = "b'refcn1', version 1.0.0 at slot 0"
        peri_str = "b'abcdef', version 1.0.0 at slot 1"

    hw, _device, _peripheral = reference_hw

    con = hw.get(8, basic=True)
    slot = hw.get(11, basic=True)
    tileman = find_proxy_plugin('iotile_standard_library/lib_controller',
                                'TileManagerPlugin')(con)

    assert tileman.count_tiles() == 2

    con = tileman.describe_tile(0)
    peri = tileman.describe_tile(1)
    assert str(con) == con_str
    assert str(peri) == peri_str

    # Make sure reseting a tile doesn't add a new entry
    slot.reset(wait=0)

    assert tileman.count_tiles() == 2

    con = tileman.describe_tile(0)
    peri = tileman.describe_tile(1)
    assert str(con) == con_str
    assert str(peri) == peri_str

    con = tileman.describe_selector('controller')
    peri = tileman.describe_selector('slot 1')
    assert str(con) == con_str
    assert str(peri) == peri_str
def rpc_sg():
    """A basic sg for testing the rpc executor."""

    device = DemoEmulatedDevice({'simulate_time': False})

    adapter = EmulatedDeviceAdapter(None, devices=[device])

    nodes = [
        "(input 1 always) => unbuffered 1024 using copy_latest_a",
        "(unbuffered 1024 when count == 1 && constant 1024 always) => output 1 using call_rpc"
    ]

    with HardwareManager(adapter=adapter) as hw:
        hw.connect(1)

        con = hw.get(8, basic=True)
        sensor_graph = find_proxy_plugin('iotile_standard_library/lib_controller', 'SensorGraphPlugin')(con)

        for node in nodes:
            sensor_graph.add_node(node)

        sensor_graph.push_reading('constant 1024', 753666)

        yield sensor_graph, hw, device
Ejemplo n.º 13
0
def test_config_database(reference_hw):
    """Test the controller config database RPCs using the canonical proxy plugin."""

    hw, _device, _peripheral = reference_hw

    con = hw.get(8, basic=True)
    slot = hw.get(11, basic=True)
    config_db = find_proxy_plugin('iotile_standard_library/lib_controller',
                                  'ConfigDatabasePlugin')(con)

    # Make sure all of the basic RPCs work
    assert config_db.count_variables() == 0
    config_db.clear_variables()

    # Make sure we can set and get config variables
    config_db.set_variable('slot 1', 0x8000, 'uint16_t', 15)
    config_db.set_variable('slot 1', 0x8001, 'uint32_t[]', "[5, 6, 7]")

    assert config_db.count_variables() == 2
    var8000 = config_db.get_variable(1)
    var8001 = config_db.get_variable(2)

    var8000['metadata'] = str(var8000['metadata'])
    var8001['metadata'] = str(var8001['metadata'])

    assert var8000 == {
        'metadata':
        'Target: slot 1\nData Offset: 0\nData Length: 4\nValid: True',
        'name': 0x8000,
        'data': bytearray([15, 0])
    }
    assert var8001 == {
        'metadata':
        'Target: slot 1\nData Offset: 4\nData Length: 14\nValid: True',
        'name': 0x8001,
        'data': bytearray([5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0])
    }

    slot_conf = slot.config_manager()

    # Make sure we stream all variables on a reset
    slot.reset(wait=0)
    assert slot_conf.get_variable(0x8000) == bytearray([15, 0])
    assert slot_conf.get_variable(0x8001) == bytearray(
        [5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0])

    # Make sure invalidated variables are not streamed and the tile resets them on reset
    config_db.invalidate_variable(1)
    assert config_db.count_variables() == 2
    slot.reset(wait=0)
    assert slot_conf.get_variable(0x8000) == bytearray()
    assert slot_conf.get_variable(0x8001) == bytearray(
        [5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0])

    # Check memory limits before and after compaction
    usage = config_db.memory_limits()
    assert usage == {
        'data_usage': 18,
        'data_compactable': 4,
        'data_limit': 4096,
        'entry_usage': 2,
        'entry_compactable': 1,
        'entry_limit': 255
    }

    # Make sure we remove invalid and keep valid entries upon compaction
    config_db.compact_database()
    usage = config_db.memory_limits()
    assert usage == {
        'data_usage': 14,
        'data_compactable': 0,
        'data_limit': 4096,
        'entry_usage': 1,
        'entry_compactable': 0,
        'entry_limit': 255
    }

    assert config_db.count_variables() == 1
    slot.reset(wait=0)
    assert slot_conf.get_variable(0x8000) == bytearray()
    assert slot_conf.get_variable(0x8001) == bytearray(
        [5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0])