-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathunion_test.sh
executable file
·143 lines (113 loc) · 3.07 KB
/
union_test.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
################################# CONSTANTS ##################################
# default timeout (can be overriden from command line)
timeout=300;
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=`readlink -f $0`
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
METHODS=(
"expl"
"symdown"
"symup"
"timbuk"
)
################################# FUNCTIONS ##################################
# Function that terminates the script with a message
function die {
echo "$1";
exit -1;
}
# Function that runs a single test
# takes: <LHS automaton> <RHS automaton> <method> <file to write result> <file to write time>
function runone {
ulimit -St "${timeout}";
${SCRIPTPATH}/union_wrapper.sh "$1" "$2" "$3" 2> "$4"
return $?
}
# Function that runs all tests for one pair of automata
function runall {
# Set trap for terminating the script
trap killscripts INT TERM EXIT
local i;
# run all methods
for (( i=0; i < ${#METHODS[*]}; i++ )); do
runone "${METHODS[$i]}" "$1" "$2" "${tmpTime[$i]}" 2> /dev/null &
pid[$i]=$!;
done;
# evaluate all methods
for (( i=0; i < ${#METHODS[*]}; i++ )); do
wait ${pid[$i]};
local ret=$?;
pid[$i]=0;
if [ "$ret" == "152" ]; then
printcolumn "-"
else
local v=`<"${tmpTime[$i]}"`;
[ "$ret" == "0" ] || die "union failed! ($ret)";
num=$(printf "%.4f" "${v}")
printcolumn "${num}";
fi;
done;
printf "\n"
}
# Prints a column into the result table
function printcolumn {
printf "%10s;" "$1"
}
function killscripts {
local i
for i in $(ps | grep "\(vata\|sfta\)" | cut -d' ' -f1); do
kill ${i}
done
}
################################## PROGRAM ###################################
# Check the number of command-line arguments
if [ \( "$#" -eq 0 \) -o \( "$#" -gt 2 \) ] ; then
die "usage: $0 <dir> [timeout]"
fi
# If timeout is specified, use it instead of the default
if [ "$2" != "" ]; then
timeout="$2";
fi;
AUT_DIR="$1"
# If the directory doesn't exist, terminate
if [ ! -d "${AUT_DIR}" ]; then
die "directory '${AUT_DIR}' does not exist!"
fi
echo "======== Computing union of automata ======="
echo "Automata directory: ${1}"
echo "Timeout: ${timeout} s"
# Create temporary files for storing the output
for (( i=0; i < ${#METHODS[*]}; i++ )); do
tmpTime[$i]=`mktemp`;
done;
echo "reading files ..."
cnt=0;
for x in $1/*; do
key[$cnt]=`basename $x`;
val[$cnt]="${x}";
#[ "$?" == "0" ] || die "unable to preprocess $x";
#printf "$x (%s)\n" "`./main i <<< ${val[$cnt]}`";
cnt=$(($cnt+1));
done;
echo "-----------------------------------------------"
for i in "aut1" "aut2" ; do
printcolumn ${i}
done
for (( i=0; i < ${#METHODS[*]}; i++ )); do
printcolumn "${METHODS[$i]}"
done;
printf "\n"
for (( i=0; i < $cnt; i++ )); do
for (( j=0; j < $cnt; j++ )); do
printcolumn ${key[$i]}
printcolumn ${key[$j]}
runall "${val[$i]}" "${val[$j]}";
done;
done;
# Remove temporary files
for (( i=0; i < ${#METHODS[*]}; i++ )); do
rm ${tmp[$i]}
rm ${tmpTime[$i]}
done;