github.com/singularityware/singularity@v3.1.1+incompatible/docs/2.x-tests/functions (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2015-2017, Gregory M. Kurtzer. All rights reserved. 4 # 5 # Copyright (c) 2016-2017, The Regents of the University of California, 6 # through Lawrence Berkeley National Laboratory (subject to receipt of any 7 # required approvals from the U.S. Dept. of Energy). All rights reserved. 8 # 9 # This software is licensed under a customized 3-clause BSD license. Please 10 # consult LICENSE file distributed with the sources of this project regarding 11 # your rights to use or distribute this software. 12 # 13 # NOTICE. This Software was developed under funding from the U.S. Department of 14 # Energy and the U.S. Government consequently retains certain rights. As such, 15 # the U.S. Government has been granted for itself and others acting on its 16 # behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software 17 # to reproduce, distribute copies to the public, prepare derivative works, and 18 # perform publicly and display publicly, and to permit other to do so. 19 # 20 # 21 22 SINGULARITY_MESSAGELEVEL=5 23 24 . ../libexec/functions 25 26 if [ `id -ru` = "0" ]; then 27 message ERROR "Don't make test as root\n" 28 ABORT 255 29 fi 30 31 alias singularity="$SINGULARITY_PATH/singularity" 32 33 test_init() { 34 if [ -z "${1:-}" ]; then 35 echo "Called test_init without a title" 36 exit 1 37 fi 38 39 TITLE="$1" 40 shift 41 42 if [ -n "${SINGULARITY_TESTDIR:-}" ]; then 43 test_cleanup 44 fi 45 46 if ! SINGULARITY_TESTDIR=`mktemp -d ${TMPDIR:-/tmp}/stest.XXXXXX`; then 47 message ERROR "Failed to create temporary directory\n" 48 ABORT 255 49 fi 50 51 echo 52 echo "################################################################################" 53 echo "$TITLE (script: $0, testdir: $SINGULARITY_TESTDIR)" 54 echo 55 } 56 57 test_cleanup() { 58 59 if [ -d "$SINGULARITY_TESTDIR" ]; then 60 rm -rf "$SINGULARITY_TESTDIR" 61 fi 62 63 exit 0 64 } 65 66 exit_cleanup() { 67 return 0 68 } 69 70 stest() { 71 ERROR="${1:-}" 72 OUTPUT="$SINGULARITY_TESTDIR/output" 73 shift 74 75 pwd > "$SINGULARITY_TESTDIR/pwd" 76 echo "$@" > "$SINGULARITY_TESTDIR/cmd" 77 message 2 " + %-90.90s " "$*" 78 79 "$@" >$OUTPUT 2>&1 80 RETVAL="$?" 81 82 if [ "$ERROR" = "0" -a "$RETVAL" != "0" ]; then 83 message 2 "%13s ERROR\n" "(retval=$RETVAL)" 84 cat "$OUTPUT" 85 echo "Full output in: $SINGULARITY_TESTDIR" 86 exit_cleanup 87 exit 1 88 elif [ "$ERROR" != "0" -a "$RETVAL" = "0" ]; then 89 message 2 "%13s ERROR\n" "(retval=$RETVAL)" 90 cat "$OUTPUT" 91 echo "Full output in: $SINGULARITY_TESTDIR" 92 exit_cleanup 93 exit 1 94 else 95 message 2 "%13s OK\n" "(retval=$RETVAL)" 96 fi 97 }