Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests memory issues with different include #173

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,20 @@ endif()

cm_project(algebra WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES ASM C CXX)

if(NOT Boost_FOUND AND NOT CMAKE_CROSSCOMPILING)
find_package(Boost)
endif()

include(CMDeploy)

option(BUILD_BENCH_TESTS "Build performance benchmark tests" FALSE)
option(BUILD_EXAMPLES "Build examples" FALSE)

# Blurprint components are using point {0, 0} as a point in infinity, while the stadard is {0, 1}
# for most curves. We will use compatibility mode with blueprint as default. Setting this flag to
# for most curves. We will use compatibility mode with blueprint as default. Setting this flag to
# TRUE will change the value of inf point for all curves to the standard value.
option(STANDARD_EC_INF_POINTS "Use standard zero points for Eliptic Curves" FALSE)

if(STANDARD_EC_INF_POINTS)
add_definitions(-DSTANDARD_EC_INF_POINTS_ENABLED)
endif()

list(APPEND ${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS)

list(APPEND ${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES)

list(APPEND ${CURRENT_PROJECT_NAME}_HEADERS ${${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS})

list(APPEND ${CURRENT_PROJECT_NAME}_SOURCES ${${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES})

cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})

add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE)
Expand All @@ -63,14 +51,11 @@ set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES

target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>

$<$<BOOL:${Boost_FOUND}>:${Boost_INCLUDE_DIRS}>)
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)

target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
${CMAKE_WORKSPACE_NAME}::multiprecision

${Boost_LIBRARIES})
Boost::unit_test_framework)

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
INCLUDE include
Expand Down
51 changes: 11 additions & 40 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,31 @@
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

include(CMTest)

if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
endif()

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

${CMAKE_WORKSPACE_NAME}::multiprecision

${Boost_LIBRARIES})
cm_test_link_libraries(
${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
${CMAKE_WORKSPACE_NAME}::multiprecision
Boost::unit_test_framework
Boost::random
)

add_custom_target(algebra_runtime_tests)

macro(define_runtime_algebra_test name)
set(test_name "algebra_${name}_test")
add_dependencies(algebra_runtime_tests ${test_name})

set(additional_args "")
if(ENABLE_JUNIT_TEST_OUTPUT)
set(TEST_RESULTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/junit_results")
set(TEST_LOGS_DIR "${TEST_RESULTS_DIR}/logs")
file(MAKE_DIRECTORY ${TEST_LOGS_DIR})

set(additional_args "--log_format=JUNIT"
"--log_sink=${TEST_LOGS_DIR}/${test_name}.xml")
endif()

cm_test(NAME ${test_name} SOURCES ${name}.cpp ARGS ${additional_args})
cm_test(NAME ${test_name} SOURCES ${name}.cpp)

target_include_directories(${test_name} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"

${Boost_INCLUDE_DIRS})
${Boost_INCLUDE_DIRS}
)

set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE)

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(${test_name} PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647" "-ftemplate-backtrace-limit=0")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand All @@ -71,13 +50,6 @@ macro(define_compile_time_algebra_test name)
${Boost_INCLUDE_DIRS})

set_target_properties(algebra_${name}_compile_test PROPERTIES CXX_STANDARD 17)

get_target_property(target_type Boost::unit_test_framework TYPE)
if(target_type STREQUAL "SHARED_LIB")
target_compile_definitions(algebra_${name}_compile_test PRIVATE BOOST_TEST_DYN_LINK)
elseif(target_type STREQUAL "STATIC_LIB")

endif()
endmacro()

set(RUNTIME_TESTS_NAMES
Expand Down Expand Up @@ -105,4 +77,3 @@ endforeach()
if(BUILD_BENCH_TESTS)
cm_add_test_subdirectory(bench_test)
endif()

2 changes: 1 addition & 1 deletion test/bench_test/bench_curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <chrono>
#include <type_traits>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down
2 changes: 1 addition & 1 deletion test/bench_test/bench_fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <cstdint>
#include <string>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down
7 changes: 3 additions & 4 deletions test/curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <chrono>
#include <type_traits>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down Expand Up @@ -72,10 +72,9 @@ namespace boost {
} // namespace test_tools
} // namespace boost

