Skip to content

Commit 505a39b

Browse files
committed
Allow tests run on every commit and miltiple fixes.
- 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;
1 parent 2e8d4ba commit 505a39b

21 files changed

+357
-140
lines changed
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: build-macos-latest
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
7+
BUILD_TYPE: Release
8+
9+
10+
jobs:
11+
build:
12+
# The CMake configure and build commands are platform agnostic and should work equally
13+
# well on Windows or Mac. You can convert this to a matrix build if you need
14+
# cross-platform coverage.
15+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
16+
runs-on: macos-latest
17+
strategy:
18+
matrix:
19+
compiler: [gcc, clang]
20+
include:
21+
- compiler: gcc
22+
cc: gcc
23+
cxx: g++
24+
- compiler: clang
25+
cc: clang
26+
cxx: clang++
27+
steps:
28+
- uses: actions/checkout@v2
29+
with:
30+
submodules: 'recursive'
31+
32+
- name: Install libraries
33+
run: |
34+
checkPkgAndInstall()
35+
{
36+
while [ $# -ne 0 ]
37+
do
38+
rm -f '/usr/local/bin/2to3'
39+
if brew ls --versions $1 ; then
40+
brew upgrade $1
41+
else
42+
brew install $1
43+
fi
44+
shift
45+
done
46+
}
47+
checkPkgAndInstall cunit
48+
49+
- name: Create Build Environment
50+
# Some projects don't allow in-source building, so create a separate build directory
51+
# We'll use this as our working directory for all subsequent commands
52+
run: cmake -E make_directory ${{github.workspace}}/build
53+
54+
- name: Configure CMake
55+
# Use a bash shell so we can use the same syntax for environment variable
56+
# access regardless of the host operating system
57+
shell: bash
58+
working-directory: ${{github.workspace}}/build
59+
# Note the current convention is to use the -S and -B options here to specify source
60+
# and build directories, but this is only available with CMake 3.13 and higher.
61+
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
62+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_LIBLCB_TESTS=1
63+
64+
- name: Build
65+
working-directory: ${{github.workspace}}/build
66+
shell: bash
67+
# Execute the build. You can specify a specific target with "--target <NAME>"
68+
run: cmake --build . --config $BUILD_TYPE -j 16
69+
70+
- name: Test
71+
working-directory: ${{github.workspace}}/build
72+
shell: bash
73+
# Execute tests defined by the CMake configuration.
74+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
75+
run: ctest -C $BUILD_TYPE -j 16 --output-on-failure --test-dir tests
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: build-ubuntu-latest
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
7+
BUILD_TYPE: Release
8+
9+
10+
jobs:
11+
build:
12+
# The CMake configure and build commands are platform agnostic and should work equally
13+
# well on Windows or Mac. You can convert this to a matrix build if you need
14+
# cross-platform coverage.
15+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
compiler: [gcc, clang]
20+
include:
21+
- compiler: gcc
22+
cc: gcc
23+
cxx: g++
24+
- compiler: clang
25+
cc: clang
26+
cxx: clang++
27+
steps:
28+
- uses: actions/checkout@v2
29+
with:
30+
submodules: 'recursive'
31+
32+
- name: Install libraries
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install cmake libcunit1 libcunit1-doc libcunit1-dev
36+
37+
- name: Create Build Environment
38+
# Some projects don't allow in-source building, so create a separate build directory
39+
# We'll use this as our working directory for all subsequent commands
40+
run: cmake -E make_directory ${{github.workspace}}/build
41+
42+
- name: Configure CMake
43+
# Use a bash shell so we can use the same syntax for environment variable
44+
# access regardless of the host operating system
45+
shell: bash
46+
working-directory: ${{github.workspace}}/build
47+
# Note the current convention is to use the -S and -B options here to specify source
48+
# and build directories, but this is only available with CMake 3.13 and higher.
49+
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
50+
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_LIBLCB_TESTS=1
51+
52+
- name: Build
53+
working-directory: ${{github.workspace}}/build
54+
shell: bash
55+
# Execute the build. You can specify a specific target with "--target <NAME>"
56+
run: cmake --build . --config $BUILD_TYPE -j 16
57+
58+
- name: Test
59+
working-directory: ${{github.workspace}}/build
60+
shell: bash
61+
# Execute tests defined by the CMake configuration.
62+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
63+
run: ctest -C $BUILD_TYPE -j 16 --output-on-failure --test-dir tests

CMakeLists.txt

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#
22
# Cmake configuration file for liblcb.
33
# Just add: include(liblcb/CMakeLists.txt) in CMakeLists.txt to use this lib.
4+
# To enable tests: -DENABLE_LIBLCB_TESTS=1
45
#
56

67
############################# INITIAL SECTION ##########################
7-
cmake_minimum_required(VERSION 3.10)
8+
cmake_minimum_required(VERSION 3.20)
89

910
############################# OPTIONS SECTION ##########################
1011

@@ -13,8 +14,20 @@ cmake_minimum_required(VERSION 3.10)
1314
include(CheckIncludeFiles)
1415
include(CheckFunctionExists)
1516
include(CheckSymbolExists)
17+
include(CheckCCompilerFlag)
18+
19+
find_library(PTHREAD_LIBRARY pthread)
20+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARY})
1621

