include $(ROOT)/usr/include/make/X86defs

TARGET_CFILES = \
    harness.c

LCINCS  = -I$(ROOT)/usr/include/sc
LDIRT += *.512.log *.2048.log

default: $(TARGETS) $(TARGET_CFILES)
	
$(TARGETS): $(ROOT)/usr/lib/x86/libiosim.a

include $(COMMONRULES)

%.512.log: FORCE
	SIMDEFS="+define+FASTFLASH +define+TOSHIBA_128M" make -C $(shell echo $(shell pwd) | sed -e 's|\(.*\)/sw/.*|\1/hw/chip/sim|') cpu.ipc > $@ 2>&1 &
	sleep 10

%.2048.log: FORCE
	SIMDEFS="+define+FASTFLASH +define+BOARD_ID=1" make -C $(shell echo $(shell pwd) | sed -e 's|\(.*\)/sw/.*|\1/hw/chip/sim|') cpu.ipc > $@ 2>&1 &
	sleep 10

FORCE:

test_512_normal: test_512_normal.512.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.512.fli ../test/hello.hash ../test/hello.pad"  ; [ $$? -eq 24 ]

test_512_sbe: test_512_sbe.512.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.512.sbe.fli ../test/hello.hash ../test/hello.pad"  ; [ $$? -eq 24 ]

test_512_dbe: test_512_dbe.512.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.512.dbe.fli ../test/hello.hash ../test/hello.pad" ; [ $$? -eq 255 ]

test_2048_normal: test_2048_normal.2048.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.2048.fli ../test/hello.hash ../test/hello.pad"  ; [ $$? -eq 24 ]

test_2048_sbe: test_2048_sbe.2048.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.2048.sbe.fli ../test/hello.hash ../test/hello.pad"  ; [ $$? -eq 24 ]

test_2048_dbe: test_2048_dbe.2048.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.2048.dbe.fli ../test/hello.hash ../test/hello.pad" ; [ $$? -eq 255 ]

test_null_hash: test_null_hash.512.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.512.fli ../test/null.hash ../test/hello.pad"  ; [ $$? -eq 24 ]

test_bad_hash: test_bad_hash.512.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.512.fli ../test/bad.hash ../test/hello.pad"  ; [ $$? -eq 254 ]

test_bad_kp: test_bad_kp.512.log $(TARGETS)
	./harness -ccpu0 -En -q -r ../boot0.bin -a "../test/hello.512.fli ../test/badkp.hash ../test/hello.pad"  ; [ $$? -eq 253 ]

TESTCASES = \
    test_512_normal \
    test_512_sbe \
    test_512_dbe \
    test_null_hash \
    test_bad_hash \
    test_bad_kp \
    test_2048_normal \
    test_2048_sbe \
    test_2048_dbe \

runtests: $(TESTCASES)
