reality_rsp_misc 9.92 KB
#!/usr/local/bin/perl

if ($ENV{"ROOT"}) {
   $ROOT = $ENV{"ROOT"};
  }
else {
  die "ROOT env not set. Plaase set ROOT environment first \n";
  }

$MISC_DIR =  $ROOT."/PR/rspsim/vuregre/src/misc";
$VUREGRES =  $ROOT."/PR/rspsim/vuregre";
$TOOL =   $VUREGRES."/bin";
$YOGI_TOOL = "/hosts/yogi/usr/people/kishor/mdevroot/PR/rspsim/vuregre/bin";
$RSPASM = $ROOT."/PR/rspasm";
$RSPSIM = $ROOT."/PR/rspsim";
$REALITY_PATH = $ROOT."/PR/hw/chip/sim";


$VCSDIR = "/ecad/vcs/vcs_2.2/sgi";

$WORKDIR = `pwd`;
chop($WORKDIR);
$TESTDIR = $WORKDIR."/tests";
$TESTDIR_CT = $TESTDIR."/ctrace";
$DESIGNC = $WORKDIR."/designc"; 


$OPTION_ASM = 1;
$OPTION_ASM_ONLY = 0;
$OPTION_VCSCOMPILE = 1;
$OPTION_VCSRUN = 1;
$OPTION_BATCH = 1;
$OPTION_ALL = 1;
$OPTION_GATE = 0;
@PlusArgs = ();
$ALL_DIAGS = 1;
$TEST_SRC_FILE = "";

while ($#ARGV >= 0) {

    if ($ARGV[0] eq '-noasm') {
      shift (@ARGV);
      $OPTION_ASM = 0;
     }
    elsif ($ARGV[0] eq '-nocompile') {
      shift (@ARGV);
      $OPTION_VCSCOMPILE = 0;
      $OPTION_ASM = 0;
    }
    elsif ($ARGV[0] eq '-asmonly') {
      shift (@ARGV);
      $OPTION_ASM_ONLY = 1;
    }
    elsif ($ARGV[0] eq '-norun') {
      shift (@ARGV);
      $OPTION_VCSRUN = 0;
    }
    elsif ($ARGV[0] eq '-gate') {
      shift (@ARGV);
      $OPTION_GATE = 1;
    }
    elsif ($ARGV[0] eq '+dumpvars') {
      $PlusArgs = push(@PlusArgs,shift(@ARGV));
    }
    elsif ($ARGV[0] eq '+rsp_mon') {
      $PlusArgs = push(@PlusArgs,shift(@ARGV));
    }
    elsif ($ARGV[0] =~ /^\+reality=/) {
      ($TEMP,$plus_arg) = split(/=/,shift(@ARGV));
      $PlusArgs = push(@PlusArgs,"+".$plus_arg);
    }
    elsif ($ARGV[0] =~ /^\+sweep_start=/) {
      $PlusArgs = push(@PlusArgs,shift(@ARGV));
    }
    elsif ($ARGV[0] =~ /^\+diag=/) {
      ($TEMP,$DIAG) = split(/=/,shift(@ARGV));
      $PlusArgs = push(@PlusArgs,"+diag_".$DIAG);
      $ALL_DIAGS = 0;
    }
    else {
    die "Illigal option provided \n";
    }

} #while ($#ARGV >= 0)

if ($ALL_DIAGS==1) {
    $PlusArgs = push(@PlusArgs,"+AllDiags");
    }

if (!(-e $TESTDIR && -d $TESTDIR)) {
  print "Creating the $TESTDIR directory\n";
  mkdir ($TESTDIR,0777)    || die "Cant make $TESTDIR \n";
  }
if (!(-e $TESTDIR_CT && -d $TESTDIR_CT)) {
  print "Creating the $TESTDIR_CT directory\n";
  mkdir ($TESTDIR_CT,0777)    || die "Cant make $TESTDIR_CT \n";
  }

if (!(-e $DESIGNC && -d $DESIGNC)) {
  print "Creating the $DESIGNC directory\n";
  mkdir ($DESIGNC,0777) || die "Cant make $DESIGNC \n";
  } 

if (!(-r $REALITY_PATH."/Makefile")){
  die "$REALITY_PATH/Makefile not found. Please p_tupdate $REALITY_PATH \n";
  }
if (!(-r $VUREGRES."/regression/rsp_ctrace.v")){
  die "rsp_ctrace.v not found. Please p_tupdate $VUREGRES \n";
  }
if (!(-r $VUREGRES."/regression/misc_tests_include.v")){
  die "misc_tests_include.v not found. Please p_tupdate $VUREGRES \n";
  }

if (-r $REALITY_PATH."/Makefile"){
    print "Getting file $REALITY_PATH/Makefile \n";
    system("cat $REALITY_PATH/Makefile | $TOOL/make_reality_makefile -MISC_TESTS > $WORKDIR/Makefile")==0
     || die " System Call interrupt";
    chmod(0666,$WORKDIR."/Makefile");
   }
