#!/bin/bash

case $(id) in
*root*)
	echo OK, running as root
	;;
*)
	echo OOPs, need to be root to do this 1>&2
	exit 1
	;;
esac


EINJ=/sys/kernel/debug/apei/einj

if [ ! -f $EINJ/notrigger ]
then
	modprobe einj
fi

insmod mcsafe_test.ko

paddr=$( dmesg | tail -2 | sed -n -e '/phys =/s/.*0x/0x/p' )

case "$paddr" in
0x*)
	echo physical address = $paddr
	;;
*)
	echo "Didn't get a physical address" 1>&2
	rmmod mcsafe_test
	exit 1
	;;
esac

echo 0x10 > $EINJ/error_type
echo $paddr > $EINJ/param1
echo 0xfffffffffffff000 > $EINJ/param2
echo 1 > $EINJ/notrigger
echo 1 > $EINJ/error_inject

rmmod mcsafe_test