1722
############################# MACRO SECTION ############################
23+
macro(try_c_flag prop flag)
24+
# Try flag once on the C compiler
25+
check_c_compiler_flag("-Werror ${flag}" C_FLAG_${prop})
26+
if (C_FLAG_${prop})
27+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
28+
endif()
29+
endmacro()
30+
1831
macro(chk_include_files incfile prop)
1932
string(TOUPPER HAVE_${prop} __tmp)
2033
check_include_files(${incfile} ${__tmp})
@@ -49,15 +62,17 @@ message(STATUS "liblcb configuring...")
4962
# Platform specific configuration.
5063
if (CMAKE_SYSTEM_NAME MATCHES "^.*BSD$|DragonFly")
5164
add_definitions(-D_BSD_SOURCE -DFREEBSD)
52-
include_directories("/usr/local/include/")
65+
include_directories("/usr/local/include")
5366
endif()
5467

5568
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
5669
add_definitions(-D_BSD_SOURCE -DDARWIN)
70+
include_directories("/usr/local/include")
5771
endif()
5872
if (APPLE)
5973
# For IPV6_PKTINFO.
6074
add_definitions(-D__APPLE_USE_RFC_3542)
75+
include_directories("/usr/local/include")
6176
endif()
6277

6378

@@ -93,13 +108,18 @@ chk_symbol_exists(sys/socket.h SOCK_CLOEXEC)
93108
chk_symbol_exists(sys/socket.h SOCK_NONBLOCK)
94109

95110
# Disable some warnings.
96-
try_c_flag(W_NO_UNUSED_RESULT "-Wno-unused-result")
111+
try_c_flag(WSWITCHDEFAULT "-Wno-switch-default")
112+
try_c_flag(WUNUSED_RESULT "-Wno-unused-result")
113+
try_c_flag(WUNSAFE_BUFFER_USAGE "-Wno-unsafe-buffer-usage")
97114

98115

99116
message(STATUS "liblcb configuring done!")
100117

101118
################################ SUBDIRS SECTION #######################
102119

120+
if (ENABLE_LIBLCB_TESTS)
121+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests")
122+
endif()
103123

104124
############################ TARGETS SECTION ###########################
105125

include/crypto/dsa/ecdsa.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2013 - 2020 Rozhuk Ivan <[email protected]>
2+
* Copyright (c) 2013-2024 Rozhuk Ivan <[email protected]>
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -54,10 +54,15 @@
5454
#ifdef _WINDOWS
5555
# define EINVAL ERROR_INVALID_PARAMETER
5656
#else
57+
# include <sys/param.h>
5758
# include <sys/types.h>
5859
# include <inttypes.h>
5960
#endif
6061

62+
#ifndef nitems /* SIZEOF() */
63+
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
64+
#endif
65+
6166
#include "math/elliptic_curve.h"
6267

6368

include/crypto/hash/gost3411-2012.h

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2016-2023 Rozhuk Ivan <[email protected]>
2+
* Copyright (c) 2016-2024 Rozhuk Ivan <[email protected]>
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -38,11 +38,6 @@
3838
#define __GOST3411_2012_H__INCLUDED__
3939

4040
#include <sys/param.h>
41-
#ifdef __linux__
42-
# include <endian.h>
43-
#else
44-
# include <sys/endian.h>
45-
#endif
4641
#include <sys/types.h>
4742
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
4843
#include <inttypes.h>
@@ -60,6 +55,14 @@
6055
# include <immintrin.h> /* AVX */
6156
#endif
6257

