Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
x-mass authored and nkaskov committed Dec 8, 2023
1 parent 01f5b00 commit ed5d8b4
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 215 deletions.
8 changes: 3 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ macro(define_runtime_algebra_test name)
set(test_name "algebra_${name}_test")

set(additional_args "")
message(STATUS "here")
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} ${TEST_REPORTS_DIR})
file(MAKE_DIRECTORY ${TEST_LOGS_DIR})

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

cm_test(NAME ${test_name} SOURCES ${name}.cpp ARGS ${additional_args})
Expand All @@ -57,6 +55,8 @@ macro(define_runtime_algebra_test name)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

target_compile_definitions(${test_name} PRIVATE TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/")
endmacro()

macro(define_compile_time_algebra_test name)
Expand Down Expand Up @@ -86,7 +86,6 @@ set(RUNTIME_TESTS_NAMES
"fields_static"
"pairing"
"hash_to_curve"
"wnaf"
"multiexp"
)

Expand All @@ -95,7 +94,6 @@ set(COMPILE_TIME_TESTS_NAMES
"vector")

foreach(TEST_NAME ${RUNTIME_TESTS_NAMES})
message(STATUS "for each")
define_runtime_algebra_test(${TEST_NAME})
endforeach()

Expand Down
10 changes: 5 additions & 5 deletions test/curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace boost {
} // namespace boost

// if target == check-algebra just data/curves.json
const char *test_data = "../../../../libs/algebra/test/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) {
boost::property_tree::ptree string_data;
Expand Down Expand Up @@ -236,11 +236,11 @@ void check_curve_operations(const std::vector<typename CurveGroup::value_type> &
BOOST_CHECK_EQUAL(result, points[p1_minus_p2]);

result = points[p1];
result *= static_cast<cpp_int>(constants[C1]);
result *= static_cast<cpp_int>(constants[C1]);
BOOST_CHECK_EQUAL(result, points[p1_mul_C1]);

result = points[p2];
result *= static_cast<cpp_int>(constants[C1]);
result *= static_cast<cpp_int>(constants[C1]);
result += points[p2] * static_cast<cpp_int>(constants[C2]);
BOOST_CHECK_EQUAL(result, points[p2_mul_C1_plus_p2_mul_C2]);
}
Expand Down Expand Up @@ -278,11 +278,11 @@ void check_curve_operations_twisted_edwards(
BOOST_CHECK_EQUAL(result, points[p1_minus_p2]);

result = points[p1];
result *= static_cast<cpp_int>(constants[C1]);
result *= static_cast<cpp_int>(constants[C1]);
BOOST_CHECK_EQUAL(result, points[p1_mul_C1]);

result = points[p2];
result *= static_cast<cpp_int>(constants[C1]);
result *= static_cast<cpp_int>(constants[C1]);
result += points[p2] * static_cast<cpp_int>(constants[C2]);
BOOST_CHECK_EQUAL(result, points[p2_mul_C1_plus_p2_mul_C2]);
}
Expand Down
228 changes: 83 additions & 145 deletions test/curves_static.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ enum field_operation_test_elements : std::size_t {
};

// if target == check-algebra just data/fields.json
const char *test_data = "../../../../libs/algebra/test/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) {
boost::property_tree::ptree string_data;
Expand Down Expand Up @@ -490,7 +490,7 @@ BOOST_AUTO_TEST_CASE(field_operation_test_maxprime){

BOOST_DATA_TEST_CASE(field_operation_test_mnt4_fq, string_data("field_operation_test_mnt4_fq"), data_set) {
using policy_type = fields::mnt4<298>;

field_operation_test<policy_type>(data_set);
}

Expand Down
11 changes: 6 additions & 5 deletions test/multiexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
// #include <nil/crypto3/algebra/curves/params/multiexp/secp.hpp>
// #include <nil/crypto3/algebra/curves/params/multiexp/sm2p_v1.hpp>
// #include <nil/crypto3/algebra/curves/params/multiexp/x962_p.hpp>
#include <nil/crypto3/algebra/curves/params/wnaf/bls12.hpp>

#include <nil/crypto3/algebra/random_element.hpp>

Expand All @@ -81,7 +82,7 @@ template<typename GroupType>
using run_result_t = std::pair<long long, std::vector<typename GroupType::value_type>>;

template<typename T>
using test_instances_t = std::vector<std::vector<T>>;
using test_instances_t = std::vector<std::vector<typename T::value_type>>;

template<typename GroupType>
test_instances_t<GroupType> generate_group_elements(std::size_t count, std::size_t size) {
Expand All @@ -92,7 +93,7 @@ test_instances_t<GroupType> generate_group_elements(std::size_t count, std::size
for (size_t i = 0; i < count; i++) {

typename GroupType::value_type x =
random_element<GroupType>().to_projective(); // djb requires input to be in special form
random_element<GroupType>(); // djb requires input to be in special form

for (size_t j = 0; j < size; j++) {
result[i].push_back(x);
Expand All @@ -111,7 +112,7 @@ test_instances_t<FieldType> generate_scalars(std::size_t count, std::size_t size

for (size_t i = 0; i < count; i++) {
for (size_t j = 0; j < size; j++) {
result[i].push_back(random_element<FieldType>(i * size + j));
result[i].push_back(random_element<FieldType>());
}
}

Expand Down Expand Up @@ -183,10 +184,10 @@ BOOST_AUTO_TEST_SUITE(multiexp_test_suite)
BOOST_AUTO_TEST_CASE(multiexp_test_case) {

std::cout << "Testing BLS12-381 G1" << std::endl;
print_performance_csv<curves::bls12<381>::g1_type<>, curves::bls12<381>::scalar_field_type>(2, 20, 14, true);
print_performance_csv<curves::bls12<381>::g1_type<>, curves::bls12<381>::scalar_field_type>(2, 12, 14, true);

std::cout << "Testing BLS12-381 G2" << std::endl;
print_performance_csv<curves::bls12<381>::g2_type<>, curves::bls12<381>::scalar_field_type>(2, 20, 14, true);
print_performance_csv<curves::bls12<381>::g2_type<>, curves::bls12<381>::scalar_field_type>(2, 12, 14, true);
}

BOOST_AUTO_TEST_SUITE_END()
14 changes: 7 additions & 7 deletions test/pairing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace boost {
} // namespace test_tools
} // namespace boost

const char *test_data = "../../../../libs/algebra/test/data/pairing.json";
std::string test_data = std::string(TEST_DATA_DIR) + R"(pairing.json)";

boost::property_tree::ptree string_data(const std::string &test_name) {
boost::property_tree::ptree string_data;
Expand Down Expand Up @@ -654,7 +654,7 @@ void pairing_test_Fr_init(std::vector<typename fields::detail::element_fp<FieldP

template<typename CurveType, typename TestSet>
void pairing_test_G1_init(std::vector<typename CurveType::template g1_type<>::value_type> &elements, const TestSet &test_set) {

using value_type = typename CurveType::template g1_type<>::value_type;

for (auto &elem_coords : test_set.second.get_child("G1")) {
Expand All @@ -664,7 +664,7 @@ void pairing_test_G1_init(std::vector<typename CurveType::template g1_type<>::va

template<typename CurveType, typename TestSet>
void pairing_test_G2_init(std::vector<typename CurveType::template g2_type<>::value_type> &elements, const TestSet &test_set) {

using value_type = typename CurveType::template g2_type<>::value_type;

for (auto &elem_coords : test_set.second.get_child("G2")) {
Expand All @@ -674,7 +674,7 @@ void pairing_test_G2_init(std::vector<typename CurveType::template g2_type<>::va

template<typename CurveType, typename TestSet>
void pairing_test_GT_init(std::vector<typename CurveType::gt_type::value_type> &elements, const TestSet &test_set) {

using value_type = typename CurveType::gt_type::value_type;

for (auto &elem_GT : test_set.second.get_child("GT")) {
Expand All @@ -688,7 +688,7 @@ void pairing_test_g1_precomp_init(std::vector<typename pairing::pairing_policy<c
using curve_type = curves::bls12<381>;
using pairing_policy = typename pairing::pairing_policy<curve_type>;
using value_type = typename pairing_policy::g1_precomputed_type;

using g1_field_value_type = typename curve_type::base_field_type::value_type;
using g2_field_value_type = typename curve_type::template g2_type<>::field_type::value_type;

Expand Down Expand Up @@ -743,7 +743,7 @@ void pairing_test_g2_precomp_init(std::vector<typename pairing::pairing_policy<c
using curve_type = curves::bls12<381>;
using pairing_policy = typename pairing::pairing_policy<curve_type>;
using value_type = typename pairing_policy::g2_precomputed_type;

using g1_field_value_type = typename curve_type::base_field_type::value_type;
using g2_field_value_type = typename curve_type::template g2_type<>::field_type::value_type;

Expand Down Expand Up @@ -825,7 +825,7 @@ void pairing_test_g2_precomp_init(std::vector<typename pairing::pairing_policy<c
using curve_type = curves::mnt6<298>;
using pairing_policy = typename pairing::pairing_policy<curve_type>;
using value_type = typename pairing_policy::g2_precomputed_type;

using g1_field_value_type = typename curve_type::base_field_type::value_type;
using g2_field_value_type = typename curve_type::template g2_type<>::field_type::value_type;

Expand Down
4 changes: 2 additions & 2 deletions test/short_weierstrass_coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void print_curve_point(std::ostream &os,

template<typename CurveParams, typename Form, typename Coordinates>
typename std::enable_if<std::is_same<Coordinates, curves::coordinates::jacobian_with_a4_minus_3>::value||
std::is_same<Coordinates, curves::coordinates::jacobian>::value||
std::is_same<Coordinates, curves::coordinates::jacobian>::value||
std::is_same<Coordinates, curves::coordinates::projective_with_a4_minus_3>::value>::type
print_curve_point(std::ostream &os, const curves::detail::curve_element<CurveParams, Form, Coordinates> &p) {
os << "( X: [";
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace boost {
} // namespace test_tools
} // namespace boost

const char *test_data = "../../../../libs/algebra/test/data/coordinates.json";
std::string test_data = std::string(TEST_DATA_DIR) + R"(coordinates.json)";

boost::property_tree::ptree string_data(std::string test_name) {
boost::property_tree::ptree string_data;
Expand Down
44 changes: 0 additions & 44 deletions test/wnaf.cpp

This file was deleted.

0 comments on commit ed5d8b4

Please sign in to comment.