Skip to content

Commit f942fe4

Browse files
committed
generate a fuzzing corpus by extracting code from testrunner [skip ci]
1 parent 00a131e commit f942fe4

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

test.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,28 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons
7979

8080
#define TEST_CASE(F) (testcase(#F, F, argc, argv))
8181

82+
#ifdef STORE_INPUT_DIR
83+
// make test CXXOPTS="-DSTORE_INPUT_DIR=\"\\\"/home/user/simple_corpus\\\"\""
84+
#include <atomic>
85+
#include <fstream>
86+
87+
static void storeInput(const std::string& str)
88+
{
89+
static std::atomic_uint64_t num(0);
90+
{
91+
std::ofstream out(STORE_INPUT_DIR "/" + std::to_string(num++));
92+
out << str;
93+
}
94+
}
95+
#endif
96+
8297
static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
8398
{
84-
std::istringstream istr(std::string(code, size));
99+
const std::string str(code, size);
100+
#ifdef STORE_INPUT_DIR
101+
storeInput(str);
102+
#endif
103+
std::istringstream istr(str);
85104
return simplecpp::TokenList(istr,filenames,filename,outputList);
86105
}
87106

0 commit comments

Comments
 (0)