summaryrefslogtreecommitdiff
path: root/test/CMakeLists.txt
blob: d0cc8d4d30512a731787af298d76fd49543813e1 (plain)
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267

add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})

include_directories(.)

set(DBUS_SESSION_BUS_LISTEN_ADDRESS ${TEST_LISTEN})

add_library(dbus-testutils STATIC
    disable-crash-handling.c
    disable-crash-handling.h
    test-utils.h
    test-utils.c
)
target_link_libraries(dbus-testutils ${DBUS_INTERNAL_LIBRARIES})

add_subdirectory( name-test )

set(manual-dir-iter_SOURCES
    manual-dir-iter.c
)

set(test-service_SOURCES
    test-service.c
)

set(test-names_SOURCES
    test-names.c
)

set(break_loader_SOURCES
    break-loader.c
)

set(test-shell-service_SOURCES
    test-shell-service.c
)

set(test-shell_SOURCES
    shell-test.c
)

set(test-atomic_SOURCES
    internals/atomic.c
)

set(test-spawn_SOURCES
    spawn-test.c
)

set(test-exit_SOURCES
    test-exit.c
)

# We have to compile a separate copy of disable-crash-handling.c for
# test-segfault rather than using the libdbus-testutils library, because
# otherwise it would fail to link when using the AddressSanitizer.
set(test-segfault_SOURCES
    disable-crash-handling.c
    disable-crash-handling.h
    test-segfault.c
)

set(test-sleep-forever_SOURCES
    test-sleep-forever.c
)

set(manual-tcp_SOURCES
    manual-tcp.c
)

set(manual-paths_SOURCES
    manual-paths.c
)

add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils)
add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils)
add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_test_executable(test-printf internals/printf.c dbus-testutils)
add_helper_executable(test-privserver test-privserver.c dbus-testutils)
add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils)
add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
if(NOT WINCE)
    add_test_executable(test-spawn-oom internals/spawn-oom.c dbus-testutils)
