diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c5af57..90501f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,8 @@ jobs: - name: liblo make x86_64 run: make + && echo -e "\n127.0.0.1 $(hostname)\n" | sudo tee -a /etc/hosts + && (cd src && ls testlo && ./testlo && ls test_bidirectional_tcp && ./test_bidirectional_tcp && ls cpp_test && ./cpp_test) && (make check || (for i in src/*.log; do echo === $i ===; cat $i; done; false)) && make install && mv ./inst/lib/liblo.7.dylib ./inst/lib/liblo.7.dylib.x86_64 @@ -104,5 +106,9 @@ jobs: run: | mkdir bld cd bld\ - cmake ..\cmake -DCMAKE_BUILD_TYPE=Release + cmake ..\cmake -DCMAKE_BUILD_TYPE=Release -DWITH_STATIC=ON cmake --build . --target all_build --config Release + - name: Run tests + run: | + cd bld\ + ctest -V diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f4eb631..c2b14cc 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.5) option(WITH_TOOLS "Enable building tools." ON) option(WITH_TESTS "Enable building tests." ON) @@ -79,6 +79,7 @@ if (WITH_TOOLS) endif() if (WITH_TESTS) set(TESTLO testlo) + set(TESTTCP test_bidirectional_tcp) set(SUBTEST subtest) if (WITH_CPP_TESTS) set(CPPTEST cpp_test) @@ -94,7 +95,7 @@ if (WITH_EXAMPLES) endif() set(TOOLS ${OSCDUMP} ${OSCSEND} ${OSCSENDFILE}) -set(TESTS ${TESTLO} ${SUBTEST}) +set(TESTS ${TESTLO} ${TESTTCP} ${SUBTEST}) list(APPEND TESTS ${CPPTEST}) set(EXAMPLES ${EXAMPLE_CLIENT} ${EXAMPLE_SERVER} ${EXAMPLE_TCP_ECHO_SERVER} ${NONBLOCKING_SERVER_EXAMPLE}) @@ -130,6 +131,7 @@ set(OSCDUMP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/tools/oscdump.c) set(OSCSEND_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/tools/oscsend.c) set(OSCSENDFILE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/tools/oscsendfile.c) set(TESTLO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/testlo.c) +set(TESTTCP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/test_bidirectional_tcp.c) set(SUBTEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/subtest.c) if (WITH_CPP_TESTS) set(CPPTEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../src/cpp_test.cpp) @@ -174,7 +176,7 @@ set(BUILD_LANGUAGE C CACHE STRING "Build language (C or CXX)") mark_as_advanced(BUILD_LANGUAGE) set_source_files_properties( ${LIBRARY_SOURCES} ${OSCDUMP_SOURCES} ${OSCSEND_SOURCES} ${OSCSENDFILE_SOURCES} - ${TESTLO_SOURCES} ${EXAMPLE_CLIENT_SOURCES} + ${TESTLO_SOURCES} ${TESTTCP_SOURCES} ${EXAMPLE_CLIENT_SOURCES} ${EXAMPLE_SERVER_SOURCES} ${EXAMPLE_TCP_ECHO_SERVER_SOURCES} ${NONBLOCKING_SERVER_EXAMPLE_SOURCES} PROPERTIES LANGUAGE ${BUILD_LANGUAGE}) @@ -201,10 +203,27 @@ endif() if (WITH_TESTS) add_executable(${TESTLO} ${TESTLO_SOURCES}) add_executable(${SUBTEST} ${SUBTEST_SOURCES}) + add_executable(${TESTTCP} ${TESTTCP_SOURCES}) target_link_libraries(${TESTLO} PRIVATE Threads::Threads) + target_link_libraries(${TESTTCP} PRIVATE Threads::Threads) + if (WIN32) + # If you use the new syntax, on Windows, you need to run `cmake -C Release` instead of `cmake`. + # We do not want that, so we use the old syntax for Windows... + add_test(${TESTLO} "tests/${TESTLO}") + add_test("test-bidirectional-tcp" "tests/${TESTTCP}") + else() + add_test(NAME ${TESTLO} COMMAND ${TESTLO} WORKING_DIRECTORY $) + add_test(NAME "test-bidirectional-tcp" COMMAND ${TESTTCP} WORKING_DIRECTORY $) + endif() + enable_testing() endif() if (WITH_CPP_TESTS) add_executable(${CPPTEST} ${CPPTEST_SOURCES}) + if (WIN32) + add_test(${CPPTEST} "tests/${CPPTEST}") + else() + add_test(NAME ${CPPTEST} COMMAND ${CPPTEST} WORKING_DIRECTORY $) + endif() endif() # Examples @@ -237,6 +256,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") endif() target_link_libraries(${NONBLOCKING_SERVER_EXAMPLE} PRIVATE "wsock32") target_link_libraries(${TESTLO} PRIVATE "wsock32") + target_link_libraries(${TESTTCP} PRIVATE "wsock32") set_target_properties(${LIBRARY_SHARED} PROPERTIES COMPILE_DEFINITIONS "LIBLO_DLL") @@ -274,7 +294,12 @@ foreach(PROG ${PROGRAMS}) target_include_directories(${PROG} PUBLIC "$" "$") - target_link_libraries(${PROG} PUBLIC ${LIBRARY_SHARED}) + if(CMAKE_SYSTEM_NAME MATCHES "Windows") + # For some yet unknown reasons, Windows has trouble finding the DLL + target_link_libraries(${PROG} PUBLIC ${LIBRARY_STATIC}) + else() + target_link_libraries(${PROG} PUBLIC ${LIBRARY_SHARED}) + endif() endforeach(PROG) foreach(PROG ${TOOLS}) diff --git a/src/test_bidirectional_tcp.c b/src/test_bidirectional_tcp.c index a8ae042..c9e85fb 100644 --- a/src/test_bidirectional_tcp.c +++ b/src/test_bidirectional_tcp.c @@ -1,5 +1,7 @@ -#ifdef WIN32 +#if defined(WIN32) || defined(_MSC_VER) #include +#else +#include #endif #ifdef HAVE_CONFIG_H @@ -37,7 +39,7 @@ int generic_handler(const char *path, const char *types, lo_arg ** argv, } #ifdef HAVE_WIN32_THREADS -unsigned __attribute__((stdcall)) sendthread(void *arg) +unsigned __stdcall sendthread(void *arg) #else void *sendthread(void *arg) #endif @@ -59,6 +61,13 @@ void *sendthread(void *arg) printf("%p.sending thread received\n", s); printf("%p.freeing address\n", s); + /* Do not close the socket immediatelly, wait 1 second for recv */ +#if defined(WIN32) || defined(_MSC_VER) + Sleep(1000); +#else + sleep(1); +#endif + lo_address_free(a); printf("%p.freeing\n", s); @@ -69,7 +78,7 @@ void *sendthread(void *arg) int main() { - /* start a new server on port 7770 */ + /* start a new server on port 7771 */ lo_server s = lo_server_new_with_proto("7771", LO_TCP, 0); if (!s) { printf("no server\n"); exit(1); } diff --git a/src/testlo.c b/src/testlo.c index e62f3e5..2d6be38 100644 --- a/src/testlo.c +++ b/src/testlo.c @@ -1320,6 +1320,7 @@ void test_server_thread(lo_server_thread *pst, lo_address *pa) server_url = lo_server_thread_get_url(st); printf("Server URL: %s\n", server_url); a = lo_address_new_from_url(server_url); + TEST(a); free(server_url); /* add method that will match the path /foo/bar, with two numbers, coerced @@ -1485,9 +1486,13 @@ void test_subtest(lo_server_thread st) #ifdef WIN32 { - char cwd[2048]; - _getcwd(cwd, 2048); - snprintf(cmd, 2048, "%s" PATHDELIM "subtest" EXTEXE, cwd); + char cwd[MAX_PATH]; + // Calculate path to subtest.exe + GetModuleFileName(NULL, cwd, MAX_PATH); + const char* pathdelim_str = PATHDELIM; + char *lastBackslash = strrchr(cwd, *pathdelim_str); + *lastBackslash = 0; // Null-terminate at the last backslash to get the directory + snprintf(cmd, sizeof(cmd), "%s" PATHDELIM "subtest" EXTEXE, cwd); } printf("spawning subtest with `%s'\n", cmd); for (i=0; i<2; i++) {