-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_job.sh
executable file
·83 lines (61 loc) · 1.88 KB
/
run_job.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
mkdir -p "$(pwd)/logs"
log="$(pwd)/logs/$1_$2_logs.txt"
if [ -e $log ]
then
echo "exists"
cat $log
else
touch $log
fi
cr="cargo run --release -- language $1 oracle $2"
compiler="scalac"
if [ "$1" = "java" ]; then
compiler="javac"
fi
if [ "$1" = "haskell" ]; then
compiler="ghc"
fi
oracle="Z3"
if [ "$2" = "construction" ]; then
oracle="Construction"
fi
if [ "$2" = "mutation" ]; then
oracle="Mutation"
fi
time_path="$(pwd)/out/Programs/$oracle/$compiler/time.txt"
cur_runtime=0
if [ -z $time_path ]; then
echo "exists"
cur_runtime=$(cat $time_path)
else
touch $time_path
fi
start_time=$(date +%s)
new_runtime=0 # Total accumulated runtime
while [ "$new_runtime" -lt 60 ]; do
remaining_time=$((60 - new_runtime)) # Calculate remaining time
# Run the command for the remaining time or timeout at 12h
timeout "$remaining_time"s $cr 2>&1 | tee -a "$log"
exit_status=$? # Capture the exit status of the previous command
end_time=$(date +%s)
elapsed_time=$((end_time - start_time)) # Calculate the time spent in this iteration
new_runtime=$((new_runtime + elapsed_time)) # Accumulate runtime
cur_runtime=$((cur_runtime + elapsed_time))
# Save the accumulated runtime to the time file
echo "$cur_runtime" > "$time_path"
# Exit if total runtime has reached 12 hours
if [ "$new_runtime" -ge 60 ]; then
echo "Reached a total runtime of 12 hours. ($elapsed_time seconds)"
break
fi
# If the command succeeded, prepare for the next iteration
if [ $exit_status -eq 0 ]; then
echo "Command completed successfully. Continuing to the next iteration."
else
echo "Command failed with exit code $exit_status. Retrying..."
fi
# Reset start time for the next iteration
start_time=$(date +%s)
done
# Final message
echo "Script execution finished after 12 hours of runtime."