Skip to content

Commit eb0ec76

Browse files
geo2arv-jenkins
andauthored
Reuse kompiled contracts.k and foundry.k in Kontrol performance test (#3845)
This PR attempts to reduce the influence of the K compiler processes on the Kontrol performance test. To achieve that, we compile everything in-advance, ensuring that there will be no calls to `kompile` when running the actual proof test: - run the single `test_foundy_kompile` test, which is essentially just a wrapper for the `foundry` pytest [fixture](https://github.com/runtimeverification/kontrol/blob/2fba281b0a73d76c1dba37f74220051901d04606/src/tests/integration/conftest.py#L53) that generates and compiles the `contracts.k` and `foundry.k` files. This produces the `foundry/out/kompiled` directory - when running the actual proof tests, pass the generated `foundry` directory to them explicitly. This makes sure that the pytest fixture will not be forced to recompile stuff in every `pytest-xdist` worker. - Re-using the `foundry` directory has a side-effect of also reusing the `foundry/out/proofs` directory. To make sure that we actually run the proofs in `master_shell`, and not re-use the ones produced by `feature_shell`, we delete them between the steps. Some things I've noticed that may be worth accounting for, but not in this PR: - the `server` [fixture](https://github.com/runtimeverification/kontrol/blob/7f45d5672a59f094e2d067e41923e037544b86f1/src/tests/integration/conftest.py#L35) is module-scoped. That means that all tests in a certain test module will reuse the same server instance, individually in each test worker. - the corollary of the above is that the proofs that are run later will use a more "tired" server, since the server state will bloat due to a bunch of duplicate (and likely empty) modules. It is not clear if this is a performance issue, but we have certainly not considered it earlier. - another thing is that the decision on which test to skip is taken dynamically at the start of the test, and the tests, even if skipped, need the fixtures to be ready for them. In most cases, however, the server connection will be reused by other tests in the same module. --------- Co-authored-by: rv-jenkins <[email protected]>
1 parent fcaae28 commit eb0ec76

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

scripts/performance-tests-kontrol.sh

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@ fi
2323

2424
# Create a temporary directory and store its name in a variable.
2525
TEMPD=$(mktemp -d)
26+
KEEP_TEMPD=${KEEP_TEMPD:-''}
2627

2728
# Exit if the temp directory wasn't created successfully.
2829
if [ ! -e "$TEMPD" ]; then
2930
>&2 echo "Failed to create temp directory"
3031
exit 1
3132
fi
3233

33-
# Make sure the temp directory gets removed and kore-rpc-booster gets killed on script exit.
34-
trap "exit 1" HUP INT PIPE QUIT TERM
35-
trap 'rm -rf "$TEMPD" && killall kore-rpc-booster || echo "no zombie processes found"' EXIT
34+
clean_up () {
35+
if [ -z "$KEEP_TEMPD" ]; then
36+
rm -rf "$TEMPD"
37+
fi
38+
killall kore-rpc-booster || echo "no zombie processes found"
39+
}
40+
41+
# Make sure the temp directory gets removed (unless KEEP_TEMPD is set) and kore-rpc-booster gets killed on script exit.
42+
trap "exit 1" HUP INT PIPE QUIT TERM
43+
trap clean_up EXIT
3644

3745
cd $TEMPD
3846
git clone --depth 1 --branch $KONTROL_VERSION https://github.com/runtimeverification/kontrol.git
@@ -93,16 +101,27 @@ master_shell() {
93101
GC_DONT_GC=1 nix develop . --extra-experimental-features 'nix-command flakes' --override-input kevm/k-framework/haskell-backend github:runtimeverification/haskell-backend/$MASTER_COMMIT --command bash -c "$1"
94102
}
95103

104+
# kompile Kontrol's K dependencies
96105
feature_shell "poetry install && poetry run kdist --verbose build evm-semantics.plugin evm-semantics.haskell kontrol.foundry --jobs 4"
97106

107+
# kompile the test contracts, to be reused in feature_shell and master_shell. Copy the result from pytest's temp directory
108+
PYTEST_TEMP_DIR=$TEMPD/pytest-temp-dir
109+
mkdir -p $PYTEST_TEMP_DIR
110+
FOUNDRY_DIR=$TEMPD/foundry
111+
mkdir -p $FOUNDRY_DIR
112+
feature_shell "make test-integration TEST_ARGS='--basetemp=$PYTEST_TEMP_DIR -n0 --dist=no -k test_foundry_kompile'"
113+
cp -r $PYTEST_TEMP_DIR/foundry/* $FOUNDRY_DIR
114+
98115
mkdir -p $SCRIPT_DIR/logs
99116

100-
feature_shell "make test-integration TEST_ARGS='--maxfail=0 --numprocesses=$PYTEST_PARALLEL -vv $BUG_REPORT' | tee $SCRIPT_DIR/logs/kontrol-$KONTROL_VERSION-$FEATURE_BRANCH_NAME.log"
117+
feature_shell "make test-integration TEST_ARGS='--foundry-root $FOUNDRY_DIR --maxfail=0 --numprocesses=$PYTEST_PARALLEL -vv $BUG_REPORT' | tee $SCRIPT_DIR/logs/kontrol-$KONTROL_VERSION-$FEATURE_BRANCH_NAME.log"
101118
killall kore-rpc-booster || echo "no zombie processes found"
102119

103120
if [ -z "$BUG_REPORT" ]; then
104121
if [ ! -e "$SCRIPT_DIR/logs/kontrol-$KONTROL_VERSION-master-$MASTER_COMMIT_SHORT.log" ]; then
105-
master_shell "make test-integration TEST_ARGS='--maxfail=0 --numprocesses=$PYTEST_PARALLEL -vv' | tee $SCRIPT_DIR/logs/kontrol-$KONTROL_VERSION-master-$MASTER_COMMIT_SHORT.log"
122+
# remove proofs so that they are not reused by the master shell call
123+
rm -r $FOUNDRY_DIR/out/proofs
124+
master_shell "make test-integration TEST_ARGS='--foundry-root $FOUNDRY_DIR --maxfail=0 --numprocesses=$PYTEST_PARALLEL -vv' | tee $SCRIPT_DIR/logs/kontrol-$KONTROL_VERSION-master-$MASTER_COMMIT_SHORT.log"
106125
killall kore-rpc-booster || echo "no zombie processes found"
107126
fi
108127

0 commit comments

Comments
 (0)