Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions #155

Merged
merged 6 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
33 changes: 29 additions & 4 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand All @@ -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 $<TARGET_FILE_DIR:${TESTLO}>)
add_test(NAME "test-bidirectional-tcp" COMMAND ${TESTTCP} WORKING_DIRECTORY $<TARGET_FILE_DIR:${TESTTCP}>)
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 $<TARGET_FILE_DIR:${CPPTEST}>)
endif()
endif()

# Examples
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -274,7 +294,12 @@ foreach(PROG ${PROGRAMS})
target_include_directories(${PROG} PUBLIC
"$<BUILD_INTERFACE:${LO_BUILD_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
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})
Expand Down
15 changes: 12 additions & 3 deletions src/test_bidirectional_tcp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifdef WIN32
#if defined(WIN32) || defined(_MSC_VER)
#include <process.h>
#else
#include <unistd.h>
#endif

#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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); }

Expand Down
11 changes: 8 additions & 3 deletions src/testlo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,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
Expand Down Expand Up @@ -1449,9 +1450,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++) {
Expand Down