File: meson.build

package info (click to toggle)
libei 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,916 kB
  • sloc: ansic: 23,868; python: 2,712; xml: 1,243; sh: 142; makefile: 63; cpp: 12; lisp: 2
file content (233 lines) | stat: -rw-r--r-- 8,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
if get_option('tests').disabled()
    summary({'Test suite enabled': false}, section: 'Test options')
    subdir_done()
endif

subproject('munit', default_options: 'werror=false')

munit = dependency('munit', fallback: ['munit', 'munit_dep'])

lib_unittest = static_library('unittest',
    '../src/util-munit.c',
    dependencies: munit,
    include_directories: [inc_builddir],
)

dep_unittest = declare_dependency(
    link_with: lib_unittest,
    dependencies: munit
)

test('unit-tests-utils',
    executable('unit-tests-utils',
               'unit-tests.c',
               src_libutil,
               include_directories: [inc_src, inc_builddir],
               c_args: ['-D_enable_tests_'],
               dependencies: [dep_unittest, dep_math, dep_epoll]),
    args: ['--log-visible', 'debug'])

if build_libei
    test('unit-tests-ei',
        executable('unit-tests-ei',
                   'unit-tests.c',
                   src_libei,
                   include_directories: [inc_src, inc_builddir],
                   c_args: ['-D_enable_tests_'],
                   dependencies: deps_libei + [dep_unittest]),
        args: ['--log-visible', 'debug'])
endif

if build_libeis
    test('unit-tests-eis',
        executable('unit-tests-eis',
                   'unit-tests.c',
                   src_libeis,
                   include_directories: [inc_src, inc_builddir],
                   c_args: ['-D_enable_tests_'],
                   dependencies: [dep_unittest, dep_libutil]),
        args: ['--log-visible', 'debug'])
endif

if build_oeffis
    test('unit-tests-oeffis',
        executable('unit-tests-oeffis',
                   'unit-tests.c',
                   src_liboeffis,
                   include_directories: [inc_src, inc_builddir],
                   c_args: ['-D_enable_tests_'],
                   dependencies: deps_liboeffis + [dep_unittest]),
        args: ['--log-visible', 'debug'])
endif

if build_libei and build_libeis
    lib_eierpecken = static_library('eierpecken',
                                    'eierpecken.h',
                                    'eierpecken.c',
                                    include_directories: [inc_src, inc_builddir],
                                    dependencies: [munit, dep_libutil, dep_libei, dep_libeis],
    )

    eierpecken = executable('eierpecken',
                            'test-ei-device.c',
                            'test-ei-seat.c',
                            'test-ei.c',
                            'test-eis.c',
                            'test-main.c',
                            link_with: lib_eierpecken,
                            include_directories: [inc_builddir],
                            dependencies: [dep_unittest, dep_libei, dep_libeis])

    test('eierpecken',
        eierpecken,
        args: ['--log-visible', 'debug', '--enable-sigalarm'],
        suite: 'sigalrm')

    test('eierpecken-no-sigalrm',
        eierpecken,
        args: ['--log-visible', 'debug'],
        suite: 'nosigalrm')
endif

valgrind = find_program('valgrind', required : false)
if valgrind.found()
    add_test_setup('valgrind',
            exe_wrapper : [ valgrind,
                    '--leak-check=full',
                    '--gen-suppressions=all',
                    '--error-exitcode=3' ],
            exclude_suites: ['python', 'sigalrm'],  # we don't want to valgrind python and SIGALRM tests
            timeout_multiplier : 100)
else
    message('valgrind not found, disabling valgrind test suite')
endif

if build_libei
    # build-test only
    executable('test-build-libei',
        'buildtest.c',
        dependencies : [dep_libei],
        include_directories : [inc_src],
        c_args : ['-Werror', '-DINCLUDE_LIBEI=1'],
        install : false)
endif

