2011-10-30 23:50:34 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# APM automatic test suite
|
|
|
|
# Andrew Tridgell, October 2011
|
|
|
|
|
|
|
|
import pexpect, os, util, sys, shutil, arducopter
|
|
|
|
import optparse, fnmatch
|
|
|
|
|
2011-11-01 08:31:01 -03:00
|
|
|
os.putenv('TMPDIR', util.reltopdir('tmp'))
|
2011-10-30 23:50:34 -03:00
|
|
|
|
|
|
|
def get_default_params(atype):
|
|
|
|
'''get default parameters'''
|
2011-11-07 07:55:21 -04:00
|
|
|
sil = util.start_SIL(atype, wipe=True)
|
2011-10-30 23:50:34 -03:00
|
|
|
mavproxy = util.start_MAVProxy_SIL(atype)
|
|
|
|
idx = mavproxy.expect(['Please Run Setup', 'Saved [0-9]+ parameters to (\S+)'])
|
|
|
|
if idx == 0:
|
|
|
|
# we need to restart it after eeprom erase
|
|
|
|
mavproxy.close()
|
|
|
|
sil.close()
|
|
|
|
sil = util.start_SIL(atype)
|
|
|
|
mavproxy = util.start_MAVProxy_SIL(atype)
|
|
|
|
idx = mavproxy.expect('Saved [0-9]+ parameters to (\S+)')
|
|
|
|
parmfile = mavproxy.match.group(1)
|
2011-11-01 08:31:01 -03:00
|
|
|
dest = util.reltopdir('../buildlogs/%s.defaults.txt' % atype)
|
2011-10-30 23:50:34 -03:00
|
|
|
shutil.copy(parmfile, dest)
|
|
|
|
mavproxy.close()
|
|
|
|
sil.close()
|
|
|
|
print("Saved defaults for %s to %s" % (atype, dest))
|
2011-11-07 05:12:51 -04:00
|
|
|
|
2011-11-07 07:55:21 -04:00
|
|
|
|
|
|
|
def dump_logs(atype):
|
|
|
|
'''dump DataFlash logs'''
|
|
|
|
print("Dumping logs for %s" % atype)
|
|
|
|
sil = util.start_SIL(atype, CLI=True)
|
|
|
|
logfile = util.reltopdir('../buildlogs/%s.flashlog' % atype)
|
|
|
|
log = open(logfile, mode='w')
|
|
|
|
mavproxy = util.start_MAVProxy_SIL(atype, setup=True, logfile=log)
|
|
|
|
mavproxy.expect(']')
|
|
|
|
mavproxy.send("logs\n")
|
|
|
|
mavproxy.expect("Log]")
|
|
|
|
mavproxy.send("dump 1\n")
|
|
|
|
mavproxy.expect("Log]")
|
|
|
|
mavproxy.close()
|
|
|
|
sil.close()
|
|
|
|
log.close()
|
|
|
|
print("Saved log for %s to %s" % (atype, logfile))
|
|
|
|
|
2011-11-07 05:12:51 -04:00
|
|
|
def test_prerequesites():
|
|
|
|
'''check we have the right directories and tools to run tests'''
|
|
|
|
print("Testing prerequesites")
|
|
|
|
util.mkdir_p(util.reltopdir('../buildlogs'))
|
|
|
|
if not os.path.exists(util.reltopdir('../HILTest/hil_quad.py')):
|
|
|
|
print('''
|
|
|
|
You need to install HILTest in %s
|
|
|
|
|
|
|
|
You can get it from git://git.samba.org/tridge/UAV/HILTest.git
|
|
|
|
|
|
|
|
''' % util.reltopdir('../HILTest'))
|
2011-10-30 23:50:34 -03:00
|
|
|
|
|
|
|
|
|
|
|
############## main program #############
|
|
|
|
parser = optparse.OptionParser("autotest")
|
|
|
|
parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
|
|
|
|
parser.add_option("--list", action='store_true', default=False, help='list the available steps')
|
|
|
|
|
|
|
|
opts, args = parser.parse_args()
|
|
|
|
|
|
|
|
steps = [
|
|
|
|
'build.ArduPlane',
|
|
|
|
'defaults.ArduPlane',
|
2011-11-07 07:55:21 -04:00
|
|
|
'logs.ArduPlane',
|
|
|
|
'build.ArduCopter',
|
2011-10-30 23:50:34 -03:00
|
|
|
'defaults.ArduCopter',
|
2011-11-07 07:55:21 -04:00
|
|
|
'fly.ArduCopter',
|
|
|
|
'logs.ArduCopter',
|
2011-10-30 23:50:34 -03:00
|
|
|
]
|
|
|
|
|
|
|
|
skipsteps = opts.skip.split(',')
|
|
|
|
|
|
|
|
def skip_step(step):
|
|
|
|
'''see if a step should be skipped'''
|
|
|
|
for skip in skipsteps:
|
|
|
|
if fnmatch.fnmatch(step, skip):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
# kill any previous instance
|
|
|
|
util.kill('ArduCopter.elf')
|
|
|
|
util.kill('ArduPilot.elf')
|
|
|
|
|
2011-11-07 05:12:51 -04:00
|
|
|
test_prerequesites()
|
|
|
|
|
2011-10-30 23:50:34 -03:00
|
|
|
for step in steps:
|
|
|
|
if skip_step(step):
|
|
|
|
continue
|
|
|
|
if step == 'build.ArduPlane':
|
|
|
|
util.build_SIL('ArduPlane')
|
|
|
|
elif step == 'build.ArduCopter':
|
|
|
|
util.build_SIL('ArduCopter')
|
|
|
|
elif step == 'defaults.ArduPlane':
|
|
|
|
get_default_params('ArduPlane')
|
|
|
|
elif step == 'defaults.ArduCopter':
|
|
|
|
get_default_params('ArduCopter')
|
2011-11-07 07:55:21 -04:00
|
|
|
elif step == 'logs.ArduPlane':
|
|
|
|
dump_logs('ArduPlane')
|
|
|
|
elif step == 'logs.ArduCopter':
|
|
|
|
dump_logs('ArduCopter')
|
2011-10-30 23:50:34 -03:00
|
|
|
elif step == 'fly.ArduCopter':
|
|
|
|
arducopter.fly_ArduCopter()
|
|
|
|
else:
|
|
|
|
raise RuntimeError("Unknown step %s" % step)
|
|
|
|
|
|
|
|
util.kill('ArduCopter.elf')
|
|
|
|
util.kill('ArduPilot.elf')
|