-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerate-files.sh
executable file
·125 lines (101 loc) · 2.97 KB
/
generate-files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
set -e
REPO_DIR=$(git rev-parse --show-toplevel)
# shellcheck source=./fuzz-util.sh
source "$REPO_DIR/fuzz/fuzz-util.sh"
# 1. Generate fuzz/Cargo.toml
cat > "$REPO_DIR/fuzz/Cargo.toml" <<EOF
[package]
name = "simplicity-fuzz"
edition = "2021"
rust-version = "1.78.0"
version = "0.0.1"
authors = ["Generated by fuzz/generate-files.sh"]
publish = false
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
simplicity-lang = { path = "..", features = ["test-utils"] }
[dev-dependencies]
base64 = "0.22.1"
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
EOF
for targetFile in $(listTargetFiles); do
targetName=$(targetFileToName "$targetFile")
cat >> "$REPO_DIR/fuzz/Cargo.toml" <<EOF
[[bin]]
name = "$targetName"
path = "$targetFile"
test = false
doc = false
bench = false
EOF
done
# 2. Generate .github/workflows/fuzz.yml
cat > "$REPO_DIR/.github/workflows/fuzz.yml" <<EOF
# Automatically generated by fuzz/generate-files.sh
name: Fuzz
on:
push:
branches:
- master
- 'test-ci/**'
pull_request:
jobs:
fuzz:
name: Run Fuzz Target
if: \${{ !github.event.act }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
fuzz_target: [
$(for name in $(listTargetNames); do echo "$name,"; done)
]
steps:
- name: Checkout Crate
uses: actions/checkout@v4
- name: Use Rust Cache
uses: actions/cache@v4
id: cache-fuzz
with:
path: |
~/.cargo/bin
fuzz/target
target
key: cache-\${{ matrix.target }}-\${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
- name: Install Toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-07-01
components: "llvm-tools-preview"
- name: Install Dependencies
run: cargo update && cargo update -p cc --precise 1.0.83 && cargo install --force cargo-fuzz
- name: Run Fuzz Target
run: ./fuzz/fuzz.sh "\${{ matrix.fuzz_target }}"
- name: Prepare Artifact
run: echo "\${{ matrix.fuzz_target }}" >executed_\${{ matrix.fuzz_target }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: executed_\${{ matrix.fuzz_target }}
path: executed_\${{ matrix.fuzz_target }}
verify-execution:
name: Verify Execution of All Targets
if: \${{ !github.event.act }}
needs: fuzz
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
uses: actions/checkout@v4
- name: Download All Artifacts
uses: actions/download-artifact@v4
- name: Display Structure of Downloaded Files
run: ls -R
- name: Write File With All Executed Targets
run: find executed_* -type f -exec cat {} + | sort > executed
- name: Compare Executed Targets With Available Targets
run: source ./fuzz/fuzz-util.sh && listTargetNames | sort | diff - executed
EOF