From 1a0f61953019416b4888edeacde4209e05314c1c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 30 May 2018 13:35:41 +0200 Subject: [PATCH] build: add test suite option to cmake build PR-URL: https://github.com/libuv/libuv/pull/1850 Reviewed-By: Colin Ihrig --- CMakeLists.txt | 173 ++++++++++++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 5 +- README.md | 10 +++ 3 files changed, 187 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dbceb0458c..f13e5295636 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ # TODO: determine CMAKE_SYSTEM_NAME on OS/390. Currently assumes "OS/390". cmake_minimum_required(VERSION 3.0) project(libuv) +enable_testing() if(MSVC) list(APPEND uv_cflags /W4) @@ -18,6 +19,151 @@ set(uv_sources src/uv-data-getter-setters.c src/version.c) +set(uv_test_sources + test/blackhole-server.c + test/echo-server.c + test/run-tests.c + test/runner.c + test/test-active.c + test/test-async-null-cb.c + test/test-async.c + test/test-barrier.c + test/test-callback-order.c + test/test-callback-stack.c + test/test-close-fd.c + test/test-close-order.c + test/test-condvar.c + test/test-connect-unspecified.c + test/test-connection-fail.c + test/test-cwd-and-chdir.c + test/test-default-loop-close.c + test/test-delayed-accept.c + test/test-dlerror.c + test/test-eintr-handling.c + test/test-embed.c + test/test-emfile.c + test/test-env-vars.c + test/test-error.c + test/test-fail-always.c + test/test-fork.c + test/test-fs-copyfile.c + test/test-fs-event.c + test/test-fs-poll.c + test/test-fs.c + test/test-get-currentexe.c + test/test-get-loadavg.c + test/test-get-memory.c + test/test-get-passwd.c + test/test-getaddrinfo.c + test/test-gethostname.c + test/test-getnameinfo.c + test/test-getsockname.c + test/test-getters-setters.c + test/test-handle-fileno.c + test/test-homedir.c + test/test-hrtime.c + test/test-idle.c + test/test-ip4-addr.c + test/test-ip6-addr.c + test/test-ip6-addr.c + test/test-ipc-heavy-traffic-deadlock-bug.c + test/test-ipc-send-recv.c + test/test-ipc.c + test/test-loop-alive.c + test/test-loop-close.c + test/test-loop-configure.c + test/test-loop-handles.c + test/test-loop-stop.c + test/test-loop-time.c + test/test-multiple-listen.c + test/test-mutexes.c + test/test-osx-select.c + test/test-pass-always.c + test/test-ping-pong.c + test/test-pipe-bind-error.c + test/test-pipe-close-stdout-read-stdin.c + test/test-pipe-connect-error.c + test/test-pipe-connect-multiple.c + test/test-pipe-connect-prepare.c + test/test-pipe-getsockname.c + test/test-pipe-pending-instances.c + test/test-pipe-sendmsg.c + test/test-pipe-server-close.c + test/test-pipe-set-fchmod.c + test/test-pipe-set-non-blocking.c + test/test-platform-output.c + test/test-poll-close-doesnt-corrupt-stack.c + test/test-poll-close.c + test/test-poll-closesocket.c + test/test-poll-oob.c + test/test-poll.c + test/test-process-title-threadsafe.c + test/test-process-title.c + test/test-queue-foreach-delete.c + test/test-ref.c + test/test-run-nowait.c + test/test-run-once.c + test/test-semaphore.c + test/test-shutdown-close.c + test/test-shutdown-eof.c + test/test-shutdown-twice.c + test/test-signal-multiple-loops.c + test/test-signal.c + test/test-socket-buffer-size.c + test/test-spawn.c + test/test-stdio-over-pipes.c + test/test-tcp-alloc-cb-fail.c + test/test-tcp-bind-error.c + test/test-tcp-bind6-error.c + test/test-tcp-close-accept.c + test/test-tcp-close-while-connecting.c + test/test-tcp-close.c + test/test-tcp-connect-error-after-write.c + test/test-tcp-connect-error.c + test/test-tcp-connect-timeout.c + test/test-tcp-connect6-error.c + test/test-tcp-create-socket-early.c + test/test-tcp-flags.c + test/test-tcp-oob.c + test/test-tcp-open.c + test/test-tcp-read-stop.c + test/test-tcp-shutdown-after-write.c + test/test-tcp-try-write.c + test/test-tcp-unexpected-read.c + test/test-tcp-write-after-connect.c + test/test-tcp-write-fail.c + test/test-tcp-write-queue-order.c + test/test-tcp-write-to-half-open-connection.c + test/test-tcp-writealot.c + test/test-thread-equal.c + test/test-thread.c + test/test-threadpool-cancel.c + test/test-threadpool.c + test/test-timer-again.c + test/test-timer-from-check.c + test/test-timer.c + test/test-tmpdir.c + test/test-tty.c + test/test-udp-alloc-cb-fail.c + test/test-udp-bind.c + test/test-udp-create-socket-early.c + test/test-udp-dgram-too-big.c + test/test-udp-ipv6.c + test/test-udp-multicast-interface.c + test/test-udp-multicast-interface6.c + test/test-udp-multicast-join.c + test/test-udp-multicast-join6.c + test/test-udp-multicast-ttl.c + test/test-udp-open.c + test/test-udp-options.c + test/test-udp-send-and-recv.c + test/test-udp-send-hang-loop.c + test/test-udp-send-immediate.c + test/test-udp-send-unreachable.c + test/test-udp-try-send.c + test/test-walk-handles.c + test/test-watcher-cross-stop.c) + if(WIN32) list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0600) list(APPEND uv_libraries @@ -56,6 +202,8 @@ if(WIN32) src/win/util.c src/win/winapi.c src/win/winsock.c) + list(APPEND uv_test_libraries ws2_32) + list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c) else() list(APPEND uv_defines _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE) list(APPEND uv_libraries pthread) @@ -78,6 +226,7 @@ else() src/unix/timer.c src/unix/tty.c src/unix/udp.c) + list(APPEND uv_test_sources test/runner-unix.c) endif() if(CMAKE_SYSTEM_NAME STREQUAL "AIX") @@ -174,6 +323,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") list(APPEND uv_sources src/unix/no-proctitle.c src/unix/sunos.c) endif() +if(CMAKE_SYSTEM_NAME MATCHES "Darwin|DragonFly|FreeBSD|Linux|NetBSD|OpenBSD") + list(APPEND uv_test_libraries util) +endif() + add_library(uv SHARED ${uv_sources}) target_compile_definitions(uv PRIVATE ${uv_defines} BUILDING_UV_SHARED=1) target_compile_options(uv PRIVATE ${uv_cflags}) @@ -186,6 +339,26 @@ target_compile_options(uv_a PRIVATE ${uv_cflags}) target_include_directories(uv_a PRIVATE include src) target_link_libraries(uv_a ${uv_libraries}) +if(BUILD_TESTING) + include(CTest) + add_executable(uv_run_tests ${uv_test_sources}) + target_compile_definitions(uv_run_tests PRIVATE ${uv_defines}) + target_compile_options(uv_run_tests PRIVATE ${uv_cflags}) + target_include_directories(uv_run_tests PRIVATE include) + target_link_libraries(uv_run_tests uv ${uv_test_libraries}) + add_test(NAME uv_test + COMMAND uv_run_tests + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(uv_run_tests_a ${uv_test_sources}) + target_compile_definitions(uv_run_tests_a PRIVATE ${uv_defines}) + target_compile_options(uv_run_tests_a PRIVATE ${uv_cflags}) + target_include_directories(uv_run_tests_a PRIVATE include) + target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries}) + add_test(NAME uv_test_a + COMMAND uv_run_tests_a + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endif() + if(UNIX) # Now for some gibbering horrors from beyond the stars... include(GNUInstallDirs) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d9bf0472fb1..f22e124e3b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -137,7 +137,10 @@ $ git rebase upstream/v1.x # or upstream/master ### TEST Bug fixes and features should come with tests. Add your tests in the -`test/` directory. Each new test needs to be registered in `test/test-list.h`. If you add a new test file, it needs to be registered in two places: +`test/` directory. Each new test needs to be registered in `test/test-list.h`. + +If you add a new test file, it needs to be registered in three places: +- `CMakeLists.txt`: add the file's name to the `uv_test_sources` list. - `Makefile.am`: add the file's name to the `test_run_tests_SOURCES` list. - `uv.gyp`: add the file's name to the `sources` list in the `run-tests` target. diff --git a/README.md b/README.md index d42ada56a82..f6e7288dedd 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,16 @@ $ make check $ make install ``` +To build with [CMake](https://cmake.org/): + +```bash +$ mkdir -p out/cmake ; cd out/cmake ; cmake -DBUILD_TESTING=ON ../.. +$ make all test +# Or manually: +$ ./uv_run_tests # shared library build +$ ./uv_run_tests_a # static library build +``` + To build with GYP, first run: ```bash