File: tests.cmake

package info (click to toggle)
azure-vm-utils 0.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 484 kB
  • sloc: python: 1,758; ansic: 1,636; sh: 128; makefile: 19
file content (45 lines) | stat: -rw-r--r-- 1,766 bytes parent folder | download | duplicates (3)
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
find_package(PkgConfig REQUIRED)
pkg_check_modules(CMOCKA REQUIRED cmocka)

function(add_test_executable test_name)
    set(multiValueArgs WRAPPED_FUNCTIONS SOURCES CFLAGS)
    cmake_parse_arguments(TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    add_executable(${test_name} ${TEST_SOURCES} tests/capture.c)
    add_test(NAME ${test_name} COMMAND ${test_name})

    # LTO may be enabled by packaging, but it must be disabled for --wrap to work.
    target_compile_options(${test_name} PRIVATE -g -O0 -fno-lto ${CMOCKA_CFLAGS_OTHER} ${TEST_CFLAGS})
    target_link_options(${test_name} PRIVATE -flto=n)

    target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIRS} src tests)
    target_link_directories(${test_name} PRIVATE ${CMOCKA_LIBRARY_DIRS})
    target_link_libraries(${test_name} PRIVATE ${JSON_C_LIBRARIES} ${CMOCKA_LIBRARIES} dl)

    if(TEST_WRAPPED_FUNCTIONS)
        foreach(func ${TEST_WRAPPED_FUNCTIONS})
            target_link_options(${test_name} PRIVATE -Wl,--wrap=${func})
        endforeach()
    endif()
endfunction()

add_test_executable(debug_tests
    WRAPPED_FUNCTIONS
    SOURCES src/debug.c tests/debug_tests.c
)

add_test_executable(identify_disks_tests
    WRAPPED_FUNCTIONS nvme_identify_namespace_vs_for_namespace_device
    SOURCES src/debug.c src/identify_disks.c src/nvme.c tests/identify_disks_tests.c
    CFLAGS -DUNIT_TESTING_SYS_CLASS_NVME=1
)

add_test_executable(identify_udev_tests
    WRAPPED_FUNCTIONS nvme_identify_namespace_vs_for_namespace_device
    SOURCES src/debug.c src/identify_udev.c src/nvme.c tests/identify_udev_tests.c
)

add_test_executable(nvme_tests
    WRAPPED_FUNCTIONS open open64 posix_memalign ioctl __ioctl_time64 close
    SOURCES src/nvme.c tests/nvme_tests.c
)