Fix weight comparison in edge BFS
[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   'graph': {
35     'code': 'test_graph.c',
36   },
37   'netutl': {
38     'code': 'test_netutl.c',
39   },
40   'net': {
41     'code': 'test_net.c',
42     'mock': ['execute_script', 'environment_init', 'environment_exit'],
43   },
44   'subnet': {
45     'code': 'test_subnet.c',
46   },
47   'protocol': {
48     'code': 'test_protocol.c',
49   },
50   'proxy': {
51     'code': 'test_proxy.c',
52   },
53   'utils': {
54     'code': 'test_utils.c',
55   },
56   'xalloc': {
57     'code': 'test_xalloc.c',
58   },
59   'memzero_null': {
60     'code': 'test_memzero_null.c',
61     'fail': true,
62   },
63   'splay_tree': {
64     'code': 'test_splay_tree.c',
65     'link': link_tinc,
66   },
67 }
68
69 env = ['CMOCKA_MESSAGE_OUTPUT=TAP']
70
71 foreach test, data : tests
72   args = ld_flags
73
74   if can_wrap
75     mocks = data.get('mock', [])
76     if mocks.length() > 0
77       args += ',--wrap='.join(['-Wl'] + mocks)
78     endif
79   endif
80
81   libs = data.get('link', link_tincd)
82
83   exe = executable(test,
84                    sources: data['code'],
85                    link_args: args,
86                    dependencies: [libs['dep'], dep_cmocka],
87                    link_with: libs['lib'],
88                    implicit_include_directories: false,
89                    include_directories: inc_conf,
90                    build_by_default: false)
91
92   must_fail = data.get('fail', false)
93
94   test(test,
95        exe,
96        suite: 'unit',
97        timeout: 60,
98        protocol: must_fail ? 'exitcode' : 'tap',
99        env: env,
100        should_fail: must_fail)
101 endforeach
102