Skip to content

Commit 5e65ebf

Browse files
committed
generate a fuzzing corpus by extracting code from testrunner [skip ci]
1 parent a4723c5 commit 5e65ebf

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

.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
@@ -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 testrunner 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)