Skip to content

Commit 2681f33

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

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

.github/workflows/corpus.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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: Install missing software on ubuntu
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y fdupes
32+
33+
- name: build testrunner
34+
run: |
35+
set -x
36+
store_dir=$(pwd)/store
37+
mkdir $store_dir
38+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
39+
make -s -j$(nproc) CXXFLAGS="-w -DSTORE_INPUT_DIR=\"\\\"$store_dir\\\"\"" testrunner
40+
41+
- name: run testrunner
42+
run: |
43+
./testrunner -q
44+
45+
- name: de-duplicate files
46+
run: |
47+
ls -l ./store | wc -l
48+
echo "removing duplicates"
49+
fdupes -qdN ./store > /dev/null
50+
ls -l ./store | wc -l
51+
# print biggest size
52+
ls -l ./store | cut -d' ' -f5 | sort -u -n -r | head -n1
53+
54+
# TODO: dedup with fuzzer?
55+
56+
- uses: actions/upload-artifact@v4
57+
if: success()
58+
with:
59+
name: corpus
60+
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)