Skip to content

Commit 2bf8392

Browse files
committed
read from kani-list.json
1 parent 4e9f6b2 commit 2bf8392

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

scripts/run-kani.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ TOML_FILE=${KANI_TOML_FILE:-$DEFAULT_TOML_FILE}
7777
REPO_URL=${KANI_REPO_URL:-$DEFAULT_REPO_URL}
7878
BRANCH_NAME=${KANI_BRANCH_NAME:-$DEFAULT_BRANCH_NAME}
7979

80+
# Kani list related variables, set in get_harnesses(); these are only used to parallelize harness verification
81+
declare -a ALL_HARNESSES
82+
declare -i HARNESS_COUNT
83+
8084
# Function to read commit ID from TOML file
8185
read_commit_from_toml() {
8286
local file="$1"
@@ -151,16 +155,17 @@ get_kani_path() {
151155
echo "$(realpath "$build_dir/scripts/kani")"
152156
}
153157

158+
# Run kani list with JSON format and process with jq to extract all harness names
159+
# Note: This code is based on `kani list` JSON version 0.1 -- if the version changes, this logic may need to change as well.
154160
get_harnesses() {
155161
local kani_path="$1"
156-
# Run kani list with JSON format and process with jq to extract all harness names
157-
# Note: This code is based on `kani list` JSON version 0.1 -- if the version changes, this logic may need to change as well.
158-
"$kani_path" list -Z list -Z function-contracts -Z mem-predicates -Z float-lib -Z c-ffi ./library --std --format json \
159-
jq -r '
162+
"$kani_path" list -Z list -Z function-contracts -Z mem-predicates -Z float-lib -Z c-ffi ./library --std --format json
163+
ALL_HARNESSES=($(jq -r '
160164
([.["standard-harnesses"] | to_entries | .[] | .value[]] +
161-
[.["contract-harnesses"] | to_entries | .[] | .value[]]) |
165+
[.["contract-harnesses"] | to_entries | .[] | .value[]]) |
162166
.[]
163-
'
167+
' $WORK_DIR/kani-list.json))
168+
HARNESS_COUNT=${#ALL_HARNESSES[@]}
164169
}
165170

166171
run_verification_subset() {
@@ -180,7 +185,7 @@ run_verification_subset() {
180185
-Z loop-contracts \
181186
-Z float-lib \
182187
-Z c-ffi \
183-
$harness_args -- exact \
188+
$harness_args --exact \
184189
$command_args \
185190
--enable-unstable \
186191
--cbmc-args --object-bits 12
@@ -239,19 +244,16 @@ main() {
239244
if [[ "$run_command" == "verify-std" ]]; then
240245
if [[ -n "$PARALLEL_INDEX" && -n "$PARALLEL_TOTAL" ]]; then
241246
echo "Running as parallel worker $PARALLEL_INDEX of $PARALLEL_TOTAL"
242-
243-
# Get all harnesses
244-
readarray -t all_harnesses < <(get_harnesses "$kani_path")
245-
total_harnesses=${#all_harnesses[@]}
247+
get_harnesses "$kani_path"
246248

247249
# Calculate this worker's portion
248-
chunk_size=$(( (total_harnesses + PARALLEL_TOTAL - 1) / PARALLEL_TOTAL ))
250+
chunk_size=$(( (HARNESS_COUNT + PARALLEL_TOTAL - 1) / PARALLEL_TOTAL ))
249251
start_idx=$(( (PARALLEL_INDEX - 1) * chunk_size ))
250252
end_idx=$(( start_idx + chunk_size ))
251-
[[ $end_idx -gt $total_harnesses ]] && end_idx=$total_harnesses
253+
[[ $end_idx -gt $HARNESS_COUNT ]] && end_idx=$HARNESS_COUNT
252254

253255
# Extract this worker's harnesses
254-
worker_harnesses=("${all_harnesses[@]:$start_idx:$chunk_size}")
256+
worker_harnesses=("${ALL_HARNESSES[@]:$start_idx:$chunk_size}")
255257

256258
# Run verification for this subset
257259
run_verification_subset "$kani_path" "${worker_harnesses[@]}"

0 commit comments

Comments
 (0)