forked from UBC-Thunderbots/Software
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe_run.sh
More file actions
executable file
·52 lines (39 loc) · 1.14 KB
/
Copy pathsafe_run.sh
File metadata and controls
executable file
·52 lines (39 loc) · 1.14 KB
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
#!/bin/bash
# Timeout in seconds
# When the time is up and no error was shown, this test will pass
TIME_LIMIT=120 # 2 minutes
# Match Python traceback
ERROR_PATTERN="Traceback (most recent call last):"
# Temporary log file
LOG_FILE=$(mktemp)
# Run the command and record the log
"$@" &> "$LOG_FILE" &
CMD_PID=$!
echo "Process Running in Wrapper with Timeout $TIME_LIMIT ..."
# Time the process
SECONDS=0
while kill -0 $CMD_PID 2>/dev/null; do
# Check if time is up
if [ $SECONDS -ge $TIME_LIMIT ]; then
echo "Time limit reached, stopping process: $CMD_PID"
kill -SIGINT $CMD_PID
wait $CMD_PID
exit 0 # Upon time out and no error, returns 0 status code
fi
# Check if the log contains Traceback
if grep -q "$ERROR_PATTERN" "$LOG_FILE"; then
echo "[Error detected] Potential error found in command output!"
kill -SIGINT $CMD_PID
wait $CMD_PID
exit 1
fi
sleep 1 # Run this loop once per second
done
cat $LOG_FILE
# Get the exit code of the process
wait $CMD_PID
EXIT_CODE=$?
# Clean up log file
rm -f "$LOG_FILE"
# Exit with the command status code
exit $EXIT_CODE