From 822ea1fbd9ee761c8dce59d727eebe943e640502 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 13 May 2022 15:48:38 +0200 Subject: [PATCH] Add sensord test to Jenkins (#24524) * Add sensord test to Jenkins * add second configuration * add other configs too * rename * move into existing HW tests --- Jenkinsfile | 1 + selfdrive/sensord/test/__init__.py | 0 selfdrive/sensord/test/test_sensord.py | 78 ++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 selfdrive/sensord/test/__init__.py create mode 100755 selfdrive/sensord/test/test_sensord.py diff --git a/Jenkinsfile b/Jenkinsfile index c5edda56fd..0c816cbb82 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -124,6 +124,7 @@ pipeline { ["test boardd loopback", "python selfdrive/boardd/tests/test_boardd_loopback.py"], ["test loggerd", "python selfdrive/loggerd/tests/test_loggerd.py"], ["test encoder", "LD_LIBRARY_PATH=/usr/local/lib python selfdrive/loggerd/tests/test_encoder.py"], + ["test sensord", "python selfdrive/sensord/test/test_sensord.py"], ]) } } diff --git a/selfdrive/sensord/test/__init__.py b/selfdrive/sensord/test/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/selfdrive/sensord/test/test_sensord.py b/selfdrive/sensord/test/test_sensord.py new file mode 100755 index 0000000000..96d8891265 --- /dev/null +++ b/selfdrive/sensord/test/test_sensord.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +import time +import unittest + +import cereal.messaging as messaging +from selfdrive.hardware import TICI +from selfdrive.test.helpers import with_processes + +TEST_TIMESPAN = 10 + +SENSOR_CONFIGURATIONS = ( + { + ('bmx055', 'acceleration'), + ('bmx055', 'gyroUncalibrated'), + ('bmx055', 'magneticUncalibrated'), + ('bmx055', 'temperature'), + ('lsm6ds3', 'acceleration'), + ('lsm6ds3', 'gyroUncalibrated'), + ('lsm6ds3', 'temperature'), + ('rpr0521', 'light'), + }, + { + ('lsm6ds3', 'acceleration'), + ('lsm6ds3', 'gyroUncalibrated'), + ('lsm6ds3', 'temperature'), + ('mmc5603nj', 'magneticUncalibrated'), + ('rpr0521', 'light'), + }, + { + ('bmx055', 'acceleration'), + ('bmx055', 'gyroUncalibrated'), + ('bmx055', 'magneticUncalibrated'), + ('bmx055', 'temperature'), + ('lsm6ds3trc', 'acceleration'), + ('lsm6ds3trc', 'gyroUncalibrated'), + ('lsm6ds3trc', 'temperature'), + ('rpr0521', 'light'), + }, + { + ('lsm6ds3trc', 'acceleration'), + ('lsm6ds3trc', 'gyroUncalibrated'), + ('lsm6ds3trc', 'temperature'), + ('mmc5603nj', 'magneticUncalibrated'), + ('rpr0521', 'light'), + }, +) + + +class TestSensord(unittest.TestCase): + @classmethod + def setUpClass(cls): + if not TICI: + raise unittest.SkipTest + + @with_processes(['sensord']) + def test_sensors_present(self): + sensor_events = messaging.sub_sock("sensorEvents", timeout=0.1) + + start_time_sec = time.time() + events = [] + while time.time() - start_time_sec < TEST_TIMESPAN: + events += messaging.drain_sock(sensor_events) + time.sleep(0.01) + + seen = set() + for event in events: + for measurement in event.sensorEvents: + # Filter out unset events + if measurement.version == 0: + continue + seen.add((str(measurement.source), measurement.which())) + + self.assertIn(seen, SENSOR_CONFIGURATIONS) + + +if __name__ == "__main__": + unittest.main()