aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tests/test_bigint.cpp36
-rw-r--r--src/tests/tests.cpp17
-rw-r--r--src/tests/tests.h4
-rw-r--r--src/tests/unit_tls.cpp20
4 files changed, 70 insertions, 7 deletions
diff --git a/src/tests/test_bigint.cpp b/src/tests/test_bigint.cpp
index 07158fee1..96ec035fe 100644
--- a/src/tests/test_bigint.cpp
+++ b/src/tests/test_bigint.cpp
@@ -80,11 +80,29 @@ class BigInt_Unit_Tests : public Test
{
Test::Result result("BigInt::random_integer");
- const size_t ITERATIONS = 1000;
+ result.start_timer();
- for(size_t range_min : { 0, 10, 100 })
+ const size_t ITERATIONS = 5000;
+
+ std::vector<size_t> min_ranges{ 0 };
+ std::vector<size_t> max_ranges{ 10 };
+
+ // This gets slow quickly:
+ if(Test::soak_level() > 10)
{
- for(size_t range_max : { 0, 10, 100 })
+ min_ranges.push_back(10);
+ max_ranges.push_back(100);
+
+ if(Test::soak_level() > 50)
+ {
+ min_ranges.push_back(79);
+ max_ranges.push_back(293);
+ }
+ }
+
+ for(size_t range_min : min_ranges)
+ {
+ for(size_t range_max : max_ranges)
{
if(range_min >= range_max)
continue;
@@ -104,14 +122,22 @@ class BigInt_Unit_Tests : public Test
double ratio = static_cast<double>(counts[i]) / ITERATIONS;
double dev = std::min(ratio, std::fabs(1.0 - ratio));
- if(dev > .15)
+ if(dev < .15)
{
- result.test_failure("random_integer distribution" + std::to_string(dev));
+ result.test_success("distribution within expected range");
+ }
+ else
+ {
+ result.test_failure("distribution " + std::to_string(dev) +
+ " outside expected range with count" +
+ std::to_string(counts[i]));
}
}
}
}
+ result.end_timer();
+
return result;
}
};
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 704ff36a8..3137c5ba7 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -37,6 +37,23 @@ void Test::Result::merge(const Result& other)
m_log.insert(m_log.end(), other.m_log.begin(), other.m_log.end());
}
+void Test::Result::start_timer()
+ {
+ if(m_started == 0)
+ {
+ m_started = Test::timestamp();
+ }
+ }
+
+void Test::Result::end_timer()
+ {
+ if(m_started > 0)
+ {
+ m_ns_taken += Test::timestamp() - m_started;
+ m_started = 0;
+ }
+ }
+
void Test::Result::test_note(const std::string& note)
{
if(note != "")
diff --git a/src/tests/tests.h b/src/tests/tests.h
index c431eb6bd..09d89459d 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -206,8 +206,12 @@ class Test
void set_ns_consumed(uint64_t ns) { m_ns_taken = ns; }
+ void start_timer();
+ void end_timer();
+
private:
std::string m_who;
+ uint64_t m_started = 0;
uint64_t m_ns_taken = 0;
size_t m_tests_passed = 0;
std::vector<std::string> m_fail_log;
diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp
index 6c15ec4e9..8502352fc 100644
--- a/src/tests/unit_tls.cpp
+++ b/src/tests/unit_tls.cpp
@@ -173,6 +173,8 @@ Test::Result test_tls_handshake(Botan::TLS::Protocol_Version offer_version,
{
bool handshake_done = false;
+ result.test_note("Test round " + std::to_string(r));
+
auto handshake_complete = [&](const Botan::TLS::Session& session) -> bool {
handshake_done = true;
@@ -279,7 +281,14 @@ Test::Result test_tls_handshake(Botan::TLS::Protocol_Version offer_version,
}
catch(std::exception& e)
{
- result.test_failure("server error", e.what());
+ if(corrupt_server_data)
+ {
+ result.test_note("corruption caused server exception");
+ }
+ else
+ {
+ result.test_failure("server error", e.what());
+ }
continue;
}
@@ -294,7 +303,14 @@ Test::Result test_tls_handshake(Botan::TLS::Protocol_Version offer_version,
}
catch(std::exception& e)
{
- result.test_failure("client error", e.what());
+ if(corrupt_client_data)
+ {
+ result.test_note("corruption caused client exception");
+ }
+ else
+ {
+ result.test_failure("client error", e.what());
+ }
continue;
}