#! /bin/sh

# Test harness to find the critical delay between cfaddd and cfstrd
# to make erratum16 bite.

set -e		# Stop if anything fails unexpectedly

for nnops in `seq 1 32`
do
    {
	cat cfstrd-bug-head.c

	n=$nnops
	while [ $n -gt 0 ]
	do
		echo '	asm("nop");'
		# Stupid expr exits 1 if result is 0
		n=`expr $n - 1` || : never mind
	done

	cat cfstrd-bug-tail.c

    } > cfstrd-bug-tmp.c

    # Stupid make thinks that an object created less than 1 second ago is up to date
    rm -f cfstrd-bug-tmp	

    make cfstrd-bug-tmp

    ./cfstrd-bug-tmp || echo "Failed with $n nops. Failing C program is in cfstrd-bug-tmp.c"
done
