Skip to content

Commit

Permalink
Allow tests run on every commit and miltiple fixes.
Browse files Browse the repository at this point in the history
- remove unused tpt_timer_add();
- fix build compilation on Linux for md5, sha1, sha2, gost3411-2012, base64, ecdsa;
- remove TP_F_EDGE and TP_F_EXCLUSIVE since it is not supported outside Linux;
- add guthub workflows to build and run tests;
- add build+test badges in readme;
- add ENABLE_LIBLCB_TESTS CMake var;
  • Loading branch information
rozhuk-im committed Apr 25, 2024
1 parent 2e8d4ba commit 505a39b
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 140 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/build-macos-latest.yml
Original file line number Diff line number Diff line change
@@ -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 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 -DENABLE_LIBLCB_TESTS=1

- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE -j 16

- 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 -j 16 --output-on-failure --test-dir tests
63 changes: 63 additions & 0 deletions .github/workflows/build-ubuntu-latest.yml
Original file line number Diff line number Diff line change
@@ -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 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 -DENABLE_LIBLCB_TESTS=1

- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE -j 16

- 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 -j 16 --output-on-failure --test-dir tests
26 changes: 23 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#
# Cmake configuration file for liblcb.
# Just add: include(liblcb/CMakeLists.txt) in CMakeLists.txt to use this lib.
# To enable tests: -DENABLE_LIBLCB_TESTS=1
#

############################# INITIAL SECTION ##########################
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.20)

############################# OPTIONS SECTION ##########################

Expand All @@ -13,8 +14,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})
Expand Down Expand Up @@ -49,15 +62,17 @@ message(STATUS "liblcb configuring...")
# Platform specific configuration.
if (CMAKE_SYSTEM_NAME MATCHES "^.*BSD$|DragonFly")
add_definitions(-D_BSD_SOURCE -DFREEBSD)
include_directories("/usr/local/include/")
include_directories("/usr/local/include")
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-D_BSD_SOURCE -DDARWIN)
include_directories("/usr/local/include")
endif()
if (APPLE)
# For IPV6_PKTINFO.
add_definitions(-D__APPLE_USE_RFC_3542)
include_directories("/usr/local/include")
endif()


Expand Down Expand Up @@ -93,13 +108,18 @@ chk_symbol_exists(sys/socket.h SOCK_CLOEXEC)
chk_symbol_exists(sys/socket.h SOCK_NONBLOCK)

# Disable some warnings.
try_c_flag(W_NO_UNUSED_RESULT "-Wno-unused-result")
try_c_flag(WSWITCHDEFAULT "-Wno-switch-default")
try_c_flag(WUNUSED_RESULT "-Wno-unused-result")
try_c_flag(WUNSAFE_BUFFER_USAGE "-Wno-unsafe-buffer-usage")


message(STATUS "liblcb configuring done!")

################################ SUBDIRS SECTION #######################

if (ENABLE_LIBLCB_TESTS)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests")
endif()

############################ TARGETS SECTION ###########################

Expand Down
7 changes: 6 additions & 1 deletion include/crypto/dsa/ecdsa.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2013 - 2020 Rozhuk Ivan <[email protected]>
* Copyright (c) 2013-2024 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -54,10 +54,15 @@
#ifdef _WINDOWS
# define EINVAL ERROR_INVALID_PARAMETER
#else
# include <sys/param.h>
# include <sys/types.h>
# include <inttypes.h>
#endif

#ifndef nitems /* SIZEOF() */
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
#endif

#include "math/elliptic_curve.h"


Expand Down
23 changes: 13 additions & 10 deletions include/crypto/hash/gost3411-2012.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2016-2023 Rozhuk Ivan <[email protected]>
* Copyright (c) 2016-2024 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -38,11 +38,6 @@
#define __GOST3411_2012_H__INCLUDED__

#include <sys/param.h>
#ifdef __linux__
# include <endian.h>
#else
# include <sys/endian.h>
#endif
#include <sys/types.h>
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
#include <inttypes.h>
Expand All @@ -60,6 +55,14 @@
# include <immintrin.h> /* AVX */
#endif

#ifndef __unused
# define __unused __attribute__((__unused__))
#endif

#ifndef nitems /* SIZEOF() */
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
#endif

