fix up fan HITL test (#2317)

* fix up fan HITL test

* cleanup

* times two

* even simpler

* append

* one more...

* speed it up now

* oops
This commit is contained in:
Adeeb Shihadeh
2026-01-12 15:59:49 -08:00
committed by GitHub
parent e42367df97
commit ce1b6a67e4
2 changed files with 13 additions and 16 deletions

View File

@@ -128,11 +128,6 @@ class Panda:
INTERNAL_DEVICES = (HW_TYPE_TRES, HW_TYPE_CUATRO)
MAX_FAN_RPMs = {
HW_TYPE_TRES: 6600,
HW_TYPE_CUATRO: 5000,
}
HARNESS_STATUS_NC = 0
HARNESS_STATUS_NORMAL = 1
HARNESS_STATUS_FLIPPED = 2

View File

@@ -5,28 +5,30 @@ from panda import Panda
pytestmark = [
pytest.mark.test_panda_types(Panda.INTERNAL_DEVICES),
pytest.mark.test_panda_types([Panda.HW_TYPE_TRES])
]
MAX_RPM = 5000
@pytest.mark.timeout(2*60)
def test_fan_curve(p):
# ensure fan curve is (roughly) linear
for power in (30, 50, 80, 100):
p.set_fan_power(0)
while p.get_fan_rpm() > 0:
time.sleep(0.1)
# wait until fan spins up, then wait a bit more for the RPM to converge
rpms = []
for power in (30, 70, 100):
# wait until fan spins up
p.set_fan_power(power)
for _ in range(20):
time.sleep(1)
if p.get_fan_rpm() > 1000:
break
time.sleep(5)
time.sleep(2) # wait for RPM to converge
rpms.append(p.get_fan_rpm())
print(rpms)
diffs = [b - a for a, b in zip(rpms, rpms[1:])]
assert all(x > 0 for x in diffs), f"Fan RPMs not strictly increasing: {rpms=}"
assert rpms[-1] > (0.75*MAX_RPM)
expected_rpm = Panda.MAX_FAN_RPMs[bytes(p.get_type())] * power / 100
assert 0.75 * expected_rpm <= p.get_fan_rpm() <= 1.25 * expected_rpm
def test_fan_cooldown(p):
# if the fan cooldown doesn't work, we get high frequency noise on the tach line
@@ -35,5 +37,5 @@ def test_fan_cooldown(p):
time.sleep(3)
p.set_fan_power(0)
for _ in range(5):
assert p.get_fan_rpm() <= Panda.MAX_FAN_RPMs[bytes(p.get_type())]
assert p.get_fan_rpm() <= MAX_RPM*2
time.sleep(0.5)