Skip to content

Commit b83e940

Browse files
authored
Merge pull request #253 from diffblue/random-waveform
ebmc: add --random-waveform and --random-trace
2 parents 8ba84a1 + 1eca0f6 commit b83e940

File tree

5 files changed

+111
-4
lines changed

5 files changed

+111
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE broken-smt-backend
2+
long_trace1.v
3+
--random-waveform
4+
^ 0 1 2 3 4 5 6 7 8 9 10$
5+
^ main\.clk $
6+
^main\.increment 0 1 1 0 1 1 1 1 1 1 1$
7+
^ main\.some_reg 0 0 1 2 2 3 4 5 6 7 8$
8+
^EXIT=0$
9+
^SIGNAL=0$
10+
--

src/ebmc/ebmc_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ int ebmc_parse_optionst::doit()
149149
if(cmdline.isset("random-traces"))
150150
return random_traces(cmdline, ui_message_handler);
151151

152+
if(cmdline.isset("random-trace") || cmdline.isset("random-waveform"))
153+
return random_trace(cmdline, ui_message_handler);
154+
152155
if(cmdline.isset("ic3"))
153156
return do_ic3(cmdline, ui_message_handler);
154157

src/ebmc/ebmc_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ebmc_parse_optionst:public parse_options_baset
4343
"(aig)(stop-induction)(stop-minimize)(start):(coverage)(naive)"
4444
"(compute-ct)(dot-netlist)(smv-netlist)(vcd):"
4545
"(random-traces)(trace-steps):(random-seed):(number-of-traces):"
46+
"(random-trace)(random-waveform)"
4647
"I:(preprocess)",
4748
argc,
4849
argv,

src/ebmc/random_traces.cpp

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2424

2525
#include "ebmc_base.h"
2626
#include "ebmc_error.h"
27+
#include "waveform.h"
2728

2829
#include <algorithm>
2930
#include <random>
@@ -48,7 +49,10 @@ class random_tracest
4849
{
4950
}
5051

52+
using outputt = enum { TRACE, WAVEFORM, VCD };
53+
5154
void operator()(
55+
outputt,
5256
const optionalt<std::string> &outfile_prefix,
5357
std::size_t random_seed,
5458
std::size_t number_of_traces,
@@ -156,7 +160,80 @@ int random_traces(const cmdlinet &cmdline, message_handlert &message_handler)
156160
get_transition_system(cmdline, message_handler);
157161

158162
random_tracest(transition_system, message_handler)(
159-
outfile_prefix, random_seed, number_of_traces, number_of_trace_steps);
163+
outfile_prefix.has_value() ? random_tracest::VCD : random_tracest::TRACE,
164+
outfile_prefix,
165+
random_seed,
166+
number_of_traces,
167+
number_of_trace_steps);
168+
169+
return 0;
170+
}
171+
172+
/*******************************************************************\
173+
174+
Function: random_trace
175+
176+
Inputs:
177+
178+
Outputs:
179+
180+
Purpose:
181+
182+
\*******************************************************************/
183+
184+
int random_trace(const cmdlinet &cmdline, message_handlert &message_handler)
185+
{
186+
if(cmdline.isset("number-of-traces"))
187+
throw ebmc_errort() << "must not give number-of-traces";
188+
189+
const std::size_t random_seed = [&cmdline]() -> std::size_t {
190+
if(cmdline.isset("random-seed"))
191+
{
192+
auto random_seed_opt =
193+
string2optional_size_t(cmdline.get_value("random-seed"));
194+
195+
if(!random_seed_opt.has_value())
196+
throw ebmc_errort() << "failed to parse random seed";
197+
198+
return random_seed_opt.value();
199+
}
200+
else
201+
return 0;
202+
}();
203+
204+
const std::size_t number_of_trace_steps = [&cmdline]() -> std::size_t {
205+
if(cmdline.isset("trace-steps"))
206+
{
207+
auto trace_steps_opt =
208+
string2optional_size_t(cmdline.get_value("trace-steps"));
209+
210+
if(!trace_steps_opt.has_value())
211+
throw ebmc_errort() << "failed to parse number of trace steps";
212+
213+
return trace_steps_opt.value();
214+
}
215+
else if(cmdline.isset("bound"))
216+
{
217+
auto bound_opt = string2optional_size_t(cmdline.get_value("bound"));
218+
219+
if(!bound_opt.has_value())
220+
throw ebmc_errort() << "failed to parse bound";
221+
222+
return bound_opt.value();
223+
}
224+
else
225+
return 10; // default
226+
}();
227+
228+
transition_systemt transition_system =
229+
get_transition_system(cmdline, message_handler);
230+
231+
if(cmdline.isset("random-trace"))
232+
random_tracest(transition_system, message_handler)(
233+
random_tracest::TRACE, {}, random_seed, 1, number_of_trace_steps);
234+
else if(cmdline.isset("random-waveform"))
235+
random_tracest(transition_system, message_handler)(
236+
random_tracest::WAVEFORM, {}, random_seed, 1, number_of_trace_steps);
160237

161238
return 0;
162239
}
@@ -182,7 +259,11 @@ void random_traces(
182259
{
183260
std::size_t random_seed = 0;
184261
random_tracest(transition_system, message_handler)(
185-
outfile_prefix, random_seed, number_of_traces, number_of_trace_steps);
262+
random_tracest::VCD,
263+
outfile_prefix,
264+
random_seed,
265+
number_of_traces,
266+
number_of_trace_steps);
186267
}
187268

188269
/*******************************************************************\
@@ -351,6 +432,7 @@ Function: random_tracest::operator()()
351432
\*******************************************************************/
352433

353434
void random_tracest::operator()(
435+
outputt output,
354436
const optionalt<std::string> &outfile_prefix,
355437
std::size_t random_seed,
356438
std::size_t number_of_traces,
@@ -403,8 +485,10 @@ void random_tracest::operator()(
403485
{
404486
auto trace = compute_trans_trace(
405487
solver, number_of_timeframes, ns, transition_system.main_symbol->name);
406-
if(outfile_prefix.has_value())
488+
489+
if(output == VCD)
407490
{
491+
PRECONDITION(outfile_prefix.has_value());
408492
auto filename = outfile_prefix.value() + std::to_string(trace_nr + 1);
409493
std::ofstream out(widen_if_needed(filename));
410494

@@ -415,11 +499,16 @@ void random_tracest::operator()(
415499

416500
show_trans_trace_vcd(trace, message, ns, out);
417501
}
418-
else
502+
else if(output == TRACE)
419503
{
420504
consolet::out() << "*** Trace " << (trace_nr + 1) << '\n';
421505
show_trans_trace(trace, message, ns, consolet::out());
422506
}
507+
else if(output == WAVEFORM)
508+
{
509+
consolet::out() << "*** Trace " << (trace_nr + 1) << '\n';
510+
show_waveform(trace, ns);
511+
}
423512
}
424513
break;
425514

src/ebmc/random_traces.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ Author: Daniel Kroening, [email protected]
1414
class cmdlinet;
1515
class message_handlert;
1616

17+
// many traces
1718
int random_traces(const cmdlinet &, message_handlert &);
1819

20+
// just one trace
21+
int random_trace(const cmdlinet &, message_handlert &);
22+
1923
class transition_systemt;
2024

2125
void random_traces(

0 commit comments

Comments
 (0)