aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tests/main.cpp9
-rw-r--r--src/tests/test_dl_group.cpp15
-rw-r--r--src/tests/test_ffi.cpp13
-rw-r--r--src/tests/test_runner.cpp2
-rw-r--r--src/tests/test_runner.h1
-rw-r--r--src/tests/tests.cpp9
-rw-r--r--src/tests/tests.h3
-rw-r--r--src/tests/unit_ecdsa.cpp11
8 files changed, 45 insertions, 18 deletions
diff --git a/src/tests/main.cpp b/src/tests/main.cpp
index f4ee76b57..f8aa2fe08 100644
--- a/src/tests/main.cpp
+++ b/src/tests/main.cpp
@@ -59,8 +59,9 @@ int main(int argc, char* argv[])
try
{
const std::string arg_spec =
- "botan-test --data-dir= --pkcs11-lib= --provider= --log-success --abort-on-first-fail "
- "--verbose --help --run-long-tests --run-online-tests --test-runs=1 --drbg-seed= "
+ "botan-test --verbose --help --data-dir= --pkcs11-lib= --provider= "
+ "--log-success --abort-on-first-fail --avoid-undefined "
+ "--run-long-tests --run-online-tests --test-runs=1 --drbg-seed= "
"*suites";
Botan_CLI::Argument_Parser parser(arg_spec);
@@ -82,6 +83,7 @@ int main(int argc, char* argv[])
const bool log_success = parser.flag_set("log-success");
const bool run_long_tests = parser.flag_set("run-long-tests");
const bool run_online_tests = parser.flag_set("run-online-tests");
+ const bool avoid_undefined = parser.flag_set("avoid-undefined");
const size_t test_runs = parser.get_arg_sz("test-runs");
const std::vector<std::string> suites = parser.get_arg_list("suites");
@@ -97,7 +99,8 @@ int main(int argc, char* argv[])
return tests.run(suites, data_dir, pkcs11_lib, provider,
log_success, run_online_tests, run_long_tests,
- abort_on_first_fail, drbg_seed, test_runs);
+ abort_on_first_fail, avoid_undefined,
+ drbg_seed, test_runs);
}
catch(std::exception& e)
{
diff --git a/src/tests/test_dl_group.cpp b/src/tests/test_dl_group.cpp
index 2644d5e1a..10a7e3bc6 100644
--- a/src/tests/test_dl_group.cpp
+++ b/src/tests/test_dl_group.cpp
@@ -44,12 +44,15 @@ class DL_Group_Tests final : public Test
"DL_Group uninitialized",
[]() { Botan::DL_Group dl; dl.get_p(); });
- result.test_throws("Bad generator param",
- "Invalid argument DL_Group unknown PrimeType",
- []() {
- auto invalid_type = static_cast<Botan::DL_Group::PrimeType>(9);
- Botan::DL_Group dl(Test::rng(), invalid_type, 1024);
- });
+ if(Test::avoid_undefined_behavior() == false)
+ {
+ result.test_throws("Bad generator param",
+ "Invalid argument DL_Group unknown PrimeType",
+ []() {
+ auto invalid_type = static_cast<Botan::DL_Group::PrimeType>(9);
+ Botan::DL_Group dl(Test::rng(), invalid_type, 1024);
+ });
+ }
return result;
}
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp
index 1eb796923..58b9852a0 100644
--- a/src/tests/test_ffi.cpp
+++ b/src/tests/test_ffi.cpp
@@ -842,11 +842,14 @@ class FFI_Unit_Tests final : public Test
// delete of null is ok/ignored
TEST_FFI_RC(0, botan_hash_destroy, (nullptr));
- // Confirm that botan_x_destroy checks the argument type
- botan_mp_t mp;
- botan_mp_init(&mp);
- TEST_FFI_RC(BOTAN_FFI_ERROR_INVALID_OBJECT, botan_hash_destroy, (reinterpret_cast<botan_hash_t>(mp)));
- TEST_FFI_RC(0, botan_mp_destroy, (mp));
+ if(Test::avoid_undefined_behavior() == false)
+ {
+ // Confirm that botan_x_destroy checks the argument type
+ botan_mp_t mp;
+ botan_mp_init(&mp);
+ TEST_FFI_RC(BOTAN_FFI_ERROR_INVALID_OBJECT, botan_hash_destroy, (reinterpret_cast<botan_hash_t>(mp)));
+ TEST_FFI_RC(0, botan_mp_destroy, (mp));
+ }
return result;
}
diff --git a/src/tests/test_runner.cpp b/src/tests/test_runner.cpp
index d8491ab73..9b4e14a7a 100644
--- a/src/tests/test_runner.cpp
+++ b/src/tests/test_runner.cpp
@@ -94,6 +94,7 @@ int Test_Runner::run(const std::vector<std::string>& requested_tests,
bool run_online_tests,
bool run_long_tests,
bool abort_on_first_fail,
+ bool avoid_undefined,
const std::string& drbg_seed,
size_t runs)
{
@@ -182,6 +183,7 @@ int Test_Runner::run(const std::vector<std::string>& requested_tests,
run_online_tests,
run_long_tests,
abort_on_first_fail,
+ avoid_undefined,
data_dir,
pkcs11_lib,
pf);
diff --git a/src/tests/test_runner.h b/src/tests/test_runner.h
index 5ae986bc9..76d669fc5 100644
--- a/src/tests/test_runner.h
+++ b/src/tests/test_runner.h
@@ -26,6 +26,7 @@ class Test_Runner final
bool run_online_tests,
bool run_long_tests,
bool abort_on_first_fail,
+ bool avoid_undefined,
const std::string& drbg_seed,
size_t runs);
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 2aa1a9d75..a22b1bb0c 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -559,6 +559,7 @@ bool Test::m_log_success = false;
bool Test::m_run_online_tests = false;
bool Test::m_run_long_tests = false;
bool Test::m_abort_on_first_fail = false;
+bool Test::m_avoid_undefined = false;
std::string Test::m_pkcs11_lib;
Botan_Tests::Provider_Filter Test::m_provider_filter;
@@ -567,6 +568,7 @@ void Test::set_test_options(bool log_success,
bool run_online,
bool run_long,
bool abort_on_first_fail,
+ bool avoid_undefined,
const std::string& data_dir,
const std::string& pkcs11_lib,
const Botan_Tests::Provider_Filter& pf)
@@ -576,6 +578,7 @@ void Test::set_test_options(bool log_success,
m_run_online_tests = run_online;
m_run_long_tests = run_long;
m_abort_on_first_fail = abort_on_first_fail;
+ m_avoid_undefined = avoid_undefined;
m_pkcs11_lib = pkcs11_lib;
m_provider_filter = pf;
}
@@ -605,6 +608,12 @@ bool Test::log_success()
}
//static
+bool Test::avoid_undefined_behavior()
+ {
+ return m_avoid_undefined;
+ }
+
+//static
bool Test::run_online_tests()
{
return m_run_online_tests;
diff --git a/src/tests/tests.h b/src/tests/tests.h
index fd7daca17..ea5be0a95 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -409,12 +409,14 @@ class Test
bool run_online_tests,
bool run_long_tests,
bool abort_on_first_fail,
+ bool avoid_undefined,
const std::string& data_dir,
const std::string& pkcs11_lib,
const Botan_Tests::Provider_Filter& pf);
static void set_test_rng(std::unique_ptr<Botan::RandomNumberGenerator> rng);
+ static bool avoid_undefined_behavior();
static bool log_success();
static bool run_online_tests();
static bool run_long_tests();
@@ -437,6 +439,7 @@ class Test
static bool m_run_online_tests;
static bool m_run_long_tests;
static bool m_abort_on_first_fail;
+ static bool m_avoid_undefined;
static std::string m_pkcs11_lib;
static Botan_Tests::Provider_Filter m_provider_filter;
};
diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp
index f91c1b345..016906e66 100644
--- a/src/tests/unit_ecdsa.cpp
+++ b/src/tests/unit_ecdsa.cpp
@@ -299,11 +299,14 @@ Test::Result test_encoding_options()
result.test_eq("Hybrid point same size as uncompressed",
enc_uncompressed.size(), enc_hybrid.size());
- auto invalid_format = static_cast<Botan::PointGFp::Compression_Type>(99);
+ if(Test::avoid_undefined_behavior() == false)
+ {
+ auto invalid_format = static_cast<Botan::PointGFp::Compression_Type>(99);
- result.test_throws("Invalid point format throws",
- "Invalid argument Invalid point encoding for EC_PublicKey",
- [&] { key.set_point_encoding(invalid_format); });
+ result.test_throws("Invalid point format throws",
+ "Invalid argument Invalid point encoding for EC_PublicKey",
+ [&] { key.set_point_encoding(invalid_format); });
+ }
return result;
}