endif()
add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
# the second argument of add_helper_executable() is a whitespace-separated
# list of source files and the third and subsequent arguments are libraries
# to link, hence the quoting here
add_helper_executable(test-segfault "${test-segfault_SOURCES}")
add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(manual-tcp ${manual-tcp_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(manual-backtrace manual-backtrace.c dbus-1)
if(WIN32)
    add_helper_executable(manual-paths ${manual-paths_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
endif()

if(DBUS_ENABLE_EMBEDDED_TESTS)
    add_test_executable(test-atomic ${test-atomic_SOURCES} dbus-testutils)
    add_test_executable(test-hash internals/hash.c dbus-testutils)
    set_target_properties(test-hash PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    set(SOURCES
        internals/dbus-marshal-recursive-util.c
        internals/dbus-marshal-recursive-util.h
        internals/marshal-recursive.c
    )
    add_test_executable(test-marshal-recursive "${SOURCES}" dbus-testutils)
    set_target_properties(test-marshal-recursive PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    set(SOURCES
        internals/dbus-marshal-recursive-util.c
        internals/dbus-marshal-recursive-util.h
        internals/dbus-message-factory.c
        internals/dbus-message-factory.h
        internals/dbus-message-util.c
        internals/dbus-message-util.h
        internals/message-internals.c
    )
    add_test_executable(test-message-internals "${SOURCES}" dbus-testutils)
    set_target_properties(test-message-internals PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    set(SOURCES
        internals/address.c
        internals/dbus-auth-script.c
        internals/dbus-auth-script.h
        internals/dbus-auth-util.c
        internals/dbus-credentials-util.c
        internals/dbus-marshal-byteswap-util.c
        internals/dbus-marshal-recursive-util.c
        internals/dbus-marshal-recursive-util.h
        internals/dbus-marshal-validate-util.c
        internals/dbus-string-util.c
        internals/dbus-sysdeps-util.c
        internals/mempool.c
        internals/misc-internals.c
        internals/misc-internals.h
        internals/sha.c
    )
    add_test_executable(test-misc-internals "${SOURCES}" dbus-testutils)
    set_target_properties(test-misc-internals PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    set(SOURCES bus/main.c)
    add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
    set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    set(SOURCES bus/dispatch.c)
    add_test_executable(test-bus-dispatch "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
    set_target_properties(test-bus-dispatch PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    set(SOURCES bus/dispatch-sha1.c)
    add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
    set_target_properties(test-bus-dispatch-sha1 PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})

    if(NOT WIN32)
        add_test_executable(test-bus-system bus/system.c launch-helper-internal dbus-testutils)
        add_test_executable(test-bus-launch-helper-oom bus/launch-helper-oom.c launch-helper-internal dbus-testutils)
        add_helper_executable(dbus-daemon-launch-helper-for-tests bus/launch-helper-for-tests.c launch-helper-internal)
    endif()
endif()

if(DBUS_WITH_GLIB)
    message(STATUS "with glib test apps")

    add_library(dbus-testutils-glib STATIC
        test-utils-glib.h
        test-utils-glib.c
    )
    target_link_libraries(dbus-testutils-glib dbus-testutils ${DBUS_INTERNAL_LIBRARIES})

    add_definitions(
        ${GLIB2_DEFINITIONS}
    )
    include_directories(
        ${GLIB2_INCLUDE_DIR}
    )

    set(TEST_LIBRARIES ${DBUS_INTERNAL_LIBRARIES} dbus-testutils dbus-testutils-glib ${GLIB2_LIBRARIES})

    add_test_executable(test-assertions internals/assertions.c ${TEST_LIBRARIES})
    add_test_executable(test-corrupt corrupt.c ${TEST_LIBRARIES})
    add_test_executable(test-dbus-daemon dbus-daemon.c ${TEST_LIBRARIES})
    add_test_executable(test-dbus-daemon-eavesdrop dbus-daemon-eavesdrop.c ${TEST_LIBRARIES})
    add_test_executable(test-desktop-file internals/desktop-file.c ${TEST_LIBRARIES})
    add_test_executable(test-fdpass fdpass.c ${TEST_LIBRARIES})
    add_test_executable(test-loopback loopback.c ${TEST_LIBRARIES})
    add_test_executable(test-marshal marshal.c ${TEST_LIBRARIES})
    add_test_executable(test-monitor monitor.c ${TEST_LIBRARIES})
    add_test_executable(test-refs internals/refs.c ${TEST_LIBRARIES})
    add_test_executable(test-relay relay.c ${TEST_LIBRARIES})
    add_test_executable(test-server-oom internals/server-oom.c ${TEST_LIBRARIES})
    add_test_executable(test-syntax syntax.c ${TEST_LIBRARIES})
    add_test_executable(test-sysdeps internals/sysdeps.c ${TEST_LIBRARIES})
    add_test_executable(test-syslog internals/syslog.c ${TEST_LIBRARIES})
    add_test_executable(test-uid-permissions uid-permissions.c ${TEST_LIBRARIES})
    add_helper_executable(manual-authz manual-authz.c ${TEST_LIBRARIES})
    add_helper_executable(manual-test-thread-blocking thread-blocking.c ${TEST_LIBRARIES})
endif()

### keep these in creation order, i.e. uppermost dirs first 
set(TESTDIRS
    data
    data/invalid-messages
    data/auth
    data/sha-1
    data/systemd-activation
    data/valid-config-files
    data/valid-config-files/basic.d
    data/valid-config-files/session.d
    data/valid-config-files-system
    data/valid-config-files-system/system.d
    data/valid-service-files
    data/valid-service-files-system
    data/invalid-config-files
    data/invalid-config-files-system
    data/invalid-messages
    data/invalid-service-files-system
    data/equiv-config-files
    data/equiv-config-files/basic
    data/equiv-config-files/basic/basic.d
    data/equiv-config-files/entities
    data/equiv-config-files/entities/basic.d
)
set(CONFIG_VERBOSE 1)

foreach(DIR ${TESTDIRS})
    file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DIR})
endforeach()

### copy tests to builddir so that generated tests and static tests 
### are all in one place.
message(STATUS "Copying test files to test directory")
foreach(FILE_TYPE *.message-raw *.auth-script *.sha1 *.txt *.conf *.service)
    foreach(DIR ${TESTDIRS})
        file(GLOB FILES "${DIR}/${FILE_TYPE}" )
        foreach(FILE ${FILES})
            get_filename_component(FILENAME ${FILE} NAME)
            set(TARGET ${CMAKE_CURRENT_BINARY_DIR}/${DIR}/${FILENAME})
            configure_file(${FILE} ${TARGET} COPYONLY)
            if(CONFIG_VERBOSE)
                message("${FILE}")
            endif()
        endforeach()
    endforeach()
endforeach()

### generate test files
message(STATUS "Generating test files from templates into test directory")

foreach(FILE_TYPE *.conf.in *.service.in)
    foreach(DIR ${TESTDIRS})
    file(GLOB FILES "${DIR}/${FILE_TYPE}" )
    foreach(FILE ${FILES})
        get_filename_component(FILENAME ${FILE} NAME)
        string(REGEX REPLACE "\\.in$" "" FILENAME ${FILENAME})
        set(TARGET ${CMAKE_CURRENT_BINARY_DIR}/${DIR}/${FILENAME})
        configure_file(${FILE} ${TARGET} @ONLY IMMEDIATE)
        if(CONFIG_VERBOSE)
        message("${FILE}")
        endif()
    endforeach()
    endforeach()
endforeach()

message(STATUS "Copying generated bus config files to test directory")
configure_file(../bus/session.conf.in ${CMAKE_BINARY_DIR}/test/data/valid-config-files/session.conf @ONLY)
configure_file(../bus/system.conf.in ${CMAKE_BINARY_DIR}/test/data/valid-config-files-system/system.conf @ONLY)