8633c186cf07f2f473cc27aeb77e5c777ed991ed
[tinc] / test / unit / meson.build
1 dep_cmocka = dependency('cmocka', required: opt_tests)
2 if not dep_cmocka.found()
3   subdir_done()
4 endif
5
6 can_wrap = cc.has_link_argument('-Wl,--wrap=func')
7 if not can_wrap
8   message('linker has no support for function wrapping, mocked tests will not run')
9 endif
10
11 link_tinc = { 'lib': lib_tinc, 'dep': deps_tinc }
12 link_tincd = { 'lib': lib_tincd, 'dep': deps_tincd }
13
14 # Test definition format:
15 #
16 # 'free-form test name': {
17 #   'code': 'test1.c',      // or ['test1.c', 'test1_util.c']
18 #   'mock': ['foo', 'bar'], // list of functions to mock (default: empty)
19 #   'link': link_tinc,      // which binary to link with (default: tincd)
20 #   'fail': true,           // whether the test should fail (default: false)
21 # }
22
23 tests = {
24   'dropin': {
25     'code': 'test_dropin.c',
26   },
27   'random': {
28     'code': 'test_random.c',
29   },
30   'random_noinit': {
31     'code': 'test_random_noinit.c',
32     'fail': true,
33   },
34   'netutl': {
35     'code': 'test_netutl.c',
36   },
37   'net': {
38     'code': 'test_net.c',
39     'mock': ['execute_script', 'environment_init', 'environment_exit'],
40   },
41   'subnet': {
42     'code': 'test_subnet.c',
43   },
44   'protocol': {
45     'code': 'test_protocol.c',
46   },
47   'proxy': {
48     'code': 'test_proxy.c',
49   },
50   'utils': {
51     'code': 'test_utils.c',
52   },
53   'xalloc': {
54     'code': 'test_xalloc.c',
55   },
56   'memzero_null': {
57     'code': 'test_memzero_null.c',
58     'fail': true,
59   },
60   'splay_tree': {
61     'code': 'test_splay_tree.c',
62     'link': link_tinc,
63   },
64 }
65
66 env = ['CMOCKA_MESSAGE_OUTPUT=TAP']
67
68 foreach test, data : tests
69   args = ld_flags
70
71   if can_wrap
72     mocks = data.get('mock', [])
73     if mocks.length() > 0
74       args += ',--wrap='.join(['-Wl'] + mocks)
75     endif
76   endif
77
78   libs = data.get('link', link_tincd)
79
80   exe = executable(test,
81                    sources: data['code'],
82                    link_args: args,
83                    dependencies: [libs['dep'], dep_cmocka],
84                    link_with: libs['lib'],
85                    implicit_include_directories: false,
86                    include_directories: inc_conf,
87                    build_by_default: false)
88
89   must_fail = data.get('fail', false)
90
91   test(test,
92        exe,
93        suite: 'unit',
94        timeout: 60,
95        protocol: must_fail ? 'exitcode' : 'tap',
96        env: env,
97        should_fail: must_fail)
98 endforeach
99