else {
  die "$REALITY_PATH/Makefile not found. Please p_tupdate $REALITY_PATH \n";
   }

if ($OPTION_ASM) {

   if (!(-r "misc_testsuite")){
      print "Getting file $VUREGRES/regression/misc_testsuite \n";
      system("cp $VUREGRES/regression/misc_testsuite $WORKDIR")==0
       || die " System Call interrupt";
      chmod(0666,$WORKDIR."/misc_testsuite");
    }

  open(TESTSUITE,"misc_testsuite") || die "Cant open misc_testsuite \n";
  open(TESTSKIPPED,">tests.skipped") || die "Cant open tests.skipped \n";

  $test_num=0;
  $DMA_ONETIME = 0;

  while ($_= <TESTSUITE>) {

     split;

     $TEST_TYPE = $_[0];
     $TEST =      $_[1]; #test

     if ($TEST_TYPE eq "MISC") {

       $TESTNAME_FULL = $MISC_DIR."/".$TEST;

       open(MAKEFILE,">$TESTDIR/Makefile") || die "Cant open $TESTDIR/Makefile \n";
  
       $TEST = `basename $TESTNAME_FULL`;
       chop($TEST);
  
       print "test is $TEST \n";
  	
       ($TEST,$FILE_TYPE) = split(/\./,$TEST);

	if (-r $TESTNAME_FULL) {

	    chdir ($TESTDIR) || die "Cant go to $TESTDIR \n";
            
	    print MAKEFILE "\n";
	    print MAKEFILE "TARGET1 = $TEST.s\n";
	    print MAKEFILE "TARGET2 = $TEST.rdram_IMEM\n";
	    print MAKEFILE "TOOL = $TOOL/lst2IMEM $TOOL/dat2rdram $RSPASM/rspasm $TOOL/d2asm ".
		           "$TOOL/trace2ver $TOOL/make_rtsk $RSPSIM/rsp $YOGI_TOOL/reorder ".
			   "$TOOL/make_dma_rtsk \n";
	    print MAKEFILE "\n";
	    print MAKEFILE "\$(TARGET2): $TEST.s $TEST.rtsk \$(TOOL)\n";
	    print MAKEFILE "\ttouch a.out\n";
	    print MAKEFILE "\trm a.out*\n";
	    print MAKEFILE "\t$RSPASM/rspasm -b 0 $TEST.s\n";
	    print MAKEFILE "\tmv a.out $TEST.out\n";
	    print MAKEFILE "\tmv a.out.lst $TEST.lst\n";
	    print MAKEFILE "\tmv a.out.dat $TEST.dat\n";
	    print MAKEFILE "\t$RSPSIM/rsp -ntz $TEST.rtsk</dev/null> $TEST.simlog \n";
	    print MAKEFILE "\tmv trace_out ctrace/$TEST.ctrace\n";
	    print MAKEFILE "\tod -vX $TEST.dat | $TOOL/dat2rdram > rdram.DMEM;\n";
	    print MAKEFILE "\t(cd ctrace; $TOOL/trace2ver $TEST)\n";
	    print MAKEFILE "\t$TOOL/lst2IMEM $TEST.lst > rdram.IMEM\n";
	    print MAKEFILE "\t$YOGI_TOOL/reorder;\n";
	    print MAKEFILE "\tmv dmem_reordered.data $TEST.rdram_DMEM; \n";
	    print MAKEFILE "\tmv imem_reordered.data $TEST.rdram_IMEM; \n";
	    print MAKEFILE "\n";
	    print MAKEFILE "$TEST.s: $MISC_DIR/$TEST.s\n";
	    print MAKEFILE "\tcp $MISC_DIR/$TEST.s $TEST.s\n";
	    print MAKEFILE "\tchmod +w $TEST.s\n";
	    print MAKEFILE "\n";
	    print MAKEFILE "$TEST.rtsk: $MISC_DIR/$TEST.rtsk\n";
	    print MAKEFILE "\tcp $MISC_DIR/$TEST.rtsk $TEST.rtsk\n";
	    print MAKEFILE "\tchmod +w $TEST.rtsk\n";
	    print MAKEFILE "\n";
	    close(MAKEFILE);
		
            if (system("make")==0) {
	       $ARRY0[$test_num] = $TEST_TYPE;
	       $ARRY1[$test_num] = $FILE_TYPE;
	       $ARRY2[$test_num] = $TEST;
	       $test_num++;
	       }
	    else {
	       print "\n\n****ERROR:asm steps: test skipped\n\n";
	       print TESTSKIPPED "$_ skipped due to Error\n";
               system("touch $TESTDIR/$TEST.rdram_IMEM")==0 || die "System Interrupt";
               system("rm $TESTDIR/$TEST.rdram_IMEM")==0 || die "System Interrupt";
	       }
	 } #if (-r $TESTNAME_FULL)

	chdir ($WORKDIR) || die "Cant go to parent \n";


      }
  } #while

close(TESTSKIPPED);
if (-z $WORKDIR."/tests.skipped") {
   system("rm $WORKDIR/tests.skipped")==0 || die "System Interrupt";
   }    

  if ($test_num==0) {
   die "NO TESTS found in testsuite \n";
   }

  if ($OPTION_ASM_ONLY==1) {
   print "DONE compiling tests \n";
   exit;
   }
  open(OUT,">misc_tests.v") || die "Cant open misc_tests.v";
  
  $TEMP = "misc_tests_include.v";
  
  print OUT "\n";
  print OUT "`timescale 1ns / 10ps \n";
  print OUT "\n";
  print OUT "module misc_tests;\n";
  print OUT "\n";
  print OUT "\n";
  print OUT "`include  \"$TEMP\""; 
  print OUT "\n";
  print OUT "\n";

  for ($i=0; $i<$test_num; $i++) {
     $TEST      = $ARRY2[$i];
     print OUT "reg diag_$TEST;\n";
    }
  print OUT "initial\n";
  print OUT "    begin\n";
  for ($i=0; $i<$test_num; $i++) {
     $TEST      = $ARRY2[$i];
     print OUT "       diag_$TEST=0;\n";
     print OUT "       if (\$test\$plusargs(\"diag_$TEST\"))\n";
     print OUT "           diag_$TEST=1;\n";
     print OUT "\n";
   }
  print OUT "    end\n";
  print OUT "\n";

  print OUT "initial \n";
  print OUT "begin \n";
  print OUT "\n";
  print OUT "\n";
  print OUT "\$fwrite(fp,\"\\n\\n\");\n";
  print OUT "\n";
  print OUT "#16\n";
  print OUT "reality.r4200b_0.test_selected = 1;\n";
  print OUT "wait(`SYSTEM_READY);\n";
  print OUT "repeat (4) @(posedge `CLK);\n";
  print OUT "reality.r4200b_0.config_rdram;\n";
  print OUT "repeat (4) @(posedge `CLK);\n";

  print OUT "\n";
  print OUT "\n";
  
  for ($i=0; $i<$test_num; $i++) {
     $TEST_TYPE = $ARRY0[$i];
     $FILE_TYPE = $ARRY1[$i];
     $TEST      = $ARRY2[$i];
      
     $j = $i+1;
     print OUT "\n";
     print OUT "/*********************************************\n";
     print OUT " * (Test# $j)  Test Name: $TEST \n";
     print OUT " *********************************************/\n";
     print OUT "\n";
     print OUT "if (diag_$TEST || AllDiags) \n";
     print OUT "begin \n";
     print OUT "   \$display(\$time,\" TEST $TEST starts\"); \n";
     print OUT "   run_$TEST;\n";
     print OUT "   \$display(\$time,\"TEST $TEST ends\"); \n";
     print OUT "end\n";
  }
  print OUT "\n";
  print OUT "\n";
  print OUT "\$finish; \n";
  print OUT "\n";
  print OUT "end \n";
  print OUT "\n";
  print OUT "endmodule \n";
  
  close(TESTSUITE);
  close(OUT);

} #if ($OPTION_ASM)  

