3209e630970783121cc82fb36f8a924c9106b3e9
[debian/gnuradio] / usrp2 / fpga / opencores / ethernet_tri_mode / sim / rtl_sim / ncsim_sim / script / start_verify.tcl
1 proc start_verify {batch index} {
2 variable compiling
3 variable simulate_times
4 variable test_case_number
5 variable batch_data {}
6 variable batchmode
7 variable piple
8 ###############################################################################
9     set batchmode $batch
10     toplevel .l
11     focus .l
12     wm title .l "Simulation Log"
13     frame .l.f1 
14     frame .l.f2
15     pack .l.f1 .l.f2  -side top
16      
17     text .l.f1.t1 -width 80 -height 40 -yscrollcommand {.l.f1.scroll set}
18     
19     scrollbar .l.f1.scroll -command {.l.f1.t1 yview}
20     button .l.f2.b1 -text "Exit" -command {destroy .l} -width 10
21     button .l.f2.b2 -text "Stop" -command {Stop_sim} -width 10
22     pack .l.f1.scroll -side right -fill y
23     pack .l.f1.t1 
24     pack .l.f2.b1 .l.f2.b2 -side left
25     
26     set output_win .l.f1.t1
27     set simulate_times 0
28     set test_case_number [lindex $index 0]    
29     cd ../bin
30     set compiling 1
31     if {$batch==0} {
32         Run "bash sim.nc " $output_win
33     } elseif {[catch {open ../data/batch.dat r} fileid]} {
34         $output_win insert end  "Failed open ../data/batch.dat file\n" 
35     } elseif {[lindex $index 0] == "empty"} {
36         $output_win insert end  "Not any test case was selected\n"
37     } else {
38         set i 0
39         gets $fileid line
40         while {[eof $fileid]==0} { 
41            lappend batch_data $line
42            gets $fileid line
43            incr i
44         }
45         $output_win insert end "Verifcation Started\n"
46         $output_win insert end "Starting Compiling Source file and libs......\n"
47         Run "bash com.nc" $output_win
48         close $fileid
49     }
50 }
51
52 proc Run {command output_win} {
53     global piple
54     if [catch {open "|$command |& cat "} piple] {
55         $output_win insert end $piple\n
56     } else {
57         fileevent $piple readable [list Log $piple $output_win]
58     }
59 }
60
61 proc Log {piple output_win} {
62     global compiling
63     global batchmode
64     set saparator "###################################################################\n"
65     if {[eof $piple]} {
66         if {$batchmode==0} {
67             $output_win insert end $saparator  
68             $output_win insert end "end of Simulation....\n"
69             $output_win insert end $saparator         
70         } elseif {$compiling==1} {
71             $output_win insert end $saparator  
72             $output_win insert end "end of Compiling....\n"
73             $output_win insert end $saparator 
74             $output_win insert end "\n \n \n" 
75             set compiling 0
76             sim_next_case 
77         } else {
78             $output_win insert end $saparator  
79             $output_win insert end "end of Testcase....\n"
80             $output_win insert end $saparator 
81             $output_win insert end "\n \n \n"  
82             sim_next_case        
83         }
84         close $piple
85     } else {
86         gets $piple line
87         $output_win insert end $line\n
88         $output_win see end
89     }
90 }   
91         
92 proc sim_next_case {} {
93     global test_case_number
94     global simulate_times
95     global batch_data
96     global index
97     set saparator "###################################################################\n"    
98     set output_win .l.f1.t1
99     set test_case_number [lindex $index $simulate_times] 
100     if {$simulate_times < [llength $index]} {
101         set line [lindex $batch_data $test_case_number]
102         set source_sti [lindex $line 1]
103         set source_reg [lindex $line 2] 
104         
105         if {$simulate_times==0 ||[file exists "../log/.sim_succeed"]} {
106             exec cp "../data/$source_sti" "../data/config.ini"
107             exec cp "../data/$source_reg" "../data/CPU.vec"
108             
109             $output_win insert end $saparator  
110             $output_win insert end "starting test case :[lindex $line 0]....\n"
111             $output_win insert end $saparator  
112             $output_win insert end "\n \n \n"  
113             incr simulate_times
114             Run "bash sim_only.nc" $output_win
115         } else {
116             $output_win insert end "test_case :[lindex $line 0] simulation failed!!\n" 
117         }    
118             
119     } else {
120         $output_win insert end "All test_case passed simulation Successfully!!\n"      
121     }           
122 }
123
124 proc Stop_sim {} {
125     global piple 
126     catch {close $piple}
127 }