-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.sh
executable file
·164 lines (134 loc) · 5.17 KB
/
status.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# ============================================================================ #
# User defined inputs.
# Define all needed folders relative to the Testing folder. (without trailing /)
RPATH="results" # Result export location
LPATH="logs" # Logging locations
# End of user inputs
# ============================================================================ #
# Help commands
function help() {
echo "status.sh"
echo " This script prints the status of the tests either currently running"
echo " or completed. Any completed test which have exited with an error"
echo " gets the error printed as well."
}
# Variable setups
MAIN_DIR=$(dirname $(realpath $0))
RPATH=$MAIN_DIR/$RPATH
LPATH=$MAIN_DIR/$LPATH
[ ! -d $LPATH ] && exit 0
# ============================================================================ #
# Keywords
# Print help
for in in $@; do
if [ "$in" = "-h" ] || [ "$in" = "--help" ]; then
help && exit
fi
done
# ============================================================================ #
# Print status
# List all the tests, if there are none we return
tests=($(find $LPATH -type d -exec test -f '{}'/output.log \; -print | sort -u))
for ((i = 0; i < ${#tests[@]}; i++)); do tests[$i]="${tests[$i]#$LPATH/}"; done
if [ ${#tests[@]} -eq 0 ]; then
printf "No tests found.\n"
exit 0
fi
# If we are running in LSF-10 mode, print the running jobs.
if [ $(which bjobs 2>/dev/null) ]; then
printf "\n\e[4mRunning jobs.\e[m\n"
bjobs -ro -noheader "time_left:8 job_name"
elif [ $(which squeue 2>/dev/null) ]; then
printf "\n\e[4mRunning jobs.\e[m\n"
squeue -ro "%.8L %j" -u $USER
fi
printf "\n\e[4mTest status.\e[m\n"
for test in ${tests[@]}; do
if [[ -d $RPATH/$test && ! -s $LPATH/$test/output.log && ! -s $LPATH/$test/error.log ]]; then
printf '\t\e[1;32m%-12s\e[m %-s\n' "Complete:" "$test"
rm -fr $LPATH/$test
fi
done
for test in ${tests[@]}; do
if [[ -s $LPATH/$test/output.log && ! -s $LPATH/$test/error.log ]]; then
file=($(find $LPATH/$test -type f -name "*.case"))
# If more than one file exists
if [[ ${#file[@]} -gt 2 ]]; then
file+="$LPATH/$test/output.log"
fi
if [ "$(head -n 1 $LPATH/$test/output.log)" = "Ready" ]; then
printf '\t\e[1;33m%-12s\e[m %s %-s\n' "Pending:" "$test"
else
for f in ${file[@]}; do
logfile=${f%.*}.log
if [ ! -f $logfile ]; then
continue
fi
if [ "$(tail -n 1 ${f%.*}.log | xargs)" == "Normal end." ]; then
stat="Complete:"
else
stat="Running:"
progress=$(
tail -n 100 "${f%.*}.log" | # Get the last 1000 lines
grep '^\s*t = ' | # Get all timestamps
tail -n 1 | # Get the last line
sed -e 's/.*\[\(.*\)].*/\1/' | # Get the progress
xargs # Trim whitespace
)
fi
printf '\t\e[1;33m%-12s\e[m' "$stat"
if [[ "$stat" == "Running:" && ! -z "$progress" ]]; then
printf ' [%7s ]' "$progress"
fi
if [[ $(basename $f) == "output.log" || ${#file[@]} -lt 2 ]]; then
printf " %s\n" "$test"
else
printf " %s\n" "$test/$(basename $f)"
fi
done
fi
fi
done
for test in ${tests[@]}; do
# Check if there were errors. Print them if there were.
if [ -s $LPATH/$test/error.log ]; then
if [ "$(head -n 1 $LPATH/$test/error.log)" = "Interrupted" ]; then
printf '\t\e[1;31m%-12s\e[m %-s\n' "Interrupted:" "$test"
else
printf '\t\e[1;31m%-12s\e[m %-s\n' "Error:" "$test"
fi
fi
done
# ============================================================================ #
# Print errors for all unfinished tests
for test in ${tests[@]}; do
# Check if there were errors. Print them if there were.
if [ -s $LPATH/$test/error.log ]; then
if [ "$(head -n 1 $LPATH/$test/error.log)" = "Interrupted" ]; then
continue
fi
# Print the header with example name
printf '\n\e[4;31m%-s\e[m' "${test:0:79}"
printf '\e[4;31m%.0s_\e[m' $(seq 1 $((80 - ${#test}))) && printf '\n'
# Find the "*** ERROR: " line in the log file and print it.
for f in $(find $LPATH/$test -type f -name "*.log"); do
if [ "$(grep -i 'error' $f)" ]; then
grep -i '*** error: ' $f | fold -w 80
fi
done
printf "\n"
if [ $(cat $LPATH/$test/error.log | wc -l) -ge "10" ]; then
head -n 5 $LPATH/$test/error.log | fold -w 80
printf ".....\n"
tail -n 5 $LPATH/$test/error.log | fold -w 80
else
cat $LPATH/$test/error.log | fold -w 80
fi
printf "\n"
fi
done
printf "\n"
# Remove all empty folders in the logs folder
find $LPATH -type d -empty -delete
# # EOF # #