aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-09-10 10:03:25 +0200
committerSimon Warta <[email protected]>2015-09-10 10:07:56 +0200
commit90ce1d58e1c7ca4fb0d190a1e6f2535e4341ade8 (patch)
treeb5a11018f5c4179020aa019ded763e9415e165db /src/tests
parenta96a7b79662f5045f0810dfa5d5cb4ebbd04ae42 (diff)
Update fuzzer test
* Handle No_Filesystem_Access case properly * Use steady_clock for benchmarking Fixes #276
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_fuzzer.cpp67
1 files changed, 39 insertions, 28 deletions
diff --git a/src/tests/test_fuzzer.cpp b/src/tests/test_fuzzer.cpp
index 212a313a8..f2343dc1f 100644
--- a/src/tests/test_fuzzer.cpp
+++ b/src/tests/test_fuzzer.cpp
@@ -8,61 +8,72 @@
#include <chrono>
#include <iostream>
-#if defined(BOTAN_HAS_X509_CERTIFICATES)
+#include <botan/internal/filesystem.h>
+#if defined(BOTAN_HAS_X509_CERTIFICATES)
#include <botan/x509cert.h>
#include <botan/x509_crl.h>
-#include <botan/internal/filesystem.h>
#include <botan/base64.h>
-
#endif
+using namespace Botan;
+
namespace {
+const std::string TEST_DATA_DIR_FUZZ_X509 = TEST_DATA_DIR "/fuzz/x509";
+
+#if defined(BOTAN_HAS_X509_CERTIFICATES)
size_t test_x509_fuzz()
{
size_t fails = 0;
-
-#if defined(BOTAN_HAS_X509_CERTIFICATES)
-
size_t tests = 0;
- const std::string fuzz_data = TEST_DATA_DIR "/fuzz";
- for(auto vec: Botan::get_files_recursive(fuzz_data + "/x509"))
+ try
{
- ++tests;
-
- auto start = std::chrono::system_clock::now();
- try
+ for(auto vec_file: get_files_recursive(TEST_DATA_DIR_FUZZ_X509))
{
- // TODO: check for memory consumption?
- Botan::X509_Certificate cert(vec);
+ ++tests;
+
+ auto start = std::chrono::steady_clock::now();
+ try
+ {
+ // TODO: check for memory consumption?
+ X509_Certificate cert(vec_file);
+ }
+ catch(std::exception& e)
+ {
+ //std::cout << e.what() << "\n";
+ }
+ auto end = std::chrono::steady_clock::now();
+
+ uint64_t duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
+
+ if(duration > 100)
+ {
+ std::cout << "Fuzzer test " << vec_file << " took " << duration << " ms" << std::endl;
+ }
}
- catch(std::exception& e)
- {
- //std::cout << e.what() << "\n";
- }
- auto end = std::chrono::system_clock::now();
-
- uint64_t duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
- if(duration > 100)
- {
- std::cout << "Fuzzer test " << vec << " took " << duration << " ms" << std::endl;
- }
+ test_report("Fuzzer checks", tests, fails);
+ }
+ catch(No_Filesystem_Access)
+ {
+ std::cout << "Warning: No filesystem access available to read test files in '"
+ << TEST_DATA_DIR_FUZZ_X509 << "'" << std::endl;
+ return 0;
}
-
- test_report("Fuzzer checks", tests, fails);
-#endif
return fails;
}
+#endif
}
size_t test_fuzzer()
{
size_t fails = 0;
+#if defined(BOTAN_HAS_X509_CERTIFICATES)
fails += test_x509_fuzz();
+#endif
return fails;
}