From 6b4a6f5389afb1af8c1667b1e329643ad91b1f14 Mon Sep 17 00:00:00 2001 From: Gustavo Jose de Sousa Date: Fri, 30 Oct 2015 14:14:28 -0200 Subject: [PATCH] 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. --- Tools/ardupilotwaf/ardupilotwaf.py | 12 +++++++++++- tests/AP_gtest.h | 11 +++++++++++ wscript | 9 +++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/AP_gtest.h diff --git a/Tools/ardupilotwaf/ardupilotwaf.py b/Tools/ardupilotwaf/ardupilotwaf.py index 85c98e3b62..c232e765d7 100644 --- a/Tools/ardupilotwaf/ardupilotwaf.py +++ b/Tools/ardupilotwaf/ardupilotwaf.py @@ -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, ) diff --git a/tests/AP_gtest.h b/tests/AP_gtest.h new file mode 100644 index 0000000000..ee9eceb2d6 --- /dev/null +++ b/tests/AP_gtest.h @@ -0,0 +1,11 @@ +/* + * Utility header for unit tests with gtest. + */ +#include + +#define AP_GTEST_MAIN() \ +int main(int argc, char *argv[]) \ +{ \ + ::testing::InitGoogleTest(&argc, argv); \ + return RUN_ALL_TESTS(); \ +} diff --git a/wscript b/wscript index 6453dbfe2a..249cee3e7c 100644 --- a/wscript +++ b/wscript @@ -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):