Skip to content

Commit

Permalink
207 test tarball runner + tweak rpc client logging (#242)
Browse files Browse the repository at this point in the history
- [X] Tweaks to `rpc-client`:
  * use `MonadLogger` and a log-level option
* cancel the request in flight if the user interrupts the program (by
`^C` or sending `SIGINT`)
- [x] unpack and use all `rpc_*` directories, with their respective path
- [x] Add a regression test for running a tarball.
 
Fixes #207

---------

Co-authored-by: Sam Balco <goodlyrottenapple@gmail.com>
  • Loading branch information
jberthold and goodlyrottenapple authored Aug 2, 2023
1 parent 0251d2d commit 662476c
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 124 deletions.
135 changes: 135 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
haskell-nix.follows = "haskell-backend/haskell-nix";
nixpkgs.follows = "haskell-backend/haskell-nix/nixpkgs-unstable";

blockchain-k-plugin.url = "github:runtimeverification/blockchain-k-plugin/da834be67f6c0aff11140ddfc0b04561494c14b8";
blockchain-k-plugin.inputs.flake-utils.follows = "k-framework/flake-utils";
blockchain-k-plugin.inputs.nixpkgs.follows = "k-framework/nixpkgs";

flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs =
{ self, nixpkgs, haskell-nix, k-framework, haskell-backend, ... }@inputs:
{ self, nixpkgs, haskell-nix, k-framework, haskell-backend, blockchain-k-plugin, ... }@inputs:
let
inherit (nixpkgs) lib;
perSystem = lib.genAttrs nixpkgs.lib.systems.flakeExposed;
Expand Down Expand Up @@ -214,6 +218,7 @@
packages."hs-backend-booster:exe:kore-rpc-booster";
rpc-client = packages."hs-backend-booster:exe:rpc-client";
inherit (k-framework.packages.${system}) k;
blockchain-k-plugin = blockchain-k-plugin.defaultPackage.${system};
};
});

Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ executables:
- extra
- filepath
- hs-backend-booster
- monad-logger
- network
- network-run
- optparse-applicative
Expand Down
6 changes: 4 additions & 2 deletions test/rpc-integration/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, coreutils, lib, kore-rpc-booster, rpc-client, git, k }:
{ stdenv, coreutils, lib, kore-rpc-booster, rpc-client, git, k, blockchain-k-plugin, openssl, procps }:

let
mkIntegrationTest =
Expand All @@ -16,7 +16,8 @@ let
export ${f}
'') buildFlags}
export SERVER=${kore-rpc-booster}/bin/kore-rpc-booster
export CLIENT=${rpc-client}/bin/rpc-client
export CLIENT="${rpc-client}/bin/rpc-client"
export PLUGIN_DIR=${blockchain-k-plugin}
patchShebangs runDirectoryTest.sh
./runDirectoryTest.sh test-${name} --time ${
Expand Down Expand Up @@ -46,4 +47,5 @@ in {
simplify = mkIntegrationTest { name = "simplify"; };
get-model = mkIntegrationTest { name = "get-model"; };
issue212 = mkIntegrationTest { name = "issue212"; };
foundry-bug-report.tar.gz = mkIntegrationTest { name = "foundry-bug-report.tar.gz"; nativeBuildInputs = [ k openssl procps ]; };
}
48 changes: 48 additions & 0 deletions test/rpc-integration/resources/foundry-bug-report.tar.gz.kompile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
set -eux

SCRIPT_DIR=$(dirname $0)
PLUGIN_DIR=${PLUGIN_DIR:-""}
NIX_LIBS=${NIX_LIBS:-""}


if [ -z "$PLUGIN_DIR" ]; then
echo "PLUGIN_DIR required to link in a crypto plugin dependency"
exit 1
else
for lib in libff libcryptopp libsecp256k1; do
LIBFILE=$(find ${PLUGIN_DIR} -name "${lib}.a" | head -1)
[ -z "$LIBFILE" ] && (echo "[Error] Unable to locate ${lib}.a"; exit 1)
PLUGIN_LIBS+="$LIBFILE "
PLUGIN_INCLUDE+="-I$(dirname $LIBFILE)/../include "
done
#PLUGIN_CPP=$(find ${PLUGIN_DIR}/plugin-c -name "*.cpp")
PLUGIN_CPP="${PLUGIN_DIR}/include/plugin-c/blake2.cpp ${PLUGIN_DIR}/include/plugin-c/crypto.cpp ${PLUGIN_DIR}/include/plugin-c/plugin_util.cpp"
fi

NAME=$(basename ${0%.tar.gz.kompile})
NAMETGZ=$(basename ${0%.kompile})

# unpack definition.kore and llvm_definition from tarball
# into a directory named after the tarball
cd $SCRIPT_DIR
mkdir -p $NAME
tar xzf ../test-$NAMETGZ -C $NAME definition.kore llvm_definition/

# provide definition
cp $NAME/definition.kore ${NAMETGZ}.kore

# kompile llvm-definition to interpreter

case "$OSTYPE" in
linux*) LPROCPS="-lprocps" ;;
*) LPROCPS="" ;;
esac

llvm-kompile $NAME/llvm_definition/definition.kore $NAME/llvm_definition/dt c -- \
-fPIC -std=c++17 -o interpreter \
$PLUGIN_LIBS $PLUGIN_INCLUDE $PLUGIN_CPP \
-lcrypto -lssl $LPROCPS
mv interpreter.* $NAMETGZ.dylib

# remove temporary artefacts
rm -r $NAME
39 changes: 22 additions & 17 deletions test/rpc-integration/runDirectoryTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dylib=resources/${dir#test-}.dylib
echo "Running tests from $dir with definition $kore"

# make sure directory and kore file exist
[ ! -d "./$dir" ] && exit 1
[ ! -e "./$dir" ] && exit 1
if [ ! -f "./$kore" ]; then
[ ! -f "./$kompile" ] && exit 2
cd resources
Expand All @@ -68,20 +68,25 @@ server_pid=$!
trap 'kill -2 ${server_pid}; popd' ERR EXIT
echo "Server PID ${server_pid}"

sleep 2
sleep 5

for test in $( ls $dir/state-*.{execute,send,simplify,add-module,get-model} 2>/dev/null ); do
tmp=${test#$dir/state-}
testname=${tmp%.*}
# determine send mode from suffix
mode=${test##*.}
printf "########## Test: %10s %20s\n" "$mode" "$testname #######"
if [ -f "$dir/params-${testname}.json" ]; then
params="--param-file $dir/params-${testname}.json"
else
params=""
fi
# call rpc-client
echo "$client $mode $test $params --expect $dir/response-${testname}.json $*"
$client $mode $test $params --expect $dir/response-${testname}.json $*
done
if [ -d $dir ]; then
for test in $( ls $dir/state-*.{execute,send,simplify,add-module,get-model} 2>/dev/null ); do
tmp=${test#$dir/state-}
testname=${tmp%.*}
# determine send mode from suffix
mode=${test##*.}
printf "########## Test: %10s %20s\n" "$mode" "$testname #######"
if [ -f "$dir/params-${testname}.json" ]; then
params="--param-file $dir/params-${testname}.json"
else
params=""
fi
# call rpc-client
echo "$client $mode $test $params --expect $dir/response-${testname}.json $*"
$client $mode $test $params --expect $dir/response-${testname}.json $*
done
else
echo "$dir is a file, running a tarball test"
$client run-tarball $dir
fi
Binary file not shown.
Loading

0 comments on commit 662476c

Please sign in to comment.