Skip to content

Commit 38f4c41

Browse files
authored
Parse log file of multi-threaded Kani run (terse output) into JSON (#324)
Given a run of Kani on the standard library with `--jobs=<N> --output-format=terse` (and, typically, `autoharness`) enabled this produces a machine-processable JSON result via ``` python3 log_parser.py \ --kani-list-file kani-list.json \ --analysis-results-dir std_lib_analysis/results/ \ verification.log -o results.json ``` where each entry in the resulting JSON array is of the form ``` { "thread_id": int, "result": { "harness": string, "is_autoharness": bool, "autoharness_result": string, "with_contract": bool, "crate": string, "function": string, "function_safeness": string, "file_name": string, "n_failed_properties": int, "n_total_properties": int, "result": string, "time": string, "output": array } } ``` With the help of `jq` one can then conveniently compute various metrics, e.g., ``` jq 'map(select(.result.result == "SUCCESSFUL" and .result.is_autoharness == true and .result.crate == "core" and .result.function_safeness == "unsafe" and .result.with_contract == true)) | length' results.json ``` to find the number of successfully-verified contracts of unsafe functions in crate `core` that were verified using automatically generated harnesses. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 30d156b commit 38f4c41

File tree

4 files changed

+689
-4
lines changed

4 files changed

+689
-4
lines changed

.github/workflows/kani-metrics.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ jobs:
2626
python-version: '3.x'
2727

2828
- name: Compute Kani Metrics
29-
run: ./scripts/run-kani.sh --run metrics --with-autoharness --path ${{github.workspace}}
29+
run: |
30+
./scripts/run-kani.sh --run metrics --with-autoharness --path ${{github.workspace}}
31+
rm kani-list.json
3032
3133
- name: Create Pull Request
3234
uses: peter-evans/create-pull-request@v7

.github/workflows/kani.yml

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Run Kani Verification
5454
run: head/scripts/run-kani.sh --path ${{github.workspace}}/head
5555

56-
kani-autoharness:
56+
kani_autoharness:
5757
name: Verify std library using autoharness
5858
runs-on: ${{ matrix.os }}
5959
strategy:
@@ -124,7 +124,121 @@ jobs:
124124
--exclude-pattern ::precondition_check \
125125
--harness-timeout 10m \
126126
--default-unwind 1000 \
127-
--jobs=3 --output-format=terse
127+
--jobs=3 --output-format=terse | tee autoharness-verification.log
128+
gzip autoharness-verification.log
129+
130+
- name: Upload Autoharness Verification Log
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: ${{ matrix.os }}-autoharness-verification.log.gz
134+
path: autoharness-verification.log.gz
135+
if-no-files-found: error
136+
# Aggressively short retention: we don't really need these
137+
retention-days: 3
138+
139+
run_kani_metrics:
140+
name: Kani Metrics
141+
runs-on: ${{ matrix.os }}
142+
strategy:
143+
matrix:
144+
os: [ubuntu-latest, macos-latest]
145+
include:
146+
- os: ubuntu-latest
147+
base: ubuntu
148+
- os: macos-latest
149+
base: macos
150+
fail-fast: true
151+
152+
steps:
153+
# Step 1: Check out the repository
154+
- name: Checkout Repository
155+
uses: actions/checkout@v4
156+
with:
157+
submodules: true
158+
159+
# The Kani metrics collection uses a Python script (kani_std_analysis.py), so make sure Python is installed
160+
- name: Set up Python
161+
uses: actions/setup-python@v4
162+
with:
163+
python-version: '3.x'
164+
165+
# Step 2: Run list on the std library
166+
- name: Run Kani Metrics
167+
run: |
168+
scripts/run-kani.sh --run metrics --with-autoharness
169+
pushd /tmp/std_lib_analysis
170+
tar czf results.tar.gz results
171+
popd
172+
173+
- name: Upload kani-list.json
174+
uses: actions/upload-artifact@v4
175+
with:
176+
name: ${{ matrix.os }}-kani-list.json
177+
path: kani-list.json
178+
if-no-files-found: error
179+
# Aggressively short retention: we don't really need these
180+
retention-days: 3
181+
182+
- name: Upload scanner results
183+
uses: actions/upload-artifact@v4
184+
with:
185+
name: ${{ matrix.os }}-results.tar.gz
186+
path: /tmp/std_lib_analysis/results.tar.gz
187+
if-no-files-found: error
188+
# Aggressively short retention: we don't really need these
189+
retention-days: 3
190+
191+
run-log-analysis:
192+
name: Build JSON from logs
193+
needs: [run_kani_metrics, kani_autoharness]
194+
runs-on: ${{ matrix.os }}
195+
strategy:
196+
matrix:
197+
os: [ubuntu-latest, macos-latest]
198+
include:
199+
- os: ubuntu-latest
200+
base: ubuntu
201+
- os: macos-latest
202+
base: macos
203+
fail-fast: false
204+
205+
steps:
206+
- name: Checkout Repository
207+
uses: actions/checkout@v4
208+
with:
209+
submodules: false
210+
211+
- name: Download log
212+
uses: actions/download-artifact@v4
213+
with:
214+
name: ${{ matrix.os }}-autoharness-verification.log.gz
215+
216+
- name: Download kani-list.json
217+
uses: actions/download-artifact@v4
218+
with:
219+
name: ${{ matrix.os }}-kani-list.json
220+
221+
- name: Download scanner results
222+
uses: actions/download-artifact@v4
223+
with:
224+
name: ${{ matrix.os }}-results.tar.gz
225+
226+
- name: Run log parser
227+
run: |
228+
gunzip autoharness-verification.log.gz
229+
tar xzf results.tar.gz
230+
python3 scripts/kani-std-analysis/log_parser.py \
231+
--kani-list-file kani-list.json \
232+
--analysis-results-dir results/ \
233+
autoharness-verification.log \
234+
-o results.json
235+
236+
- name: Upload JSON
237+
uses: actions/upload-artifact@v4
238+
with:
239+
name: ${{ matrix.os }}-results.json
240+
path: results.json
241+
if-no-files-found: error
128242

129243
run-kani-list:
130244
name: Kani List

0 commit comments

Comments
 (0)