Skip to content

Commit ce67f5a

Browse files
authored
Merge pull request #1393 from flxzt/customizable-linesep
driver: add ability to customize the line separator in drivers using ConsoleProtocol
2 parents e7a4844 + 35e75c7 commit ce67f5a

11 files changed

Lines changed: 20 additions & 11 deletions

File tree

doc/configuration.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,7 @@ Arguments:
19741974
- txchunk (int, default=1): number of bytes the `txdelay` should apply to
19751975
- timeout (float, default=3.0): time in seconds to wait for a network serial port before
19761976
an error occurs
1977+
- linesep (str, default="\n"): the separator when sending complete lines
19771978

19781979
ModbusRTUDriver
19791980
~~~~~~~~~~~~~~~
@@ -2231,6 +2232,7 @@ Arguments:
22312232
- cmd (str): command to execute and then bind to.
22322233
- txdelay (float, default=0.0): time in seconds to wait before sending a chunk
22332234
- txchunk (int, default=1): number of bytes the `txdelay` should apply to
2235+
- linesep (str, default="\n"): the separator when sending complete lines
22342236

22352237
AndroidFastbootDriver
22362238
~~~~~~~~~~~~~~~~~~~~~
@@ -3099,6 +3101,7 @@ Arguments:
30993101
- qemu-default: Don't override QEMU default settings
31003102

31013103
- nic (str): optional, configuration string to pass to QEMU to create a network interface
3104+
- linesep (str, default="\n"): the separator when sending complete lines
31023105

31033106
The QEMUDriver also requires the specification of:
31043107

doc/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ specific driver set a binding mapping before creating the driver:
147147
>>> t.set_binding_map({"port": "Second"})
148148
>>> sd = SerialDriver(t, "Driver")
149149
>>> sd
150-
SerialDriver(target=Target(name='Test', env=None), name='Driver', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1, timeout=3.0)
150+
SerialDriver(target=Target(name='Test', env=None), name='Driver', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1, timeout=3.0, linesep='\n')
151151
>>> sd.port
152152
SerialPort(target=Target(name='Test', env=None), name='Second', state=<BindingState.bound: 1>, avail=True, port=None, speed=115200)
153153

doc/usage.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ Active drivers can be accessed by class (any :any:`Driver <labgrid.driver>` or
283283
>>> console = FakeConsoleDriver(target, 'console')
284284
>>> target.activate(console)
285285
>>> target[FakeConsoleDriver]
286-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
286+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, linesep='\n')
287287
>>> target[FakeConsoleDriver, 'console']
288-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
288+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, linesep='\n')
289289

290290
Driver Deactivation
291291
^^^^^^^^^^^^^^^^^^^
@@ -302,7 +302,7 @@ Driver deactivation works in a similar manner:
302302
.. doctest:: driver-deactivation
303303

304304
>>> target.deactivate(console)
305-
[FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1)]
305+
[FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.bound: 1>, txdelay=0.0, txchunk=1, linesep='\n')]
306306

307307
Drivers need to be deactivated in the following cases:
308308

@@ -393,7 +393,7 @@ To access the target's console, the correct driver object can be found by using
393393

394394
>>> cp = t.get_driver('ConsoleProtocol')
395395
>>> cp
396-
SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, timeout=3.0)
396+
SerialDriver(target=Target(name='example', env=Environment(config_file='example-env.yaml')), name=None, state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, timeout=3.0, linesep='\n')
397397
>>> cp.write(b'test')
398398
4
399399

labgrid/driver/consoleexpectmixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class ConsoleExpectMixin:
1111
Console driver mixin to implement the read, write, expect and sendline methods. It uses
1212
the internal _read and _write methods.
1313
14-
The class using the ConsoleExpectMixin must provide a logger and a txdelay attribute.
14+
The class using the ConsoleExpectMixin must provide a logger, txdelay and linesep attribute.
1515
"""
1616

1717
def __attrs_post_init__(self):
1818
super().__attrs_post_init__()
19-
self._expect = PtxExpect(self)
19+
self._expect = PtxExpect(self, self.linesep.encode("ASCII"))
2020

2121
@Driver.check_active
2222
@step(result=True, tag='console')

labgrid/driver/externalconsoledriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ExternalConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
2222
cmd = attr.ib(validator=attr.validators.instance_of(str))
2323
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
2424
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
25+
linesep = attr.ib(default="\n", validator=attr.validators.instance_of(str))
2526

2627
def __attrs_post_init__(self):
2728
super().__attrs_post_init__()

labgrid/driver/fake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class FakeConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
1616
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
1717
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
18+
linesep = attr.ib(default="\n", validator=attr.validators.instance_of(str))
1819

1920
def __attrs_post_init__(self):
2021
super().__attrs_post_init__()

labgrid/driver/laadriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class LAASerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
3434

3535
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
3636
timeout = attr.ib(default=3.0, validator=attr.validators.instance_of(float))
37+
linesep = attr.ib(default="\n", validator=attr.validators.instance_of(str))
3738

3839
def __attrs_post_init__(self):
3940
super().__attrs_post_init__()

labgrid/driver/qemudriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):
9595
nic = attr.ib(
9696
default=None,
9797
validator=attr.validators.optional(attr.validators.instance_of(str)))
98+
linesep = attr.ib(default="\n", validator=attr.validators.instance_of(str))
9899

99100
def __attrs_post_init__(self):
100101
super().__attrs_post_init__()

labgrid/driver/serialdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class SerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
2222
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
2323
txchunk = attr.ib(default=1, validator=attr.validators.instance_of(int))
2424
timeout = attr.ib(default=3.0, validator=attr.validators.instance_of(float))
25+
linesep = attr.ib(default="\n", validator=attr.validators.instance_of(str))
2526

2627
def __attrs_post_init__(self):
2728
super().__attrs_post_init__()

labgrid/target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ def __getitem__(self, key):
264264
>>> console = FakeConsoleDriver(target, 'console')
265265
>>> target.activate(console)
266266
>>> target[FakeConsoleDriver]
267-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
267+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, linesep='\\n')
268268
>>> target[FakeConsoleDriver, 'console']
269-
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1)
269+
FakeConsoleDriver(target=Target(name='main', env=None), name='console', state=<BindingState.active: 2>, txdelay=0.0, txchunk=1, linesep='\\n')
270270
"""
271271
name = None
272272
if not isinstance(key, tuple):

0 commit comments

Comments
 (0)