Skip to content

Commit e33952a

Browse files
committed
added basic1
1 parent deff3df commit e33952a

File tree

7 files changed

+558
-0
lines changed

7 files changed

+558
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module simple_wire ( input in, output out );
2+
3+
assign out = in; // Simple wire connection from input to output
4+
// NOTE: This creates a continuous assignment (combinational logic)
5+
6+
endmodule
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is a top module with a simple wire
2+
module simple_wire ( input in, output out );
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is a top module with a simple wire
2+
module simple_wire ( input in, output out );
3+
// Assign the appropriate values to one and another
4+
// Insert code here
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This is a top module with a simple wire
2+
module simple_wire ( input in, output out );
3+
// Assign the appropriate values to one and another
4+
// Assign output to input
5+
// Insert code here
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
$date
2+
Tue Aug 19 20:15:56 2025
3+
$end
4+
$version
5+
Icarus Verilog
6+
$end
7+
$timescale
8+
1ps
9+
$end
10+
$scope module tb_top_module $end
11+
$var wire 1 ! out $end
12+
$var reg 1 " in $end
13+
$var reg 1 # test_passed $end
14+
$var integer 32 $ i [31:0] $end
15+
$var integer 32 % num_tests_passed [31:0] $end
16+
$scope module dut $end
17+
$var wire 1 " in $end
18+
$var wire 1 ! out $end
19+
$upscope $end
20+
$upscope $end
21+
$enddefinitions $end
22+
$comment Show the parameter values. $end
23+
$dumpall
24+
$end
25+
#0
26+
$dumpvars
27+
b0 %
28+
bx $
29+
1#
30+
x"
31+
x!
32+
$end
33+
#10000
34+
0!
35+
0"
36+
#20000
37+
1!
38+
1"
39+
b1 %
40+
#30000
41+
0!
42+
0"
43+
b0 $
44+
b10 %
45+
#35000
46+
1!
47+
1"
48+
b1 $
49+
b11 %
50+
#40000
51+
0!
52+
0"
53+
b10 $
54+
b100 %
55+
#45000
56+
1!
57+
1"
58+
b11 $
59+
b101 %
60+
#50000
61+
0!
62+
0"
63+
b100 $
64+
b110 %
65+
#55000
66+
1!
67+
1"
68+
b101 $
69+
b111 %
70+
#60000
71+
0!
72+
0"
73+
b110 $
74+
b1000 %
75+
#65000
76+
1!
77+
1"
78+
b111 $
79+
b1001 %
80+
#70000
81+
0!
82+
0"
83+
b1000 $
84+
b1010 %
85+
#75000
86+
1!
87+
1"
88+
b1001 $
89+
b1011 %
90+
#80000
91+
b1010 $
92+
b1100 %
93+
#90000
94+
0!
95+
0"
96+
b0 $
97+
b1101 %
98+
#95000
99+
1!
100+
1"
101+
b1 $
102+
b1110 %
103+
#100000
104+
0!
105+
0"
106+
b10 $
107+
b1111 %
108+
#105000
109+
1!
110+
1"
111+
b11 $
112+
b10000 %
113+
#110000
114+
0!
115+
0"
116+
b100 $
117+
b10001 %
118+
#115000
119+
1!
120+
1"
121+
b101 $
122+
b10010 %
123+
#120000
124+
0!
125+
0"
126+
b110 $
127+
b10011 %
128+
#125000
129+
1!
130+
1"
131+
b111 $
132+
b10100 %
133+
#130000
134+
0!
135+
0"
136+
b1000 $
137+
b10101 %
138+
#135000
139+
1!
140+
1"
141+
b1001 $
142+
b10110 %
143+
#140000
144+
b1010 $
145+
b10111 %
146+
#150000
147+
0!
148+
0"
149+
#160000
150+
1!
151+
1"
152+
#220000
153+
0!
154+
0"
155+
#230000
156+
1!
157+
1"
158+
#250000
159+
0!
160+
0"
161+
#260000
162+
1!
163+
1"
164+
#280000
165+
0!
166+
0"
167+
#290000
168+
1!
169+
1"
170+
#300000
171+
0!
172+
0"
173+
#310000
174+
1!
175+
1"
176+
#320000
177+
0!
178+
0"
179+
#330000
180+
1!
181+
1"
182+
#360000
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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\tOutput\tExpected\tResult");
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\tPASS", $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\tFAIL", $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\tPASS", $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\tFAIL", $time, in, out, in);
52+
test_passed = 1'b0;
53+
end
54+
55+
// Test Case 3: Multiple transitions
56+
$display("\nTesting 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\tPASS", $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\tFAIL", $time, in, out, in);
65+
test_passed = 1'b0;
66+
end
67+
end
68+
69+
// Test Case 3: Multiple transitions
70+
$display("\nTesting 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\tPASS", $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\tFAIL", $time, in, out, in);
79+
test_passed = 1'b0;
80+
end
81+
end
82+
83+
// Test Case 4: Continuous monitoring
84+
$display("\nContinuous 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

Comments
 (0)