Пример #1
0
    def set_up(self):
        # this checks a simple communication that works
        class FakeManager:
            def get_route(self, addr):
                return 'file'

        self.j = Jarvis()
        self.j.set_hardware_manager(FakeManager())
Пример #2
0
class TestJarvis:
    @pytest.fixture(autouse=True)
    def set_up(self):
        # this checks a simple communication that works
        class FakeManager:
            def get_route(self, addr):
                return 'file'

        self.j = Jarvis()
        self.j.set_hardware_manager(FakeManager())

    def test_jarvis_create(self):
        assert self.j is not None

    def test_jarvis_class_iface(self):
        # Assure the class implements the declared interface
        assert verifyClass(ICommunicationSlave, Jarvis)

    def test_jarvis_instance_iface(self):
        # Assure instances of the class provide the declared interface
        assert verifyObject(ICommunicationSlave, self.j)

    def test_jarvis_packet(self, tmpdir):
        f = tmpdir.mkdir("sub").join("hello.txt")
        f.write_binary("helloworld")

        @self.j.register('file')
        class TestIO(SimpleIO):
            __f__ = f.strpath

        p = IPBusPacket(TESTPACKETS['big-endian'])
        self.j(p)

        self.j.unregister('file')

    def test_jarvis_no_read(self):
        with pytest.raises(AttributeError) as excinfo:
            @self.j.register('bad-method')
            class Bad(object):
                def write(self): pass
        assert "has no attribute 'read'" in str(excinfo.value)

    def test_jarvis_no_write(self):
        with pytest.raises(AttributeError) as excinfo:
            @self.j.register('bad-method')
            class Bad(object):
                def read(self): pass
        assert "has no attribute 'write'" in str(excinfo.value)

    def test_jarvis_ducktyping(self):
        @self.j.register('ok-method')
        class Ok(object):
            def read(self): pass
            def write(self): pass
        assert 1  # we should have no error
Пример #3
0
    def set_up(self):
        # this checks a simple communication that works
        class FakeManager:
            def get_route(self, addr):
                return 'file'

        self.j = Jarvis()
        self.j.set_hardware_manager(FakeManager())
Пример #4
0
class TestJarvis:
    @pytest.fixture(autouse=True)
    def set_up(self):
        # this checks a simple communication that works
        class FakeManager:
            def get_route(self, addr):
                return 'file'

        self.j = Jarvis()
        self.j.set_hardware_manager(FakeManager())

    def test_jarvis_create(self):
        assert self.j is not None

    def test_jarvis_class_iface(self):
        # Assure the class implements the declared interface
        assert verifyClass(ICommunicationSlave, Jarvis)

    def test_jarvis_instance_iface(self):
        # Assure instances of the class provide the declared interface
        assert verifyObject(ICommunicationSlave, self.j)

    def test_jarvis_packet(self, tmpdir):
        f = tmpdir.mkdir("sub").join("hello.txt")
        f.write_binary("helloworld")

        @self.j.register('file')
        class TestIO(SimpleIO):
            __f__ = f.strpath

        p = IPBusPacket(TESTPACKETS['big-endian'])
        self.j(p)

        self.j.unregister('file')

    def test_jarvis_no_read(self):
        with pytest.raises(AttributeError) as excinfo:

            @self.j.register('bad-method')
            class Bad(object):
                def write(self):
                    pass

        assert "has no attribute 'read'" in str(excinfo.value)

    def test_jarvis_no_write(self):
        with pytest.raises(AttributeError) as excinfo:

            @self.j.register('bad-method')
            class Bad(object):
                def read(self):
                    pass

        assert "has no attribute 'write'" in str(excinfo.value)

    def test_jarvis_ducktyping(self):
        @self.j.register('ok-method')
        class Ok(object):
            def read(self):
                pass

            def write(self):
                pass

        assert 1  # we should have no error
Пример #5
0
from ironman.hardware import HardwareManager, HardwareMap, HardwareNode
manager = HardwareManager()
manager.add(HardwareMap(file('xadc.yml').read(), 'xadc'))

from ironman.communicator import Jarvis, ComplexIO
j = Jarvis()
j.set_hardware_manager(manager)


@j.register('xadc')
class XADCController(ComplexIO):
    __base__ = "/sys/devices/soc0/amba/f8007100.adc/iio:device0/"
    __f__ = {
        0: __base__ + "in_temp0_offset",
        1: __base__ + "in_temp0_raw",
        2: __base__ + "in_temp0_scale",
        17: __base__ + "in_voltage0_vccint_raw",
        18: __base__ + "in_voltage0_vccint_scale",
        33: __base__ + "in_voltage1_vccaux_raw",
        34: __base__ + "in_voltage1_vccaux_scale",
        49: __base__ + "in_voltage2_vccbram_raw",
        50: __base__ + "in_voltage2_vccbram_scale",
        65: __base__ + "in_voltage3_vccpint_raw",
        66: __base__ + "in_voltage3_vccpint_scale",
        81: __base__ + "in_voltage4_vccpaux_raw",
        82: __base__ + "in_voltage4_vccpaux_scale",
        97: __base__ + "in_voltage5_vccoddr_raw",
        98: __base__ + "in_voltage5_vccoddr_scale",
        113: __base__ + "in_voltage6_vrefp_raw",
        114: __base__ + "in_voltage6_vrefp_scale",
        129: __base__ + "in_voltage7_vrefn_raw",
Пример #6
0
from ironman.hardware import HardwareManager, HardwareMap, HardwareNode
manager = HardwareManager()
manager.add(HardwareMap(file('xadc.yml').read(), 'xadc'))

from ironman.communicator import Jarvis, ComplexIO
j = Jarvis()
j.set_hardware_manager(manager)

@j.register('xadc')
class XADCController(ComplexIO):
    __base__ = "/sys/devices/soc0/amba/f8007100.adc/iio:device0/"
    __f__ = {
                0:   __base__+"in_temp0_offset",
                1:   __base__+"in_temp0_raw",
                2:   __base__+"in_temp0_scale",
                17:  __base__+"in_voltage0_vccint_raw",
                18:  __base__+"in_voltage0_vccint_scale",
                33:  __base__+"in_voltage1_vccaux_raw",
                34:  __base__+"in_voltage1_vccaux_scale",
                49:  __base__+"in_voltage2_vccbram_raw",
                50:  __base__+"in_voltage2_vccbram_scale",
                65:  __base__+"in_voltage3_vccpint_raw",
                66:  __base__+"in_voltage3_vccpint_scale",
                81:  __base__+"in_voltage4_vccpaux_raw",
                82:  __base__+"in_voltage4_vccpaux_scale",
                97:  __base__+"in_voltage5_vccoddr_raw",
                98:  __base__+"in_voltage5_vccoddr_scale",
                113: __base__+"in_voltage6_vrefp_raw",
                114: __base__+"in_voltage6_vrefp_scale",
                129: __base__+"in_voltage7_vrefn_raw",
                130: __base__+"in_voltage7_vrefn_scale"