Skip to content

Commit

Permalink
Convenience scripts
Browse files Browse the repository at this point in the history
I added two convenience scripts:

 - klee.env to get the flags you need to compile. Those flags do not
   include optimization/debug symbols flags as they are up to the user.
 - klee.run to run a klee testcase without having to manually setup the
   environment.
  • Loading branch information
marco6 committed Jul 11, 2023
1 parent 4fc5703 commit f0bc2e4
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/env.comp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

_klee_env()
{
local cur prev

COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}

_expand || return 0

case "$cur" in
-*)
COMPREPLY=( $( compgen -W '-h --help' -- "$cur" ))
;;
*)
COMPREPLY=( $( compgen -W 'CFLAGS LDFLAGS' -- "$cur" ))
;;
esac

return 0
} &&
complete -F _klee_env $nospace $filenames klee.env

46 changes: 46 additions & 0 deletions scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

function print_help() {
res=${1:-0}
echo "Usage klee.env [FLAGS] VARIABLES"
echo "Prints the variables needed to compile klee programs"
echo ""
echo "Available FLAGS:"
echo " -h, --help Display this help and exit."
echo ""
echo "Available VARIABLES:"
echo " CFLAGS returns the flags to pass to clang or gcc with"
echo " include/lib paths to compile a klee program."
echo " LDFLAGS returns the link flags to pass to clang or gcc"
echo " to link a klee program, so that it can run the"
echo " testcases generated by a klee run."
echo ""
exit $res
}

DIR="$( realpath "$( dirname -- "${BASH_SOURCE[0]}"; )/.." )"

command=

while [ "$1" != "$EOL" ]; do
opt="$1"; shift
case $opt in
-h | --help) print_help;;
* ) command=$opt;;
esac
done


case $command in
CFLAGS )
echo "-I $DIR/include -L $DIR/lib"
;;
LDFLAGS)
echo "-lkleeRuntest"
;;
* )
>&2 echo "Error: unknown variable $command"
print_help 1
;;
esac

25 changes: 25 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

function print_help() {
res=${1:-0}
echo "Usage: klee.run TESTCASE COMMAND..."
echo "Run a klee TESTCASE for COMMAND"
echo ""
exit $res
}

DIR="$(realpath "$( dirname -- "${BASH_SOURCE[0]}"; )/.." )"

if [ $# -lt 2 ]
then
>&2 echo "Error: TESTCASE and COMMAND are required"
print_help 1
fi

testcase=$1
shift
command=$1
shift

LD_LIBRARY_PATH="$DIR/lib/:$LD_LIBRARY_PATH" KTEST_FILE="$testcase" $command $@

14 changes: 14 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,25 @@ parts:
- libz3-4
- libgoogle-perftools4
- libunwind8
scripts:
source: scripts
source-type: local
plugin: nil
override-build: |
mkdir -p "${SNAPCRAFT_PART_INSTALL}/usr/local/bin/"
cp --archive --link --no-dereference --update . "${SNAPCRAFT_PART_INSTALL}/usr/local/bin/"
apps:
klee:
command: usr/local/bin/klee
plugs: [home]
ktest-tool:
command: usr/local/bin/ktest-tool
plugs: [home]
env:
command: usr/local/bin/env.sh
completer: usr/local/bin/env.comp.sh
run:
command: usr/local/bin/run.sh
plugs: [home]

0 comments on commit f0bc2e4

Please sign in to comment.