testsuite/systemtest_long/bintools/PIG/limmTest/run_limm_test.sh
#!/bin/bash
##############################################################################
# This test checks that LIMM behaviour is equal on HW and in simulator. In
# addition LIMM behaviour is also tested using both instruction compressors.
#
# Test has 2 machines:
# 1. 3 bus mach where 2 buses are used for LIMMs (16b+16b)
# 2. 3 bus mach where 3 buses are used for LIMMs (12b+11b+9b)
#
# Test program is is written assembly and it's generated by the initialize
# script. Test data is random.

TCEASM=../../../../../openasip/src/bintools/Assembler/tceasm
TTASIM=../../../../../openasip/src/codesign/ttasim/ttasim
PROGE=../../../../../openasip/src/procgen/ProGe/generateprocessor
PIG=../../../../../openasip/src/bintools/PIG/generatebits
CREATEBEM=../../../../../openasip/src/bintools/BEMGenerator/createbem

COMP1=../../../../../openasip/compressors/InstructionDictionary.so
COMP2=../../../../../openasip/compressors/MoveSlotDictionary.so

# this is the cycle count of tceasm execution
CYCLES=2048

ASM=limm_test.tceasm
SIM_IN1=sim_in1
SIM_IN2=sim_in2

ADF1=data/limm_2bus.adf
IDF1=data/limm_2bus.idf
TPEF1=limm_test_2bus.tpef
IMEM1=limm_test_2bus.img
DMEM1=limm_test_2bus_data.img
BEM1=limm_2bus.bem

ADF2=data/limm_3bus.adf
IDF2=data/limm_3bus.idf
TPEF2=limm_test_3bus.tpef
IMEM2=limm_test_3bus.img
DMEM2=limm_test_3bus_data.img
BEM2=limm_3bus.bem

P_DIR1=proge-output_2bus
P_DIR1_ID=proge-output_2bus_simple
P_DIR1_MS=proge-output_2bus_moveslot

P_DIR2=proge-output_3bus
P_DIR2_ID=proge-output_3bus_simple
P_DIR2_MS=proge-output_3bus_moveslot

function eexit {
    echo $1
    exit 1
}

# no point running the test if ghdl is missing
GHDL=$(which ghdl 2> /dev/null)
if [ "x$GHDL" == "x" ]
then
    # avoid false failure
    cat limm_test/1_output.txt
    exit 0
fi

$TCEASM -o $TPEF1 $ADF1 $ASM || eexit "Failed to compile asm"
$TCEASM -o $TPEF2 $ADF2 $ASM || eexit "Failed to compile asm"

# create simulation commands
#(simulator won't get stuck this way if input is illegal)
echo "setting bus_trace 1" > $SIM_IN1
echo "setting bus_trace 1" > $SIM_IN2
echo "mach $ADF1" >> $SIM_IN1
echo "mach $ADF2" >> $SIM_IN2
echo "prog $TPEF1" >> $SIM_IN1
echo "prog $TPEF2" >> $SIM_IN2
echo "run" >> $SIM_IN1
echo "run" >> $SIM_IN2
echo "quit" >> $SIM_IN1
echo "quit" >> $SIM_IN2

$TTASIM < $SIM_IN1 || eexit "Failed to simulate"
$TTASIM < $SIM_IN2 || eexit "Failed to simulate"


$CREATEBEM $ADF1 || eexit "Failed to create bem"
$CREATEBEM $ADF2 || eexit "Failed to create bem"

$PROGE -t -b $BEM1 -o $P_DIR1 -i $IDF1 $ADF1 2>&1 || eexit "ProGe failed"
cp -r $P_DIR1 $P_DIR1_ID
cp -r $P_DIR1 $P_DIR1_MS

$PROGE -t -b $BEM2 -o $P_DIR2 -i $IDF2 $ADF2 2>&1 || eexit "ProGe failed"
cp -r $P_DIR2 $P_DIR2_ID
cp -r $P_DIR2 $P_DIR2_MS


