aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Gierlings <[email protected]>2018-04-07 17:47:11 +0200
committerMatthias Gierlings <[email protected]>2018-04-07 18:03:37 +0200
commita96d1ca450a9cadea8157f3295a970af1f16a58f (patch)
tree08ff02463b8e61f1caf123ca4799c62347dcae34 /src
parent4476c07bae00dc2cec5183878d81b3e53ff3b97e (diff)
Moves UBSAN macros from test files to Test_Options
To keep the code more readable change the behavior of `Test_Options::no_avoid_undefined_behavior()`, instead of the conditionals inside the tests. `Test_Options::no_avoid_undefined_behavior()` will always return `true` if UBSAN is inactive. This way all tests, including those that cause undefined behaviour, will run. Once botan is compiled with UBSAN those tests will be automatically skipped unless the `--no-avoid-undefined` is passed to the test-bench.
Diffstat (limited to 'src')
-rw-r--r--src/tests/test_dl_group.cpp5
-rw-r--r--src/tests/test_ffi.cpp4
-rw-r--r--src/tests/tests.h9
-rw-r--r--src/tests/unit_ecdsa.cpp4
4 files changed, 9 insertions, 13 deletions
diff --git a/src/tests/test_dl_group.cpp b/src/tests/test_dl_group.cpp
index c9e654bd7..064cb2221 100644
--- a/src/tests/test_dl_group.cpp
+++ b/src/tests/test_dl_group.cpp
@@ -44,19 +44,16 @@ class DL_Group_Tests final : public Test
"DL_Group uninitialized",
[]() { Botan::DL_Group dl; dl.get_p(); });
-#if defined(BOTAN_HAS_SANITIZER_UNDEFINED)
if(Test::no_avoid_undefined_behavior())
{
-#endif
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 defined(BOTAN_HAS_SANITIZER_UNDEFINED)
}
-#endif
+
return result;
}
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp
index 0d831f251..d5627a45f 100644
--- a/src/tests/test_ffi.cpp
+++ b/src/tests/test_ffi.cpp
@@ -842,18 +842,14 @@ class FFI_Unit_Tests final : public Test
// delete of null is ok/ignored
TEST_FFI_RC(0, botan_hash_destroy, (nullptr));
-#if defined(BOTAN_HAS_SANITIZER_UNDEFINED)
if(Test::no_avoid_undefined_behavior())
{
-#endif
// 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 defined(BOTAN_HAS_SANITIZER_UNDEFINED)
}
-#endif
return result;
}
diff --git a/src/tests/tests.h b/src/tests/tests.h
index 56aa4b8c5..8551e4e4d 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -97,7 +97,14 @@ class Test_Options
bool abort_on_first_fail() const { return m_abort_on_first_fail; }
- bool no_avoid_undefined_behavior() const { return m_no_avoid_undefined; }
+ bool no_avoid_undefined_behavior() const
+ {
+#if defined(BOTAN_HAS_SANITIZER_UNDEFINED)
+ return m_no_avoid_undefined;
+#else
+ return true;
+#endif
+ }
private:
std::vector<std::string> m_requested_tests;
diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp
index f94f445ee..e21d4764c 100644
--- a/src/tests/unit_ecdsa.cpp
+++ b/src/tests/unit_ecdsa.cpp
@@ -299,18 +299,14 @@ Test::Result test_encoding_options()
result.test_eq("Hybrid point same size as uncompressed",
enc_uncompressed.size(), enc_hybrid.size());
-#if defined(BOTAN_HAS_SANITIZER_UNDEFINED)
if(Test::no_avoid_undefined_behavior())
{
-#endif
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); });
-#if defined(BOTAN_HAS_SANITIZER_UNDEFINED)
}
-#endif
return result;
}