test_command () {
  output=`"$@" 2>&1 > /dev/null`
  result=$?
  if [ $result != 0 ]; then
     echo "$output" | head
     echo
     echo "**** TEST FAILED ****"
     echo
     exit $result
  fi
}

echo "Testing..."

test_command memtester -t 'Random Value' 48M 1
test_command memtester -t 'Compare XOR' 48M 1
test_command memtester -t 'Compare SUB' 5M 240

echo
echo "**** TEST PASSED ****"
echo