// if target == check-algebra just data/curves.json
std::string test_data = std::string(TEST_DATA_DIR) + R"(curves.json)";

boost::property_tree::ptree string_data(std::string test_name) {
// if target == check-algebra just data/curves.json
static std::string test_data = std::string(TEST_DATA_DIR) + R"(curves.json)";
boost::property_tree::ptree string_data;
boost::property_tree::read_json(test_data, string_data);

Expand Down
6 changes: 3 additions & 3 deletions test/fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <cstdint>
#include <string>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down Expand Up @@ -99,10 +99,10 @@ enum field_operation_test_elements : std::size_t {
elements_set_size
};

// if target == check-algebra just data/fields.json
std::string test_data = std::string(TEST_DATA_DIR) + R"(fields.json)";

boost::property_tree::ptree string_data(std::string test_name) {
// if target == check-algebra just data/fields.json
static std::string test_data = std::string(TEST_DATA_DIR) + R"(fields.json)";
boost::property_tree::ptree string_data;
boost::property_tree::read_json(test_data, string_data);

Expand Down
4 changes: 2 additions & 2 deletions test/fields_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <cstdint>
#include <string>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down Expand Up @@ -103,7 +103,7 @@ constexpr bool check_field_operations_static(const ElementsRange &elements, cons
static_assert(elements[e1] * elements[e2] == elements[e1_mul_e2], "mul error");
static_assert(elements[e1].doubled() == elements[e1_dbl], "dbl error");
static_assert(elements[e2].inversed() == elements[e2_inv], "inv error");

static_assert(elements[e1].pow(constants[C1]) == elements[e1_pow_C1], "pow error");
static_assert(elements[e2].squared() == elements[e2_pow_2], "sqr error");
static_assert((elements[e2].squared()).sqrt() == elements[e2_pow_2_sqrt], "sqrt error");
Expand Down
2 changes: 1 addition & 1 deletion test/multiexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define BOOST_TEST_MODULE multiexpr_test

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down
9 changes: 4 additions & 5 deletions test/pairing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <vector>
#include <array>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down Expand Up @@ -70,9 +70,8 @@ namespace boost {
} // namespace test_tools
} // namespace boost

std::string test_data = std::string(TEST_DATA_DIR) + R"(pairing.json)";

boost::property_tree::ptree string_data(const std::string &test_name) {
static std::string test_data = std::string(TEST_DATA_DIR) + R"(pairing.json)";
boost::property_tree::ptree string_data;
boost::property_tree::read_json(test_data, string_data);

Expand Down Expand Up @@ -112,10 +111,10 @@ void check_pairing_operations(std::vector<Fr_value_type> &Fr_elements,
BOOST_CHECK_EQUAL((Fr_elements[A2_poly] * Fr_elements[B2_poly] - Fr_elements[VKx_poly] * Fr_elements[VKy_poly]) *
Fr_elements[VKz_poly].inversed(),
Fr_elements[C2_poly]);

BOOST_CHECK_EQUAL(Fr_elements[A1_poly] * G1_value_type::zero(), G1_value_type::zero());
BOOST_CHECK_EQUAL(Fr_elements[B1_poly] * G2_value_type::zero(), G2_value_type::zero());

BOOST_CHECK_EQUAL(Fr_elements[VKx_poly] * G1_value_type::one(), G1_elements[VKx]);
BOOST_CHECK_EQUAL(Fr_elements[VKy_poly] * G2_value_type::one(), G2_elements[VKy]);
BOOST_CHECK_EQUAL(Fr_elements[VKz_poly] * G2_value_type::one(), G2_elements[VKz]);
Expand Down
5 changes: 2 additions & 3 deletions test/short_weierstrass_coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <iostream>
#include <type_traits>

#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

Expand Down Expand Up @@ -58,9 +58,8 @@ namespace boost {
} // namespace test_tools
} // namespace boost

std::string test_data = std::string(TEST_DATA_DIR) + R"(coordinates.json)";

boost::property_tree::ptree string_data(std::string test_name) {
static std::string test_data = std::string(TEST_DATA_DIR) + R"(coordinates.json)";
boost::property_tree::ptree string_data;
boost::property_tree::read_json(test_data, string_data);

Expand Down
Loading