# Stress Test Suite Configuration.

# Changes should be added to a `hostname` file in this directory.
# As a minimum you must updated "testuser".

export SHELL=/bin/sh
: ${allconfig:=/tmp/stress2.d/`hostname`}
[ -f  "$allconfig" ] && .  $allconfig	# Source in local configuration

# Default values
export RUNDIR=${RUNDIR:-/tmp/stressX}
export RUNTIME=${RUNTIME:-2m}
export VERBOSE=${VERBOSE:-1}
export LOAD=${LOAD:-20}

# The INCARNATIONS variable may be set to match the number of CPUs and
# the amount of RAM in the test box.
export INCARNATIONS=${INCARNATIONS:-20}

export BLASTHOST=${BLASTHOST:-192.168.1.1}		# host with udp discard enabled in inetd.conf
#export nfs_export=somehost:mount	# Used by the NFS tests

# Run all test cases:
export runRUNTIME=${runRUNTIME:-3d}	# Run tests for three days
export runINCARNATIONS=1
export runLOAD=100

export swapINCARNATIONS=${swapINCARNATIONS:-$((2 * INCARNATIONS))}
export swapLOAD=${swapLOAD:-80}

export syscallKILL=1
export swapKILL=1			# May takes a long time to stop

export rwLOAD=${rwLOAD:-70}
export mkdirLOAD=${mkdirLOAD:-80}
export creatLOAD=${creatLOAD:-80}

export symlinkLOAD=${symlinkLOAD:-20}

export tcpKILL=1
export shmINCARNATIONS=${shmINCARNATIONS:-5}

[ -z "$TESTPROGS" ] && export TESTPROGS="
testcases/rw/rw
testcases/swap/swap
testcases/creat/creat
testcases/mkdir/mkdir
testcases/thr1/thr1
testcases/udp/udp
testcases/tcp/tcp
"

#
# Defaults for ./misc tests
#

export diskimage=${diskimage:-/tmp/diskimage}	# Location of 1G disk image
export mntpoint=${mntpoint:-/mnt}		# Disk image mount point
export testuser=${testuser:-TBD}		# Name of non root test user
export mdstart=${mdstart:-10}			# Start of free md units
export newfs_flags=${newfs_flags:-"-U"}		# Default file system flags
export stress2origin=${stress2origin:-`pwd`}
export stress2tools=`dirname $stress2origin`/tools

# fsck wrapper
checkfs () {
	local s

	fsck -t ufs -fy $1 > /tmp/fsck.log 2>&1
	if grep -v "IS CLEAN" /tmp/fsck.log | \
	    LANG=C egrep -q "[A-Z][A-Z]"; then
		echo "fsck -t ufs -fy $1"
		cat /tmp/fsck.log
		s=1
	else
		rm -f /tmp/fsck.log
		s=0
	fi
	return $s
}

# Support for pre-build binaries for stress2/misc tests
# Build modes:
# 1	Build and copy binary to $STRESS2BIN
# 2	Do not compile; use binary from $STRESS2BIN

# Examples:
# BMODE=1 ./all.sh -on `grep -lw mycc *.sh`
# BMODE=2 STRESS2BIN=/home/pho/stress2/bin.i386.r276368 ./all.sh

CC=${CC:-cc}
top=`dirname $(pwd)`	# cwd for the all.sh script
STRESS2BIN=${STRESS2BIN:-$top/bin}
mycc () {	# "-o" must be first argument
	local file

	[ "$1" = "-o" ] && file=`basename $2`
	if [ "$BMODE" = "1" ]; then
		$CC $@ || return
		[ -z "$file" ] && return	# "-c"
		[ -d $STRESS2BIN ] || mkdir $STRESS2BIN
		[ -x $STRESS2BIN/$file ] &&
		    echo "Overwriting $STRESS2BIN/$file"
		echo "cp $2 $STRESS2BIN"
		cp $2 $STRESS2BIN
		exit 0 # Build but do not run the test
	elif [ "$BMODE" = "2" ]; then
		[ -z "$file" ] && return
		if [ ! -x $STRESS2BIN/$file ]; then
			echo "$STRESS2BIN/$file not found"
			exit 1
		fi
		echo "Using binary $STRESS2BIN/$file"
		cp $STRESS2BIN/$file /tmp
	else
		$CC $@	# default "build and run" mode
	fi
}

id $testuser > /dev/null 2>&1 ||
    { echo "Non-root \$testuser \"$testuser\" not found."; exit 1; }