File: test_export.py

package info (click to toggle)
labgrid 25.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: python: 21,352; sh: 846; makefile: 35
file content (112 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import pytest

from labgrid.resource import Resource, NetworkSerialPort, TFTPProvider
from labgrid.resource.remote import RemoteNetworkInterface, RemoteTFTPProvider
from labgrid.driver import Driver, SerialDriver, NetworkInterfaceDriver, TFTPProviderDriver
from labgrid.strategy import Strategy
from labgrid.binding import StateError


class ResourceA(Resource):
    pass


class DriverA(Driver):
    bindings = {"res": ResourceA}

    @Driver.check_bound
    def get_export_vars(self):
        return {
            "a": "b",
        }


class StrategyA(Strategy):
    bindings = {
        "drv": DriverA,
    }


def test_export(target):
    ra = ResourceA(target, "resource")
    d = DriverA(target, "driver")
    s = StrategyA(target, "strategy")

    exported = target.export()
    assert exported == {
        "LG__DRV_A": "b",
    }

    target.activate(d)
    with pytest.raises(StateError):
        d.get_export_vars()


class StrategyB(Strategy):
    bindings = {
        "drv": DriverA,
    }

    def prepare_export(self):
        return {
            self.drv: "custom_name",
        }


def test_export_custom(target):
    ra = ResourceA(target, "resource")
    d = DriverA(target, "driver")
    s = StrategyB(target, "strategy")

    exported = target.export()
    assert exported == {
        "LG__CUSTOM_NAME_A": "b",
    }


def test_export_network_serial(target):
    NetworkSerialPort(target, None, host='testhost', port=12345, speed=115200)
    SerialDriver(target, None)

    exported = target.export()
    assert exported == {
        'LG__SERIALDRIVER_HOST': 'testhost',
        'LG__SERIALDRIVER_PORT': '12345',
        'LG__SERIALDRIVER_PROTOCOL': 'rfc2217',
        'LG__SERIALDRIVER_SPEED': '115200'
    }


def test_export_remote_network_interface(target):
    RemoteNetworkInterface(target, None, host='testhost', ifname='wlan0')
    NetworkInterfaceDriver(target, "netif")

    exported = target.export()
    assert exported == {
        'LG__NETIF_HOST': 'testhost',
        'LG__NETIF_IFNAME': 'wlan0'
    }


def test_export_tftp_provider(target):
    TFTPProvider(target, None, internal='/srv/tftp/testboard/', external='testboard/')
    TFTPProviderDriver(target, "tftp")

    exported = target.export()
    assert exported == {
        'LG__TFTP_HOST': 'localhost',
        'LG__TFTP_INTERNAL': '/srv/tftp/testboard/',
        'LG__TFTP_EXTERNAL': 'testboard/',
    }


def test_export_remote_tftp_provider(target):
    RemoteTFTPProvider(target, None, host='testhost', internal='/srv/tftp/testboard/', external='testboard/')
    TFTPProviderDriver(target, "tftp")

    exported = target.export()
    assert exported == {
        'LG__TFTP_HOST': 'testhost',
        'LG__TFTP_INTERNAL': '/srv/tftp/testboard/',
        'LG__TFTP_EXTERNAL': 'testboard/',
    }