Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit f4a68ed

Browse files
committed
Make tests use linked unit_test_framework
1 parent a3d40d8 commit f4a68ed

10 files changed

+31
-78
lines changed

Diff for: CMakeLists.txt

+3-18
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,20 @@ endif()
2828

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

31-
if(NOT Boost_FOUND AND NOT CMAKE_CROSSCOMPILING)
32-
find_package(Boost)
33-
endif()
34-
3531
include(CMDeploy)
3632

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

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

4541
if(STANDARD_EC_INF_POINTS)
4642
add_definitions(-DSTANDARD_EC_INF_POINTS_ENABLED)
4743
endif()
4844

49-
list(APPEND ${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS)
50-
51-
list(APPEND ${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES)
52-
53-
list(APPEND ${CURRENT_PROJECT_NAME}_HEADERS ${${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS})
54-
55-
list(APPEND ${CURRENT_PROJECT_NAME}_SOURCES ${${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES})
56-
5745
cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})
5846

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

6452
target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
6553
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
66-
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
67-
68-
$<$<BOOL:${Boost_FOUND}>:${Boost_INCLUDE_DIRS}>)
54+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
6955

7056
target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
7157
${CMAKE_WORKSPACE_NAME}::multiprecision
72-
73-
${Boost_LIBRARIES})
58+
Boost::unit_test_framework)
7459

7560
cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
7661
INCLUDE include

Diff for: test/CMakeLists.txt

+11-40
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,31 @@
66
# http://www.boost.org/LICENSE_1_0.txt
77
#---------------------------------------------------------------------------#
88

9-
include(CMTest)
10-
11-
if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND)
12-
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
13-
endif()
14-
15-
cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
16-
17-
${CMAKE_WORKSPACE_NAME}::multiprecision
18-
19-
${Boost_LIBRARIES})
9+
cm_test_link_libraries(
10+
${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
11+
${CMAKE_WORKSPACE_NAME}::multiprecision
12+
Boost::unit_test_framework
13+
Boost::random
14+
)
2015

2116
add_custom_target(algebra_runtime_tests)
2217

2318
macro(define_runtime_algebra_test name)
2419
set(test_name "algebra_${name}_test")
2520
add_dependencies(algebra_runtime_tests ${test_name})
2621

27-
set(additional_args "")
28-
if(ENABLE_JUNIT_TEST_OUTPUT)
29-
set(TEST_RESULTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/junit_results")
30-
set(TEST_LOGS_DIR "${TEST_RESULTS_DIR}/logs")
31-
file(MAKE_DIRECTORY ${TEST_LOGS_DIR})
32-
33-
set(additional_args "--log_format=JUNIT"
34-
"--log_sink=${TEST_LOGS_DIR}/${test_name}.xml")
35-
endif()
36-
37-
cm_test(NAME ${test_name} SOURCES ${name}.cpp ARGS ${additional_args})
22+
cm_test(NAME ${test_name} SOURCES ${name}.cpp)
3823

3924
target_include_directories(${test_name} PRIVATE
40-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
41-
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"
25+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
26+
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"
4227

43-
${Boost_INCLUDE_DIRS})
28+
${Boost_INCLUDE_DIRS}
29+
)
4430

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

48-
get_target_property(target_type Boost::unit_test_framework TYPE)
49-
if(target_type STREQUAL "SHARED_LIB")
50-
target_compile_definitions(${test_name} PRIVATE BOOST_TEST_DYN_LINK)
51-
elseif(target_type STREQUAL "STATIC_LIB")
52-
53-
endif()
54-
5534
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
5635
target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647" "-ftemplate-backtrace-limit=0")
5736
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -71,13 +50,6 @@ macro(define_compile_time_algebra_test name)
7150
${Boost_INCLUDE_DIRS})
7251

7352
set_target_properties(algebra_${name}_compile_test PROPERTIES CXX_STANDARD 17)
74-
75-
get_target_property(target_type Boost::unit_test_framework TYPE)
76-
if(target_type STREQUAL "SHARED_LIB")
77-
target_compile_definitions(algebra_${name}_compile_test PRIVATE BOOST_TEST_DYN_LINK)
78-
elseif(target_type STREQUAL "STATIC_LIB")
79-
80-
endif()
8153
endmacro()
8254

8355
set(RUNTIME_TESTS_NAMES
@@ -105,4 +77,3 @@ endforeach()
10577
if(BUILD_BENCH_TESTS)
10678
cm_add_test_subdirectory(bench_test)
10779
endif()
108-

Diff for: test/bench_test/bench_curves.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <chrono>
3131
#include <type_traits>
3232

33-
#include <boost/test/included/unit_test.hpp>
33+
#include <boost/test/unit_test.hpp>
3434
#include <boost/test/data/test_case.hpp>
3535
#include <boost/test/data/monomorphic.hpp>
3636

Diff for: test/bench_test/bench_fields.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <cstdint>
3131
#include <string>
3232

33-
#include <boost/test/included/unit_test.hpp>
33+
#include <boost/test/unit_test.hpp>
3434
#include <boost/test/data/test_case.hpp>
3535
#include <boost/test/data/monomorphic.hpp>
3636

Diff for: test/curves.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <chrono>
3131
#include <type_traits>
3232

33-
#include <boost/test/included/unit_test.hpp>
33+
#include <boost/test/unit_test.hpp>
3434
#include <boost/test/data/test_case.hpp>
3535
#include <boost/test/data/monomorphic.hpp>
3636

@@ -72,10 +72,9 @@ namespace boost {
7272
} // namespace test_tools
7373
} // namespace boost
7474

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

