Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions labgrid/driver/bareboxdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def on_deactivate(self):
@Driver.check_active
@step(args=['cmd'])
def run(self, cmd: str, *, step, timeout: int = 30): # pylint: disable=unused-argument
return self._run(cmd, step=step, timeout=timeout)

def _run(self, cmd: str, *, step, timeout: int = 30): # pylint: disable=unused-argument
"""
Runs the specified command on the shell and returns the output.

Expand Down
3 changes: 2 additions & 1 deletion labgrid/driver/commandmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def _run_check(self, cmd: str, timeout=30):
Returns:
List[str]: stdout of the executed command
"""
stdout, stderr, exitcode = self.run(cmd, timeout=timeout)
stdout, stderr, exitcode = self._run(cmd, timeout=timeout)
if exitcode != 0:
raise ExecutionError(cmd, stdout, stderr)
return stdout

@Driver.check_active
@step(args=['cmd'], result=True)
def run_check(self, cmd: str, timeout=30):
"""
External run_check function, only available if the driver is active.
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def on_activate(self):
def on_deactivate(self):
self._status = 0

@step(args=['cmd'], result=True)
def _run(self, cmd, *, step, timeout=30.0, codec="utf-8", decodeerrors="strict"):
"""
Runs the specified cmd on the shell and returns the output.
Expand Down Expand Up @@ -96,6 +95,7 @@ def _run(self, cmd, *, step, timeout=30.0, codec="utf-8", decodeerrors="strict")
return (data, [], exitcode)

@Driver.check_active
@step(args=['cmd'], result=True)
def run(self, cmd, timeout=30.0, codec="utf-8", decodeerrors="strict"):
return self._run(cmd, timeout=timeout, codec=codec, decodeerrors=decodeerrors)

Expand Down
1 change: 0 additions & 1 deletion labgrid/driver/smallubootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def _await_prompt(self):
# wait until UBoot has reached it's prompt
self.console.expect(self.prompt)

@step(args=['cmd'], result=True)
def _run(self, cmd):
"""
If Uboot is in Command-Line mode: Run command cmd and return it's
Expand Down
5 changes: 4 additions & 1 deletion labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ def _check_master(self):
return self._start_own_master()

@Driver.check_active
@step(args=['cmd'])
@step(args=['cmd'], result=True)
def run(self, cmd, codec="utf-8", decodeerrors="strict", timeout=None): # pylint: disable=unused-argument
return self._run(cmd, codec=codec, decodererrors=decodeerrors)

def _run(self, cmd, codec, decodeerrors): # pylint: disable=unused-argument
"""Execute `cmd` on the target.

This method runs the specified `cmd` as a command on its target.
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/ubootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def on_deactivate(self):
"""
self._status = 0

@step(args=['cmd'], result=True)
def _run(self, cmd):
# FIXME: Handle pexpect Timeout
# TODO: Shell Escaping for the U-Boot Shell
Expand Down Expand Up @@ -94,6 +93,7 @@ def _run(self, cmd):
return None

@Driver.check_active
@step(args=['cmd'], result=True)
def run(self, cmd, timeout=None): # pylint: disable=unused-argument
"""
Runs the specified command on the shell and returns the output.
Expand Down
8 changes: 6 additions & 2 deletions tests/test_bareboxdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ def test_barebox_run(self, target_with_fakeconsole, mocker):
t = target_with_fakeconsole
d = BareboxDriver(t, "barebox")
d = t.get_driver(BareboxDriver)
d.run = mocker.MagicMock(return_value=[['success'],[],0])
d._run = mocker.MagicMock(return_value=(['success'], [], 0))
res = d.run_check("test")
assert res == ['success']
res = d.run("test")
assert res == (['success'], [], 0)

def test_barebox_run_error(self, target_with_fakeconsole, mocker):
t = target_with_fakeconsole
d = BareboxDriver(t, "barebox")
d = t.get_driver(BareboxDriver)
d.run = mocker.MagicMock(return_value=[['error'],[],1])
d._run = mocker.MagicMock(return_value=(['error'], [], 1))
with pytest.raises(ExecutionError):
res = d.run_check("test")
res = d.run("test")
assert res == (['error'], [], 1)
12 changes: 9 additions & 3 deletions tests/test_shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,30 @@ def test_run(self, target_with_fakeconsole, mocker):
d = ShellDriver(t, "shell", prompt='dummy', login_prompt='dummy', username='dummy')
d.on_activate = mocker.MagicMock()
d = t.get_driver('ShellDriver')
d.run = mocker.MagicMock(return_value=[['success'],[],0])
d._run = mocker.MagicMock(return_value=(['success'], [], 0))
res = d.run_check("test")
assert res == ['success']
res = d.run("test")
assert res == (['success'], [], 0)

def test_run_error(self, target_with_fakeconsole, mocker):
t = target_with_fakeconsole
d = ShellDriver(t, "shell", prompt='dummy', login_prompt='dummy', username='dummy')
d.on_activate = mocker.MagicMock()
d = t.get_driver('ShellDriver')
d.run = mocker.MagicMock(return_value=[['error'],[],1])
d._run = mocker.MagicMock(return_value=(['error'], [], 1))
with pytest.raises(ExecutionError):
res = d.run_check("test")
res = d.run("test")
assert res == (['error'], [], 1)

def test_run_with_timeout(self, target_with_fakeconsole, mocker):
t = target_with_fakeconsole
d = ShellDriver(t, "shell", prompt='dummy', login_prompt='dummy', username='dummy')
d.on_activate = mocker.MagicMock()
d = t.get_driver('ShellDriver')
d.run = mocker.MagicMock(return_value=[['success'],[],0])
d._run = mocker.MagicMock(return_value=(['success'], [], 0))
res = d.run_check("test", timeout=30.0)
assert res == ['success']
res = d.run("test")
assert res == (['success'], [], 0)
8 changes: 6 additions & 2 deletions tests/test_sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ def test_create(self, target, mocker):

def test_run_check(self, ssh_driver_mocked_and_activated, mocker):
s = ssh_driver_mocked_and_activated
s.run = mocker.MagicMock(return_value=[['success'],[],0])
s._run = mocker.MagicMock(return_value=(['success'], [], 0))
res = s.run_check("test")
assert res == ['success']
res = s.run("test")
assert res == (['success'], [], 0)

def test_run_check_raise(self, ssh_driver_mocked_and_activated, mocker):
s = ssh_driver_mocked_and_activated
s.run = mocker.MagicMock(return_value=[['error'],[],1])
s._run = mocker.MagicMock(return_value=(['error'], [], 1))
with pytest.raises(ExecutionError):
res = s.run_check("test")
res = s.run("test")
assert res == (['error'], [], 1)