Skip to content

Commit 4db111f

Browse files
kani list Workflow (#146)
Adds a workflow that runs `kani list` on the standard library and posts the results in a comment on the pull request. This workflow runs iff a pull request is merged, so that we have one comment at the end of a PR with the most up-to-date list results. (I considered other approaches, like running it on opening the PR or with every commit, but decided having one single comment with the final changes was best for brevity/clarity). See this [test PR](https://github.com/carolynzech/verify-rust-std/pull/10) on my fork as a demo of how it would work. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Celina G. Val <[email protected]>
1 parent 922c51a commit 4db111f

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

.github/workflows/kani.yml

+14
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,17 @@ jobs:
6565
- name: Test Kani script (In Repo Directory)
6666
working-directory: ${{github.workspace}}/head
6767
run: scripts/run-kani.sh --kani-args --harness ptr::verify::check_read_u128 --harness ptr --output-format=terse
68+
69+
# Step 4: Run list on the std library and add output to job summary
70+
- name: Run Kani List
71+
run: head/scripts/run-kani.sh --run list --path ${{github.workspace}}/head
72+
73+
- name: Add Kani List output to job summary
74+
uses: actions/github-script@v6
75+
with:
76+
script: |
77+
const fs = require('fs');
78+
const kaniOutput = fs.readFileSync('${{github.workspace}}/head/kani_list.txt', 'utf8');
79+
await core.summary
80+
.addRaw(kaniOutput)
81+
.write();

scripts/run-kani.sh

+28-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
set -e
44

55
usage() {
6-
echo "Usage: $0 [options] [-p <path>] [--kani-args <command arguments>]"
6+
echo "Usage: $0 [options] [-p <path>] [--run <verify-std|list>] [--kani-args <command arguments>]"
77
echo "Options:"
88
echo " -h, --help Show this help message"
99
echo " -p, --path <path> Optional: Specify a path to a copy of the std library. For example, if you want to run the script from an outside directory."
10+
echo " --run <verify-std|list> Optional: Specify whether to run 'verify-std' or 'list' command. Defaults to 'verify-std' if not specified."
1011
echo " --kani-args <command arguments to kani> Optional: Arguments to pass to the command. Simply pass them in the same way you would to the Kani binary. This should be the last argument."
1112
exit 1
1213
}
1314

1415
# Initialize variables
1516
command_args=""
1617
path=""
18+
run_command="verify-std"
1719

1820
# Parse command line arguments
1921
# TODO: Improve parsing with getopts
@@ -31,13 +33,23 @@ while [[ $# -gt 0 ]]; do
3133
usage
3234
fi
3335
;;
36+
--run)
37+
if [[ -n $2 && ($2 == "verify-std" || $2 == "list") ]]; then
38+
run_command=$2
39+
shift 2
40+
else
41+
echo "Error: Invalid run command. Must be 'verify-std' or 'list'."
42+
usage
43+
fi
44+
;;
3445
--kani-args)
3546
shift
3647
command_args="$@"
3748
break
3849
;;
3950
*)
40-
break
51+
echo "Error: Unknown option $1"
52+
usage
4153
;;
4254
esac
4355
done
@@ -181,9 +193,20 @@ main() {
181193
echo "Running Kani command..."
182194
"$kani_path" --version
183195

184-
echo "Running Kani verify-std command..."
185-
186-
"$kani_path" verify-std -Z unstable-options ./library --target-dir "$temp_dir_target" -Z function-contracts -Z mem-predicates -Z loop-contracts --output-format=terse $command_args --enable-unstable --cbmc-args --object-bits 12
196+
if [[ "$run_command" == "verify-std" ]]; then
197+
echo "Running Kani verify-std command..."
198+
"$kani_path" verify-std -Z unstable-options ./library --target-dir "$temp_dir_target" \
199+
-Z function-contracts \
200+
-Z mem-predicates \
201+
-Z loop-contracts \
202+
--output-format=terse \
203+
$command_args \
204+
--enable-unstable \
205+
--cbmc-args --object-bits 12
206+
elif [[ "$run_command" == "list" ]]; then
207+
echo "Running Kani list command..."
208+
"$kani_path" list -Z list -Z function-contracts -Z mem-predicates ./library --std > $path/kani_list.txt
209+
fi
187210
}
188211

189212
main

0 commit comments

Comments
 (0)