meson: build: Add support for unit tests
Tested: Verified unit test ran successfully:
$ meson -Doe-sdk=enabled -Dtests=enabled build
$ ninja -C build test
ninja: Entering directory `build'
[25/26] Running all tests.
1/1 utest OK 3.00 s
Change-Id: I46acccec5b3c1837ead707e4e4610eb61a023148
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/meson.build b/meson.build
index b678268..cd4dd16 100644
--- a/meson.build
+++ b/meson.build
@@ -182,3 +182,39 @@
output: u,
)
endforeach
+
+# If test coverage of source files within the root directory are wanted,
+# need to define and build the tests from here
+build_tests = get_option('tests')
+if not build_tests.disabled()
+ oe_sdk = get_option('oe-sdk')
+ if oe_sdk.enabled()
+ # Setup OE SYSROOT
+ OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
+ if OECORE_TARGET_SYSROOT == ''
+ error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
+ endif
+ message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
+ rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
+ ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
+ dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
+ else
+ dynamic_linker = []
+ endif
+
+ gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
+ include_srcs = declare_dependency(sources: [
+ 'image_verify.cpp',
+ 'version.cpp']
+ )
+
+ test('utest',
+ executable(
+ 'utest',
+ './test/utest.cpp',
+ link_args: dynamic_linker,
+ build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
+ dependencies: [deps, gtest, include_srcs, ssl]
+ )
+)
+endif