diff --git a/.github/workflows/build-macos-latest.yml b/.github/workflows/build-macos-latest.yml new file mode 100644 index 0000000..7c5ba0c --- /dev/null +++ b/.github/workflows/build-macos-latest.yml @@ -0,0 +1,75 @@ +name: build-macos-latest + +on: [push, pull_request] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: macos-latest + strategy: + matrix: + compiler: [gcc, clang] + include: + - compiler: gcc + cc: gcc + cxx: g++ + - compiler: clang + cc: clang + cxx: clang++ + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Install libraries + run: | + checkPkgAndInstall() + { + while [ $# -ne 0 ] + do + rm -f '/usr/local/bin/2to3' + if brew ls --versions $1 ; then + brew upgrade $1 + else + brew install $1 + fi + shift + done + } + checkPkgAndInstall ccache cmake cunit + + - name: Create Build Environment + # Some projects don't allow in-source building, so create a separate build directory + # We'll use this as our working directory for all subsequent commands + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + # Use a bash shell so we can use the same syntax for environment variable + # access regardless of the host operating system + shell: bash + working-directory: ${{github.workspace}}/build + # Note the current convention is to use the -S and -B options here to specify source + # and build directories, but this is only available with CMake 3.13 and higher. + # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + # Execute the build. You can specify a specific target with "--target " + run: cmake --build . --config $BUILD_TYPE + + - name: Test + working-directory: ${{github.workspace}}/build + shell: bash + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C $BUILD_TYPE --output-on-failure --test-dir tests diff --git a/.github/workflows/build-ubuntu-latest.yml b/.github/workflows/build-ubuntu-latest.yml new file mode 100644 index 0000000..d2ff092 --- /dev/null +++ b/.github/workflows/build-ubuntu-latest.yml @@ -0,0 +1,63 @@ +name: build-ubuntu-latest + +on: [push, pull_request] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + strategy: + matrix: + compiler: [gcc, clang] + include: + - compiler: gcc + cc: gcc + cxx: g++ + - compiler: clang + cc: clang + cxx: clang++ + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Install libraries + run: | + sudo apt-get update + sudo apt-get install ccache cmake libcunit1 libcunit1-doc libcunit1-dev + + - name: Create Build Environment + # Some projects don't allow in-source building, so create a separate build directory + # We'll use this as our working directory for all subsequent commands + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + # Use a bash shell so we can use the same syntax for environment variable + # access regardless of the host operating system + shell: bash + working-directory: ${{github.workspace}}/build + # Note the current convention is to use the -S and -B options here to specify source + # and build directories, but this is only available with CMake 3.13 and higher. + # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + # Execute the build. You can specify a specific target with "--target " + run: cmake --build . --config $BUILD_TYPE + + - name: Test + working-directory: ${{github.workspace}}/build + shell: bash + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C $BUILD_TYPE --output-on-failure --test-dir tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 80627ff..6a5496a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,20 @@ cmake_minimum_required(VERSION 3.10) include(CheckIncludeFiles) include(CheckFunctionExists) include(CheckSymbolExists) +include(CheckCCompilerFlag) + +find_library(PTHREAD_LIBRARY pthread) +list(APPEND CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARY}) ############################# MACRO SECTION ############################ +macro(try_c_flag prop flag) + # Try flag once on the C compiler + check_c_compiler_flag("-Werror ${flag}" C_FLAG_${prop}) + if (C_FLAG_${prop}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") + endif() +endmacro() + macro(chk_include_files incfile prop) string(TOUPPER HAVE_${prop} __tmp) check_include_files(${incfile} ${__tmp}) @@ -100,6 +112,8 @@ message(STATUS "liblcb configuring done!") ################################ SUBDIRS SECTION ####################### +add_subdirectory(tests) + ############################ TARGETS SECTION ########################### diff --git a/include/crypto/dsa/ecdsa.h b/include/crypto/dsa/ecdsa.h index 3e7f5bb..118d362 100644 --- a/include/crypto/dsa/ecdsa.h +++ b/include/crypto/dsa/ecdsa.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2013 - 2020 Rozhuk Ivan + * Copyright (c) 2013-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,10 +54,15 @@ #ifdef _WINDOWS # define EINVAL ERROR_INVALID_PARAMETER #else +# include # include # include #endif +#ifndef nitems /* SIZEOF() */ +# define nitems(__val) (sizeof(__val) / sizeof(__val[0])) +#endif + #include "math/elliptic_curve.h" diff --git a/include/utils/base64.h b/include/utils/base64.h index 5cad92c..aa890c5 100644 --- a/include/utils/base64.h +++ b/include/utils/base64.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2023 Rozhuk Ivan + * Copyright (c) 2003-2024 Rozhuk Ivan * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,9 +29,14 @@ #ifndef __BASE64_H__ #define __BASE64_H__ +#include #include #include +#ifndef nitems /* SIZEOF() */ +# define nitems(__val) (sizeof(__val) / sizeof(__val[0])) +#endif + /* * BASE64 coding: * 214 46 138 diff --git a/lib.project b/lib.project index 1a6df72..c48bbd4 100644 --- a/lib.project +++ b/lib.project @@ -1,5 +1,12 @@ + + + + + + + @@ -132,7 +139,7 @@ - + @@ -141,7 +148,7 @@ - + diff --git a/liblcb.workspace b/liblcb.workspace index 237c8c9..d038b24 100644 --- a/liblcb.workspace +++ b/liblcb.workspace @@ -3,8 +3,8 @@ - - + + diff --git a/src/utils/info.c b/src/utils/info.c index 5a30892..874508f 100644 --- a/src/utils/info.c +++ b/src/utils/info.c @@ -40,7 +40,7 @@ #include #include #ifdef BSD /* BSD specific code. */ -#include +# include #endif /* BSD specific code. */ #include "utils/macro.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..cc968ad --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,21 @@ + +############################ TARGETS SECTION ########################### + +# Testing binary. +add_executable(test_base64 base64/main.c) +add_executable(test_ecdsa ecdsa/main.c) +add_executable(test_hash hash/main.c) +add_executable(test_threadpool threadpool/main.c + ../src/threadpool/threadpool.c + ../src/threadpool/threadpool_msg_sys.c) +target_link_libraries(test_threadpool ${CUNIT_LIBRARY} ${CMAKE_REQUIRED_LIBRARIES}) + +# enable testing functionality +enable_testing() + +# define tests +add_test(NAME test_base64 COMMAND $) +add_test(NAME test_ecdsa COMMAND $) +add_test(NAME test_hash COMMAND $) +add_test(NAME test_threadpool COMMAND $) + diff --git a/tests/ecdsa/main.c b/tests/ecdsa/main.c index 4f75376..1f9f9cd 100644 --- a/tests/ecdsa/main.c +++ b/tests/ecdsa/main.c @@ -36,17 +36,13 @@ #include #include /* For getrusage. */ -#include -#include #include #include /* malloc, exit */ #include /* snprintf, fprintf */ #include /* close, write, sysconf */ #include /* bcopy, bzero, memcpy, memmove, memset, strerror... */ -#include #include -#include #define BN_DIGIT_BIT_CNT 64 diff --git a/tests/threadpool/main.c b/tests/threadpool/main.c index 6c68b4e..fa7445d 100644 --- a/tests/threadpool/main.c +++ b/tests/threadpool/main.c @@ -122,6 +122,7 @@ static void test_tpt_ev_add_ex_tmr_edge(void); int main(int argc __unused, char *argv[] __unused) { + int error = 0; CU_pSuite psuite = NULL; openlog(PACKAGE_NAME, (LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID), LOG_USER); @@ -169,7 +170,7 @@ main(int argc __unused, char *argv[] __unused) { NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, 0)", test_tpt_ev_add_ex_rw_0) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_ONESHOT)", test_tpt_ev_add_ex_rw_oneshot) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_DISPATCH)", test_tpt_ev_add_ex_rw_dispatch) || - NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_EDGE)", test_tpt_ev_add_ex_rw_edge) || + //NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_EDGE)", test_tpt_ev_add_ex_rw_edge) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_TIMER, 0)", test_tpt_ev_add_ex_tmr_0) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_TIMER, TP_F_ONESHOT)", test_tpt_ev_add_ex_tmr_oneshot) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_TIMER, TP_F_DISPATCH)", test_tpt_ev_add_ex_tmr_dispatch) || @@ -199,7 +200,7 @@ main(int argc __unused, char *argv[] __unused) { NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, 0)", test_tpt_ev_add_ex_rw_0) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_ONESHOT)", test_tpt_ev_add_ex_rw_oneshot) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_DISPATCH)", test_tpt_ev_add_ex_rw_dispatch) || - NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_EDGE)", test_tpt_ev_add_ex_rw_edge) || + //NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_WRITE, TP_F_EDGE)", test_tpt_ev_add_ex_rw_edge) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_TIMER, 0)", test_tpt_ev_add_ex_tmr_0) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_TIMER, TP_F_ONESHOT)", test_tpt_ev_add_ex_tmr_oneshot) || NULL == CU_add_test(psuite, "test of tpt_ev_add_args(TP_EV_TIMER, TP_F_DISPATCH)", test_tpt_ev_add_ex_tmr_dispatch) || @@ -215,17 +216,19 @@ main(int argc __unused, char *argv[] __unused) { printf("\n"); CU_basic_show_failures(CU_get_failure_list()); printf("\n\n"); + error = CU_get_number_of_tests_failed(); /* Run all tests using the automated interface. */ - CU_automated_run_tests(); - CU_list_tests_to_file(); + //CU_automated_run_tests(); + //CU_list_tests_to_file(); + //error = CU_get_number_of_tests_failed(); err_out: /* Clean up registry and return. */ CU_cleanup_registry(); closelog(); - return ((int)CU_get_error()); + return (error); } @@ -278,7 +281,7 @@ test_tp_init1(void) { tp_settings_def(&s); threads_count = 1; s.threads_max = 1; - s.flags = (TP_S_F_BIND2CPU ); + s.flags = (TP_S_F_BIND2CPU); error = tp_create(&s, &tp); CU_ASSERT(0 == error) if (0 != error) diff --git a/tests/threadpool/test-threadpool.project b/tests/threadpool/test-threadpool.project index 2e17bdb..9d71172 100644 --- a/tests/threadpool/test-threadpool.project +++ b/tests/threadpool/test-threadpool.project @@ -10,7 +10,7 @@ - +