tests: limit usertime and filesize with ulimit
authorJean Privat <jean@pryen.org>
Sat, 13 Jun 2015 02:03:10 +0000 (22:03 -0400)
committerJean Privat <jean@pryen.org>
Sat, 13 Jun 2015 02:03:10 +0000 (22:03 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/tests.sh

index df90f73..534aab1 100755 (executable)
@@ -37,11 +37,20 @@ shopt -u nullglob
 outdir="out"
 compdir="nit_compile"
 
+# User CPU time limit (in seconds)
+# Is used to avoid to CPU intensive test (infinite loops). See ulimit -t
+usertimelimit=600 # 1 CPU minute
+
 # Real-time limit (in seconds)
 # Is used to avoid waiting or sleeping tests.
 # Require timeout or timelimit, or else is not used.
 realtimelimit=300 # 5 min
 
+# User limit for write files (in kilo-bytes)
+# Is used to avoid execution that loop and fill the hard drive. See ulimit -f
+# Note that a test might require a lot of temporary disk space (eg. nitc+gcc)
+filelimit=100000 # ~100MB
+
 # Limit (in bytes) for generated .res file.
 # Larger ones are truncated and will fail tests
 # Is used to avoid processing huge crappy res file (diff, xml, etc)
@@ -80,6 +89,9 @@ saferun()
                        *) stop=true
                esac
        done
+       (
+       ulimit -f "$filelimit"
+       ulimit -t "$usertimelimit"
        if test -d "$1"; then
                find $1 | sort
        elif test -n "$TIME"; then
@@ -88,6 +100,7 @@ saferun()
                if test -n "$a"; then echo 0 >> "$o"; else echo 0 > "$o"; fi
                $TIMEOUT "$@"
        fi
+       )
 }
 
 # Output a timestamp attribute for XML, or an empty line