Diff for: test/fields.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <cstdint>
3232
#include <string>
3333

34-
#include <boost/test/included/unit_test.hpp>
34+
#include <boost/test/unit_test.hpp>
3535
#include <boost/test/data/test_case.hpp>
3636
#include <boost/test/data/monomorphic.hpp>
3737

@@ -99,10 +99,10 @@ enum field_operation_test_elements : std::size_t {
9999
elements_set_size
100100
};
101101

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

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

Diff for: test/fields_static.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <cstdint>
3131
#include <string>
3232

33-
#include <boost/test/included/unit_test.hpp>
33+
#include <boost/test/unit_test.hpp>
3434
#include <boost/test/data/test_case.hpp>
3535
#include <boost/test/data/monomorphic.hpp>
3636

@@ -103,7 +103,7 @@ constexpr bool check_field_operations_static(const ElementsRange &elements, cons
103103
static_assert(elements[e1] * elements[e2] == elements[e1_mul_e2], "mul error");
104104
static_assert(elements[e1].doubled() == elements[e1_dbl], "dbl error");
105105
static_assert(elements[e2].inversed() == elements[e2_inv], "inv error");
106-
106+
107107
static_assert(elements[e1].pow(constants[C1]) == elements[e1_pow_C1], "pow error");
108108
static_assert(elements[e2].squared() == elements[e2_pow_2], "sqr error");
109109
static_assert((elements[e2].squared()).sqrt() == elements[e2_pow_2_sqrt], "sqrt error");

Diff for: test/multiexp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#define BOOST_TEST_MODULE multiexpr_test
2727

28-
#include <boost/test/included/unit_test.hpp>
28+
#include <boost/test/unit_test.hpp>
2929
#include <boost/test/data/test_case.hpp>
3030
#include <boost/test/data/monomorphic.hpp>
3131

Diff for: test/pairing.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <vector>
3131
#include <array>
3232

33-
#include <boost/test/included/unit_test.hpp>
33+
#include <boost/test/unit_test.hpp>
3434
#include <boost/test/data/test_case.hpp>
3535
#include <boost/test/data/monomorphic.hpp>
3636

@@ -70,9 +70,8 @@ namespace boost {
7070
} // namespace test_tools
7171
} // namespace boost
7272

73-
std::string test_data = std::string(TEST_DATA_DIR) + R"(pairing.json)";
74-
7573
boost::property_tree::ptree string_data(const std::string &test_name) {
74+
static std::string test_data = std::string(TEST_DATA_DIR) + R"(pairing.json)";
7675
boost::property_tree::ptree string_data;
7776
boost::property_tree::read_json(test_data, string_data);
7877

@@ -112,10 +111,10 @@ void check_pairing_operations(std::vector<Fr_value_type> &Fr_elements,
112111
BOOST_CHECK_EQUAL((Fr_elements[A2_poly] * Fr_elements[B2_poly] - Fr_elements[VKx_poly] * Fr_elements[VKy_poly]) *
113112
Fr_elements[VKz_poly].inversed(),
114113
Fr_elements[C2_poly]);
115-
114+
116115
BOOST_CHECK_EQUAL(Fr_elements[A1_poly] * G1_value_type::zero(), G1_value_type::zero());
117116
BOOST_CHECK_EQUAL(Fr_elements[B1_poly] * G2_value_type::zero(), G2_value_type::zero());
118-
117+
119118
BOOST_CHECK_EQUAL(Fr_elements[VKx_poly] * G1_value_type::one(), G1_elements[VKx]);
120119
BOOST_CHECK_EQUAL(Fr_elements[VKy_poly] * G2_value_type::one(), G2_elements[VKy]);
121120
BOOST_CHECK_EQUAL(Fr_elements[VKz_poly] * G2_value_type::one(), G2_elements[VKz]);

Diff for: test/short_weierstrass_coordinates.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <iostream>
3131
#include <type_traits>
3232

33-
#include <boost/test/included/unit_test.hpp>
33+
#include <boost/test/unit_test.hpp>
3434
#include <boost/test/data/test_case.hpp>
3535
#include <boost/test/data/monomorphic.hpp>
3636

@@ -58,9 +58,8 @@ namespace boost {
5858
} // namespace test_tools
5959
} // namespace boost
6060

61-
std::string test_data = std::string(TEST_DATA_DIR) + R"(coordinates.json)";
62-
6361
boost::property_tree::ptree string_data(std::string test_name) {
62+
static std::string test_data = std::string(TEST_DATA_DIR) + R"(coordinates.json)";
6463
boost::property_tree::ptree string_data;
6564
boost::property_tree::read_json(test_data, string_data);
6665

0 commit comments

Comments
 (0)