Skip to content

Commit 29bd95e

Browse files
committed
refactor(test): eliminate overcomplicated state machine
In test_serial_console_login, we were implementing something that takes three lines (send and receive data via serial) via an overcomplicated state machine system. Eliminate the 100 lines of state machine code and instead just... do the 3 lines of serial.tx/rx. Signed-off-by: Patrick Roy <[email protected]>
1 parent f69a191 commit 29bd95e

File tree

2 files changed

+3
-93
lines changed

2 files changed

+3
-93
lines changed

tests/framework/state_machine.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

tests/integration_tests/functional/test_serial_io.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,10 @@
1111

1212
from framework import utils
1313
from framework.microvm import Serial
14-
from framework.state_machine import TestState
1514

1615
PLATFORM = platform.machine()
1716

1817

19-
class WaitTerminal(TestState):
20-
"""Initial state when we wait for the login prompt."""
21-
22-
def handle_input(self, serial, input_char) -> TestState:
23-
"""Handle input and return next state."""
24-
if self.match(input_char):
25-
serial.tx("id")
26-
return WaitIDResult("uid=0(root) gid=0(root) groups=0(root)")
27-
return self
28-
29-
30-
class WaitIDResult(TestState):
31-
"""Wait for the console to show the result of the 'id' shell command."""
32-
33-
def handle_input(self, unused_serial, input_char) -> TestState:
34-
"""Handle input and return next state."""
35-
if self.match(input_char):
36-
return TestFinished()
37-
return self
38-
39-
40-
class TestFinished(TestState):
41-
"""Test complete and successful."""
42-
43-
def handle_input(self, unused_serial, _) -> TestState:
44-
"""Return self since the test is about to end."""
45-
return self
46-
47-
4818
def test_serial_after_snapshot(uvm_plain, microvm_factory):
4919
"""
5020
Serial I/O after restoring from a snapshot.
@@ -104,11 +74,9 @@ def test_serial_console_login(uvm_plain_any):
10474

10575
serial = Serial(microvm)
10676
serial.open()
107-
current_state = WaitTerminal("ubuntu-fc-uvm:")
108-
109-
while not isinstance(current_state, TestFinished):
110-
output_char = serial.rx_char()
111-
current_state = current_state.handle_input(serial, output_char)
77+
serial.rx("ubuntu-fc-uvm:")
78+
serial.tx("id")
79+
serial.rx("uid=0(root) gid=0(root) groups=0(root)")
11280

11381

11482
def get_total_mem_size(pid):

0 commit comments

Comments
 (0)