-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfizz
executable file
·125 lines (105 loc) · 2.82 KB
/
fizz
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
#!/bin/bash
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]:-$0}")")"
WORKING_DIR="$(pwd)"
usage() {
echo "Usage: $0 [-x|--simulation] [--seed int64Number] [-- max_runs intNumber] filename"
exit 1
}
# Initialize variables
simulation=false
seed=0
max_runs=0
# Parse options
while [[ "$1" =~ ^- ]]; do
case $1 in
-x | --simulation )
simulation=true
shift
;;
--seed )
if [[ -n "$2" ]] && [[ "$2" =~ ^[0-9]+$ ]]; then
seed="$2"
shift 2
else
echo "Error: --seed requires a numeric value." 1>&2
usage
fi
;;
--max_runs )
if [[ -n "$2" ]] && [[ "$2" =~ ^[0-9]+$ ]]; then
max_runs="$2"
shift 2
else
echo "Error: --max_runs requires a numeric value." 1>&2
usage
fi
;;
--internal_profile )
internal_profile=true
shift
;;
-h | --help )
usage
;;
* )
echo "Invalid option: $1" 1>&2
usage
;;
esac
done
# Check for the required positional argument
if [ -z "$1" ]; then
echo "Error: filename is required" 1>&2
usage
fi
input_filename=$1
# Example usage of the parsed options and arguments
if [ "$simulation" = true ]; then
echo "Simulation mode is enabled"
fi
input_filename=$1
# Check if the script directory and working directory are the same
if [ "$SCRIPT_DIR" = "$WORKING_DIR" ]; then
# Check if parser_bin exists, otherwise run bazel build
if ! test -f bazel-bin/parser/parser_bin; then
echo "bazel-bin/parser/parser_bin not found. Running 'bazel build parser/parser_bin'!"
bazel build parser/parser_bin
fi
# Check if fizzbee exists, otherwise run bazel build
if ! test -f bazel-bin/fizzbee_/fizzbee; then
echo "bazel-bin/fizzbee_/fizzbee not found. Running 'bazel build //:fizzbee'!"
bazel build //:fizzbee
fi
fi
# Set the paths for the binaries relative to the script directory
PARSER_BIN="$SCRIPT_DIR/bazel-bin/parser/parser_bin"
FIZZBEE_BIN="$SCRIPT_DIR/bazel-bin/fizzbee_/fizzbee"
# Call the first binary and redirect output to a temporary file
temp_output=$(mktemp)
if ! "$PARSER_BIN" "$input_filename" > "$temp_output"; then
echo "Error: Compilation failed"
echo "Logs at $temp_output"
exit 1
fi
# Create the JSON filename by replacing the extension
json_filename="${input_filename%.*}.json"
echo "Model checking" $json_filename
# Prepare arguments for the Go binary
args=()
if [ "$simulation" = true ]; then
args+=("--simulation")
fi
if [ "$internal_profile" = true ]; then
args+=("--internal_profile")
fi
if [ "$seed" -ne 0 ]; then
args+=("--seed" "$seed")
fi
if [ "$max_runs" -ne 0 ]; then
args+=("--max_runs" "$max_runs")
fi
args+=("$json_filename")
# Run the second command with the JSON filename
"$FIZZBEE_BIN" "${args[@]}"
# Clean up the temporary file
rm "$temp_output"