tb_kasumi.cpp 3.91 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
//========================================================================================
// 
// File Name    : tb_kasumi.cpp
// Description  : Testbench
// Release Date : 23/07/2013
// Author       : PolyU DARC Lab
//                Benjamin Carrion Schafer, Anushree Mahapatra 
//
// Revision History
//---------------------------------------------------------------------------------------
// Date       Version  Author            Description
//----------------------------------------------------------------------------------------
//23/07/2013   1.0     PolyU DARC lab    kasumi testbench
//
//=======================================================================================
#include "tb_kasumi.h"


//-----------------------
// Send data thread
//----------------------
void test_kasumi::send(){

  // Variables declaration
  int x, y, ret1=0, ret2=0;
  unsigned int  in_read, in_k;

  //Reset routine

  in_file = fopen(INFILENAME, "rt");
  in_kfile = fopen(INFILEKEY, "rt");


  if(!in_file){
    cout << "Could not open " << INFILENAME << endl;
    sc_stop();
  }

  if(!in_kfile){
    cout << "Could not open " << INFILEKEY << endl;
    sc_stop();
  }


  wait();

  while(true){

    do{
      for(x=0; x< DEPTH; x++){
	for(y=0;y< WIDTH;y++){

	  ret1 = fscanf(in_file,"%d", &in_read);
	  if(ret1 == EOF){
	    x= DEPTH; break;
	  }
	    
	  indata[x][y].write(in_read);
	}
      }

      for(x=0; x< 8; x++){
	for(y=0;y< 2;y++){

	  ret2 = fscanf(in_kfile,"%d", &in_k);
	  if(ret2 == EOF){
	    x = 8;
	    break;
	  }

	  k[x][y].write(in_k);
	}
      }
  
    
      if(ret1 == EOF || ret2 == EOF)
	break;

    wait();
    
    }while(1);
 

    fclose(in_file);
    fclose(in_kfile);

    cout << endl << "Starting comparing results " << endl;
 
    compare_results();
    sc_stop();

    wait();

  }//while_loop
}



//-----------------------------
// Receive data thread
//-----------------------------
void test_kasumi::recv(){

  // Variables declaration
  unsigned int out_write=0;
  int x=0, y=0;

  out_file = fopen (OUTFILENAME, "wt");

  if(!out_file){
    cout << "Could not open " << OUTFILENAME << endl;
    sc_stop();
    exit(-1);
  }


  wait();

  while(true){

    for(x=0; x< DEPTH; x++){
	for(y=0;y< WIDTH;y++){ 
	  out_write = odata[x][y].read();
	  fprintf(out_file,"%d\n",out_write);
	  wait();
    }
  }
  }
}


//-------------------------------
// Compare results function
//------------------------------
void test_kasumi::compare_results(){

  int outkasumi, out_golden, line=1, errors=0;

  // Close file where outputs are stored
  fclose(out_file);

  //  out_filter_file_read.open(OUTFILENAME);
  out_file = fopen (OUTFILENAME, "rt");

  if(!out_file){
    cout << "Could not open " << OUTFILENAME << "\n";
    sc_stop();
  }

    //
    // Read the golden output
    //
    out_golden_file = fopen (OUTFILENAME_GOLDEN, "rt");
    if(!out_golden_file){
      cout << "Could not open " << OUTFILENAME_GOLDEN << "\n";
      sc_stop();
     }

    //
    // Compare SystemC simulation results vs. golden output
    //
    diff_file = fopen (DIFFFILENAME, "w");
    if(!diff_file){
	 cout << "Could not open " << DIFFFILENAME<< "\n";
	 sc_stop();
       }

    while(fscanf(out_golden_file, "%d", &out_golden) != EOF){
      fscanf(out_file,"%d", &outkasumi);
     

      cout << endl <<"Cycle["<< line << "]: " << out_golden << " -- "<< outkasumi;

	   if(outkasumi != out_golden){
	     cout << "\nOutput missmatch [line:" << line << "] Golden:" << out_golden << " -- Output: " << outkasumi;

	     fprintf(diff_file,"\nOutput missmatch[line:%d] Golden: %d -- Output: %d",line, out_golden, outkasumi);
	     
	     errors++;
	   }

          line ++;

    }

    if(errors == 0)
      cout << endl << "Finished simulation SUCCESSFULLY" << endl;
    else
      cout << endl << "Finished simulation " << errors << " MISSMATCHES between Golden and Simulation" << endl;


    fclose(out_file);
    fclose(diff_file);
    fclose(out_golden_file);


}