Skip to content

Commit

Permalink
Fix CI issues (#29)
Browse files Browse the repository at this point in the history
- 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"
  • Loading branch information
bjosv authored Jun 26, 2024
1 parent 75da159 commit 4b601d9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ jobs:
- uses: actions/checkout@v3

- name: Build in FreeBSD
uses: vmactions/[email protected].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
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: C/C++ CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: [push, pull_request]

jobs:
full-build:
Expand Down
12 changes: 6 additions & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#include <ctype.h>
#include <errno.h>
#ifndef _WIN32
#if !defined(__FreeBSD__)
#include <alloca.h>
#else
#include <stdlib.h>
#endif
#include <strings.h>
#else
#include <malloc.h>
Expand Down
25 changes: 10 additions & 15 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -81,52 +87,43 @@ endif()
add_executable(ct_async ct_async.c)
target_link_libraries(ct_async valkey ${SSL_LIBRARY} ${LIBEVENT_LIBRARY})
add_test(NAME ct_async COMMAND "$<TARGET_FILE:ct_async>")
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 "$<TARGET_FILE:ct_commands>")
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 "$<TARGET_FILE:ct_connection>")
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 "$<TARGET_FILE:ct_pipeline>")
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 "$<TARGET_FILE:ct_connection_ipv6>")
set_tests_properties(ct_connection_ipv6 PROPERTIES LABELS "CT")
if(NOT ENABLE_IPV6_TESTS)
set_tests_properties(ct_connection_ipv6 PROPERTIES DISABLED True)
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 "$<TARGET_FILE:ct_out_of_memory_handling>")
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 "$<TARGET_FILE:ct_specific_nodes>")
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 "$<TARGET_FILE:ut_parse_cmd>")
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 "$<TARGET_FILE:ct_async_libuv>")
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)
Expand All @@ -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 "$<TARGET_FILE:ct_async_libev>")
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)
Expand All @@ -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 "$<TARGET_FILE:ct_async_glib>")
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)
Expand Down
2 changes: 2 additions & 0 deletions tests/client_test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if !defined(__FreeBSD__)
#define _POSIX_C_SOURCE 200112L
#endif
#include "sockcompat.h"
#include <stdio.h>
#include <stdlib.h>
Expand Down
25 changes: 14 additions & 11 deletions tests/test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <stdlib.h>
#include <string.h>

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;
Expand All @@ -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;
Expand All @@ -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;
}

0 comments on commit 4b601d9

Please sign in to comment.