#
# Copyright CESR CNRS 
# 	      9 avenue du Colonel Roche
# 	      31028 Toulouse Cedex 4
#
# Contributor(s) : 
#
#  - Bernard Bertrand 
#   
#
# This software is a computer program whose purpose is to implement a spacewire 
# link according to the ECSS-E-50-12A.
#
# This software is governed by the CeCILL-C license under French law and
# abiding by the rules of distribution of free software.  You can  use, 
# modify and/ or redistribute the software under the terms of the CeCILL-C
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info". 
#
# As a counterpart to the access to the source code and  rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty  and the software's author,  the holder of the
# economic rights,  and the successive licensors  have only  limited
# liability. 
#
# In this respect, the user's attention is drawn to the risks associated
# with loading,  using,  modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean  that it is complicated to manipulate,  and  that  also
# therefore means  that it is reserved for developers  and  experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or 
# data to be ensured and,  more generally, to use and operate it in the 
# same conditions as regards security. 
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL-C license and that you accept its terms.
#

#!/bin/bash
# $1 : test case file
#Target_DIR=.
WORKSPACE_DIR=.
cp ../../src/Spacewire_Pack.vhd .
#################################################################
cp ../components/emu/emu_pack.vhd .
cp ../components/emu/emu_spwr_pack.vhd .
cp ../components/emu/emu_spwr.vhd .
cp ../../src/Rx.vhd .
cp ../../src/Tx.vhd .
cp ../../src/Rx_Fifo.vhd .
cp ../../src/Tx_Fifo.vhd .
cp ../../src/fsm.vhd .
cp ../../src/width_to_short_n.vhd .
cp ../../src/twodomainclock.vhd .
cp ../TB_ghdl/src/tb_check_spwr_ip.vhd .
#################################################################
counter=0
echo $1
case $1 in
'test')
echo "TEST CONNECT BETWEEN IP2 ET IP "
cp ../TB_ghdl/test_cases/test/com.txt .
cp ../TB_ghdl/src/test.vhd .
;;
'test0')
echo "TEST0 IP2 SEND DATA TO IP "
#cp ../TB_ghdl/test_cases/test0/com.txt .
cp ../TB_ghdl/src/test0.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
;;
'test1')
echo "TEST1 IP SEND DATA TO IP2  "
#cp ../TB_ghdl/test_cases/test1/com.txt .
cp ../TB_ghdl/src/test1.vhd .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test2')
echo "TEST2 FULL DUPLEX DATA BETWEEN IP2 and IP"
#cp ../TB_ghdl/test_cases/test2/com.txt .
cp ../TB_ghdl/src/test2.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test3')
echo "TEST3 TEST FULL FIFO RX IP"
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/src/test3.vhd .
;;
'test4')
echo "TEST4 CREDIT ERROR in RX IP"
echo "EMULATOR VS IP"
cp ../TB_ghdl/test_cases/test4/com.txt .
cp ../TB_ghdl/src/test4.vhd .
;;
'test5')
echo "TEST5 CREDIT ERROR in TX IP"
echo "EMULATOR VS IP"
cp ../TB_ghdl/test_cases/test5/com.txt .
cp ../TB_ghdl/src/test5.vhd .
;;
'test6')
echo "TEST6 DISCONNECT ERROR IN ErrorWAIT STATE "
cp ../TB_ghdl/test_cases/test6/com.txt .
cp ../TB_ghdl/src/test6.vhd .
;;
'test7')
echo "TEST7 DISCONNECT ERROR IN Ready STATE "
cp ../TB_ghdl/test_cases/test6/com.txt .
cp ../TB_ghdl/src/test7.vhd .
;;
'test8')
echo "TEST8 DISCONNECT ERROR IN STARTED STATE "
cp ../TB_ghdl/test_cases/test6/com.txt .
cp ../TB_ghdl/src/test8.vhd .
;;
'test9')
echo "TEST9 DISCONNECT ERROR IN CONNECTING STATE "
cp ../TB_ghdl/test_cases/test6/com.txt .
cp ../TB_ghdl/src/test9.vhd .
;;
'test10')
echo "TEST10 DISCONNECT ERROR IN RUN STATE "
cp ../TB_ghdl/test_cases/test6/com.txt .
cp ../TB_ghdl/src/test10.vhd .
;;
'test11')
echo "TEST11 continuous CHAR ERROR since reset"
cp ../TB_ghdl/test_cases/test11/com.txt .
cp ../TB_ghdl/src/test11.vhd .
;;
'test12')
echo "TEST12 receive FCT ERROR in ErrorWait"
cp ../TB_ghdl/test_cases/test12/com.txt .
cp ../TB_ghdl/src/test12.vhd .
;;
'test13')
echo "TEST13 receive TIME ID ERROR in ErrorWait"
cp ../TB_ghdl/test_cases/test13/com.txt .
cp ../TB_ghdl/src/test13.vhd .
;;
'test14')
echo "TEST14 receive CHAR ID ERROR in ErrorWait"
cp ../TB_ghdl/test_cases/test14/com.txt .
cp ../TB_ghdl/src/test14.vhd .
;;
'test15')
echo "TEST15 receive FCT ERROR in ErrorWait"
cp ../TB_ghdl/test_cases/test15/com.txt .
cp ../TB_ghdl/src/test15.vhd .
;;
'test16')
echo "TEST16 receive TIME ID ERROR in started state"
cp ../TB_ghdl/test_cases/test16/com.txt .
cp ../TB_ghdl/src/test16.vhd .
;;
'test17')
echo "TEST17 receive DATA ERROR in started state"
cp ../TB_ghdl/test_cases/test17/com.txt .
cp ../TB_ghdl/src/test17.vhd .
;;
'test18')
echo "TEST18 receive FCT ERROR in started state"
cp ../TB_ghdl/test_cases/test18/com.txt .
cp ../TB_ghdl/src/test18.vhd .
;;
'test19')
echo "TEST19 receive DATA in connecting state"
cp ../TB_ghdl/test_cases/test19/com.txt .
cp ../TB_ghdl/src/test19.vhd .
;;
'test20')
echo "TEST20 receive TIME ID in connecting state"
cp ../TB_ghdl/test_cases/test20/com.txt .
cp ../TB_ghdl/src/test20.vhd .
;;
'test21')
echo "TEST21 parity error in error wait state"
cp ../TB_ghdl/test_cases/test21/com.txt .
cp ../TB_ghdl/src/test21.vhd .
;;
'test22')
echo "TEST22 esc error in error wait state"
cp ../TB_ghdl/test_cases/test22/com.txt .
cp ../TB_ghdl/src/test22.vhd .
;;
'test23')
echo "TEST23 parity error in started state"
cp ../TB_ghdl/test_cases/test23/com.txt .
cp ../TB_ghdl/src/test23.vhd .
;;
'test24')
echo "TEST24 esc error in started state"
cp ../TB_ghdl/test_cases/test24/com.txt .
cp ../TB_ghdl/src/test24.vhd .
;;
'test25')
echo "TEST25 parity error in connecting state"
cp ../TB_ghdl/test_cases/test25/com.txt .
cp ../TB_ghdl/src/test25.vhd .
;;
'test26')
echo "TEST26 esc error in connecting state"
cp ../TB_ghdl/test_cases/test26/com.txt .
cp ../TB_ghdl/src/test26.vhd .
;;
'test27')
echo "TEST27 parity error in Run state"
cp ../TB_ghdl/test_cases/test27/com.txt .
cp ../TB_ghdl/src/test27.vhd .
;;
'test28')
echo "TEST28 esc error in Run state"
cp ../TB_ghdl/test_cases/test28/com.txt .
cp ../TB_ghdl/src/test28.vhd .
;;
'test29')
echo "TEST29 IP send time id to IP2"
cp ../TB_ghdl/src/test29.vhd .
cp ../TB_ghdl/test_cases/in_ip_time.txt .
;;
'test30')
echo "TEST30 IP2 send time id to IP"
cp ../TB_ghdl/src/test30.vhd .
cp ../TB_ghdl/test_cases/in_ip_time_2.txt .
;;
'test31')
echo "TEST31 IP2 - IP full duplex shifted, IP send after IP2"
cp ../TB_ghdl/src/test31.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test32')
echo "TEST32 IP2 - IP full duplex shifted, IP2 send after IP"
cp ../TB_ghdl/src/test32.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test33')
echo "TEST33 receive FCT ERROR in ready state"
cp ../TB_ghdl/test_cases/test33/com.txt .
cp ../TB_ghdl/src/test33.vhd .
;;
'test34')
echo "TEST34 receive CHAR ERROR in ready state"
cp ../TB_ghdl/test_cases/test34/com.txt .
cp ../TB_ghdl/src/test34.vhd .
;;
'test35')
echo "TEST35 receive time ERROR in ready state"
cp ../TB_ghdl/test_cases/test35/com.txt .
cp ../TB_ghdl/src/test35.vhd .
;;
'test36')
echo "TEST36 full duplex reset IP after reset IP2"
cp ../TB_ghdl/src/test36.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test37')
echo "TEST37 full duplex reset IP2 after reset IP"
cp ../TB_ghdl/src/test37.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test38')
echo "TEST38 ip to IP2 send mixe time id and data id  "
cp ../TB_ghdl/src/test38.vhd .
cp ../TB_ghdl/test_cases/in_ip.txt .
cp ../TB_ghdl/test_cases/in_ip_time.txt .
;;
'test39')
echo "TEST39 IP2 send to ip mixe time id and data id  "
cp ../TB_ghdl/src/test39.vhd .
cp ../TB_ghdl/test_cases/in_ip_2.txt .
cp ../TB_ghdl/test_cases/in_ip_time_2.txt .
;;
'test40')
echo "TEST40 esc+eop escape error in error wait state "
cp ../TB_ghdl/test_cases/test40/com.txt .
cp ../TB_ghdl/src/test40.vhd .
;;
'test41')
echo "TEST41 esc+eep escape error in error wait state "
cp ../TB_ghdl/test_cases/test40/com.txt .
cp ../TB_ghdl/src/test41.vhd .
;;
'test42')
echo "TEST42 out to in ip with disconnect "
cp ../TB_ghdl/src/test42.vhd .
;;
'test43')
echo "TEST43 parity error in ready state"
cp ../TB_ghdl/test_cases/test43/com.txt .
cp ../TB_ghdl/src/test43.vhd .
;;
'test44')
echo "TEST44 esc error ready state"
cp ../TB_ghdl/test_cases/test44/com.txt .
cp ../TB_ghdl/src/test44.vhd .
;;
'test99')
echo "TEST99 out to in ip with data,eop,time-id "
echo "--TEST A EFFECTUER XT_Tck_tx_spwr:=32ns--"
cp ../TB_ghdl/test_cases/in_ip_time.txt .
cp ../TB_ghdl/src/test99.vhd .
cp ../TB_ghdl/test_cases/in_ip.txt .
;;
'test100')
echo "TEST generate null in continuous"
cp test100/com.txt .
;;
'test101')
echo "TEST generate null in continuous"
cp test101/com.txt .
;;
*)
echo "aucune option"
;;
esac
echo "COPY FILE SRC"
cp ../components/emu/*.vhd .
cp ../../src/*.vhd .
cp ../TB_ghdl/src/tb_check_spwr_ip.vhd .
echo "END COPY FILE SRC"
#################################################################
ghdl -a --ieee=synopsys -fexplicit --std=93 Spacewire_Pack.vhd
#################################################################
ghdl -a --ieee=synopsys -fexplicit --std=93 emu_pack.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93 emu_spwr_pack.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93 emu_spwr.vhd
##################################################################	
##################################################################
ghdl -a --ieee=synopsys -fexplicit --std=93  Rx.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  Tx.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  Rx_Fifo.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  Tx_Fifo.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  fsm.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  width_to_short_n.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  twodomainclock.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  tb_check_spwr_ip.vhd
ghdl -a --ieee=synopsys -fexplicit --std=93  $1.vhd
ghdl -c --ieee=synopsys -fexplicit --std=93 -r $1 --stop-time=8250us --wave=$1.ghw
if [ $2 = 1 ]
then
gtkwave $1.ghw a.sav
fi		
echo $1
case $1 in
'test0')
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test1')
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt
diff out_ip_2.txt in_ip.txt >> result_diff.txt
mv out_ip_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report 
;;
'test2')
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt
diff out_ip_2.txt in_ip.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv out_ip_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test29')
echo "RESULTAT DIFF entre in_ip_time.txt et out_ip_time_2.txt"
diff in_ip_time.txt out_ip_time_2.txt
diff in_ip_time.txt out_ip_time_2.txt >> result_diff.txt
mv out_ip_time_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test30')
echo "RESULTAT DIFF entre out_ip_time.txt et in_ip_time_2.txt"
diff out_ip_time.txt in_ip_time_2.txt
diff out_ip_time.txt in_ip_time_2.txt >> result_diff.txt
mv result_diff.txt ../TB_ghdl/report
mv out_ip_time.txt ../TB_ghdl/report
;;
'test31')
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt
diff out_ip_2.txt in_ip.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv out_ip_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test32')
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt 
diff out_ip_2.txt in_ip.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report 
mv out_ip_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test36')
echo "TEST36 full duplex reset IP after reset IP2" >> result_diff.txt
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt" >> result_diff.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt" >> result_diff.txt
diff out_ip_2.txt in_ip.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv out_ip_2.txt ../TB_ghdl/report 
;;
'test37')
echo "RESULTAT DIFF entre in_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt
diff out_ip_2.txt in_ip.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv out_ip_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test38')
echo "RESULTAT DIFF entre out_ip_2.txt et in_ip.txt"
diff out_ip_2.txt in_ip.txt
diff out_ip_2.txt in_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre out_ip_time_2.txt et in_ip_time.txt"
diff out_ip_time_2.txt in_ip_time.txt
diff out_ip_time_2.txt in_ip_time.txt >> result_diff.txt
mv out_ip_2.txt ../TB_ghdl/report
mv out_ip_time_2.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test39')
echo "RESULTAT DIFF entre out_ip_2.txt et out_ip.txt"
diff in_ip_2.txt out_ip.txt
diff in_ip_2.txt out_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre in_ip_time2.txt et out_ip_time.txt"
diff in_ip_time_2.txt out_ip_time.txt
diff in_ip_time_2.txt out_ip_time.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv out_ip_time.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
'test99')
echo "RESULTAT DIFF entre out_ip.txt et in_ip.txt"
diff out_ip.txt in_ip.txt
diff out_ip.txt in_ip.txt >> result_diff.txt
echo "RESULTAT DIFF entre in_ip_time.txt et out_ip_time.txt"
diff in_ip_time.txt out_ip_time.txt
diff in_ip_time.txt out_ip_time.txt >> result_diff.txt
mv out_ip.txt ../TB_ghdl/report
mv out_ip_time.txt ../TB_ghdl/report
mv result_diff.txt ../TB_ghdl/report
;;
*)
echo "aucune option"
;;
esac
mv file_log.txt ../TB_ghdl/report
#rm *.vhd
rm *.txt
#rm *.ghw
#rm *.cf