mini-gmp testing (was: Re: Help stabilising mini-gmp)

Niels Möller nisse at lysator.liu.se
Mon Nov 21 21:39:23 UTC 2016


tg at gmplib.org (Torbjörn Granlund) writes:

> We should at least make sure the algorithms' corner cases are exercised,
> e.g., that large quotient are generated for Euclid's algorithm and that
> remainders of +-epsilon are used for division.

The mini-gmp testsuite is a bit hairy because it uses both gmp and
mini-gmp. This works fine with linking, thanks to the name mangling of
gmp symbols, but we can't include both gmp.h and mini-gmp.h in the same
compilation unit, and we have to types called mpz_t which in general
aren't compatible.

Most of the current tests works by invoking a function which uses the
real gmp to produce random inputs and a reference answer. E.g., (a, b,
a+b), or (a, b, gcd(a,b)). These are then translated between gmp mpz_t
and mini-gmp mpz_t via hex representation.

I think this is reasonable for simple things like add and mul, but maybe
not for the more complex things.

In particular, for division and gcd(ext), where the result is easy to
validate using multiplication and addition, there are different ways to
do things. We need to call into gmp to generate inputs or pieces of
inputs (because mini-gmp lacks mpz_urandom and mpz_rrandom). And we
obviously want to do the operation under test using mini-gmp. But we can
choose freely whether or not the code to produce inputs and validate
outputs should use gmp or mini-gmp.

One opposite way to organize the tests would be to have the main part of
the test programs use the real gmp, i.e., include gmp.h rather than
mini-gmp.h. And then do wrapper functions for the functions under test,
e.g, a mini_mpz_gcd which accepts gmp mpz_t as inputs, converts to hex,
passes on to a separate compilation unit which uses mini-gmp.h rather
than gmp.h to convert the hex inputs to mini-gmp mpz_t, call the
corresponding mini-gmp function, and convert back.

That should make it easier to copy testcases from the real gmp. The main
drawback I see is that testcases get less clear if there's a hairy
wrapper between the the testcode and the function it's testing. Complex
wrappers around generation of test inputs and validation of results
somehow suits my taste better, but I have no good rational motivation
for that.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list