Skip to content

Commit f22f913

Browse files
committed
generate a fuzzing corpus by extracting code from testrunner
1 parent 10bab82 commit f22f913

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

.github/workflows/corpus.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
3+
name: corpus
4+
5+
on:
6+
schedule:
7+
- cron: '0 0 * * 0'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
corpus:
15+
runs-on: ubuntu-22.04
16+
if: ${{ github.repository_owner == 'danmar' }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
23+
- name: ccache
24+
uses: hendrikmuhs/[email protected]
25+
with:
26+
key: ${{ github.workflow }}-${{ runner.os }}
27+
28+
- name: build testrunner
29+
run: |
30+
set -x
31+
store_dir=$(pwd)/store
32+
mkdir $store_dir
33+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
34+
make -j$(nproc) -s CXXFLAGS="-w -DSTORE_INPUT_DIR=\"$store_dir\"" testrunner
35+
36+
- name: run testrunner
37+
run: |
38+
./testrunner
39+
ls -l ./store | wc -l
40+
41+
# TODO: dedup
42+
43+
- uses: actions/upload-artifact@v4
44+
if: success()
45+
with:
46+
name: corpus
47+
path: ./store

lib/tokenlist.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,30 @@ bool TokenList::createTokens(std::istream &code, Standards::Language lang)
361361

362362
//---------------------------------------------------------------------------
363363

364+
#ifdef STORE_INPUT_DIR
365+
#include <atomic>
366+
#include <fstream>
367+
#include <sstream>
368+
369+
static void storeInput(std::istream &code)
370+
{
371+
static std::atomic_uint64_t num(0);
372+
{
373+
std::ostringstream oss;
374+
oss << code.rdbuf();
375+
code.seekg(0);
376+
std::ofstream out(STORE_INPUT_DIR "/" + std::to_string(num++));
377+
out << oss.str();
378+
}
379+
}
380+
#endif
381+
364382
bool TokenList::createTokensInternal(std::istream &code, const std::string& file0)
365383
{
384+
#ifdef STORE_INPUT_DIR
385+
storeInput(code);
386+
#endif
387+
366388
simplecpp::OutputList outputList;
367389
simplecpp::TokenList tokens(code, mFiles, file0, &outputList);
368390

0 commit comments

Comments
 (0)