Skip to content

Commit 4181766

Browse files
committed
Add tests run
1 parent 2e8d4ba commit 4181766

19 files changed

+262
-82
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 ccache cmake 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
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
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 --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 ccache 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
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
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 --output-on-failure --test-dir tests

CMakeLists.txt

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@ cmake_minimum_required(VERSION 3.10)
1313
include(CheckIncludeFiles)
1414
include(CheckFunctionExists)
1515
include(CheckSymbolExists)
16+
include(CheckCCompilerFlag)
17+
18+
find_library(PTHREAD_LIBRARY pthread)
19+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARY})
1620

1721
############################# MACRO SECTION ############################
22+
macro(try_c_flag prop flag)
23+
# Try flag once on the C compiler
24+
check_c_compiler_flag("-Werror ${flag}" C_FLAG_${prop})
25+
if (C_FLAG_${prop})
26+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
27+
endif()
28+
endmacro()
29+
1830
macro(chk_include_files incfile prop)
1931
string(TOUPPER HAVE_${prop} __tmp)
2032
check_include_files(${incfile} ${__tmp})
@@ -93,13 +105,17 @@ chk_symbol_exists(sys/socket.h SOCK_CLOEXEC)
93105
chk_symbol_exists(sys/socket.h SOCK_NONBLOCK)
94106

95107
# Disable some warnings.
96-
try_c_flag(W_NO_UNUSED_RESULT "-Wno-unused-result")
108+
try_c_flag(WSWITCHDEFAULT "-Wno-switch-default")
109+
try_c_flag(WUNUSED_RESULT "-Wno-unused-result")
110+
try_c_flag(WUNSAFE_BUFFER_USAGE "-Wno-unsafe-buffer-usage")
97111

98112

99113
message(STATUS "liblcb configuring done!")
100114

101115
################################ SUBDIRS SECTION #######################
102116

117+
add_subdirectory(tests)
118+
103119

104120
############################ TARGETS SECTION ###########################
105121

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 */

include/math/big_num.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2013 - 2017 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
@@ -52,6 +52,9 @@
5252
# include <inttypes.h>
5353
# include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */
5454
# include <stdio.h> /* snprintf, fprintf */
55+
# ifndef __unused
56+
# define __unused __attribute__((__unused__))
57+
# endif
5558
#endif
5659

5760

include/utils/base64.h

+6-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
@@ -29,9 +29,14 @@
2929
#ifndef __BASE64_H__
3030
#define __BASE64_H__
3131

32+
#include <sys/param.h>
3233
#include <sys/types.h>
3334
#include <inttypes.h>
3435

36+
#ifndef nitems /* SIZEOF() */
37+
# define nitems(__val) (sizeof(__val) / sizeof(__val[0]))
38+
#endif
39+
3540
/*
3641
* BASE64 coding:
3742
* 214 46 138

0 commit comments

Comments
 (0)