#!/bin/bash 

#
# Tests that can lock up some kernels or are CPU / arch specific, so exclude them for now
#
EXCLUDE="sysfs procfs rdrand numa quota apparmor cpu-online kcmp copy-file mmapmany userfaultfd getrandom aio aiol tsc membarrier bind-mount sockpair remap pty exec seccomp oom-pipe"
#
# Get built-in stressor names
#
STRESSORS=$(stress-ng --help | grep "\-ops " | awk '{print $1}' | sed 's/--//' | sed 's/-ops//g')
rc=0

not_exclude()
{
	for x in $2
	do
		if [ $x == $1 ]
		then
			return 1
		fi
	done
	return 0
}

p=0
f=0
sk=0
for s in ${STRESSORS}
do
	if not_exclude $s "$EXCLUDE"
	then
		stress-ng -v -t 1 --${s} 4 2>&1
		ret=$?
		
		case $ret in
		0)	echo "$s PASSED"
			p=$((p + 1))
			;;
		1)	echo "$s SKIPPED (test framework out of resources)"
			sk=$((sk + 1))
			;;
		2)	echo "$s FAILED"
			f=$((f + 1))
			rc=1
			;;
		3)	echo "$s SKIPPED (out of resources or missing syscall)"
			sk=$((sk + 1))
			;;
		*)	echo "$s SKIPPED (unknown error return $ret)"
			sk=$((sk + 1))
			;;
		esac
	fi
done

echo "$p PASSED"
echo "$f FAILED"
echo "$sk SKIPPED"

exit $rc
