]> granicus.if.org Git - libevent/commitdiff
Only test the event backends available on the system.
authorJoakim Soderberg <joakim.soderberg@gmail.com>
Mon, 16 Dec 2013 15:37:51 +0000 (16:37 +0100)
committerJoakim Soderberg <joakim.soderberg@gmail.com>
Mon, 16 Dec 2013 15:37:51 +0000 (16:37 +0100)
Fix how the CMake project adds the tests using the different backends. At
first we tried to do it exactly as it's done in test/test.sh.

However, test.sh uses a special program test-init to decide if a given
backend is available or not before running the actual tests. Doing it this way
will not be possible using CMake. Since then we would have to have the
test-init executable compiled at the time we run CMake, to know what tests
we should add. (And since CMake generates the make/project files that
compiles the executables, there's a catch 22).

Instead of deciding what tests to run this way, we simply use the result
of the CMake system introspection (that figures out what backends are
available) to decide what backend tests to add.

CMakeLists.txt

index a3ced8a981ddb4dee8a10ccbdbe369533896df77..21528b355aa0e85a360390766fb6d3ee1f8e7aa5 100644 (file)
@@ -745,35 +745,74 @@ if (NOT EVENT__DISABLE_TESTS)
     # We run all tests with the different backends turned on one at a time.
     #
 
+    # Add event backends based on system introspection result.
+    set(BACKENDS "")
+
+    if (EVENT__HAVE_EPOLL)
+        list(APPEND BACKENDS EPOLL)
+    endif()
+
+    if (EVENT__HAVE_SELECT)
+        list(APPEND BACKENDS SELECT)
+    endif()
+
+    if (EVENT__HAVE_POLL)
+        list(APPEND BACKENDS POLL)
+    endif()
+
+    if (EVENT__HAVE_KQUEUE)
+        list(APPEND BACKENDS KQUEUE)
+    endif()
+
+    if (EVENT__HAVE_EVENT_PORTS)
+        list(APPEND BACKENDS EVPORT)
+    endif()
+
+    if (EVENT__HAVE_DEVPOLL)
+        list(APPEND BACKENDS DEVPOLL)
+    endif()
+
+    if (WIN32)
+        list(APPEND BACKENDS WIN32)
+    endif()
+
+    message("Available event backends: ${BACKENDS}")
+
     # Default environment variables turns off all event systems,
     # then we enable each one, one at a time when creating the tests.
-    set(BACKENDS EVPORT KQUEUE EPOLL DEVPOLL POLL SELECT WIN32)
-    set(DEFAULT_TEST_ENV_VARS "")
+    set(DEFAULT_TEST_ENV_VARS "EVENT_SHOW_METHOD=1;")
     foreach(BACKEND ${BACKENDS})
         list(APPEND DEFAULT_TEST_ENV_VARS "EVENT_NO${BACKEND}=1")
     endforeach()
 
     # Macro that creates the ctest test for a backend.
     macro(add_backend_test BACKEND_TEST_NAME ENV_VARS)
+        set(TEST_NAMES "")
+
         foreach (TESTPROG ${TESTPROGS})
-            add_test(${TESTPROG}_${BACKEND_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTPROG})
-            set_tests_properties(${TESTPROG}_${BACKEND_TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
+            set(TEST_NAME ${TESTPROG}_${BACKEND_TEST_NAME})
+            add_test(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTPROG})
+            list(APPEND TEST_NAMES ${TEST_NAME})
+            set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
         endforeach()
 
         # Dump events test.
         if (PYTHONINTERP_FOUND)
-            add_test(test-dumpevents_${BACKEND_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-dumpevents | ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/check-dumpevents.py)
-            set_tests_properties(test-dumpevents_${BACKEND_TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
+            set(TEST_NAME test-dumpevents_${BACKEND_TEST_NAME})
+            add_test(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-dumpevents | ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/check-dumpevents.py)
+            set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
         else()
             message(WARNING "test-dumpevents will be run without output check since python was not found!")
-            add_test(test-dumpevents_${BACKEND_TEST_NAME}_no_check ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-dumpevents)
-            set_tests_properties(test-dumpevents_${BACKEND_TEST_NAME}_no_check PROPERTIES ENVIRONMENT "${ENV_VARS}")
+            set(TEST_NAME test-dumpevents_${BACKEND_TEST_NAME}_no_check)
+            add_test(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-dumpevents)
+            set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
         endif()
 
         # Regress tests.
         if (NOT EVENT__DISABLE_REGRESS AND PYTHONINTERP_FOUND)
-            add_test(regress_${BACKEND_TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress)
-            set_tests_properties(regress_${BACKEND_TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
+            set(TEST_NAME regress_${BACKEND_TEST_NAME})
+            add_test(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress)
+            set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARS}")
         endif()
     endmacro()
 
@@ -789,7 +828,7 @@ if (NOT EVENT__DISABLE_TESTS)
             add_backend_test(changelist_${BACKEND} "${BACKEND_ENV_VARS};EVENT_EPOLL_USE_CHANGELIST=yes")
             add_backend_test(timerfd_changelist_${BACKEND} "${BACKEND_ENV_VARS};EVENT_EPOLL_USE_CHANGELIST=yes;EVENT_PRECISE_TIMER=1")
         else()
-            add_backend_test(${BACKEND} ${BACKEND_ENV_VARS})
+            add_backend_test(${BACKEND} "${BACKEND_ENV_VARS}")
         endif()
     endforeach()