Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/examples.py
Views: 1798
"""1Contains functions used to test the ArduPilot examples23AP_FLAKE8_CLEAN4"""56from __future__ import print_function789import os10import pexpect11import signal12import subprocess13import time1415from pysim import util161718def run_example(filepath, valgrind=False, gdb=False):19cmd = []20if valgrind:21cmd.append("valgrind")22if gdb:23cmd.append("gdb")24cmd.append(filepath)25print("Running: (%s)" % str(cmd))26bob = subprocess.Popen(cmd, stdin=None, close_fds=True)27retcode = bob.poll()28time.sleep(10)29print("pre-kill retcode: %s" % str(retcode))30if retcode is not None:31raise ValueError("Process exited before I could kill it (%s)" % str(retcode))32bob.send_signal(signal.SIGTERM)33time.sleep(1)34retcode = bob.poll()35print("retcode: %s" % str(retcode))36if retcode is None:37# if we get this far then we're not going to get a gcda file38# out of this process for coverage analysis; it has to exit39# normally, and it hasn't responded to a TERM.40bob.kill()41retcode2 = bob.wait()42print("retcode2: %s" % str(retcode2))43elif retcode == -15:44print("process exited with -15, indicating it didn't catch the TERM signal and exit properly")45elif retcode != 0:46# note that process could exit with code 0 and we couldn't tell...47raise ValueError("Process exitted with non-zero exitcode %s" % str(retcode))4849print("Ran: (%s)" % str(cmd))505152def run_examples(debug=False, valgrind=False, gdb=False):53dirpath = util.reltopdir(os.path.join('build', 'sitl', 'examples'))5455print("Running Hello")56# explicitly run helloworld and check for output57hello_path = os.path.join(dirpath, "Hello")58p = pexpect.spawn(hello_path, ["Hello"])59ex = None60try:61p.expect("hello world", timeout=5)62except pexpect.TIMEOUT as e:63ex = e64print("ran Hello")6566p.close()6768if ex is not None:69raise ex7071skip = {72"BARO_generic": "Most linux computers don't have baros...",73"RCProtocolDecoder": "This assumes specific hardware is connected",74"FlashTest": "https://github.com/ArduPilot/ardupilot/issues/14168",75"UART_chargen": "This nuke the term",76}77for afile in os.listdir(dirpath):78if afile in skip:79print("Skipping %s: %s" % (afile, skip[afile]))80continue81filepath = os.path.join(dirpath, afile)82if not os.path.isfile(filepath):83continue84run_example(filepath, valgrind=valgrind, gdb=gdb)8586return True878889