mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-07 21:13:41 +08:00
a82935f326
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: pharmacomaniac <blittle65@gmail.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import threading
|
|
import unittest
|
|
|
|
from openpilot.starpilot.ui.camera_availability import CameraAvailability
|
|
|
|
|
|
class TestCameraAvailability(unittest.TestCase):
|
|
def test_native_frames_freshness_throttle_and_background_publication(self):
|
|
now = [1_000_000_000]
|
|
written = []
|
|
published = threading.Event()
|
|
def write(*, clock):
|
|
written.append((clock(), threading.get_ident()))
|
|
published.set()
|
|
owner = CameraAvailability(clock=lambda: now[0], write=write)
|
|
self.addCleanup(owner.close)
|
|
self.assertFalse(owner.available())
|
|
owner.observe()
|
|
self.assertTrue(published.wait(1))
|
|
self.assertTrue(owner.available())
|
|
self.assertNotEqual(written[0][1], threading.get_ident())
|
|
for tick in range(1,100):
|
|
now[0] = 1_000_000_000 + tick * 10_000_000
|
|
owner.observe()
|
|
self.assertEqual(len(written), 1)
|
|
published.clear()
|
|
now[0] = 2_000_000_000
|
|
owner.observe()
|
|
self.assertTrue(published.wait(1))
|
|
self.assertEqual(len(written), 2)
|
|
now[0] += 500_000_001
|
|
self.assertFalse(owner.available())
|
|
now[0] = 1
|
|
self.assertFalse(owner.available())
|
|
|
|
def test_slow_writer_keeps_latest_bounded_frame_and_never_blocks_observer(self):
|
|
now = [1_000_000_000]
|
|
entered, release, done = threading.Event(), threading.Event(), threading.Event()
|
|
written = []
|
|
def write(*, clock):
|
|
stamp = clock()
|
|
if not written:
|
|
entered.set()
|
|
release.wait(1)
|
|
written.append(stamp)
|
|
if len(written) == 2:
|
|
done.set()
|
|
owner = CameraAvailability(clock=lambda: now[0], write=write)
|
|
self.addCleanup(owner.close)
|
|
owner.observe()
|
|
self.assertTrue(entered.wait(1))
|
|
now[0] = 2_000_000_000
|
|
owner.observe()
|
|
now[0] = 3_000_000_000
|
|
owner.observe()
|
|
self.assertEqual(owner.pending, 3_000_000_000)
|
|
release.set()
|
|
self.assertTrue(done.wait(1))
|
|
self.assertEqual(written, [1_000_000_000, 3_000_000_000])
|