Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit ce8472c

Browse files
committed
Adds speedup for sitl tests.
1 parent a6899bc commit ce8472c

File tree

4 files changed

+72
-32
lines changed

4 files changed

+72
-32
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
before_install: []
22
env:
3-
global: []
3+
global:
4+
- TEST_SPEEDUP=10
5+
- TEST_RATE=200
6+
- TEST_RETRY=1
47
install:
58
- 'a() { set -e; }'
69
- "z() { E=$?; test $E -eq 0 && return 0; printf \"\\n\\033[1;31mThe command failed with exit code $?.\\033[0m\"; set -e; return $E; }"
@@ -9,7 +12,7 @@ install:
912
script:
1013
- (a; sudo python setup.py install );z
1114
- (a; nosetests tests/web );z
12-
- (a; cd tests; python -m sitl );z
15+
- (a; cd tests; python -um sitl );z
1316
git:
1417
depth: 10
1518
language: objective-c

appveyor.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
environment:
2-
global: {}
2+
global:
3+
TEST_SPEEDUP: 10
4+
TEST_RATE: 200
5+
TEST_RETRY: 4
36
init: []
47
cache:
58
- "c:\\Users\\appveyor\\.pip-wheelhouse"
@@ -20,7 +23,7 @@ install:
2023
build_script:
2124
- cmd: 'setlocal & python setup.py install & endlocal'
2225
- cmd: "setlocal & SET PATH=%PYTHON%;c:\\Python27\\Scripts;%PATH% & nosetests tests\\web & endlocal"
23-
- cmd: "setlocal & SET PATH=%PYTHON%;c:\\Python27\\Scripts;%PATH% & cd tests & python -u -m sitl & endlocal"
26+
- cmd: "setlocal & SET PATH=%PYTHON%;c:\\Python27\\Scripts;%PATH% & cd tests & python -um sitl & endlocal"
2427
clone_depth: 10
2528
test: 'off'
2629
branches:

circle.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
machine:
2-
environment: {}
2+
environment:
3+
TEST_SPEEDUP: 10
4+
TEST_RATE: 200
5+
TEST_RETRY: 1
36
dependencies:
47
override:
58
- python setup.py install:
69
environment: {}
710
- nosetests tests/web:
811
environment: {}
9-
- cd tests; python -m sitl:
12+
- cd tests; python -um sitl:
1013
environment: {}
1114
pre:
1215
- pip2 install nose psutil:

tests/sitl/__main__.py

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ def wrap_fd(pipeout):
6767

6868
def lets_run_a_test(name):
6969
sitl_args = ['dronekit-sitl', 'copter-3.3-rc5', '-I0', '-S', '--model', 'quad', '--home=-35.363261,149.165230,584,353']
70+
71+
speedup = os.environ.get('TEST_SPEEDUP', '1')
72+
rate = os.environ.get('TEST_RATE', '200')
73+
sitl_args += ['--speedup', str(speedup), '-r', str(rate)]
74+
75+
# Change CPU core affinity.
76+
# TODO change affinity on osx/linux
7077
if sys.platform == 'win32':
78+
# 0x14 = 0b1110 = all cores except cpu 1
7179
sitl = Popen(['start', '/affinity', '14', '/realtime', '/b', '/wait'] + sitl_args, shell=True, stdout=PIPE, stderr=PIPE)
7280
else:
7381
sitl = Popen(sitl_args, stdout=PIPE, stderr=PIPE)
@@ -104,36 +112,47 @@ def lets_run_a_test(name):
104112
sys.stdout.flush()
105113
sys.stderr.flush()
106114

