-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar_parking_system_tb.v
133 lines (117 loc) · 2.88 KB
/
car_parking_system_tb.v
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
// car_parking_system_tb.v
`timescale 1ns/1ns // Set the timescale for simulation
module tb_car_parking_system;
// Inputs
reg sensor1;
reg sensor2;
reg sensor3;
reg sensor4;
reg sensor5;
reg sensor6;
reg sensor7;
reg sensor8;
// Outputs
wire [7:0] parking_spaces;
// Instantiate the module under test
car_parking_system uut (
.sensors({sensor1, sensor2, sensor3, sensor4, sensor5, sensor6, sensor7, sensor8}),
.parking_spaces(parking_spaces)
);
// File for VCD (Value Change Dump) output
initial begin
$dumpfile("car_parking_system_tb.vcd");
$dumpvars(0, tb_car_parking_system);
end
// Initial block for stimulus generation
initial begin
// Test case 1: No cars, all spaces should be vacant
sensor1 = 0;
sensor2 = 0;
sensor3 = 0;
sensor4 = 0;
sensor5 = 0;
sensor6 = 0;
sensor7 = 0;
sensor8 = 0;
#10; // Wait for 10 time units
// Expected output: parking_spaces = 00000000
// Test case 2: Car in space 1, other spaces vacant
sensor1 = 1;
sensor2 = 0;
sensor3 = 0;
sensor4 = 0;
sensor5 = 0;
sensor6 = 0;
sensor7 = 0;
sensor8 = 0;
#10;
// Expected output: parking_spaces = 00000001
// Test case 3: Car in space 2, other spaces vacant
sensor1 = 0;
sensor2 = 1;
sensor3 = 0;
sensor4 = 0;
sensor5 = 0;
sensor6 = 0;
sensor7 = 0;
sensor8 = 0;
#10;
// Expected output: parking_spaces = 00000010
// Test case 4: Cars in spaces 1 and 2, other spaces vacant
sensor1 = 1;
sensor2 = 1;
sensor3 = 0;
sensor4 = 0;
sensor5 = 0;
sensor6 = 0;
sensor7 = 0;
sensor8 = 0;
#10;
// Expected output: parking_spaces = 00000011
// Test case 5: Cars in spaces 7 and 8, other spaces vacant
sensor1 = 0;
sensor2 = 0;
sensor3 = 0;
sensor4 = 0;
sensor5 = 0;
sensor6 = 0;
sensor7 = 1;
sensor8 = 1;
#10;
// Expected output: parking_spaces = 11000000
// Test case 6: Cars in spaces 1,3, 5 and 7, other spaces vacant
sensor1 = 1;
sensor2 = 0;
sensor3 = 1;
sensor4 = 0;
sensor5 = 1;
sensor6 = 0;
sensor7 = 1;
sensor8 = 0;
#10;
// Expected output: parking_spaces = 01010101
// Test case 7: Cars in spaces 2, 4, 6 and 8, other spaces vacant
sensor1 = 0;
sensor2 = 1;
sensor3 = 0;
sensor4 = 1;
sensor5 = 0;
sensor6 = 1;
sensor7 = 0;
sensor8 = 1;
#10;
// Expected output: parking_spaces = 10101010
// Test case 8: Cars in all spaces
sensor1 = 1;
sensor2 = 1;
sensor3 = 1;
sensor4 = 1;
sensor5 = 1;
sensor6 = 1;
sensor7 = 1;
sensor8 = 1;
#10;
// Expected output: parking_spaces = 11111111
$stop; // Stop simulation
end
endmodule