Stop rt-test script from hanging
This commit is contained in:
parent
032d08ebfe
commit
a3b565629e
1 changed files with 29 additions and 7 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
import atexit
|
||||||
|
import queue
|
||||||
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
|
@ -6,15 +9,21 @@ import datetime
|
||||||
import os
|
import os
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
|
||||||
|
msg_queue = queue.Queue(-1)
|
||||||
|
proc = None
|
||||||
|
|
||||||
class TestCase:
|
class TestCase:
|
||||||
def __init__(self, name, expected):
|
def __init__(self, name, expected):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.expected = expected
|
self.expected = expected
|
||||||
|
|
||||||
def test_failure(case, exp, expected_idx, found):
|
def failure(msg):
|
||||||
print("FAILURE: %s #%d, expected '%s', found '%s'" %(case.name, expected_idx + 1, exp, found))
|
print("FAILURE: %s" %(msg))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def test_failure(case, exp, expected_idx, found):
|
||||||
|
failure("%s #%d, expected '%s', found '%s'" %(case.name, expected_idx + 1, exp, found))
|
||||||
|
|
||||||
def test_pass(case, exp, expected_idx, found):
|
def test_pass(case, exp, expected_idx, found):
|
||||||
print("PASS: %s #%d, expected '%s', found '%s'" %(case.name, expected_idx + 1, exp, found))
|
print("PASS: %s #%d, expected '%s', found '%s'" %(case.name, expected_idx + 1, exp, found))
|
||||||
|
|
||||||
|
@ -33,6 +42,15 @@ def get_post_archinit_cases():
|
||||||
TestCase("Init finishes", [r"Init done"])
|
TestCase("Init finishes", [r"Init done"])
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def read_messages(proc):
|
||||||
|
while True:
|
||||||
|
line = proc.stdout.readline().decode("utf-8")
|
||||||
|
msg_queue.put(line)
|
||||||
|
|
||||||
|
def cleanup():
|
||||||
|
global proc
|
||||||
|
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
arch = sys.argv[1]
|
arch = sys.argv[1]
|
||||||
zig_path = sys.argv[2]
|
zig_path = sys.argv[2]
|
||||||
|
@ -46,8 +64,12 @@ if __name__ == "__main__":
|
||||||
cases = get_pre_archinit_cases() + arch_module.get_test_cases(TestCase) + get_post_archinit_cases()
|
cases = get_pre_archinit_cases() + arch_module.get_test_cases(TestCase) + get_post_archinit_cases()
|
||||||
|
|
||||||
if len(cases) > 0:
|
if len(cases) > 0:
|
||||||
proc = subprocess.Popen(zig_path + " build run -Drt-test=true", stdout=subprocess.PIPE, shell=True)
|
proc = subprocess.Popen(zig_path + " build run -Drt-test=true", stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
|
||||||
|
atexit.register(cleanup)
|
||||||
case_idx = 0
|
case_idx = 0
|
||||||
|
read_thread = threading.Thread(target=read_messages, args=(proc,))
|
||||||
|
read_thread.daemon = True
|
||||||
|
read_thread.start()
|
||||||
# Go through the cases
|
# Go through the cases
|
||||||
while case_idx < len(cases):
|
while case_idx < len(cases):
|
||||||
case = cases[case_idx]
|
case = cases[case_idx]
|
||||||
|
@ -55,9 +77,10 @@ if __name__ == "__main__":
|
||||||
# Go through the expected log messages
|
# Go through the expected log messages
|
||||||
while expected_idx < len(case.expected):
|
while expected_idx < len(case.expected):
|
||||||
e = r"\[INFO\] " + case.expected[expected_idx]
|
e = r"\[INFO\] " + case.expected[expected_idx]
|
||||||
line = proc.stdout.readline().decode("utf-8")
|
try:
|
||||||
if not line:
|
line = msg_queue.get(block=True, timeout=5)
|
||||||
break
|
except queue.Empty:
|
||||||
|
failure("Timed out waiting for '%s'" %(e))
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
pattern = re.compile(e)
|
pattern = re.compile(e)
|
||||||
# Pass if the line matches the expected pattern, else fail
|
# Pass if the line matches the expected pattern, else fail
|
||||||
|
@ -67,5 +90,4 @@ if __name__ == "__main__":
|
||||||
test_failure(case, e, expected_idx, line)
|
test_failure(case, e, expected_idx, line)
|
||||||
expected_idx += 1
|
expected_idx += 1
|
||||||
case_idx += 1
|
case_idx += 1
|
||||||
proc.kill()
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
Loading…
Reference in a new issue