-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest
executable file
·96 lines (79 loc) · 2.43 KB
/
test
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
# Usage:./test [format]
# Tests will run if format is a java class
# Otherwise, will only compile and transform to target format (e.g. J for jimple)
SRCDIR=Test/src
OUTDIR=test-out/original
TFDIR=test-out/transformed
TIMEOUT=5 # Time allowed per program
FORMAT=${1:-c} # Format of output
set -e
shopt -s globstar # Allow ** to query directories recursively
rm -rf test-out
mkdir -p test-out/{original,transformed}
# Compile test .java files
echo "[+] Compiling test classes"
SRC_JAVA_FILES=$(find $SRCDIR -name "*.java")
javac -cp out/production/Transformer \
-d $OUTDIR \
$SRC_JAVA_FILES
# Write unmodified .jimple files for completeness
java -cp ./lib/soot.jar soot.Main \
-w \
-allow-phantom-refs \
-process-dir $OUTDIR \
-f J \
-d $OUTDIR
# Transform
echo "[+] Transforming class files..."
java -ea -cp \
"./lib/soot.jar:./out/production/Transformer" \
ch.ethz.ivogels.Main \
-w \
-process-dir $OUTDIR \
-f $FORMAT \
-d $TFDIR
if [ $FORMAT != "c" ] && [ $FORMAT != "class" ]; then
echo "[+] Transformation of test classes to format $FORMAT complete. Exiting."
exit 0
fi
execute(){
# Do not exit when java runtime or program exits with a nonzero exit code
#set +e
for f in $1/**/*.class # Find class files in $1 and its subdirectories
do
RELATIVE_PATH=$(realpath --relative-to="$1" $f) # Find relative location of .java files
TMP=${RELATIVE_PATH%.class} # Cut off .class suffix
CLASS=${TMP////.} # Replace / with . to obtain package name
if javap $f | grep "public static void main(java.lang.String\[\])" > /dev/null ; then
echo "[+] Found main method in class: $CLASS Executing class and logging behavior with timeout of $TIMEOUT seconds."
timeout $TIMEOUT java -cp $1:$HOME/Android/Sdk/platforms/android-26/android.jar:./out/production/Transformer $CLASS > $f.out
else
echo "[-] Ignoring file $f with no main method"
fi
done
#set -e
}
echo "--== Executing original class files ==--"
# Execute original class files
execute $OUTDIR
echo
echo "--== Executing transformed class files ==--"
# Execute transformed class files
execute $TFDIR
echo
echo "--== Test Results ==--"
echo
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
for f in $OUTDIR/**/*.out
do
if diff -q $f $TFDIR/$(realpath --relative-to="$OUTDIR" $f); then
echo -e "[${GREEN}OK${NC}] $f"
else
echo -e "[${RED}FAIL${NC}] $f"
ERR=1
fi
done
exit $ERR