aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-09-10 10:46:04 +0200
committerSimon Warta <[email protected]>2015-09-10 10:46:04 +0200
commit8dc3b8993b39ac4d0603afc451a62222241c2e21 (patch)
tree26ff758819d333fd1559568a787f4a0d368105e0 /src
parentbdc6ea4fbc59673965b3eaefdd98d3ce3a9a5331 (diff)
parent90ce1d58e1c7ca4fb0d190a1e6f2535e4341ade8 (diff)
Merge pull request #278 from webmaster128/fuzzer_test
Update fuzzer test
Diffstat (limited to 'src')
-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;
}