| 268 | } // namespace |
| 269 | |
| 270 | int main(int argc, char** argv) { |
| 271 | uint64_t test_complexity = 4; |
| 272 | if (argc > 1) { |
| 273 | size_t len = 0; |
| 274 | std::string arg{argv[1]}; |
| 275 | try { |
| 276 | test_complexity = 0; |
| 277 | long long complexity = std::stoll(arg, &len); |
| 278 | if (complexity >= 1 && len == arg.size() && ((uint64_t)complexity <= std::numeric_limits<uint64_t>::max() >> 10)) { |
| 279 | test_complexity = complexity; |
| 280 | } |
| 281 | } catch (const std::logic_error&) {} |
| 282 | if (test_complexity == 0) { |
| 283 | fprintf(stderr, "Invalid complexity specified: '%s'\n", arg.c_str()); |
| 284 | return 1; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | #ifdef MINISKETCH_VERIFY |
| 289 | const char* mode = " in verify mode"; |
| 290 | #else |
| 291 | const char* mode = ""; |
| 292 | #endif |
| 293 | printf("Running libminisketch tests%s with complexity=%llu\n", mode, (unsigned long long)test_complexity); |
| 294 | |
| 295 | TestComputeFunctions(); |
| 296 | |
| 297 | for (unsigned j = 2; j <= 64; ++j) { |
| 298 | TestRandomized(j, 8, (test_complexity << 10) / j); |
| 299 | TestRandomized(j, 128, (test_complexity << 7) / j); |
| 300 | TestRandomized(j, 4096, test_complexity / j); |
| 301 | } |
| 302 | |
| 303 | // Test capacity==0 together with all field sizes, and then |
| 304 | // all combinations of bits and capacity up to a certain bits*capacity, |
| 305 | // depending on test_complexity. |
| 306 | for (int weight = 0; weight <= 40; ++weight) { |
| 307 | for (int bits = 2; weight == 0 ? bits <= 64 : (bits <= 32 && bits <= weight); ++bits) { |
| 308 | int capacity = weight / bits; |
| 309 | if (capacity * bits != weight) continue; |
| 310 | TestExhaustive(bits, capacity); |
| 311 | } |
| 312 | if (weight >= 16 && test_complexity >> (weight - 16) == 0) break; |
| 313 | } |
| 314 | |
| 315 | printf("All tests successful.\n"); |
| 316 | return 0; |
| 317 | } |
nothing calls this directly
no test coverage detected