# create images for 2 bus limm without compression
$PIG -b $BEM1 -d -w 4 -x $P_DIR1 -p $TPEF1 $ADF1 2>&1 || eexit "PIG failed..oink oink"

# create images for 2 bus limm using instruction dictionary compression
$PIG -b $BEM1 -d -w 4 -x $P_DIR1_ID -p $TPEF1 -g -c $COMP1 $ADF1 2>&1 || eexit "PIG failed with InstructionDictionary"

# create images for 2 bus limm using moveslot dictionary compression
$PIG -b $BEM1 -d -w 4 -x $P_DIR1_MS -p $TPEF1 -g -c $COMP2 $ADF1 2>&1 || eexit "PIG failed with MoveSlotDictionary"

# create images for 3 bus limm without compression
$PIG -b $BEM2 -d -w 4 -x $P_DIR2 -p $TPEF2 $ADF2 2>&1 || eexit "PIG failed..oink oink"

# create images for 3 bus limm using instruction dictionary compression
$PIG -b $BEM2 -d -w 4 -x $P_DIR2_ID -p $TPEF2 -g -c $COMP1 $ADF2 2>&1 || eexit "PIG failed with InstructionDictionary"

# create images for 3 bus limm using moveslot dictionary compression
$PIG -b $BEM2 -d -w 4 -x $P_DIR2_MS -p $TPEF2 -g -c $COMP2 $ADF2 2>&1 || eexit "PIG failed with MoveSlotDictionary"


cd $P_DIR1
./ghdl_compile.sh >& /dev/null
./ghdl_simulate.sh >& /dev/null
cd ..

cd $P_DIR1_ID
./ghdl_compile.sh >& /dev/null
./ghdl_simulate.sh >& /dev/null
cd ..

cd $P_DIR1_MS
./ghdl_compile.sh >& /dev/null
./ghdl_simulate.sh >& /dev/null
cd ..


cd $P_DIR2
./ghdl_compile.sh >& /dev/null
./ghdl_simulate.sh >& /dev/null
cd ..

cd $P_DIR2_ID
./ghdl_compile.sh >& /dev/null
./ghdl_simulate.sh >& /dev/null
cd ..

cd $P_DIR2_MS
./ghdl_compile.sh >& /dev/null
./ghdl_simulate.sh >& /dev/null
cd ..


head -n $CYCLES $P_DIR1/bus.dump > $TPEF1.rtl_bustrace
head -n $CYCLES $P_DIR1_ID/bus.dump > $TPEF1.rtl_id_comp_bustrace
head -n $CYCLES $P_DIR1_MS/bus.dump > $TPEF1.rtl_ms_comp_bustrace

head -n $CYCLES $P_DIR2/bus.dump > $TPEF2.rtl_bustrace
head -n $CYCLES $P_DIR2_ID/bus.dump > $TPEF2.rtl_id_comp_bustrace
head -n $CYCLES $P_DIR2_MS/bus.dump > $TPEF2.rtl_ms_comp_bustrace


diff -u $TPEF1.bustrace $TPEF1.rtl_bustrace || echo "$ADF1 without compression failed"
diff -u $TPEF1.bustrace $TPEF1.rtl_id_comp_bustrace || echo "$ADF1 with instruction dictionary failed"
diff -u $TPEF1.bustrace $TPEF1.rtl_ms_comp_bustrace || echo "$ADF1 with moveslot dictionary failed"

diff -u $TPEF2.bustrace $TPEF2.rtl_bustrace || echo "$ADF2 without compression failed"
diff -u $TPEF2.bustrace $TPEF2.rtl_id_comp_bustrace || echo "$ADF2 with instruction dictionary failed"
diff -u $TPEF2.bustrace $TPEF2.rtl_ms_comp_bustrace || echo "$ADF2 with moveslot dictionary failed"