sensord: remove hardcoded irq from test (#27759)

* sensord: remove hardcoded irq from test

* fix linter

---------

Co-authored-by: Comma Device <device@comma.ai>
pull/27761/head
Adeeb Shihadeh 2 years ago committed by GitHub
parent 2c13bfac74
commit 08be9eed08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      system/sensord/tests/test_sensord.py

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import glob
import time import time
import unittest import unittest
import numpy as np import numpy as np
@ -7,7 +8,7 @@ from collections import namedtuple, defaultdict
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import log from cereal import log
from system.hardware import TICI, HARDWARE from system.hardware import TICI
from selfdrive.manager.process_config import managed_processes from selfdrive.manager.process_config import managed_processes
BMX = { BMX = {
@ -70,7 +71,6 @@ ALL_SENSORS = {
} }
} }
LSM_IRQ = 336
def get_irq_count(irq: int): def get_irq_count(irq: int):
with open(f"/sys/kernel/irq/{irq}/per_cpu_count") as f: with open(f"/sys/kernel/irq/{irq}/per_cpu_count") as f:
@ -101,9 +101,6 @@ class TestSensord(unittest.TestCase):
if not TICI: if not TICI:
raise unittest.SkipTest raise unittest.SkipTest
# make sure gpiochip0 is readable
HARDWARE.initialize_hardware()
# enable LSM self test # enable LSM self test
os.environ["LSM_SELF_TEST"] = "1" os.environ["LSM_SELF_TEST"] = "1"
@ -114,6 +111,15 @@ class TestSensord(unittest.TestCase):
time.sleep(3) time.sleep(3)
cls.sample_secs = 10 cls.sample_secs = 10
cls.events = read_sensor_events(cls.sample_secs) cls.events = read_sensor_events(cls.sample_secs)
# determine sensord's irq
cls.sensord_irq = None
for fn in glob.glob('/sys/kernel/irq/*/actions'):
with open(fn) as f:
if "sensord" in f.read():
cls.sensord_irq = int(fn.split('/')[-2])
break
assert cls.sensord_irq is not None
finally: finally:
# teardown won't run if this doesn't succeed # teardown won't run if this doesn't succeed
managed_processes["sensord"].stop() managed_processes["sensord"].stop()
@ -121,8 +127,6 @@ class TestSensord(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
managed_processes["sensord"].stop() managed_processes["sensord"].stop()
if "LSM_SELF_TEST" in os.environ:
del os.environ['LSM_SELF_TEST']
def tearDown(self): def tearDown(self):
managed_processes["sensord"].stop() managed_processes["sensord"].stop()
@ -250,9 +254,9 @@ class TestSensord(unittest.TestCase):
time.sleep(3) time.sleep(3)
# read /proc/interrupts to verify interrupts are received # read /proc/interrupts to verify interrupts are received
state_one = get_irq_count(LSM_IRQ) state_one = get_irq_count(self.sensord_irq)
time.sleep(1) time.sleep(1)
state_two = get_irq_count(LSM_IRQ) state_two = get_irq_count(self.sensord_irq)
error_msg = f"no interrupts received after sensord start!\n{state_one} {state_two}" error_msg = f"no interrupts received after sensord start!\n{state_one} {state_two}"
assert state_one != state_two, error_msg assert state_one != state_two, error_msg
@ -261,9 +265,9 @@ class TestSensord(unittest.TestCase):
time.sleep(1) time.sleep(1)
# read /proc/interrupts to verify no more interrupts are received # read /proc/interrupts to verify no more interrupts are received
state_one = get_irq_count(LSM_IRQ) state_one = get_irq_count(self.sensord_irq)
time.sleep(1) time.sleep(1)
state_two = get_irq_count(LSM_IRQ) state_two = get_irq_count(self.sensord_irq)
assert state_one == state_two, "Interrupts received after sensord stop!" assert state_one == state_two, "Interrupts received after sensord stop!"

Loading…
Cancel
Save