From 1ad034f487b4ded98f50b3a04089d7c60cfb8c49 Mon Sep 17 00:00:00 2001 From: Marcin Date: Wed, 31 Jan 2024 14:20:02 +0100 Subject: [PATCH] Optional #iterations in group & field tests (#766) * enable specifying a custom number of iterations for testing * decrease iterations for mnt6_753 * fix macros * decrease iterations for mnt4-753 * decrease iters further * Update test-templates/src/fields.rs --- curves/mnt4_753/src/curves/tests.rs | 6 +++--- curves/mnt4_753/src/fields/tests.rs | 8 ++++---- curves/mnt6_753/src/curves/tests.rs | 6 +++--- curves/mnt6_753/src/fields/tests.rs | 8 ++++---- test-templates/src/fields.rs | 17 ++++++++++++++++- test-templates/src/groups.rs | 15 ++++++++++++++- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/curves/mnt4_753/src/curves/tests.rs b/curves/mnt4_753/src/curves/tests.rs index 3829a9765..9d16856e9 100644 --- a/curves/mnt4_753/src/curves/tests.rs +++ b/curves/mnt4_753/src/curves/tests.rs @@ -1,7 +1,7 @@ use crate::*; use ark_algebra_test_templates::*; -test_group!(g1; G1Projective; sw); -test_group!(g2; G2Projective; sw); -test_group!(pairing_output; ark_ec::pairing::PairingOutput; msm); +test_group!(50; g1; G1Projective; sw); +test_group!(50; g2; G2Projective; sw); +test_group!(50; pairing_output; ark_ec::pairing::PairingOutput; msm); test_pairing!(pairing; crate::MNT4_753); diff --git a/curves/mnt4_753/src/fields/tests.rs b/curves/mnt4_753/src/fields/tests.rs index 635ba919f..7be0f6740 100644 --- a/curves/mnt4_753/src/fields/tests.rs +++ b/curves/mnt4_753/src/fields/tests.rs @@ -1,7 +1,7 @@ use crate::*; use ark_algebra_test_templates::*; -test_field!(fr; Fr; mont_prime_field); -test_field!(fq; Fq; mont_prime_field); -test_field!(fq2; Fq2); -test_field!(fq4; Fq4); +test_field!(100; fr; Fr; mont_prime_field); +test_field!(100; fq; Fq; mont_prime_field); +test_field!(100; fq2; Fq2); +test_field!(100; fq4; Fq4); diff --git a/curves/mnt6_753/src/curves/tests.rs b/curves/mnt6_753/src/curves/tests.rs index dc145880c..c1b71b9ef 100644 --- a/curves/mnt6_753/src/curves/tests.rs +++ b/curves/mnt6_753/src/curves/tests.rs @@ -1,7 +1,7 @@ use crate::*; use ark_algebra_test_templates::*; -test_group!(g1; G1Projective; sw); -test_group!(g2; G2Projective; sw); -test_group!(pairing_output; ark_ec::pairing::PairingOutput; msm); +test_group!(50; g1; G1Projective; sw); +test_group!(50; g2; G2Projective; sw); +test_group!(50; pairing_output; ark_ec::pairing::PairingOutput; msm); test_pairing!(pairing; crate::MNT6_753); diff --git a/curves/mnt6_753/src/fields/tests.rs b/curves/mnt6_753/src/fields/tests.rs index de96429ac..7d8b10325 100644 --- a/curves/mnt6_753/src/fields/tests.rs +++ b/curves/mnt6_753/src/fields/tests.rs @@ -3,10 +3,10 @@ use ark_algebra_test_templates::*; use ark_ff::fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig}; use ark_std::{rand::Rng, test_rng}; -test_field!(fr; Fr; mont_prime_field); -test_field!(fq; Fq; mont_prime_field); -test_field!(fq3; Fq3); -test_field!(fq6; Fq6); +test_field!(100; fr; Fr; mont_prime_field); +test_field!(100; fq; Fq; mont_prime_field); +test_field!(100; fq3; Fq3); +test_field!(100; fq6; Fq6); #[test] fn test_fq3_more() { diff --git a/test-templates/src/fields.rs b/test-templates/src/fields.rs index d82c580e5..5676486cf 100644 --- a/test-templates/src/fields.rs +++ b/test-templates/src/fields.rs @@ -528,7 +528,7 @@ macro_rules! __test_field { #[macro_export] macro_rules! test_field { - ($mod_name: ident; $field: ty $(; $tail:tt)*) => { + ($mod_name:ident; $field:ty $(; $tail:tt)*) => { mod $mod_name { use super::*; use ark_ff::{ @@ -542,4 +542,19 @@ macro_rules! test_field { $crate::__test_field!($field $(; $tail)*); } }; + + ($iters:expr; $mod_name:ident; $field:ty $(; $tail:tt)*) => { + mod $mod_name { + use super::*; + use ark_ff::{ + fields::{FftField, Field, LegendreSymbol, PrimeField}, + Fp, MontBackend, MontConfig, + }; + use ark_serialize::{buffer_bit_byte_size, Flags}; + use ark_std::{io::Cursor, rand::Rng, vec::Vec, test_rng, vec, Zero, One, UniformRand}; + const ITERATIONS: usize = $iters; + + $crate::__test_field!($field $(; $tail)*); + } + }; } diff --git a/test-templates/src/groups.rs b/test-templates/src/groups.rs index 20cbf009a..49bd8ccc1 100644 --- a/test-templates/src/groups.rs +++ b/test-templates/src/groups.rs @@ -405,7 +405,7 @@ macro_rules! __test_group { #[macro_export] macro_rules! test_group { - ($mod_name: ident; $group: ty $(; $tail:tt)*) => { + ($mod_name:ident; $group:ty $(; $tail:tt)* ) => { mod $mod_name { use super::*; use ark_ff::*; @@ -417,4 +417,17 @@ macro_rules! test_group { $crate::__test_group!($group $(; $tail)*); } }; + + ($iters:expr; $mod_name:ident; $group:ty $(; $tail:tt)* ) => { + mod $mod_name { + use super::*; + use ark_ff::*; + use ark_ec::{PrimeGroup, CurveGroup, ScalarMul, AffineRepr, CurveConfig, short_weierstrass::SWCurveConfig, twisted_edwards::TECurveConfig, scalar_mul::{*, wnaf::*}}; + use ark_serialize::*; + use ark_std::{io::Cursor, rand::Rng, vec::Vec, test_rng, vec, Zero, One, UniformRand}; + const ITERATIONS: usize = $iters; + + $crate::__test_group!($group $(; $tail)*); + } + }; }