You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
956 B

#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# wrap execution of sledge with time and memory limits
# and add RESULT status to output in case of an unexpected exit
# usage: wrap.sh <timeout(sec)> <memout(MB)> <command> <testdir/testname>
set -u
timeout=$1
memout=$(( $2*1024 ))
command=${@: 3: $#-3}
test=${@: -1}
testdir=$(dirname $test)
testname=$(basename $test)
cd $testdir
(
ulimit -t $timeout -v $memout
$command $testname 1> $testname.out 2> $testname.err
)
status=$?
case $status in
( 139 ) echo -e "RESULT: SEGFAULT" >> $testname.out ;;
( 127 ) echo -e "RESULT: MEMOUT" >> $testname.out ;;
( 137 | 152 ) echo -e "RESULT: TIMEOUT" >> $testname.out ;;
( * ) ;;
esac
if ! grep -q 'RESULT:' $testname.out; then
echo -e "RESULT: Internal error: "$status >> $testname.out
fi
exit $status