From 0970dd74b705307a0200932cd47a2f85ef90cd8b Mon Sep 17 00:00:00 2001 From: Jason Young <46612682+jyoung8607@users.noreply.github.com> Date: Wed, 1 Apr 2020 10:51:47 -0700 Subject: [PATCH] Boot-loop testing script for EON/C2 device sensors (#1303) * Sensor test boot-loop script * Changing file permissions * Set executable * Changing file permissions * Sensor test boot-loop script * Changing file permissions * Set executable * Changing file permissions * Bugfix to text_window * Capture logs during a failure event * Capture logs during a failure event --- common/text_window.py | 2 +- panda | 2 +- selfdrive/test/sensor_test_bootloop.py | 67 ++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100755 selfdrive/test/sensor_test_bootloop.py diff --git a/common/text_window.py b/common/text_window.py index fb9ed4f836..bc30e135a3 100755 --- a/common/text_window.py +++ b/common/text_window.py @@ -17,7 +17,7 @@ class TextWindow(): def get_status(self): if self.text_proc is not None: self.text_proc.poll() - return s.text_proc.returncode + return self.text_proc.returncode return None diff --git a/panda b/panda index de89fcdc4f..98ee810a03 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit de89fcdc4f6957e2cfe085d0cfd60cce745a7e36 +Subproject commit 98ee810a0382e22290df2494b3877ed47d196230 diff --git a/selfdrive/test/sensor_test_bootloop.py b/selfdrive/test/sensor_test_bootloop.py new file mode 100755 index 0000000000..4b6e993e7f --- /dev/null +++ b/selfdrive/test/sensor_test_bootloop.py @@ -0,0 +1,67 @@ +#!/usr/bin/python3 +import sys +import os +import stat +import subprocess +import json +from common.text_window import TextWindow +import time + +# Required for sensord not to bus-error on startup +# commaai/cereal#22 +try: + os.mkdir("/dev/shm") +except FileExistsError: + pass +except PermissionError: + print("WARNING: failed to make /dev/shm") + +try: + with open('/tmp/test-results.json', 'r') as infile: + data = json.load(infile) +except: + data = {'sensor-pass': 0, 'sensor-fail': 0} + +STARTUP_SCRIPT = "/data/data/com.termux/files/continue.sh" +try: + with open(STARTUP_SCRIPT, 'w') as startup_script: + startup_script.write("#!/usr/bin/bash\n\n/data/openpilot/selfdrive/test/sensor_test_bootloop.py\n") + os.chmod(STARTUP_SCRIPT, stat.S_IRWXU) +except: + print("Failed to install new startup script -- aborting") + sys.exit(-1) + +sensord_env = {**os.environ, 'SENSOR_TEST': '1'} +process = subprocess.run("./sensord", cwd="/data/openpilot/selfdrive/sensord", env=sensord_env) + +if process.returncode == 40: + text = "Current run: SUCCESS\n" + data['sensor-pass'] += 1 +else: + text = "Current run: FAIL\n" + data['sensor-fail'] += 1 + + timestr = str(int(time.time())) + with open('/tmp/dmesg-' + timestr + '.log', 'w') as dmesg_out: + subprocess.call('dmesg', stdout=dmesg_out, shell=False) + with open("/tmp/logcat-" + timestr + '.log', 'w') as logcat_out: + subprocess.call(['logcat','-d'], stdout=logcat_out, shell=False) + +text += "Sensor pass history: " + str(data['sensor-pass']) + "\n" +text += "Sensor fail history: " + str(data['sensor-fail']) + "\n" + +print(text) + +with open('/tmp/test-results.json', 'w') as outfile: + json.dump(data, outfile, indent=4) + +with TextWindow(text) as status: + for _ in range(100): + if status.get_status() == 1: + with open(STARTUP_SCRIPT, 'w') as startup_script: + startup_script.write("#!/usr/bin/bash\n\ncd /data/openpilot\nexec ./launch_openpilot.sh\n") + os.chmod(STARTUP_SCRIPT, stat.S_IRWXU) + break + time.sleep(0.1) + +subprocess.Popen("reboot")