Debian Codegraph @

tests/test_ubootdriver.py

raw symbols SCIP
1 import pytest
2
3 from labgrid import Target
4 from labgrid.driver import UBootDriver
5 from labgrid.driver.fake import FakeConsoleDriver
6 from labgrid.protocol import CommandProtocol, LinuxBootProtocol
7 from labgrid.driver import ExecutionError
8
9
10 class TestUBootDriver:
11 def test_create(self):
12 t = Target('dummy')
13 cp = FakeConsoleDriver(t, "console")
14 d = UBootDriver(t, "uboot")
15 assert (isinstance(d, UBootDriver))
16 assert (isinstance(d, CommandProtocol))
17 assert (isinstance(d, LinuxBootProtocol))
18
19 def test_uboot_run(self, target_with_fakeconsole, mocker):
20 t = target_with_fakeconsole
21 d = UBootDriver(t, "uboot")
22 d.console.rxq.append(b"U-Boot 2019\n")
23 d = t.get_driver(UBootDriver)
24 d._run = mocker.MagicMock(return_value=(['success'], [], 0))
25 res = d.run_check("test")
26 assert res == ['success']
27 d._run.assert_called_once_with("test", timeout=30, codec='utf-8', decodeerrors='strict')
28 d._run.reset_mock()
29 res = d.run("test")
30 assert res == (['success'], [], 0)
31 d._run.assert_called_once_with("test", timeout=30)
32
33 def test_uboot_run_error(self, target_with_fakeconsole, mocker):
34 t = target_with_fakeconsole
35 d = UBootDriver(t, "uboot")
36 d.console.rxq.append(b"U-Boot 2019\n")
37 d = t.get_driver(UBootDriver)
38 d._run = mocker.MagicMock(return_value=(['error'], [], 1))
39 with pytest.raises(ExecutionError):
40 res = d.run_check("test")
41 d._run.assert_called_once_with("test", timeout=30, codec='utf-8', decodeerrors='strict')
42 d._run.reset_mock()
43 res = d.run("test")
44 assert res == (['error'], [], 1)
45 d._run.assert_called_once_with("test", timeout=30)
46
47 def test_uboot_boot(self, target_with_fakeconsole):
48 t = target_with_fakeconsole
49 d = UBootDriver(t, "uboot", boot_command='run bootcmd', boot_commands = {"foo": "bar"})
50 d = t.get_driver(UBootDriver)
51 d.boot()
52 assert d.console.txq.pop() == b"run bootcmd\n"
53 d.boot('foo')
54 assert d.console.txq.pop() == b"bar\n"
55 with pytest.raises(Exception):
56 d.boot('nop')