From 4b601d9fe34b21d3a41d747c8cb64ce810ef971a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Wed, 26 Jun 2024 18:02:22 +0200 Subject: [PATCH] Fix CI issues (#29) - Fixes to build on FreeBSD in CI: - Header `alloca.h` is not available on FreeBSD. - Only add `libevent` includes if found. - Don't build tests in CI job on FreeBSD when using CMake. - Skip test/examples using `glib` if `pkg-config` is not installed. - Remove unused test label UT/CT. - Run CI workflow "C/C++ CI" - Get redis_version if valkey_version missing in INFO. Fixes issues in CI job "DB compatibility testing" --- .github/workflows/build.yml | 4 ++-- .github/workflows/test.yml | 6 +----- examples/CMakeLists.txt | 12 ++++++------ src/command.c | 4 ++++ tests/CMakeLists.txt | 25 ++++++++++--------------- tests/client_test.c | 2 ++ tests/test_utils.c | 25 ++++++++++++++----------- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ca0ffa0..91d9b9e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -137,12 +137,12 @@ jobs: - uses: actions/checkout@v3 - name: Build in FreeBSD - uses: vmactions/freebsd-vm@v1.0.5 + uses: vmactions/freebsd-vm@f8be330398166d1eb0601f01353839d4052367b2 # v1.0.7 with: prepare: pkg install -y gmake cmake run: | - mkdir build && cd build && cmake .. && make && cd .. gmake + mkdir build && cd build && cmake -DDISABLE_TESTS=ON .. && gmake macos: name: macOS diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0e10a1f6..f4a162ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,10 +1,6 @@ name: C/C++ CI -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] +on: [push, pull_request] jobs: full-build: diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 35db2ca3..136d0ac8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,13 +1,13 @@ -INCLUDE(FindPkgConfig) -# Check for GLib - -PKG_CHECK_MODULES(GLIB2 glib-2.0) -if (GLIB2_FOUND) +find_package(PkgConfig QUIET) +if(PkgConfig_FOUND) + pkg_check_modules(GLIB2 glib-2.0) + if(GLIB2_FOUND) INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS}) LINK_DIRECTORIES(${GLIB2_LIBRARY_DIRS}) ADD_EXECUTABLE(async-glib async-glib.c) TARGET_LINK_LIBRARIES(async-glib valkey ${GLIB2_LIBRARIES}) -ENDIF(GLIB2_FOUND) + endif() +endif() FIND_PATH(LIBEV ev.h HINTS /usr/local /usr/opt/local diff --git a/src/command.c b/src/command.c index 14fb0d11..40ae869d 100644 --- a/src/command.c +++ b/src/command.c @@ -31,7 +31,11 @@ #include #include #ifndef _WIN32 +#if !defined(__FreeBSD__) #include +#else +#include +#endif #include #else #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 62eb68be..099da151 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -42,13 +42,17 @@ add_custom_target(stop ) # Find dependencies -find_package(PkgConfig REQUIRED) -pkg_check_modules(GLIB_LIBRARY IMPORTED_TARGET glib-2.0) +find_package(PkgConfig QUIET) +if(PkgConfig_FOUND) + pkg_check_modules(GLIB_LIBRARY IMPORTED_TARGET glib-2.0) +endif() find_library(LIBUV_LIBRARY uv HINTS /usr/lib/x86_64-linux-gnu) find_library(LIBEV_LIBRARY ev HINTS /usr/lib/x86_64-linux-gnu) find_library(LIBEVENT_LIBRARY event HINTS /usr/lib/x86_64-linux-gnu) find_path(LIBEVENT_INCLUDES event2/event.h) -include_directories(${LIBEVENT_INCLUDES}) +if(LIBEVENT_INCLUDES_FOUND) + include_directories(${LIBEVENT_INCLUDES}) +endif() if(MSVC OR MINGW) find_library(LIBEVENT_LIBRARY Libevent) @@ -61,13 +65,15 @@ endif() # Add non-cluster tests add_executable(client_test client_test.c) +target_link_libraries(client_test valkey) if(SSL_LIBRARY) target_compile_definitions(client_test PUBLIC VALKEY_TEST_SSL=1) + target_link_libraries(client_test ${SSL_LIBRARY}) endif() if(LIBEVENT_LIBRARY) target_compile_definitions(client_test PUBLIC VALKEY_TEST_ASYNC=1) + target_link_libraries(client_test ${LIBEVENT_LIBRARY}) endif() -target_link_libraries(client_test valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME client_test COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/test.sh") if(TEST_WITH_REDIS_VERSION) set_property(TEST client_test PROPERTY ENVIRONMENT "VALKEY_SERVER=redis-server") @@ -81,27 +87,22 @@ endif() add_executable(ct_async ct_async.c) target_link_libraries(ct_async valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME ct_async COMMAND "$") -set_tests_properties(ct_async PROPERTIES LABELS "CT") add_executable(ct_commands ct_commands.c test_utils.c) target_link_libraries(ct_commands valkey ${SSL_LIBRARY}) add_test(NAME ct_commands COMMAND "$") -set_tests_properties(ct_commands PROPERTIES LABELS "CT") add_executable(ct_connection ct_connection.c test_utils.c) target_link_libraries(ct_connection valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME ct_connection COMMAND "$") -set_tests_properties(ct_connection PROPERTIES LABELS "CT") add_executable(ct_pipeline ct_pipeline.c) target_link_libraries(ct_pipeline valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME ct_pipeline COMMAND "$") -set_tests_properties(ct_pipeline PROPERTIES LABELS "CT") add_executable(ct_connection_ipv6 ct_connection_ipv6.c) target_link_libraries(ct_connection_ipv6 valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME ct_connection_ipv6 COMMAND "$") -set_tests_properties(ct_connection_ipv6 PROPERTIES LABELS "CT") if(NOT ENABLE_IPV6_TESTS) set_tests_properties(ct_connection_ipv6 PROPERTIES DISABLED True) endif() @@ -109,24 +110,20 @@ endif() add_executable(ct_out_of_memory_handling ct_out_of_memory_handling.c) target_link_libraries(ct_out_of_memory_handling valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME ct_out_of_memory_handling COMMAND "$") -set_tests_properties(ct_out_of_memory_handling PROPERTIES LABELS "CT") add_executable(ct_specific_nodes ct_specific_nodes.c test_utils.c) target_link_libraries(ct_specific_nodes valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY}) add_test(NAME ct_specific_nodes COMMAND "$") -set_tests_properties(ct_specific_nodes PROPERTIES LABELS "CT") add_executable(ut_parse_cmd ut_parse_cmd.c test_utils.c) target_include_directories(ut_parse_cmd PRIVATE "${PROJECT_SOURCE_DIR}/src") target_link_libraries(ut_parse_cmd valkey ${SSL_LIBRARY}) add_test(NAME ut_parse_cmd COMMAND "$") -set_tests_properties(ut_parse_cmd PROPERTIES LABELS "UT") if(LIBUV_LIBRARY) add_executable(ct_async_libuv ct_async_libuv.c) target_link_libraries(ct_async_libuv valkey ${SSL_LIBRARY} ${LIBUV_LIBRARY}) add_test(NAME ct_async_libuv COMMAND "$") - set_tests_properties(ct_async_libuv PROPERTIES LABELS "CT") else() add_test(NAME ct_async_libuv COMMAND "") set_tests_properties(ct_async_libuv PROPERTIES DISABLED True) @@ -136,7 +133,6 @@ if(LIBEV_LIBRARY) add_executable(ct_async_libev ct_async_libev.c) target_link_libraries(ct_async_libev valkey ${SSL_LIBRARY} ${LIBEV_LIBRARY}) add_test(NAME ct_async_libev COMMAND "$") - set_tests_properties(ct_async_libev PROPERTIES LABELS "CT") else() add_test(NAME ct_async_libev COMMAND "") set_tests_properties(ct_async_libev PROPERTIES DISABLED True) @@ -146,7 +142,6 @@ if(GLIB_LIBRARY_FOUND) add_executable(ct_async_glib ct_async_glib.c) target_link_libraries(ct_async_glib valkey ${SSL_LIBRARY} PkgConfig::GLIB_LIBRARY) add_test(NAME ct_async_glib COMMAND "$") - set_tests_properties(ct_async_glib PROPERTIES LABELS "CT") else() add_test(NAME ct_async_glib COMMAND "") set_tests_properties(ct_async_glib PROPERTIES DISABLED True) diff --git a/tests/client_test.c b/tests/client_test.c index 8aa5e048..60a3c4e3 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -1,4 +1,6 @@ +#if !defined(__FreeBSD__) #define _POSIX_C_SOURCE 200112L +#endif #include "sockcompat.h" #include #include diff --git a/tests/test_utils.c b/tests/test_utils.c index b71a414f..760ca67d 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -4,11 +4,12 @@ #include #include -static int valkey_version_major; -static int valkey_version_minor; +static int server_version_major; +static int server_version_minor; -/* Helper to extract Valkey version information. */ +/* Helper to extract version information. */ #define VALKEY_VERSION_FIELD "valkey_version:" +#define REDIS_VERSION_FIELD "redis_version:" void load_valkey_version(valkeyClusterContext *cc) { valkeyClusterNodeIterator ni; valkeyClusterNode *node; @@ -22,20 +23,22 @@ void load_valkey_version(valkeyClusterContext *cc) { reply = valkeyClusterCommandToNode(cc, node, "INFO"); if (reply == NULL || cc->err || reply->type != VALKEY_REPLY_STRING) goto abort; - if ((s = strstr(reply->str, VALKEY_VERSION_FIELD)) == NULL) + if ((s = strstr(reply->str, VALKEY_VERSION_FIELD)) != NULL) + s += strlen(VALKEY_VERSION_FIELD); + else if ((s = strstr(reply->str, REDIS_VERSION_FIELD)) != NULL) + s += strlen(REDIS_VERSION_FIELD); + else goto abort; - s += strlen(VALKEY_VERSION_FIELD); - /* We need a field terminator and at least 'x.y.z' (5) bytes of data */ if ((e = strstr(s, "\r\n")) == NULL || (e - s) < 5) goto abort; /* Extract version info */ - valkey_version_major = strtol(s, &eptr, 10); + server_version_major = strtol(s, &eptr, 10); if (*eptr != '.') goto abort; - valkey_version_minor = strtol(eptr + 1, NULL, 10); + server_version_minor = strtol(eptr + 1, NULL, 10); freeReplyObject(reply); return; @@ -48,14 +51,14 @@ void load_valkey_version(valkeyClusterContext *cc) { /* Helper to verify Valkey version information. */ int valkey_version_less_than(int major, int minor) { - if (valkey_version_major == 0) { + if (server_version_major == 0) { fprintf(stderr, "Error: Valkey version not loaded, aborting..\n"); exit(1); } - if (valkey_version_major < major) + if (server_version_major < major) return 1; - if (valkey_version_major == major && valkey_version_minor < minor) + if (server_version_major == major && server_version_minor < minor) return 1; return 0; }