#!/bin/bash

# Tests CPU/DMA hitting on memory

# Copyright (C) 2003-2006 IBM
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.


# Can we find the script?
if [ ! -f "$POUNDER_OPTDIR/memtest.sh" ]; then
	echo "Can't find memtest.sh; did you run Install?"
	exit -1
fi

MEMTESTDIR="$POUNDER_TMPDIR/memtest/"
rm -rf "$MEMTESTDIR"
mkdir -p "$MEMTESTDIR"

# Did we see any failures?
LOGFILE=/proc/$$/fd/1
OLD_ERRORS=`egrep -ic "(err|fail|invalid|cannot|denied|diff)" $LOGFILE`

# Run the test
cd "$POUNDER_OPTDIR"
cp "$POUNDER_OPTDIR/linux-2.6.39.tar.bz2" "$MEMTESTDIR/linux-2.6.39.tar.bz2"
#NR_PASSES=2 TEST_DIR="$MEMTESTDIR" SOURCE_FILE="$POUNDER_OPTDIR/linux-2.6.39.tar.gz"
./memtest.sh

# Now clean up
rm -rf "$POUNDER_TMPDIR/memtest/"

# Did we see any failures?
NEW_ERRORS=`egrep -ic "(err|fail|invalid|denied|cannot|diff)" $LOGFILE`
ERRORS=$((NEW_ERRORS - OLD_ERRORS))
if [ $ERRORS -eq 255 ]; then
        ERRORS=254
fi
exit $ERRORS

