CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/autotest/examples.py
Views: 1798
1
"""
2
Contains functions used to test the ArduPilot examples
3
4
AP_FLAKE8_CLEAN
5
"""
6
7
from __future__ import print_function
8
9
10
import os
11
import pexpect
12
import signal
13
import subprocess
14
import time
15
16
from pysim import util
17
18
19
def run_example(filepath, valgrind=False, gdb=False):
20
cmd = []
21
if valgrind:
22
cmd.append("valgrind")
23
if gdb:
24
cmd.append("gdb")
25
cmd.append(filepath)
26
print("Running: (%s)" % str(cmd))
27
bob = subprocess.Popen(cmd, stdin=None, close_fds=True)
28
retcode = bob.poll()
29
time.sleep(10)
30
print("pre-kill retcode: %s" % str(retcode))
31
if retcode is not None:
32
raise ValueError("Process exited before I could kill it (%s)" % str(retcode))
33
bob.send_signal(signal.SIGTERM)
34
time.sleep(1)
35
retcode = bob.poll()
36
print("retcode: %s" % str(retcode))
37
if retcode is None:
38
# if we get this far then we're not going to get a gcda file
39
# out of this process for coverage analysis; it has to exit
40
# normally, and it hasn't responded to a TERM.
41
bob.kill()
42
retcode2 = bob.wait()
43
print("retcode2: %s" % str(retcode2))
44
elif retcode == -15:
45
print("process exited with -15, indicating it didn't catch the TERM signal and exit properly")
46
elif retcode != 0:
47
# note that process could exit with code 0 and we couldn't tell...
48
raise ValueError("Process exitted with non-zero exitcode %s" % str(retcode))
49
50
print("Ran: (%s)" % str(cmd))
51
52
53
def run_examples(debug=False, valgrind=False, gdb=False):
54
dirpath = util.reltopdir(os.path.join('build', 'sitl', 'examples'))
55
56
print("Running Hello")
57
# explicitly run helloworld and check for output
58
hello_path = os.path.join(dirpath, "Hello")
59
p = pexpect.spawn(hello_path, ["Hello"])
60
ex = None
61
try:
62
p.expect("hello world", timeout=5)
63
except pexpect.TIMEOUT as e:
64
ex = e
65
print("ran Hello")
66
67
p.close()
68
69
if ex is not None:
70
raise ex
71
72
skip = {
73
"BARO_generic": "Most linux computers don't have baros...",
74
"RCProtocolDecoder": "This assumes specific hardware is connected",
75
"FlashTest": "https://github.com/ArduPilot/ardupilot/issues/14168",
76
"UART_chargen": "This nuke the term",
77
}
78
for afile in os.listdir(dirpath):
79
if afile in skip:
80
print("Skipping %s: %s" % (afile, skip[afile]))
81
continue
82
filepath = os.path.join(dirpath, afile)
83
if not os.path.isfile(filepath):
84
continue
85
run_example(filepath, valgrind=valgrind, gdb=gdb)
86
87
return True
88
89