107-
# APPVEYOR = SLOW
108-
timeout = 15*60 if sys.platform == 'win32' else 5*60
115+
mavproxy_verbose = False
116+
timeout = 5*60
117+
109118
try:
110-
p = Popen([sys.executable, '-m', 'MAVProxy.mavproxy', '--logfile=' + tempfile.mkstemp()[1], '--master=tcp:127.0.0.1:5760'], cwd=testpath, env=newenv, stdin=PIPE, stdout=PIPE)#, stderr=PIPE)
119+
p = Popen([sys.executable, '-m', 'MAVProxy.mavproxy', '--logfile=' + tempfile.mkstemp()[1], '--master=tcp:127.0.0.1:5760'], cwd=testpath, env=newenv, stdin=PIPE, stdout=PIPE, stderr=PIPE if not mavproxy_verbose else None)
111120
bg.append(p)
112121

122+
# TODO this sleep is only for us to waiting until
123+
# all parameters to be received; would prefer to
124+
# move this to testlib.py and happen asap
113125
while p.poll() == None:
114126
line = p.stdout.readline()
115-
sys.stdout.write(line)
116-
sys.stdout.flush()
127+
if mavproxy_verbose:
128+
sys.stdout.write(line)
129+
sys.stdout.flush()
117130
if 'parameters' in line:
118131
break
119132

120-
# TODO this sleep is only for us to waiting until
121-
# all parameters to be received; would prefer to
122-
# move this to testlib.py and happen asap
123133
time.sleep(3)
124-
p.stdin.write('module load droneapi.module.api\n')
134+
135+
# NOTE these are *very inappropriate settings*
136+
# to make on a real vehicle. They are leveraged
137+
# exclusively for simulation. Take heed!!!
125138
p.stdin.write('param set ARMING_CHECK 0\n')
139+
p.stdin.write('param set FS_THR_ENABLE 0\n')
140+
p.stdin.write('param set FS_GCS_ENABLE 0\n')
141+
p.stdin.write('param set EKF_CHECK_THRESH 0\n')
142+
143+
p.stdin.write('module load droneapi.module.api\n')
126144
p.stdin.write('api start testlib.py\n')
127145
p.stdin.flush()
128146

129-
while True:
130-
nextline = p.stdout.readline()
131-
if nextline == '' and p.poll() != None:
132-
break
133-
sys.stdout.write(nextline)
134-
sys.stdout.flush()
135-
136-
# wait_timeout(p, timeout)
147+
if mavproxy_verbose:
148+
while True:
149+
nextline = p.stdout.readline()
150+
if nextline == '' and p.poll() != None:
151+
break
152+
sys.stdout.write(nextline)
153+
sys.stdout.flush()
154+
else:
155+
wait_timeout(p, timeout)
137156
except RuntimeError:
138157
kill(p.pid)
139158
p.returncode = 143
@@ -148,17 +167,29 @@ def lets_run_a_test(name):
148167
bg.remove(sitl)
149168

150169
if p.returncode != 0:
151-
print('[runner] ...aborting with dronekit error code ' + str(p.returncode))
152-
sys.stdout.flush()
153-
sys.stderr.flush()
154-
sys.exit(p.returncode)
155-
156-
print('[runner] ...success.')
170+
print('[runner] ...failed with dronekit error code ' + str(p.returncode))
171+
else:
172+
print('[runner] ...success.')
173+
174+
sys.stdout.flush()
175+
sys.stderr.flush()
157176
time.sleep(5)
177+
return p.returncode
158178

159-
for i in os.listdir(testpath):
160-
if i.startswith('test_') and i.endswith('.py'):
161-
lets_run_a_test(i[:-3])
179+
retry = int(os.environ.get('TEST_RETRY', '1'))
180+
for path in os.listdir(testpath):
181+
if path.startswith('test_') and path.endswith('.py'):
182+
name = path[:-3]
183+
i = retry
184+
while True:
185+
ret = lets_run_a_test(name)
186+
if ret == 0:
187+
break
188+
i = i - 1
189+
if i == 0:
190+
print('[runner] aborting after failed test.')
191+
sys.exit(ret)
192+
print('[runner] retrying %s %s more times' % (name, i, ))
162193

163194
print('[runner] finished.')
164195
sys.stdout.flush()

0 commit comments

Comments
 (0)