if ($OPTION_VCSCOMPILE) {
  print "\n\nVCS Compile in progress\n\n";
  chdir ("$WORKDIR");

  if ($OPTION_GATE==1) {
    if (-r "designc/simv_gate"){
        system("rm designc/simv_gate")==0 || die "System Interrupt";
        }
    chdir ("$WORKDIR");
    system("make simv_rsp_regr_gate")==0 || die "VCS compile system call interupt";
    system("mv simv_rsp_regr_gate designc/simv_gate")==0 || die "System Interrupt";
   }
  else {
    if (-r "$WORKDIR/designc/simv"){
      system("rm $WORKDIR/designc/simv")==0 || die "System Interrupt";
      }
    chdir ("$WORKDIR");
    system("make simv_rsp_regr")==0 || die "VCS compile interupt";
    system("mv simv_rsp_regr designc/simv")==0 || die "System Interrupt";
   }
}

if ($OPTION_VCSRUN) {
  chdir ("$WORKDIR");
    print "\n\n Running Simulation in BATCH mode \n\n";
    print "plusargs passed to vcs are: @PlusArgs \n";

    if ($OPTION_GATE==1) {
      print "\nRunning Gate level version \n";
      system("/bin/csh -c 'setenv LD_LIBRARY_PATH $VCSDIR/lib; ".
      "time designc/simv_gate -q @PlusArgs ' > ,out")==0
                 || die("Interrupt occured, cannot run regression");
     }
    else {
      system("/bin/csh -c 'setenv LD_LIBRARY_PATH $VCSDIR/lib; ".
      "time designc/simv -q @PlusArgs ' > ,out")==0
                 || die("Interrupt occured, cannot run regression");
     }
    print "SImulation Complete\n";
}