if build_libeis
    executable('test-build-libeis',
        'buildtest.c',
        dependencies : [dep_libeis],
        include_directories : [inc_src],
        c_args : ['-Werror', '-DINCLUDE_LIBEIS=1'],
        install : false)
endif

if add_languages('cpp', required: false)
    if build_libei
        executable('test-build-cxx-libei',
                'buildtest.cc',
                dependencies: [dep_libei],
                include_directories: [inc_src],
                c_args : ['-Werror', '-DINCLUDE_LIBEI=1'],
                install: false)
    endif

    if build_libeis
        executable('test-build-cxx-libeis',
                'buildtest.cc',
                dependencies: [dep_libeis],
                include_directories: [inc_src],
                c_args : ['-Werror', '-DINCLUDE_LIBEIS=1'],
                install: false)
    endif
endif

# Python-based tests

pymod = import('python')
required_python_modules = ['pytest', 'structlog']
python = pymod.find_installation('python3', required: get_option('tests'))
if python.found() and python.language_version().version_compare('< 3.11')
    required_python_modules += ['strenum']
endif
if build_oeffis
    required_python_modules += ['dbusmock']
endif

python = pymod.find_installation('python3',
                                 modules: required_python_modules,
                                 required: get_option('tests'))
pytest = find_program('pytest-3', 'pytest', required: get_option('tests'))
pytest_args = ['--verbose', '--log-level=DEBUG']

enable_pytest = python.found() and pytest.found() and build_libeis

if enable_pytest
    # pytest xdist is nice because it significantly speeds up our
    # test process, but it's not required
    optional_python_modules = ['xdist']
    if pymod.find_installation('python3', modules: optional_python_modules, required: false).found()
        pytest_args += ['-n', 'auto']
        configure_file(input: 'conftest.py', output: '@PLAINNAME@', copy: true)
    endif

    eiproto_python_template = files('eiproto.py.tmpl')
    eiproto_python = custom_target('eiproto.py',
                                   input: protocol_xml,
                                   output: 'eiproto.py',
                                   command: [scanner, '--component=ei', '--output=@OUTPUT@', '@INPUT@', eiproto_python_template],
                                   build_by_default: true)

    protocol_test_config = configuration_data()
    protocol_test_config.set('LIBEI_TEST_SERVER', eis_demo_server.full_path())
    configure_file(input: 'test_protocol.py',
                   output: '@PLAINNAME@',
                   configuration: protocol_test_config)

    test('protocol-test', pytest,
        args: pytest_args + ['-k', 'TestEiProtocol'],
        suite: 'python',
        workdir: meson.project_build_root(),
    )
    if valgrind.found()
        env = environment()
        env.set('LIBEI_USE_VALGRIND', '1')
        test('protocol-test-valgrind', pytest,
            args: pytest_args + ['-k', 'TestEiProtocol'],
            suite: 'python',
            workdir: meson.project_build_root(),
            env: env,
            timeout: 300
        )
    endif

    if build_oeffis
        env = environment()
        env.set('LD_LIBRARY_PATH', fs.parent(lib_liboeffis.full_path()))
        test('oeffis-pytest', pytest,
            args: pytest_args,
            suite: 'python',
            workdir: meson.current_source_dir(),
            env: env,
        )
    endif

    test_scanner_config = configuration_data()
    test_scanner_config.set('PROTOFILE', protocol_xml_path)

    # ei-scanner can't be imported as-is in python, so we copy + rename it
    configure_file(input: scanner_source,
                   output: 'eiscanner.py',
                   copy: true)
    configure_file(input: 'test_scanner.py',
                   output: '@PLAINNAME@',
                   configuration: test_scanner_config)
    test('scanner-pytest', pytest,
         args: pytest_args + ['-k', 'TestScanner'],
         suite: 'python',
         workdir: meson.current_build_dir())
endif

summary({'valgrind available': valgrind.found(),
         'unit tests enabled': true,
         'pytest tests enabled': enable_pytest,
        }, section: 'Test options')