Skip to content

Commit

Permalink
Add tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
rozhuk-im committed Apr 25, 2024
1 parent 2e8d4ba commit ed54811
Show file tree
Hide file tree
Showing 16 changed files with 233 additions and 28 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 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 <NAME>"
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
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 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 <NAME>"
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
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -100,6 +112,8 @@ message(STATUS "liblcb configuring done!")

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

add_subdirectory(tests)


############################ 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
6 changes: 5 additions & 1 deletion 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 @@ -60,6 +60,10 @@
# include <immintrin.h> /* AVX */
#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
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
12 changes: 8 additions & 4 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,12 +65,12 @@
#define __SHA1_H__INCLUDED__

#include <sys/param.h>
#include <sys/types.h>
#ifdef __linux__
# include <endian.h>
# include <endian.h> /* bswap64() */
#else
# include <sys/endian.h>
# include <sys/endian.h> /* bswap64() */
#endif
#include <sys/types.h>
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
#include <inttypes.h>
#ifdef __SSE2__
Expand All @@ -84,6 +84,10 @@
# include <immintrin.h> /* AVX */
#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
12 changes: 8 additions & 4 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,12 +35,12 @@
#define __SHA2_H__INCLUDED__

#include <sys/param.h>
#include <sys/types.h>
#ifdef __linux__
# include <endian.h>
# include <endian.h> /* bswap64() */
#else
# include <sys/endian.h>
# include <sys/endian.h> /* bswap64() */
#endif
#include <sys/types.h>
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strerror... */
#include <inttypes.h>
#if defined(__SHA__) && defined(__SSSE3__) && defined(__SSE4_1__)
Expand All @@ -56,6 +56,10 @@
# define SHA2_ENABLE_SIMD 1
#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
7 changes: 6 additions & 1 deletion include/utils/base64.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 @@ -29,9 +29,14 @@
#ifndef __BASE64_H__
#define __BASE64_H__

#include <sys/param.h>
#include <sys/types.h>
#include <inttypes.h>

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

/*
* BASE64 coding:
* 214 46 138
Expand Down
11 changes: 9 additions & 2 deletions lib.project
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="lib" Version="11000" InternalType="">
<VirtualDirectory Name="tests">
<File Name="tests/CMakeLists.txt"/>
</VirtualDirectory>
<VirtualDirectory Name="workflows">
<File Name=".github/workflows/build-ubuntu-latest.yml"/>
<File Name=".github/workflows/build-macos-latest.yml"/>
</VirtualDirectory>
<Plugins>
<Plugin Name="CppCheck"/>
</Plugins>
Expand Down Expand Up @@ -132,7 +139,7 @@
<Dependencies Name="Debug"/>
<Settings Type="Static Library">
<GlobalSettings>
<Compiler Options="" C_Options="-DHAVE_STRLCPY;-DHAVE_PIPE2;-DHAVE_ACCEPT4;-DHAVE_REALLOCARRAY;-DHAVE_ACCEPT4;-DHAVE_MEMRCHR;-DHAVE_MEMMEM;-DHAVE_REALLOCARRAY;-DHAVE_MEMSET_S;-DHAVE_EXPLICIT_BZERO;-Wimplicit-fallthrough" Assembler="">
<Compiler Options="" C_Options="-DHAVE_STRLCPY;-DHAVE_PIPE2;-DHAVE_ACCEPT4;-DHAVE_REALLOCARRAY;-DHAVE_ACCEPT4;-DHAVE_MEMRCHR;-DHAVE_MEMMEM;-DHAVE_REALLOCARRAY;-DHAVE_MEMSET_S;-DHAVE_EXPLICIT_BZERO;-DHAVE_KQUEUEX;-Wimplicit-fallthrough" Assembler="">
<IncludePath Value="./include"/>
</Compiler>
<Linker Options="">
Expand All @@ -141,7 +148,7 @@
<ResourceCompiler Options=""/>
</GlobalSettings>
<Configuration Name="Debug" CompilerType="clang system" DebuggerType="GNU gdb debugger" Type="Static Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="" C_Options="-Weverything;-g -DDEBUG;-pedantic;-W;-Wall;-g -Wall;-Wno-reserved-id-macro;-Wno-variadic-macros;-Wno-gnu-zero-variadic-macro-arguments;-Wno-unused-macros;-Wno-padded;-Wno-packed;-Wno-date-time;-Wno-unsafe-buffer-usage" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0"/>
<Compiler Options="" C_Options="-Weverything;-g -DDEBUG;-pedantic;-W;-Wall;-g -Wall;-Wno-reserved-id-macro;-Wno-variadic-macros;-Wno-gnu-zero-variadic-macro-arguments;-Wno-unused-macros;-Wno-padded;-Wno-packed;-Wno-date-time;-Wno-unsafe-buffer-usage;-Wno-switch-default" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0"/>
<Linker Options="-O0" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="./Debug" PauseExecWhenProcTerminates="no" IsGUIProgram="no" IsEnabled="yes"/>
Expand Down
4 changes: 2 additions & 2 deletions liblcb.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<VirtualDirectory Name="test">
<Project Name="test-base64" Path="tests/base64/test-base64.project" Active="No"/>
<Project Name="test-ecdsa" Path="tests/ecdsa/test-ecdsa.project" Active="No"/>
<Project Name="test-threadpool" Path="tests/threadpool/test-threadpool.project" Active="Yes"/>
<Project Name="test-hash" Path="tests/hash/test-hash.project" Active="No"/>
<Project Name="test-threadpool" Path="tests/threadpool/test-threadpool.project" Active="No"/>
<Project Name="test-hash" Path="tests/hash/test-hash.project" Active="Yes"/>
</VirtualDirectory>
<BuildMatrix>
<WorkspaceConfiguration Name="Debug">
Expand Down
2 changes: 1 addition & 1 deletion src/utils/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <time.h>
#include <errno.h>
#ifdef BSD /* BSD specific code. */
#include <sys/sysctl.h>
# include <sys/sysctl.h>
#endif /* BSD specific code. */

#include "utils/macro.h"
Expand Down
21 changes: 21 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<TARGET_FILE:test_base64>)
add_test(NAME test_ecdsa COMMAND $<TARGET_FILE:test_ecdsa>)
add_test(NAME test_hash COMMAND $<TARGET_FILE:test_hash>)
add_test(NAME test_threadpool COMMAND $<TARGET_FILE:test_threadpool>)

Loading

0 comments on commit ed54811

Please sign in to comment.