-
Notifications
You must be signed in to change notification settings - Fork 48
/
juliet-run.sh
executable file
·62 lines (49 loc) · 1.65 KB
/
juliet-run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
# the first parameter specifies a non-default timeout duration
# the second parameter specifies the path of a library to LD_CHERI_PRELOAD when running test cases
# this script will run all good and bad tests in the bin subdirectory and write
# the names of the tests and their return codes into the files "good.run" and
# "bad.run". all tests are run with a timeout so that tests requiring input
# terminate quickly with return code 124.
ulimit -c 0
SCRIPT_DIR=$(dirname $(realpath "$0"))
TIMEOUT="1s"
PRELOAD_PATH=""
INPUT_FILE="/tmp/in.txt"
if [ $# -ge 1 ]
then
TIMEOUT="$1"
fi
if [ $# -ge 2 ]
then
PRELOAD_PATH="$2"
if [ ! -f "${PRELOAD_PATH}" ]
then
echo "preload path ${PRELOAD_PATH} does not exist - not running tests"
exit 1
fi
fi
# parameter 1: the CWE directory corresponding to the tests
# parameter 2: the type of tests to run (should be "good" or "bad")
run_tests()
{
local CWE_DIRECTORY="$1"
local TEST_TYPE="$2"
local TYPE_PATH="${CWE_DIRECTORY}/${TEST_TYPE}"
local PREV_CWD=$(pwd)
cd "${CWE_DIRECTORY}" # change directory in case of test-produced output files
echo "========== STARTING TEST ${TYPE_PATH} $(date) ==========" >> "${TYPE_PATH}.run"
for TESTCASE in $(ls -1 "${TYPE_PATH}"); do
local TESTCASE_PATH="${TYPE_PATH}/${TESTCASE}"
if [ ! -z "${PRELOAD_PATH}" ]
then
timeout "${TIMEOUT}" env LD_CHERI_PRELOAD="${PRELOAD_PATH}" "${TESTCASE_PATH}" < "${INPUT_FILE}"
else
timeout "${TIMEOUT}" "${TESTCASE_PATH}" < "${INPUT_FILE}"
fi
echo "${TESTCASE_PATH} $?" >> "${TYPE_PATH}.run"
done
cd "${PREV_CWD}"
}
run_tests "${SCRIPT_DIR}/bin" "good"
run_tests "${SCRIPT_DIR}/bin" "bad"