More encoder test cleanup (#20623)

* more encode test cleanup

* fix check at end of function
pull/20626/head
Willem Melching 4 years ago committed by GitHub
parent ec5465ffd5
commit c4e2d374c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      selfdrive/loggerd/tests/test_encoder.py
  2. 6
      selfdrive/test/helpers.py

@ -16,6 +16,7 @@ from common.timeout import Timeout
from selfdrive.hardware import EON, TICI
from selfdrive.loggerd.config import ROOT
from selfdrive.test.helpers import with_processes
from selfdrive.manager.process_config import managed_processes
from tools.lib.logreader import LogReader
SEGMENT_LENGTH = 2
@ -60,12 +61,12 @@ class TestEncoder(unittest.TestCase):
shutil.rmtree(ROOT)
def _get_latest_segment_path(self):
last_route = sorted(Path(ROOT).iterdir(), key=os.path.getmtime)[-1]
last_route = sorted(Path(ROOT).iterdir())[-1]
return os.path.join(ROOT, last_route)
# TODO: this should run faster than real time
@parameterized.expand([(True, ), (False, )])
@with_processes(['camerad', 'sensord', 'loggerd'], init_time=3)
@with_processes(['camerad', 'sensord', 'loggerd'], init_time=3, ignore_stopped=['loggerd'])
def test_log_rotation(self, record_front):
Params().put("RecordFront", str(int(record_front)))
@ -132,12 +133,14 @@ class TestEncoder(unittest.TestCase):
self.assertEqual(min(counts), expected_frames)
shutil.rmtree(f"{route_prefix_path}--{i}")
for i in trange(num_segments):
for i in trange(num_segments + 1):
# poll for next segment
with Timeout(int(SEGMENT_LENGTH*2), error_msg=f"timed out waiting for segment {i}"):
while int(self._get_latest_segment_path().rsplit("--", 1)[1]) <= i:
while Path(f"{route_prefix_path}--{i}") not in Path(ROOT).iterdir():
time.sleep(0.1)
managed_processes['loggerd'].stop()
for i in trange(num_segments):
check_seg(i)

@ -24,7 +24,9 @@ def phone_only(x):
return x
def with_processes(processes, init_time=0):
def with_processes(processes, init_time=0, ignore_stopped=None):
ignore_stopped = [] if ignore_stopped is None else ignore_stopped
def wrapper(func):
@wraps(func)
def wrap(*args, **kwargs):
@ -39,7 +41,7 @@ def with_processes(processes, init_time=0):
try:
func(*args, **kwargs)
# assert processes are still started
assert all(managed_processes[name].proc.exitcode is None for name in processes)
assert all(managed_processes[name].proc.exitcode is None for name in processes if name not in ignore_stopped)
finally:
for p in processes:
managed_processes[p].stop()

Loading…
Cancel
Save