! Tests the XBC version of FANIN and FANOUT
!
! author: Jay Hallam / Neon Ngo
! version: $Id: test_fanin.mm,v 1.2 2009/08/20 20:06:57 ntn Exp $
!
startmacro
  set fanin_infile1   "test_fanin_c1.tmp"
  set fanin_infile2   "test_fanin_c2.tmp"
  set fanin_outfile   "test_fanin_join.tmp"
  set fanout_outfile1 "test_fanout_c1.tmp"
  set fanout_outfile2 "test_fanout_c2.tmp"

  ! generate input files for FANIN (and to verify output of FANOUT)
  WAVEFORM,OUT=fanin_infile1,FORM=SF,ELEM=4K,SHAPE=CONST,AMP=1
  WAVEFORM,OUT=fanin_infile2,FORM=SF,ELEM=4K,SHAPE=CONST,AMP=2

  ! run/test FANIN
  fanin;xbc  fanin_outfile fanin_infile1  fanin_infile2

  ! verify FANIN output file
  assert/text="^reg.main.name: FANIN output file exists" fanin_outfile FEXISTS
  assert/text="^reg.main.name: FANIN output file # elements" FILE(fanin_outfile).size eq 8K
  ! verify first four data elements in FANINT output file
  assert/text="^reg.main.name: FANIN output file data element #1" FILE(fanin_outfile).data(0) eq 1
  assert/text="^reg.main.name: FANIN output file data element #2" FILE(fanin_outfile).data(1) eq 2
  assert/text="^reg.main.name: FANIN output file data element #3" FILE(fanin_outfile).data(2) eq 1
  assert/text="^reg.main.name: FANIN output file data element #4" FILE(fanin_outfile).data(3) eq 2


  ! run/test FANOUT
  fanout;xbc fanin_outfile fanout_outfile1 fanout_outfile2

  ! verify FANOUT output files
  assert/text="^reg.main.name: FANOUT output file 1 exists" fanout_outfile1 FEXISTS
  assert/text="^reg.main.name: FANOUT output file 2 exists" fanout_outfile2 FEXISTS
  assert/text="^reg.main.name: FANOUT output file # elements" FILE(fanout_outfile1).size eq 4K
  assert/text="^reg.main.name: FANOUT output file # elements" FILE(fanout_outfile2).size eq 4K
  ! verify contents of FANOUT output files against FANIN input files
  assert/text="^reg.main.name: FANIN -> FANOUT Constant 1" fanin_infile1 FEQ fanout_outfile1
  assert/text="^reg.main.name: FANIN -> FANOUT Constant 2" fanin_infile2 FEQ fanout_outfile2

  ! cleanup
  files/e test_fanin_*
  files/e test_fanout_*

endmacro
