From cc2c6180f9749aa6f30fbb05dce202058c061c9e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 27 Aug 2020 15:50:48 -0700 Subject: [PATCH] Sound stability test (#2089) * play sound * clean this up * no cereal * fix module issue Co-authored-by: Comma Device old-commit-hash: 685340d57897b8a0db4aa1c754c1760c59b92ead --- selfdrive/modeld/test/polyfit/__init__.py | 0 selfdrive/ui/test/__init__.py | 0 selfdrive/ui/test/test_sound_stability.py | 49 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 selfdrive/modeld/test/polyfit/__init__.py create mode 100644 selfdrive/ui/test/__init__.py create mode 100755 selfdrive/ui/test/test_sound_stability.py diff --git a/selfdrive/modeld/test/polyfit/__init__.py b/selfdrive/modeld/test/polyfit/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/selfdrive/ui/test/__init__.py b/selfdrive/ui/test/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/selfdrive/ui/test/test_sound_stability.py b/selfdrive/ui/test/test_sound_stability.py new file mode 100755 index 0000000000..f0d51ec960 --- /dev/null +++ b/selfdrive/ui/test/test_sound_stability.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +import os +import random +import subprocess +import time +from pathlib import Path +from common.basedir import BASEDIR + +os.environ["LD_LIBRARY_PATH"] = "" + +# pull this from the provisioning tests +play_sound = os.path.join(BASEDIR, "selfdrive/ui/test/play_sound") +waste = os.path.join(BASEDIR, "scripts/waste") +sound_path = Path(os.path.join(BASEDIR, "selfdrive/assets/sounds")) + +def sound_test(): + + # max volume + vol = 15 + sound_files = [p.absolute() for p in sound_path.iterdir() if str(p).endswith(".wav")] + + # start waste + p = subprocess.Popen([waste], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + start_time = time.monotonic() + frame = 0 + while True: + # start a few processes + procs = [] + for _ in range(random.randint(5, 20)): + sound = random.choice(sound_files) + p = subprocess.Popen([play_sound, str(sound), str(vol)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + procs.append(p) + time.sleep(random.uniform(0, 0.75)) + + # and kill them + time.sleep(random.uniform(0, 5)) + for p in procs: + p.terminate() + + # write stats + stats = f"running time {time.monotonic() - start_time}s, cycle {frame}" + with open("/tmp/sound_stats.txt", "a") as f: + f.write(stats) + print(stats) + frame +=1 + +if __name__ == "__main__": + sound_test()