OpenCores
URL https://opencores.org/ocsvn/mesi_isc/mesi_isc/trunk

Subversion Repositories mesi_isc

[/] [mesi_isc/] [trunk/] [src/] [tb/] [mesi_isc_tb_sanity_check.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 yaira
//////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
//////////////////////////////////////////////////////////////////////
29
////                                                              ////
30
////  MESI_ISC Project                                            ////
31
////                                                              ////
32
////  Author(s):                                                  ////
33
////      - Yair Amitay       yair.amitay@yahoo.com               ////
34
////                          www.linkedin.com/in/yairamitay      ////
35
////                                                              ////
36
////  Description                                                 ////
37
////  mesi_isc_tb                                                 ////
38
////  -------------------                                         ////
39
////  Project test bench.                                         ////
40
////  Check coherency rules 1,2, and 3.                           ////
41
////  Check fifos overflow and underflow.                         ////
42
////                                                              ////
43
////  To Do:                                                      ////
44
////   -                                                          ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
 
48
 
49
// Sanity checks
50
//================================
51
 
52
// Sanity Check 1 - coherency rules
53
//================================
54
//   
55
// Rule | time  | CPU ID  | Memory | Address | Data | Condition   |
56
//      |       |         | Event  |         |      |             |
57
// -----|-------|---------|--------|---------|------|-------------|
58
//      |  x    |   1     |  WR    |  A1     |  D1  |
59
//   1  |-------|---------|--------|---------|------|
60
//      |  x+1  |   1     |  RD    |  A1     |  D1  |
61
// -----|-------|---------|--------|---------|------|
62
//      |  x    |   1     |  WR    |  A1     |  D1  |
63
//   2  |-------|---------|--------|---------|------|
64
//      |  x+1  |   2     |  RD    |  A1     |  D1  |
65
// -----|-------|---------|--------|---------|------|
66
//      |  x    |   1     |  WR    |  A1     |  D1  |
67
//      |-------|---------|--------|---------|------|
68
//      |  x+1  |   2     |  WD    |  A1     |  D2  |
69
//   3  |-------|---------|--------|---------|------|
70
//      |  y    |   3     |  RD    |  A1     |  D2  |
71
//      |-------|---------|--------|---------|------|--------------|
72
//      |  y+1  |   3     |  RD    |  A1     |  D1  |  Not allowed |
73
// -----|-------|---------|--------|---------|------|--------------|
74
//
75
// For each read from the memory, check that the read data contains the most
76
// update written data. The check is done separately for each CPU written data. 
77
// This check covers the three rules for coherency system.
78
// task sanity_check_rule1
79
task sanity_check_rule1_rule2;
80
input [3:0]              cpu_id;
81
input [ADDR_WIDTH-1:0]   mbus_addr;
82
input [DATA_WIDTH-1:0]   mbus_wr_data;
83
reg   [DATA_WIDTH-1:0]   cur_mem_data;
84
 
85
begin
86
`ifdef messages
87
  $display("Message: check err 7. time:%d", $time);
88
`endif
89
  cur_mem_data = mem[mbus_addr];
90
  if (cur_mem_data[(3+1)*8-1 : 3*8] > mbus_wr_data[(3+1)*8-1 : 3*8] |
91
      cur_mem_data[(2+1)*8-1 : 2*8] > mbus_wr_data[(2+1)*8-1 : 2*8] |
92
      cur_mem_data[(1+1)*8-1 : 1*8] > mbus_wr_data[(1+1)*8-1 : 1*8] |
93
      cur_mem_data[(0+1)*8-1 : 0*8] > mbus_wr_data[(0+1)*8-1 : 0*8])
94
  begin
95
    $display("ERROR 7. The current memory data is bigger then the written data\n");
96
    $display("  CPU: %h, Cur data: %h, Written data: %h, Address: %h, time:%d\n",
97
             cpu_id,
98
             cur_mem_data,
99
             mbus_wr_data,
100
             mbus_addr,
101
             $time);
102
    @(negedge clk) $finish();
103
  end
104
end
105
endtask
106
 
107
// Sanity Check 2- cache states
108
//================================
109
// Checks that, at any time, there are not 2 cache lines or more, that contains
110
// the same memory address, with stats M or state E.
111
always @(posedge clk or posedge rst)
112
  for (k=0; k < 4; k = k + 1)
113
    if (mbus_ack[k]) sanity_check_cache_status(mbus_addr_array[k]);
114
 
115
// task sanity_check_cache_status;
116
task sanity_check_cache_status;
117
input [ADDR_WIDTH-1:0]   mbus_addr;
118
reg [1:0]                num_of_lines_in_m_e_state;
119
 
120
begin
121
`ifdef messages
122
     $display("Message: check err 6. time:%d", $time);
123
`endif
124
  num_of_lines_in_m_e_state = 0;
125
  //               \ /
126
  if(mesi_isc_tb_cpu3.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_E |
127
  //               \ /
128
     mesi_isc_tb_cpu3.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_M)
129
     num_of_lines_in_m_e_state = num_of_lines_in_m_e_state + 1;
130
 
131
  if(mesi_isc_tb_cpu2.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_E |
132
  //               \ /
133
     mesi_isc_tb_cpu2.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_M)
134
     num_of_lines_in_m_e_state = num_of_lines_in_m_e_state + 1;
135
 
136
  if(mesi_isc_tb_cpu1.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_E |
137
  //               \ /
138
     mesi_isc_tb_cpu1.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_M)
139
     num_of_lines_in_m_e_state = num_of_lines_in_m_e_state + 1;
140
 
141
  if(mesi_isc_tb_cpu0.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_E |
142
  //               \ /
143
     mesi_isc_tb_cpu0.cache_state[mbus_addr] == `MESI_ISC_TB_CPU_MESI_M)
144
     num_of_lines_in_m_e_state = num_of_lines_in_m_e_state + 1;
145
 
146
  if (num_of_lines_in_m_e_state > 1)
147
  begin
148
     $display("Error 6. %d of cache lines are in M or E state. time:%d\n",
149
                                                 num_of_lines_in_m_e_state,
150
                                                 $time);
151
     @(negedge clk) $finish;
152
  end
153
end
154
endtask
155
 
156
 
157
// Error state
158
//================================
159
`ifdef mesi_isc_debug
160
 
161
always @(mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_overflow or
162
         mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_underflow or
163
         mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_overflow or
164
         mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_underflow or
165
         mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_overflow or
166
         mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_underflow or
167
         mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_overflow or
168
         mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_underflow or
169
         mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_overflow or
170
         mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_underflow)
171
if (mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_overflow  |
172
    mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_underflow |
173
    mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_overflow  |
174
    mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_underflow |
175
    mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_overflow  |
176
    mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_underflow |
177
    mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_overflow  |
178
    mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_underflow |
179
    mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_overflow   |
180
    mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_underflow)
181
  begin
182
    $display("ERROR 8. Fifo overflow or underflow\n");
183
    $display("mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_overflow = %h,              mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_underflow = %h,    mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_overflow = %h,    mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_underflow = %h,    mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_overflow = %h,    mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_underflow = %h,    mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_overflow = %h,    mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_underflow = %h,    mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_overflow = %h,    mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_underflow = %h",    mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_overflow,
184
    mesi_isc.mesi_isc_breq_fifos.fifo_3.dbg_fifo_underflow,
185
    mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_overflow,
186
    mesi_isc.mesi_isc_breq_fifos.fifo_2.dbg_fifo_underflow,
187
    mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_overflow,
188
    mesi_isc.mesi_isc_breq_fifos.fifo_1.dbg_fifo_underflow,
189
    mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_overflow,
190
    mesi_isc.mesi_isc_breq_fifos.fifo_0.dbg_fifo_underflow,
191
    mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_overflow,
192
    mesi_isc.mesi_isc_broad.broad_fifo.dbg_fifo_underflow);
193
    $finish();
194
  end
195
`endif
196
 

powered by: WebSVN 2.1.0

© copyright 1999-2019 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.