aboutsummaryrefslogtreecommitdiffstats
path: root/experiments/instructions.org
blob: ee5827fcfe379f33bda6aefc0e89a04bd9eca093 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#+TITLE: Rerun Instructions

** Introduction

The version of Verismith that is assumed to be used is Verismith 0.6.0.2, which is also available on [hackage](https://hackage.haskell.org/package/verismith-0.6.0.2) using:

#+begin_src
cabal install verismith
#+end_src

** Finding failures in Yosys 0.8

Yosys 0.8 was found to fail about 30% of the time, which means that it should be quite simple to find errors in it. However, different versions of Yosys can be tested this way as well and should also result in failures, such as Yosys 0.9 or Yosys commit hashes 3333e00 or 70d0f38.

However, to find failures in Yosys 0.8, a newer version of Yosys has to be used for the equivalence check. For this we can use Yosys master. An alternative for this is to use a simulator with a test bench, which is also supported by Verismith using Icarus Verilog.

*Note*: The most common error in Yosys 0.8 is regarding for loops, which are not dealt that well with the reducer at the moment.

*** Installing Yosys master

The first step is to install Yosys master (which will in this case be installed to ~/opt/yosys/master~):

#+begin_src
git clone https://github.com/yosyshq/yosys && cd yosys
sed -i 's:^PREFIX ?=.*:PREFIX ?= /opt/yosys/master:' Makefile
make -j4
sudo make install
#+end_src

Then we want to install Yosys 0.8 (which will be installed to ~/opt/yosys/0.8~):

#+begin_src 
git clean -dfx && git reset --hard HEAD
git checkout yosys-0.8
sed -i 's:^PREFIX ?=.*:PREFIX ?= /opt/yosys/0.8:' Makefile
make -j4
sudo make install
#+end_src

*** Running Verismith

We are then ready to run Verismith using the two Yosys versions that were installed.

Using the following config file saved in ~config.toml~:

#+begin_src
[info]
  commit = "UNKNOWN"
  version = "0.6.0.2"

[probability]
  expr.binary = 5
  expr.concatenation = 3
  expr.number = 1
  expr.rangeselect = 5
  expr.signed = 5
  expr.string = 0
  expr.ternary = 5
  expr.unary = 5
  expr.unsigned = 5
  expr.variable = 5
  moditem.assign = 5
  moditem.combinational = 0
  moditem.instantiation = 1
  moditem.sequential = 1
  statement.blocking = 0
  statement.conditional = 1
  statement.forloop = 1
  statement.nonblocking = 5

[property]
  determinism = 1
  module.depth = 2
  module.max = 5
  nondeterminism = 0
  output.combine = false
  sample.method = "hat"
  sample.size = 10
  size = 20
  statement.depth = 3
  default.yosys = "/opt/yosys/master/bin"

[[synthesiser]]
  bin = "/opt/yosys/0.8/bin"
  description = "yosys_0_8"
  name = "yosys"
  output = "syn_yosys_0_8.v"

[[synthesiser]]
  bin = "/opt/yosys/master/bin"
  description = "yosys_master"
  name = "yosys"
  output = "syn_yosys_master.v"
#+end_src

To run Verismith for 10 iterations, which should find a bug, we can run the following:

#+begin_src
verismith fuzz -c config.toml -n 10 -o yosys_output
#+end_src

Failures can then either be seen on the output, or a summary can be seen in the browser using the following:

#+begin_src 
firefox yosys_output/index.html
#+end_src

*** Using a pre-existing seed

If a failure still cannot be found in Yosys 0.8 using the previous, it should be possible using the following config file, which will generate Verilog based on a seed that was found to produce an error in Yosys 0.8:

#+begin_src

[info]
  commit = "UNKNOWN"
  version = "0.6.0.2"

[probability]
  expr.binary = 5
  expr.concatenation = 3
  expr.number = 1
  expr.rangeselect = 5
  expr.signed = 5
  expr.string = 0
  expr.ternary = 5
  expr.unary = 5
  expr.unsigned = 5
  expr.variable = 5
  moditem.assign = 5
  moditem.combinational = 1
  moditem.instantiation = 1
  moditem.sequential = 1
  statement.blocking = 0
  statement.conditional = 1
  statement.forloop = 1
  statement.nonblocking = 5

[property]
  default.yosys = "/opt/yosys/master/bin"
  determinism = 1
  module.depth = 2
  module.max = 5
  nondeterminism = 0
  output.combine = false
  sample.method = "hat"
  sample.size = 10
  seed = "Seed 17999570691447884947 12099254006121016321"
  size = 20
  statement.depth = 3

[[synthesiser]]
  bin = "/opt/yosys/0.8/bin"
  description = "yosys_0_8"
  name = "yosys"
  output = "syn_yosys_0_8.v"

[[synthesiser]]
  bin = "/opt/yosys/master/bin"
  description = "yosys_master"
  name = "yosys"
  output = "syn_yosys_master.v"
#+end_src

Just save the config file in ~config.toml~ and run the following:

#+begin_src 
verismith fuzz -c config.toml -o yosys_one
#+end_src

Which should find a bug and reduce it to around 200 loc out of 1000.
** Better example of reduction and interesting failure

This bug was found in a development version of Yosys (commit hash 3333e002) and was [reported and fixed in Yosys](https://github.com/YosysHQ/yosys/issues/997). In addition to that, a crash can also be reproduced which was also [reported and fixed in Yosys](https://github.com/YosysHQ/yosys/issues/993).

*** Build Yosys 3333e002

First, we need to build Yosys 3333e002, in addition to the version of Yosys master [[*Installing Yosys master][built earlier]].

#+begin_src
git clean -dfx && git reset --hard HEAD
git checkout 3333e002 -b test
sed -i 's:^PREFIX ?=.*:PREFIX ?= /opt/yosys/3333e002:' Makefile
make -j4
sudo make install
#+end_src

*** Running Verismith for mis-synthesis

Save the following config file in ~config.toml~:

#+begin_src
[info]
  commit = "UNKNOWN"
  version = "0.6.0.2"

[probability]
  expr.binary = 5
  expr.concatenation = 3
  expr.number = 1
  expr.rangeselect = 5
  expr.signed = 5
  expr.string = 0
  expr.ternary = 5
  expr.unary = 5
  expr.unsigned = 5
  expr.variable = 5
  moditem.assign = 5
  moditem.combinational = 1
  moditem.instantiation = 1
  moditem.sequential = 1
  statement.blocking = 0
  statement.conditional = 1
  statement.forloop = 0
  statement.nonblocking = 3

[property]
  default.yosys = "/opt/yosys/master/bin"
  determinism = 1
  module.depth = 2
  module.max = 5
  nondeterminism = 0
  output.combine = false
  sample.method = "random"
  sample.size = 10
  seed = "Seed 6762640716476645086 15760899726111280279"
  size = 20
  statement.depth = 3

[[synthesiser]]
  bin = "/opt/yosys/3333e002/bin"
  description = "yosys"
  name = "yosys"
  output = "syn_yosys.v"
#+end_src

Then run Verismith with the following:

#+begin_src 
verismith fuzz -c config.toml -o output_ms
#+end_src

The result should be that the equivalence check fails and a reduced testcase should be available in ~output_ms/fuzz_1/reduce_identity_yosys.v~.

Contrary to what is expected, the simulation runs will pass. This is because the bug occurs in the initial values that are assigned to the variables. These are set to 0 in the design, but mistakenly set to x in the synthesised design. The testbench does not check for those values and the error is therefore not found by the testbench.

To fix this manually, one can add a ~$strobe("%b", y);~ on line 22 in the yosys testbench:

#+begin_src bash
cd output_ms/fuzz_1/simulation_yosys
sed -i '21 a $strobe("%b", y);' yosys_testbench.v
iverilog -o yosys_main yosys_testbench.v
# ./yosys_main | grep 'x'
./yosys_main
#+end_src

which should show some ~x~ in the output which should not be there.

*** Running Verismith for crash

*Note*: Verismith is not that great at reducing crashes, as is explained in our paper.

Save the following config file in ~config.toml~:

#+begin_src
[info]
  commit = "UNKNOWN"
  version = "0.6.0.2"

[probability]
  expr.binary = 5
  expr.concatenation = 3
  expr.number = 1
  expr.rangeselect = 5
  expr.signed = 5
  expr.string = 0
  expr.ternary = 5
  expr.unary = 5
  expr.unsigned = 5
  expr.variable = 5
  moditem.assign = 5
  moditem.combinational = 1
  moditem.instantiation = 1
  moditem.sequential = 1
  statement.blocking = 0
  statement.conditional = 1
  statement.forloop = 0
  statement.nonblocking = 3

[property]
  default.yosys = "/opt/yosys/master/bin"
  determinism = 1
  module.depth = 2
  module.max = 5
  nondeterminism = 0
  output.combine = false
  sample.method = "random"
  sample.size = 10
  seed = "Seed 10125302424574354942 828176532243040297"
  size = 20
  statement.depth = 3

[[synthesiser]]
  bin = "/opt/yosys/3333e002/bin"
  description = "yosys"
  name = "yosys"
  output = "syn_yosys.v"
#+end_src

Then run Verismith with the following:

#+begin_src 
verismith fuzz -c config.toml -o output_c
#+end_src