Browse Source

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.
master
Gustavo Jose de Sousa 9 years ago committed by Andrew Tridgell
parent
commit
6b4a6f5389
  1. 12
      Tools/ardupilotwaf/ardupilotwaf.py
  2. 11
      tests/AP_gtest.h
  3. 9
      wscript

12
Tools/ardupilotwaf/ardupilotwaf.py

@ -1,7 +1,8 @@ @@ -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): @@ -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

@ -0,0 +1,11 @@ @@ -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

@ -152,6 +152,13 @@ def configure(cfg): @@ -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): @@ -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):

Loading…
Cancel
Save