62 lines
2.0 KiB
C++
62 lines
2.0 KiB
C++
// Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
// 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;
|
|
}
|