58+
#ifndef __unused
59+
# define __unused __attribute__((__unused__))
60+
#endif
61+
62+
#ifndef nitems /* SIZEOF() */
63+
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
64+
#endif
65+
6366
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
6467
# define GOST3411_2012_ALIGN(__n) __declspec(align(__n)) /* DECLSPEC_ALIGN() */
6568
#else /* GCC/clang */
@@ -1728,18 +1731,18 @@ gost3411_2012_init(const size_t bits, gost3411_2012_ctx_p ctx) {
17281731
__get_cpuid_count(1, 0, &eax, &ebx, &ecx, &edx);
17291732
# ifdef __SSE4_1__
17301733
ctx->use_sse |= (ecx & (((uint32_t)1) << 19));
1731-
# elifdef __SSSE3__
1734+
# elif defined(__SSSE3__)
17321735
ctx->use_sse |= (ecx & (((uint32_t)1) << 9));
1733-
# elifdef __SSE3__
1736+
# elif defined(__SSE3__)
17341737
ctx->use_sse |= (ecx & (((uint32_t)1) << 0));
1735-
# elifdef __SSE2__
1738+
# elif defined(__SSE2__)
17361739
ctx->use_sse |= (edx & (((uint32_t)1) << 26));
17371740
# endif
17381741
#endif
17391742
#ifdef __AVX2__
17401743
__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
17411744
ctx->use_avx |= (ebx & (((uint32_t)1) << 5)); /* AVX2. */
1742-
#elifdef __AVX__
1745+
#elif defined(__AVX__)
17431746
__get_cpuid_count(1, 0, &eax, &ebx, &ecx, &edx);
17441747
ctx->use_avx |= (ecx & (((uint32_t)1) << 28)); /* AVX. */
17451748
#endif

include/crypto/hash/md5.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2003-2023 Rozhuk Ivan <[email protected]>
2+
* Copyright (c) 2003-2024 Rozhuk Ivan <[email protected]>
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -39,6 +39,10 @@
3939
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
4040
#include <inttypes.h>
4141

42+
#ifndef nitems /* SIZEOF() */
43+
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
44+
#endif
45+
4246
static void *(*volatile md5_memset_volatile)(void*, int, size_t) = memset;
4347
#define md5_bzero(__mem, __size) md5_memset_volatile((__mem), 0x00, (__size))
4448

include/crypto/hash/sha1.h

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2003-2023 Rozhuk Ivan <[email protected]>
2+
* Copyright (c) 2003-2024 Rozhuk Ivan <[email protected]>
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -65,11 +65,6 @@
6565
#define __SHA1_H__INCLUDED__
6666

6767
#include <sys/param.h>
68-
#ifdef __linux__
69-
# include <endian.h>
70-
#else
71-
# include <sys/endian.h>
72-
#endif
7368
#include <sys/types.h>
7469
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
7570
#include <inttypes.h>
@@ -84,6 +79,14 @@
8479
# include <immintrin.h> /* AVX */
8580
#endif
8681

82+
#ifndef bswap64
83+
# define bswap64 __builtin_bswap64
84+
#endif
85+
86+
#ifndef nitems /* SIZEOF() */
87+
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
88+
#endif
89+
8790
#if defined(__SHA__) && defined(__SSSE3__) && defined(__SSE4_1__)
8891
# include <shaintrin.h>
8992
# define SHA1_ENABLE_SIMD 1
@@ -185,11 +188,11 @@ sha1_init(sha1_ctx_p ctx) {
185188
ctx->use_sse = 0;
186189
# ifdef __SSE4_1__
187190
ctx->use_sse |= (ecx & (((uint32_t)1) << 19));
188-
# elifdef __SSSE3__
191+
# elif defined(__SSSE3__)
189192
ctx->use_sse |= (ecx & (((uint32_t)1) << 9));
190-
# elifdef __SSE3__
193+
# elif defined(__SSE3__)
191194
ctx->use_sse |= (ecx & (((uint32_t)1) << 0));
192-
# elifdef __SSE2__
195+
# elif defined(__SSE2__)
193196
ctx->use_sse |= (edx & (((uint32_t)1) << 26));
194197
# endif
195198
#endif

include/crypto/hash/sha2.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2013-2023 Rozhuk Ivan <[email protected]>
2+
* Copyright (c) 2013-2024 Rozhuk Ivan <[email protected]>
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -35,11 +35,6 @@
3535
#define __SHA2_H__INCLUDED__
3636

3737
#include <sys/param.h>
38-
#ifdef __linux__
39-
# include <endian.h>
40-
#else
41-
# include <sys/endian.h>
42-
#endif
4338
#include <sys/types.h>
4439
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
4540
#include <inttypes.h>
@@ -56,6 +51,14 @@
5651
# define SHA2_ENABLE_SIMD 1
5752
#endif
5853

54+
#ifndef bswap64
55+
# define bswap64 __builtin_bswap64
56+
#endif
57+
58+
#ifndef nitems /* SIZEOF() */
59+
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
60+
#endif
61+
5962
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
6063
# define SHA2_ALIGN(__n) __declspec(align(__n)) /* DECLSPEC_ALIGN() */
6164
#else /* GCC/clang */

0 commit comments

Comments
 (0)