#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
# define GOST3411_2012_ALIGN(__n) __declspec(align(__n)) /* DECLSPEC_ALIGN() */
#else /* GCC/clang */
Expand Down Expand Up @@ -1728,18 +1731,18 @@ gost3411_2012_init(const size_t bits, gost3411_2012_ctx_p ctx) {
__get_cpuid_count(1, 0, &eax, &ebx, &ecx, &edx);
# ifdef __SSE4_1__
ctx->use_sse |= (ecx & (((uint32_t)1) << 19));
# elifdef __SSSE3__
# elif defined(__SSSE3__)
ctx->use_sse |= (ecx & (((uint32_t)1) << 9));
# elifdef __SSE3__
# elif defined(__SSE3__)
ctx->use_sse |= (ecx & (((uint32_t)1) << 0));
# elifdef __SSE2__
# elif defined(__SSE2__)
ctx->use_sse |= (edx & (((uint32_t)1) << 26));
# endif
#endif
#ifdef __AVX2__
__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
ctx->use_avx |= (ebx & (((uint32_t)1) << 5)); /* AVX2. */
#elifdef __AVX__
#elif defined(__AVX__)
__get_cpuid_count(1, 0, &eax, &ebx, &ecx, &edx);
ctx->use_avx |= (ecx & (((uint32_t)1) << 28)); /* AVX. */
#endif
Expand Down
6 changes: 5 additions & 1 deletion include/crypto/hash/md5.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2003-2023 Rozhuk Ivan <[email protected]>
* Copyright (c) 2003-2024 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -39,6 +39,10 @@
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
#include <inttypes.h>

#ifndef nitems /* SIZEOF() */
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
#endif

static void *(*volatile md5_memset_volatile)(void*, int, size_t) = memset;
#define md5_bzero(__mem, __size) md5_memset_volatile((__mem), 0x00, (__size))

Expand Down
21 changes: 12 additions & 9 deletions include/crypto/hash/sha1.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2003-2023 Rozhuk Ivan <[email protected]>
* Copyright (c) 2003-2024 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -65,11 +65,6 @@
#define __SHA1_H__INCLUDED__

#include <sys/param.h>
#ifdef __linux__
# include <endian.h>
#else
# include <sys/endian.h>
#endif
#include <sys/types.h>
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
#include <inttypes.h>
Expand All @@ -84,6 +79,14 @@
# include <immintrin.h> /* AVX */
#endif

#ifndef bswap64
# define bswap64 __builtin_bswap64
#endif

#ifndef nitems /* SIZEOF() */
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
#endif

#if defined(__SHA__) && defined(__SSSE3__) && defined(__SSE4_1__)
# include <shaintrin.h>
# define SHA1_ENABLE_SIMD 1
Expand Down Expand Up @@ -185,11 +188,11 @@ sha1_init(sha1_ctx_p ctx) {
ctx->use_sse = 0;
# ifdef __SSE4_1__
ctx->use_sse |= (ecx & (((uint32_t)1) << 19));
# elifdef __SSSE3__
# elif defined(__SSSE3__)
ctx->use_sse |= (ecx & (((uint32_t)1) << 9));
# elifdef __SSE3__
# elif defined(__SSE3__)
ctx->use_sse |= (ecx & (((uint32_t)1) << 0));
# elifdef __SSE2__
# elif defined(__SSE2__)
ctx->use_sse |= (edx & (((uint32_t)1) << 26));
# endif
#endif
Expand Down
15 changes: 9 additions & 6 deletions include/crypto/hash/sha2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2013-2023 Rozhuk Ivan <[email protected]>
* Copyright (c) 2013-2024 Rozhuk Ivan <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -35,11 +35,6 @@
#define __SHA2_H__INCLUDED__

#include <sys/param.h>
#ifdef __linux__
# include <endian.h>
#else
# include <sys/endian.h>
#endif
#include <sys/types.h>
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
#include <inttypes.h>
Expand All @@ -56,6 +51,14 @@
# define SHA2_ENABLE_SIMD 1
#endif

#ifndef bswap64
# define bswap64 __builtin_bswap64
#endif

#ifndef nitems /* SIZEOF() */
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
#endif

#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
# define SHA2_ALIGN(__n) __declspec(align(__n)) /* DECLSPEC_ALIGN() */
#else /* GCC/clang */
Expand Down
Loading

0 comments on commit 505a39b

Please sign in to comment.