mirror of https://github.com/ArduPilot/ardupilot
waf: use gtest for tests
It was implemented in such a way that gtest is required only if the user wants to build and run tests. Initially we're considering all tests should be gtests. We can change that assumption in the future if necessary.
This commit is contained in:
parent
8556b5dfb8
commit
6b4a6f5389
|
@ -1,7 +1,8 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from waflib import Logs
|
from __future__ import print_function
|
||||||
|
from waflib import Logs, Utils
|
||||||
|
|
||||||
SOURCE_EXTS = [
|
SOURCE_EXTS = [
|
||||||
'*.S',
|
'*.S',
|
||||||
|
@ -133,15 +134,24 @@ def vehicle_stlib(bld, **kw):
|
||||||
)
|
)
|
||||||
|
|
||||||
def find_tests(bld, use=[]):
|
def find_tests(bld, use=[]):
|
||||||
|
if not bld.env.HAS_GTEST:
|
||||||
|
return
|
||||||
|
|
||||||
features = ''
|
features = ''
|
||||||
if bld.cmd == 'check':
|
if bld.cmd == 'check':
|
||||||
features='test'
|
features='test'
|
||||||
|
|
||||||
|
use = Utils.to_list(use)
|
||||||
|
use.append('GTEST')
|
||||||
|
|
||||||
|
includes = [bld.srcnode.abspath() + '/tests/']
|
||||||
|
|
||||||
for f in bld.path.ant_glob(incl='*.cpp'):
|
for f in bld.path.ant_glob(incl='*.cpp'):
|
||||||
target = f.change_ext('.' + bld.env.BOARD)
|
target = f.change_ext('.' + bld.env.BOARD)
|
||||||
bld.program(
|
bld.program(
|
||||||
features=features,
|
features=features,
|
||||||
target=target,
|
target=target,
|
||||||
|
includes=includes,
|
||||||
source=[f],
|
source=[f],
|
||||||
use=use,
|
use=use,
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Utility header for unit tests with gtest.
|
||||||
|
*/
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#define AP_GTEST_MAIN() \
|
||||||
|
int main(int argc, char *argv[]) \
|
||||||
|
{ \
|
||||||
|
::testing::InitGoogleTest(&argc, argv); \
|
||||||
|
return RUN_ALL_TESTS(); \
|
||||||
|
}
|
9
wscript
9
wscript
|
@ -152,6 +152,13 @@ def configure(cfg):
|
||||||
cfg.load('clang_compilation_database')
|
cfg.load('clang_compilation_database')
|
||||||
cfg.load('waf_unit_test')
|
cfg.load('waf_unit_test')
|
||||||
|
|
||||||
|
cfg.env.HAS_GTEST = cfg.check_cxx(
|
||||||
|
lib='gtest',
|
||||||
|
mandatory=False,
|
||||||
|
uselib_store='GTEST',
|
||||||
|
errmsg='not found, unit tests disabled',
|
||||||
|
)
|
||||||
|
|
||||||
cfg.msg('Setting board to', cfg.options.board)
|
cfg.msg('Setting board to', cfg.options.board)
|
||||||
cfg.env.BOARD = cfg.options.board
|
cfg.env.BOARD = cfg.options.board
|
||||||
board = BOARDS[cfg.env.BOARD]
|
board = BOARDS[cfg.env.BOARD]
|
||||||
|
@ -223,6 +230,8 @@ def build(bld):
|
||||||
bld.recurse(d)
|
bld.recurse(d)
|
||||||
|
|
||||||
if bld.cmd == 'check':
|
if bld.cmd == 'check':
|
||||||
|
if not bld.env.HAS_GTEST:
|
||||||
|
bld.fatal('check: gtest library is required')
|
||||||
bld.add_post_fun(ardupilotwaf.test_summary)
|
bld.add_post_fun(ardupilotwaf.test_summary)
|
||||||
|
|
||||||
class CheckContext(waflib.Build.BuildContext):
|
class CheckContext(waflib.Build.BuildContext):
|
||||||
|
|
Loading…
Reference in New Issue