Files
sunnypilot/selfdrive/debug/internal/sounds/test_sound_stability.py
Willem Melching bd06434243 pre-commit pylint (#1580)
* "The commit-hook project sounds interesting though. I would definitely merge something that runs flake8 and pylint on the modified files!"
-  pd0wm, https://github.com/commaai/openpilot/pull/1575#issuecomment-634974344

* add pylint to pre-commit and make everything pass

* Remove uncommented stuff

Co-authored-by: J <user@4800.lan>
2020-05-27 20:00:14 -07:00

46 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import subprocess
import time
import datetime
import random
from common.basedir import BASEDIR
import cereal.messaging as messaging
if __name__ == "__main__":
sound_dir = os.path.join(BASEDIR, "selfdrive/assets/sounds")
sound_files = [f for f in os.listdir(sound_dir) if f.endswith(".wav")]
play_sound = os.path.join(BASEDIR, "selfdrive/ui/test/play_sound")
print("disabling charging")
os.system('echo "0" > /sys/class/power_supply/battery/charging_enabled')
os.environ["LD_LIBRARY_PATH"] = ""
sm = messaging.SubMaster(["thermal"])
FNULL = open(os.devnull, "w")
start_time = time.time()
while True:
volume = 15
n = random.randint(5, 10)
procs = []
for _ in range(n):
sound = random.choice(sound_files)
p = subprocess.Popen([play_sound, os.path.join(sound_dir, sound), str(volume)], stdout=FNULL, stderr=FNULL)
procs.append(p)
time.sleep(random.uniform(0, 0.75))
time.sleep(random.randint(0, 5))
for p in procs:
p.terminate()
sm.update(0)
s = time.time() - start_time
hhmmss = str(datetime.timedelta(seconds=s)).split(".")[0]
print("test duration:", hhmmss)
print("\tbattery percent", sm["thermal"].batteryPercent)