camerad jenkins box test (#20413)
* separate test
* send
* update test
* snapshot is rgb
* this does not belong here
* clean up
* tici
* no if
* no black frames
* flaky leds
* rename and cleanup
* should be stable and avoid lucky pass
* print
* logical and
* run in jenkins
* source profile on tici
Co-authored-by: Comma Device <device@comma.ai>
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: 97133a8fac
commatwo_master
parent
70dc3598a6
commit
40b1877c04
3 changed files with 91 additions and 68 deletions
@ -0,0 +1,68 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import time |
||||
import unittest |
||||
import os |
||||
import numpy as np |
||||
|
||||
from selfdrive.test.helpers import with_processes |
||||
from selfdrive.camerad.snapshot.snapshot import get_snapshots |
||||
|
||||
from selfdrive.hardware import EON, TICI |
||||
|
||||
TEST_TIME = 45 |
||||
REPEAT = 5 |
||||
|
||||
os.environ["SEND_ROAD"] = "1" |
||||
os.environ["SEND_DRIVER"] = "1" |
||||
if TICI: |
||||
os.environ["SEND_WIDE_ROAD"] = "1" |
||||
|
||||
class TestCamerad(unittest.TestCase): |
||||
@classmethod |
||||
def setUpClass(cls): |
||||
if not (EON or TICI): |
||||
raise unittest.SkipTest |
||||
|
||||
def _numpy_rgb2gray(self, im): |
||||
ret = np.clip(im[:,:,2] * 0.114 + im[:,:,1] * 0.587 + im[:,:,0] * 0.299, 0, 255).astype(np.uint8) |
||||
return ret |
||||
|
||||
def _is_exposure_okay(self, i, med_mean=np.array([[0.2,0.4],[0.2,0.6]])): |
||||
h, w = i.shape[:2] |
||||
i = i[h//10:9*h//10,w//10:9*w//10] |
||||
med_ex, mean_ex = med_mean |
||||
i = self._numpy_rgb2gray(i) |
||||
i_median = np.median(i) / 255. |
||||
i_mean = np.mean(i) / 255. |
||||
print([i_median, i_mean]) |
||||
return med_ex[0] < i_median < med_ex[1] and mean_ex[0] < i_mean < mean_ex[1] |
||||
|
||||
|
||||
@with_processes(['camerad']) |
||||
def test_camera_operation(self): |
||||
print("checking image outputs") |
||||
|
||||
start = time.time() |
||||
passed = 0 |
||||
while(time.time() - start < TEST_TIME and passed < REPEAT): |
||||
rpic, dpic = get_snapshots(frame="roadCameraState", front_frame="driverCameraState") |
||||
|
||||
res = self._is_exposure_okay(rpic) |
||||
res = res and self._is_exposure_okay(dpic) |
||||
|
||||
if TICI: |
||||
wpic, _ = get_snapshots(frame="wideRoadCameraState") |
||||
res = res and self._is_exposure_okay(wpic) |
||||
|
||||
if passed > 0 and not res: |
||||
passed = -passed # fails test if any failure after first sus |
||||
break |
||||
|
||||
passed += int(res) |
||||
time.sleep(2) |
||||
print(passed) |
||||
self.assertTrue(passed >= REPEAT) |
||||
|
||||
if __name__ == "__main__": |
||||
unittest.main() |
Loading…
Reference in new issue