Testing: add bounded corpus runner (M-TESTING-05)
This commit is contained in:
1 parent
d338305cc7
commit
80e6ed9afc
3 files changed
+263
No files matched your search
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Testing
|
||||
{
|
||||
/// Bounds for one corpus replay.
|
||||
struct CorpusLimits {
|
||||
/// Files larger than this are rejected instead of read.
|
||||
std::size_t max_input_bytes{1024ULL * 1024ULL};
|
||||
/// Maximum number of files replayed; the rest are reported as
|
||||
/// truncated so a huge directory cannot stall a run.
|
||||
std::size_t max_files{10000};
|
||||
};
|
||||
|
||||
/// One failing input and why it failed.
|
||||
struct CorpusFailure {
|
||||
std::filesystem::path path{};
|
||||
std::string message{};
|
||||
};
|
||||
|
||||
struct CorpusReport {
|
||||
std::size_t files{0};
|
||||
std::size_t passed{0};
|
||||
std::size_t failed{0};
|
||||
/// True when max_files cut the replay short.
|
||||
bool truncated{false};
|
||||
std::vector<CorpusFailure> failures{};
|
||||
};
|
||||
|
||||
/// A single corpus case: success means the input was handled correctly.
|
||||
using CorpusCase =
|
||||
std::function<Void::Result::Result<void>(std::span<const std::byte>)>;
|
||||
|
||||
/// Replay every regular file in `directory` (sorted, non-recursive).
|
||||
///
|
||||
/// Each file is bounded by `limits.max_input_bytes`; a case failure,
|
||||
/// exception or oversized file is recorded and the replay continues, so
|
||||
/// one bad input never hides the rest. A missing directory is an error.
|
||||
[[nodiscard]] Void::Result::Result<CorpusReport>
|
||||
run_corpus(const std::filesystem::path& directory,
|
||||
const CorpusCase& run,
|
||||
CorpusLimits limits = {});
|
||||
} // namespace Void::Testing
|
||||
Reference in new issue
Block a user