UltrafastSecp256k1 3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
selftest.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
7namespace secp256k1::fast {
8
9// -- Selftest execution modes --
10// Controls which test subsets run and how many iterations stress tests perform.
11//
12// smoke -- 1-2 seconds, core KAT vectors only (suitable for app startup)
13// ci -- 30-90 seconds, full coverage (GitHub Actions / every push)
14// stress -- 10-60 minutes, extended iterations + big sweeps (nightly / manual)
15enum class SelftestMode : uint8_t {
16 smoke = 0, // Core vectors + field/scalar identities (~1-2 s)
17 ci = 1, // All tests including batch sweeps, bilinearity, NAF (~30-90 s)
18 stress = 2 // ci + extended iterations, large random sweeps (~10-60 min)
19};
20
21// -- Structured selftest result (for bindings / programmatic use) --
23 std::string name; // e.g. "scalar_mul_KAT_10_vectors"
24 bool passed; // true = PASS
25 std::string detail; // empty on pass; failure description on fail
26};
27
29 bool all_passed; // true if every case passed
30 int total; // number of test cases run
31 int passed; // number that passed
32 std::string mode; // "smoke", "ci", or "stress"
33 uint64_t seed; // PRNG seed used
34 std::string platform; // e.g. "x86_64 clang-17"
35 std::vector<SelftestCaseResult> cases; // per-test results
36
37 // Render as human-readable multi-line text
38 std::string to_text() const;
39
40 // Render as JSON string
41 std::string to_json() const;
42};
43
44// Run comprehensive self-tests on the library
45// Returns true if all tests pass, false otherwise
46// Set verbose=true to see detailed test output
47bool Selftest(bool verbose);
48
49// Run self-tests with explicit mode and deterministic PRNG seed.
50// seed=0 uses default seed (deterministic but fixed).
51// Prints repro bundle: commit, compiler, platform, seed, mode.
52bool Selftest(bool verbose, SelftestMode mode, uint64_t seed = 0);
53
54// Run self-tests and return a structured report (no stdout output).
55// Suitable for bindings (Python, Rust, Node.js, etc.) that need
56// a programmatic result rather than console output.
58 uint64_t seed = 0);
59
60} // namespace secp256k1::fast
SelftestReport selftest_report(SelftestMode mode=SelftestMode::smoke, uint64_t seed=0)
bool Selftest(bool verbose)
std::string to_text() const
std::vector< SelftestCaseResult > cases
Definition selftest.hpp:35
std::string to_json() const