1+ `timescale 1ns/ 1ps
2+
3+ module tb_top_module ();
4+ // Signal to connect to DUT output
5+ reg in;
6+ wire out;
7+
8+ // Instantiate the Design Under Test (DUT)
9+ simple_wire dut (
10+ .in(in), .out(out)
11+ );
12+
13+ // Test variables
14+ reg test_passed;
15+ integer num_tests_passed;
16+ integer i;
17+
18+ initial begin
19+ // Initialize test tracking
20+ test_passed = 1'b1 ;
21+ num_tests_passed = 0 ;
22+
23+ // Display header
24+ $display ("====================================" );
25+ $display ("Testing simple_wire" );
26+ $display ("====================================" );
27+ $display ("Time\t Output\t Expected\t Result" );
28+ $display ("------------------------------------" );
29+
30+ // Wait for any initialization
31+ #10 ;
32+
33+ // Test Case 1: Output follows input at 0
34+ in = 1'b0 ;
35+ #10 ; // Wait for propagation
36+ if (out == in) begin
37+ $display ("%0t\t %b\t %b\t %b\t\t PASS" , $time , in, out, in);
38+ num_tests_passed = num_tests_passed + 1 ;
39+ end else begin
40+ $display ("%0t\t %b\t %b\t %b\t\t FAIL" , $time , in, out, in);
41+ test_passed = 1'b0 ;
42+ end
43+
44+ // Test Case 2: Output follows input at 1
45+ in = 1'b1 ;
46+ #10 ;
47+ if (out == in) begin
48+ $display ("%0t\t %b\t %b\t %b\t\t PASS" , $time , in, out, in);
49+ num_tests_passed = num_tests_passed + 1 ;
50+ end else begin
51+ $display ("%0t\t %b\t %b\t %b\t\t FAIL" , $time , in, out, in);
52+ test_passed = 1'b0 ;
53+ end
54+
55+ // Test Case 3: Multiple transitions
56+ $display ("\n Testing multiple transitions:" );
57+ for (i = 0 ; i < 10 ; i = i + 1 ) begin
58+ in = ~ in; // Toggle input
59+ #5 ; // Small delay
60+ if (out == in) begin
61+ $display ("%0t\t %b\t %b\t %b\t\t PASS" , $time , in, out, in);
62+ num_tests_passed = num_tests_passed + 1 ;
63+ end else begin
64+ $display ("%0t\t %b\t %b\t %b\t\t FAIL" , $time , in, out, in);
65+ test_passed = 1'b0 ;
66+ end
67+ end
68+
69+ // Test Case 3: Multiple transitions
70+ $display ("\n Testing multiple transitions:" );
71+ for (i = 0 ; i < 10 ; i = i + 1 ) begin
72+ in = ~ in; // Toggle input
73+ #5 ; // Small delay
74+ if (out == in) begin
75+ $display ("%0t\t %b\t %b\t %b\t\t PASS" , $time , in, out, in);
76+ num_tests_passed = num_tests_passed + 1 ;
77+ end else begin
78+ $display ("%0t\t %b\t %b\t %b\t\t FAIL" , $time , in, out, in);
79+ test_passed = 1'b0 ;
80+ end
81+ end
82+
83+ // Test Case 4: Continuous monitoring
84+ $display ("\n Continuous monitoring test:" );
85+ fork
86+ begin
87+ // Drive random values
88+ repeat (20 ) begin
89+ #10 in = $random ;
90+ end
91+ end
92+ begin
93+ // Monitor continuously
94+ repeat (20 ) begin
95+ #10 ;
96+ if (out !== in) begin
97+ $display ("ERROR at time %0t: in=%b, out=%b" , $time , in, out);
98+ test_passed = 1'b0 ;
99+ end
100+ end
101+ end
102+ join
103+
104+ // Final Summary
105+ #10 ;
106+ $display ("====================================" );
107+ $display ("Test Summary: %0d/%0d tests passed" , num_tests_passed, num_tests_passed + (test_passed ? 0 : 1 ));
108+ if (test_passed)
109+ $display ("Overall Result: ALL TESTS PASSED" );
110+ else
111+ $display ("Overall Result: SOME TESTS FAILED" );
112+ $display ("====================================" );
113+
114+ // End simulation
115+ #10 ;
116+ $finish ;
117+ end
118+
119+ // Optional: Generate VCD file for waveform viewing
120+ initial begin
121+ $dumpfile ("simple_wire_tb.vcd" );
122+ $dumpvars (0 , tb_top_module);
123+ end
124+
125+ endmodule
0 commit comments