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

Productionize testing + add CI #33

Merged
merged 13 commits into from Apr 26, 2021
Merged

Productionize testing + add CI #33

merged 13 commits into from Apr 26, 2021

Conversation

sipa
Copy link
Owner

@sipa sipa commented Apr 16, 2021

Various improvements to testing:

  • Add Cirrus CI
  • exercise the C++ wrapper interface
  • operate on all field implementations simultaneously, and compare the results
  • make tests not run forever (but controlled by command-line complexity argument)
  • make tests single threaded
  • generic improvements to the tests
  • rename the test binary from test-exhaust to test
  • drop analysis/debug output

Also fix two bugs discovered while writing these improvements:

  • when requesting a clmul 64-bit field, a sketch for 63 bits was returned.
  • an internal sanity check in the root finding function could fail incorrectly on 32-bit platforms

@sipa sipa force-pushed the 202104_test_improvements branch 5 times, most recently from 2801604 to 6c7e46e Compare April 17, 2021 00:39
@sipa sipa changed the title Productionize unit tests Productionize testing + add CI Apr 17, 2021
@sipa sipa force-pushed the 202104_test_improvements branch 5 times, most recently from bf514d4 to 707aaad Compare April 17, 2021 17:43
src/test.cpp Outdated Show resolved Hide resolved
src/test.cpp Outdated Show resolved Hide resolved
src/test-exhaust.cpp Outdated Show resolved Hide resolved
@gmaxwell
Copy link
Contributor

ACK 707aaad

I didn't review any of the CI stuff more than a glance, and didn't test on 32-bit hosts yet (I assume CI is doing it!)

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested approach ACK 707aaad with a few minor comments. Each commit builds cleanly. Did not review or test the CI. Tested only on Debian 5.10.28-1 (2021-04-09) x86_64 GNU/Linux.

src/test.cpp Outdated Show resolved Hide resolved
src/test.cpp Outdated Show resolved Hide resolved
src/test.cpp Outdated Show resolved Hide resolved
src/fields/clmul_8bytes.cpp Show resolved Hide resolved
src/test-exhaust.cpp Outdated Show resolved Hide resolved
src/test-exhaust.cpp Outdated Show resolved Hide resolved
@sipa sipa force-pushed the 202104_test_improvements branch 2 times, most recently from f149995 to e05ed05 Compare April 25, 2021 03:10
@jonatack
Copy link
Contributor

Smoke test at e05ed05

~/projects/bitcoin/minisketch ((HEAD detached at origin/pr/33))$ ./test 99999999999999999999
Invalid complexity specified: `99999999999999999999'

~/projects/bitcoin/minisketch ((HEAD detached at origin/pr/33))$ ./test 0
Invalid complexity specified: `0'

~/projects/bitcoin/minisketch ((HEAD detached at origin/pr/33))$ ./test -1
Invalid complexity specified: `-1'

~/projects/bitcoin/minisketch ((HEAD detached at origin/pr/33))$ ./test a
Invalid complexity specified: `a'

~/projects/bitcoin/minisketch ((HEAD detached at origin/pr/33))$ ./test 1
Running libminisketch tests with complexity=1
All tests succesfull.

~/projects/bitcoin/minisketch ((HEAD detached at origin/pr/33))$ ./test
Running libminisketch tests with complexity=4
All tests succesfull.

s/succesfull/successful/

* Rename function from TestAll to TestExhaustive
* Use C++ wrapper interface
* Test all implementations simultaneously, and compare them
* No need to report counts back to caller
* Rename from TestRand to TestRandomized
* Use C++ wrapper interface
* Add a lot more sanity checks
* Compare more results between implementations
* Test cases where the number of elements exceeds the capacity, but
  not when cancelling out duplicates.
@sipa
Copy link
Owner Author

sipa commented Apr 26, 2021

Ok, this is ready I think.

@gmaxwell
Copy link
Contributor

ACK 84b87d5

@jonatack
Copy link
Contributor

ACK 84b87d5 per git range-diff 7408bde 707aaad 84b87d5, only skimmed the CI changes

@sipa sipa merged commit 901bbd3 into master Apr 26, 2021
Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a very cursory review and ran the tests. Looks good.

Comment on lines +272 to +273
long long complexity = std::stoll(arg, &len);
if (complexity >= 1 && len == arg.size() && ((uint64_t)complexity <= std::numeric_limits<uint64_t>::max() >> 10)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're using complexity as a uint64_t later. Why not:

Suggested change
long long complexity = std::stoll(arg, &len);
if (complexity >= 1 && len == arg.size() && ((uint64_t)complexity <= std::numeric_limits<uint64_t>::max() >> 10)) {
auto complexity = static_cast<uint64_t>(std::stoll(arg, &len));
if (complexity >= 1 && len == arg.size() && (complexity <= std::numeric_limits<uint64_t>::max() >> 10)) {

try {
test_complexity = 0;
long long complexity = std::stoll(arg, &len);
if (complexity >= 1 && len == arg.size() && ((uint64_t)complexity <= std::numeric_limits<uint64_t>::max() >> 10)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something special about std::numeric_limits<uint64_t>::max() >> 10 ? Perhaps make a variable named max_complexity and comment what's special about that value.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a test_complexity << 10; this tests prevents that from overflowing.

if (complexity >= 1 && len == arg.size() && ((uint64_t)complexity <= std::numeric_limits<uint64_t>::max() >> 10)) {
test_complexity = complexity;
}
} catch (const std::logic_error&) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What logic error is this potentially catching? The only exceptions that stoll() can throw are std::invalid_argument and std::out_of_range.

Copy link
Owner Author

@sipa sipa May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both std::invalid_argument and std::out_of_range are subclasses of std::logic_error, so this way we can avoid 2 catch statement.

void TestComputeFunctions() {
for (uint32_t bits = 0; bits <= 256; ++bits) {
for (uint32_t fpbits = 0; fpbits <= 512; ++fpbits) {
std::vector<size_t> table_max_elements(1025);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::array ?

if (capacity > 0) CHECK(table_max_elements[capacity] == 0 || table_max_elements[capacity] > table_max_elements[capacity - 1]);
}

std::vector<size_t> table_capacity(513);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::array ?

@sipa
Copy link
Owner Author

sipa commented May 7, 2021

@jnewbery Feel free to PR your comments here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants