-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathharness.py
41 lines (33 loc) · 964 Bytes
/
harness.py
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
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#
import argparse
import pexpect
import sys
import time
EXIT_TIMEOUT = .5
class Simulation:
def __init__(self, child):
self.child = child
def __enter__(self):
return self
def __exit__(self, *args):
self.flush_read(timeout=EXIT_TIMEOUT)
@classmethod
def from_args(cls):
parser = argparse.ArgumentParser()
parser.add_argument('cmd', nargs=argparse.REMAINDER)
args = parser.parse_args()
child = pexpect.spawn(args.cmd[0], args.cmd[1:], encoding='utf-8')
child.logfile = sys.stdout
return cls(child)
def flush_read(self, timeout=0):
while True:
try:
self.child.read_nonblocking(timeout=timeout)
except pexpect.TIMEOUT:
break
def simple_test(self, timeout=20):
self.child.expect('TEST_PASS', timeout=timeout)