|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright Kani Contributors |
| 3 | +# SPDX-License-Identifier: Apache-2.0 OR MIT |
| 4 | + |
| 5 | +# Checks situations where running kani multiple times will work as expected when |
| 6 | +# the target crate is binary. |
| 7 | +# |
| 8 | +# The following checks should not trigger recompilation. |
| 9 | +# - Exact same input being invoked a second time. |
| 10 | +# - Different options that do not affect the compilation, only the Kani workt flow. |
| 11 | +# While the following should recompile the target. |
| 12 | +# - Pass a new argument that affects compilation |
| 13 | +# - Add a dependency |
| 14 | +set -e |
| 15 | +set -u |
| 16 | + |
| 17 | +ORIG=bin |
| 18 | +OUT_DIR=target |
| 19 | +MANIFEST=${OUT_DIR}/${ORIG}/Cargo.toml |
| 20 | + |
| 21 | +# Expects two arguments: "kani arguments" "output_file" |
| 22 | +function check_kani { |
| 23 | + local args=$1 |
| 24 | + local log_file="${OUT_DIR}/$2" |
| 25 | + # Run kani with the given arguments |
| 26 | + if [ -z "${args}" ] |
| 27 | + then |
| 28 | + cargo kani --manifest-path "${MANIFEST}" --target-dir "${OUT_DIR}" \ |
| 29 | + 2>&1 | tee "${log_file}" |
| 30 | + else |
| 31 | + cargo kani --manifest-path "${MANIFEST}" --target-dir "${OUT_DIR}" \ |
| 32 | + "${args}" 2>&1 | tee "${log_file}" |
| 33 | + fi |
| 34 | + |
| 35 | + # Print information about the generated log file. |
| 36 | + # Check for occurrences of "Compiling" messages in the log files |
| 37 | + local compiled=$(grep -c "Compiling" ${log_file}) |
| 38 | + echo "${log_file}:Compiled ${compiled} crates" |
| 39 | + |
| 40 | + # Check which harnesses were verified |
| 41 | + grep "Checking harness" -H ${log_file} || echo "${log_file}:No harness verified" |
| 42 | + |
| 43 | + # Check the verification summary |
| 44 | + grep "successfully verified harnesses" -H ${log_file} || true |
| 45 | +} |
| 46 | + |
| 47 | +# Ensure output folder is clean |
| 48 | +rm -rf ${OUT_DIR} |
| 49 | +mkdir -p ${OUT_DIR} |
| 50 | +# Move the original source to the output folder since it will be modified |
| 51 | +cp -r ${ORIG} ${OUT_DIR} |
| 52 | + |
| 53 | +echo "Initial compilation" |
| 54 | +check_kani --only-codegen initial.log |
| 55 | + |
| 56 | +echo "Re-execute the same command" |
| 57 | +check_kani --only-codegen same.log |
| 58 | + |
| 59 | +echo "Run with new arg that affects kani-driver workflow only" |
| 60 | +check_kani "" driver_opt.log |
| 61 | + |
| 62 | +echo "Run with a new argument that affects compilation" |
| 63 | +check_kani --no-assertion-reach-checks disable_checks.log |
| 64 | + |
| 65 | +echo "Run with new dependency" |
| 66 | +cargo new --lib ${OUT_DIR}/new_dep |
| 67 | +cargo add new_dep --manifest-path ${MANIFEST} --path ${OUT_DIR}/new_dep |
| 68 | +check_kani --no-assertion-reach-checks new_dep.log |
| 69 | + |
| 70 | +# Try to leave a clean output folder at the end |
| 71 | +rm -rf ${OUT_DIR} |
0 commit comments