Skip to content

Commit 2370ad9

Browse files
committed
generate a fuzzing corpus by extracting code from testrunner
1 parent a04cac4 commit 2370ad9

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

.github/workflows/fuzz.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ jobs:
3434
chmod +x llvm.sh
3535
sudo ./llvm.sh 21
3636
37+
- name: Generate corpus
38+
run: |
39+
mkdir corpus_test
40+
make testrunner CXXOPTS="-DSTORE_INPUT_DIR=\"\\\"$(pwd)/corpus_test\\\"\""
41+
./testrunner
42+
43+
- name: Upload corpus (testrunner)
44+
uses: actions/upload-artifact@v6
45+
with:
46+
name: corpus_test
47+
path: ./corpus_test
48+
3749
- name: Build fuzzer
3850
id: build
3951
run: |

test.cpp

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

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

83+
#ifdef STORE_INPUT_DIR
84+
// make testrunner CXXOPTS="-DSTORE_INPUT_DIR=\"\\\"/home/user/simple_corpus\\\"\""
85+
#include <atomic>
86+
#include <fstream>
87+
88+
static void storeInput(const std::string& str)
89+
{
90+
static std::atomic_uint64_t num(0);
91+
{
92+
std::ofstream out(STORE_INPUT_DIR "/" + std::to_string(num++));
93+
out << str;
94+
}
95+
}
96+
#endif
97+
8398
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)
8499
{
85-
std::istringstream istr(std::string(code, size));
100+
const std::string str(code, size);
101+
#ifdef STORE_INPUT_DIR
102+
storeInput(str);
103+
#endif
104+
std::istringstream istr(str);
86105
return {istr,filenames,filename,outputList};
87106
}
88107

0 commit comments

Comments
 (0)