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:
Gustavo Jose de Sousa 2015-10-30 14:14:28 -02:00 committed by Andrew Tridgell
parent 8556b5dfb8
commit 6b4a6f5389
3 changed files with 31 additions and 1 deletions

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python
# encoding: utf-8
from waflib import Logs
from __future__ import print_function
from waflib import Logs, Utils
SOURCE_EXTS = [
'*.S',
@ -133,15 +134,24 @@ def vehicle_stlib(bld, **kw):
)
def find_tests(bld, use=[]):
if not bld.env.HAS_GTEST:
return
features = ''
if bld.cmd == 'check':
features='test'
use = Utils.to_list(use)
use.append('GTEST')
includes = [bld.srcnode.abspath() + '/tests/']
for f in bld.path.ant_glob(incl='*.cpp'):
target = f.change_ext('.' + bld.env.BOARD)
bld.program(
features=features,
target=target,
includes=includes,
source=[f],
use=use,
)

11
tests/AP_gtest.h Normal file
View File

@ -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(); \
}

View File

@ -152,6 +152,13 @@ def configure(cfg):
cfg.load('clang_compilation_database')
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.env.BOARD = cfg.options.board
board = BOARDS[cfg.env.BOARD]
@ -223,6 +230,8 @@ def build(bld):
bld.recurse(d)
if bld.cmd == 'check':
if not bld.env.HAS_GTEST:
bld.fatal('check: gtest library is required')
bld.add_post_fun(ardupilotwaf.test_summary)
class CheckContext(waflib.Build.BuildContext):