From d6b90a0d8f154c8fa30f634b87b1d2fcd8f4c6cd Mon Sep 17 00:00:00 2001 From: x-mass <36629999+x-mass@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:51:05 +0000 Subject: [PATCH] Add consistent testing, fix pack test --- .github/workflows/pull-request.yml | 54 ++++++++++++++++++++++ CMakeLists.txt | 5 +- include/nil/crypto3/detail/type_traits.hpp | 6 ++- test/CMakeLists.txt | 14 +++--- test/pack.cpp | 23 +++++---- 5 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..4e8d368 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,54 @@ +name: PR Testing + +on: + pull_request: + push: + branches: + - master + +concurrency: + # In master we want to run for every commit, in other branches — only for the last one + group: ${{ + ( github.ref == 'refs/heads/master' && format('{0}/{1}/{2}', github.workflow, github.ref, github.sha) ) + || + format('{0}/{1}', github.workflow, github.ref) }} + cancel-in-progress: true + +jobs: + handle-syncwith: + name: Call Reusable SyncWith Handler + uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1.2.0 + with: + ci-cd-ref: 'v1.2.0' + secrets: inherit + + test-linux: + name: Linux Reusable Crypto3 Testing + needs: + - handle-syncwith + uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-testing-linux.yml@crypto-nix + + secrets: inherit + with: + submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }} + check-names: | + block-clang + + test-mac: + name: Mac Reusable Crypto3 Testing + needs: + - handle-syncwith + uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-testing-mac.yml@crypto-nix + + secrets: inherit + with: + submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }} + check-names: | + block-clang + + publish-results: + name: Publish JUnit results + needs: + - test-linux + - test-mac + uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-publish-result.yml@crypto-nix diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fef0fb..a77c9f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -523,6 +523,5 @@ cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INCLUDE include NAMESPACE ${CMAKE_WORKSPACE_NAME}::) -if(BUILD_TESTS) - add_subdirectory(test) -endif() +include(CMTest) +cm_add_test_subdirectory(test) diff --git a/include/nil/crypto3/detail/type_traits.hpp b/include/nil/crypto3/detail/type_traits.hpp index 67912ee..56bd973 100644 --- a/include/nil/crypto3/detail/type_traits.hpp +++ b/include/nil/crypto3/detail/type_traits.hpp @@ -25,6 +25,10 @@ #ifndef CRYPTO3_TYPE_TRAITS_HPP #define CRYPTO3_TYPE_TRAITS_HPP +#include +#include + + #define GENERATE_HAS_MEMBER_TYPE(Type) \ template \ class HasMemberType_##Type { \ @@ -325,4 +329,4 @@ namespace nil { } // namespace crypto3 } // namespace nil -#endif // CRYPTO3_TYPE_TRAITS_HPP \ No newline at end of file +#endif // CRYPTO3_TYPE_TRAITS_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 523e125..d19e512 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,8 +6,6 @@ # http://www.boost.org/LICENSE_1_0.txt #---------------------------------------------------------------------------# -include(CMTest) - if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND) cm_find_package(Boost REQUIRED COMPONENTS unit_test_framework) endif() @@ -16,27 +14,29 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} ${Boost_LIBRARIES}) macro(define_block_cipher_test name) - cm_test(NAME block_${name}_test SOURCES ${name}.cpp) + set(test_name "block_${name}_test") + + cm_test(NAME ${test_name} SOURCES ${name}.cpp) - target_include_directories(block_${name}_test PRIVATE + target_include_directories(${test_name} PRIVATE "$" "$" ${Boost_INCLUDE_DIRS}) if(NOT CMAKE_CXX_STANDARD) - set_target_properties(block_${name}_test PROPERTIES CXX_STANDARD 14) + set_target_properties(${test_name} PROPERTIES CXX_STANDARD 14) endif() get_target_property(target_type Boost::unit_test_framework TYPE) if(target_type STREQUAL "SHARED_LIB") - target_compile_definitions(block_${name}_test PRIVATE BOOST_TEST_DYN_LINK) + target_compile_definitions(${test_name} PRIVATE BOOST_TEST_DYN_LINK) elseif(target_type STREQUAL "STATIC_LIB") endif() string(CONCAT TEST_DATA ${CMAKE_CURRENT_SOURCE_DIR} "/data/" "${name}" ".json") - target_compile_definitions(block_${name}_test PRIVATE TEST_DATA="${TEST_DATA}") + target_compile_definitions(${test_name} PRIVATE TEST_DATA_DIR="${TEST_DATA}") endmacro() set(TESTS_NAMES diff --git a/test/pack.cpp b/test/pack.cpp index 7d05af4..c438628 100644 --- a/test/pack.cpp +++ b/test/pack.cpp @@ -25,16 +25,15 @@ #define BOOST_TEST_MODULE block_pack_test -#include -#include - -#include +#include +#include +#include #include #include #include -#include +#include using namespace nil::crypto3; using namespace nil::crypto3::detail; @@ -66,7 +65,7 @@ BOOST_AUTO_TEST_CASE(bubb_to_bubb_2) { BOOST_AUTO_TEST_CASE(bubb_to_bulb_1) { std::array in = {{0x12, 0x34, 0x56, 0x78}}; std::array out {}; - std::array res = {{0x482c6a1e}}; + std::array res = {{0x482c6a1e}}; pack(in.begin(), in.end(), out.begin()); @@ -90,7 +89,7 @@ BOOST_AUTO_TEST_CASE(bubb_to_lubb_1) { pack(in.begin(), in.end(), out.begin()); - BOOST_CHECK(out == res); + BOOST_CHECK(out == res); } BOOST_AUTO_TEST_CASE(bubb_to_lubb_2) { @@ -204,7 +203,7 @@ BOOST_AUTO_TEST_CASE(lubb_to_lulb_2) { } BOOST_AUTO_TEST_CASE(bulb_to_bubb_1) { - std::array in = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, + std::array in = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x48, 0x2c, 0x6a, 0x1e, 0x09, 0xd5, 0xb3, 0xf7}}; std::array out {}; std::array res = {{0x482c6a1e09d5b3f7, 0x1234567890abcdef}}; @@ -392,7 +391,7 @@ BOOST_AUTO_TEST_CASE(bubb_to_bubb_2) { BOOST_AUTO_TEST_CASE(bubb_to_bulb_1) { std::array in = {{0x482c6a1e}}; std::array out {}; - std::array res = {{0x12, 0x34, 0x56, 0x78}}; + std::array res = {{0x12, 0x34, 0x56, 0x78}}; pack(in.begin(), in.end(), out.begin()); @@ -416,7 +415,7 @@ BOOST_AUTO_TEST_CASE(bubb_to_lubb_1) { pack(in.begin(), in.end(), out.begin()); - BOOST_CHECK(out == res); + BOOST_CHECK(out == res); } BOOST_AUTO_TEST_CASE(bubb_to_lubb_2) { @@ -530,9 +529,9 @@ BOOST_AUTO_TEST_CASE(lubb_to_lulb_2) { } BOOST_AUTO_TEST_CASE(bulb_to_bubb_1) { - std::array in = {{0x482c6a1e09d5b3f7, 0x1234567890abcdef}}; + std::array in = {{0x482c6a1e09d5b3f7, 0x1234567890abcdef}}; std::array out {}; - std::array res = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, + std::array res = {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x48, 0x2c, 0x6a, 0x1e, 0x09, 0xd5, 0xb3, 0xf7}}; pack(in.begin(), in.end(), out.begin());