Files
conflict-range/cpp/tests/fuzz_readable.cpp
T
andrew 273ad72f0c Polish release docs and add CI checks
- Correct stale references and headline-path wording in READMEs and Lean docstrings
- Document build steps, comparator requirements, sweep scope, and coverage
- Unify Apache headers across Lean and C++ sources
- Add a bwrap-free axiom audit for the headline theorems
- Add a Gitea workflow running lake build, the axiom audit, C++ tests, and coverage
- Match LLVM coverage tool versions to the compiler and recreate stale build dirs
2026-11-17 21:29:16 -05:00

64 lines
2.1 KiB
C++

// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
// Released under Apache 2.0 license as described in the file LICENSE.
// Authors: FormalConflictRange contributors
// libFuzzer differential harness: the literal translation versus the
// summarised implementation, on readable-by-construction instances.
#include <cstddef>
#include <cstdint>
#include <string>
#include <cstdio>
#include <cstdlib>
#include "../src/fast.h"
#include "../src/literal.h"
#include "readable_gen.h"
namespace {
std::string enc(cr::OptKeyView k) {
if (!k) return "T";
if (k->empty()) return "-";
static const char* d = "0123456789abcdef";
std::string s;
for (char c : *k) {
auto b = static_cast<cr::Byte>(c);
s.push_back(d[b >> 4]);
s.push_back(d[b & 15]);
}
return s;
}
std::string enc(const cr::OptKey& k) { return enc(cr::optView(k)); }
} // namespace
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
std::size_t size) {
cr::gen::Bytes bytes{data, size, 0};
for (int i = 0; i < 8; ++i) {
cr::gen::Instance inst = cr::gen::readable(bytes);
cr::RangeRead r = inst.read();
cr::Result res = inst.result();
cr::ConflictRange lit = cr::literal::closedForm(r, res);
cr::ConflictRange fast = cr::fast::closedForm(r, res);
if (!cr::gen::equivalent(lit, fast)) {
std::fprintf(stderr,
"MISMATCH literal [%s,%s) fast [%s,%s)\n"
" beginKey=%s beginOffset=%lld endKey=%s endOffset=%lld "
"reverse=%d more=%d n=%zu\n",
enc(lit.begin).c_str(), enc(lit.end_).c_str(),
enc(fast.begin).c_str(), enc(fast.end_).c_str(),
enc(r.begin.key).c_str(),
static_cast<long long>(r.begin.offset),
enc(r.end_.key).c_str(),
static_cast<long long>(r.end_.offset), (int)r.reverse,
(int)res.more, res.keys.size());
for (cr::KeyView k : res.keys)
std::fprintf(stderr, " key %s\n", enc(k).c_str());
std::abort();
}
}
return 0;
}