Skip to content

Commit 012e544

Browse files
authored
Merge pull request #3796 from peterschrammel/stop-on-fail-verifier
Stop-on-fail verifier [blocks: 3968]
2 parents d7a91ad + 3b71199 commit 012e544

File tree

4 files changed

+133
-5
lines changed

4 files changed

+133
-5
lines changed

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ Author: Daniel Kroening, [email protected]
1919
#include <util/config.h>
2020
#include <util/exit_codes.h>
2121
#include <util/invariant.h>
22+
#include <util/make_unique.h>
2223
#include <util/unicode.h>
23-
#include <util/xml.h>
2424
#include <util/version.h>
25+
#include <util/xml.h>
2526

2627
#include <langapi/language.h>
2728

2829
#include <ansi-c/ansi_c_language.h>
2930

3031
#include <goto-checker/all_properties_verifier.h>
3132
#include <goto-checker/all_properties_verifier_with_trace_storage.h>
33+
#include <goto-checker/stop_on_fail_verifier.h>
3234

3335
#include <goto-programs/adjust_float_expressions.h>
3436
#include <goto-programs/lazy_goto_model.h>
@@ -566,11 +568,33 @@ int jbmc_parse_optionst::doit()
566568
}
567569
}
568570

571+
if(
572+
options.get_bool_option("dimacs") ||
573+
!options.get_option("outfile").empty())
574+
{
575+
if(!options.get_bool_option("paths"))
576+
{
577+
stop_on_fail_verifiert<multi_path_symex_checkert> verifier(
578+
options, ui_message_handler, goto_model);
579+
(void)verifier();
580+
return CPROVER_EXIT_SUCCESS;
581+
}
582+
}
583+
569584
std::unique_ptr<goto_verifiert> verifier = nullptr;
570585

571-
if(!options.get_bool_option("paths") && !options.is_set("cover"))
586+
if(
587+
!options.get_bool_option("paths") && !options.is_set("cover") &&
588+
!options.get_bool_option("dimacs") &&
589+
options.get_option("outfile").empty())
572590
{
573-
if(!options.get_bool_option("stop-on-fail"))
591+
if(options.get_bool_option("stop-on-fail"))
592+
{
593+
verifier = util_make_unique<
594+
stop_on_fail_verifiert<java_multi_path_symex_checkert>>(
595+
options, ui_message_handler, goto_model);
596+
}
597+
else
574598
{
575599
verifier = util_make_unique<all_properties_verifier_with_trace_storaget<
576600
java_multi_path_symex_checkert>>(

src/cbmc/cbmc_parse_options.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <util/exception_utils.h>
2121
#include <util/exit_codes.h>
2222
#include <util/invariant.h>
23+
#include <util/make_unique.h>
2324
#include <util/unicode.h>
2425
#include <util/version.h>
2526

@@ -38,6 +39,7 @@ Author: Daniel Kroening, [email protected]
3839
#include <goto-checker/multi_path_symex_checker.h>
3940
#include <goto-checker/multi_path_symex_only_checker.h>
4041
#include <goto-checker/properties.h>
42+
#include <goto-checker/stop_on_fail_verifier.h>
4143

4244
#include <goto-programs/adjust_float_expressions.h>
4345
#include <goto-programs/initialize_goto_model.h>
@@ -564,11 +566,31 @@ int cbmc_parse_optionst::doit()
564566
}
565567
}
566568

569+
if(
570+
options.get_bool_option("dimacs") || !options.get_option("outfile").empty())
571+
{
572+
if(!options.get_bool_option("paths"))
573+
{
574+
stop_on_fail_verifiert<multi_path_symex_checkert> verifier(
575+
options, ui_message_handler, goto_model);
576+
(void)verifier();
577+
return CPROVER_EXIT_SUCCESS;
578+
}
579+
}
580+
567581
std::unique_ptr<goto_verifiert> verifier = nullptr;
568582

569-
if(!options.get_bool_option("paths") && !options.is_set("cover"))
583+
if(
584+
!options.get_bool_option("paths") && !options.is_set("cover") &&
585+
!options.get_bool_option("dimacs") && options.get_option("outfile").empty())
570586
{
571-
if(!options.get_bool_option("stop-on-fail"))
587+
if(options.get_bool_option("stop-on-fail"))
588+
{
589+
verifier =
590+
util_make_unique<stop_on_fail_verifiert<multi_path_symex_checkert>>(
591+
options, ui_message_handler, goto_model);
592+
}
593+
else
572594
{
573595
verifier = util_make_unique<
574596
all_properties_verifier_with_trace_storaget<multi_path_symex_checkert>>(

src/goto-checker/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ The combination of these three concepts enables:
5151
without impacting others.
5252

5353
There are the following variants of goto verifiers at the moment:
54+
* \ref stop_on_fail_verifiert : Checks all properties, but terminates
55+
as soon as the first violated property is found and reports this violation.
56+
A trace ends at a violated property.
5457
* \ref all_properties_verifier_with_trace_storaget : Determines the status of
5558
all properties and outputs results when the verification algorithm has
5659
terminated. A trace ends at a violated property.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*******************************************************************\
2+
3+
Module: Goto Verifier for stopping at the first failing property
4+
5+
Author: Daniel Kroening, Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Goto Verifier for stopping at the first failing property
11+
12+
#ifndef CPROVER_GOTO_CHECKER_STOP_ON_FAIL_VERIFIER_H
13+
#define CPROVER_GOTO_CHECKER_STOP_ON_FAIL_VERIFIER_H
14+
15+
#include "bmc_util.h"
16+
#include "goto_verifier.h"
17+
18+
/// Stops when the first failing property is found.
19+
/// Requires an incremental goto checker that is a
20+
/// `goto_trace_providert` and `witness_providert`.
21+
template <class incremental_goto_checkerT>
22+
class stop_on_fail_verifiert : public goto_verifiert
23+
{
24+
public:
25+
stop_on_fail_verifiert(
26+
const optionst &options,
27+
ui_message_handlert &ui_message_handler,
28+
abstract_goto_modelt &goto_model)
29+
: goto_verifiert(options, ui_message_handler),
30+
goto_model(goto_model),
31+
incremental_goto_checker(options, ui_message_handler, goto_model)
32+
{
33+
properties = std::move(initialize_properties(goto_model));
34+
}
35+
36+
resultt operator()() override
37+
{
38+
(void)incremental_goto_checker(properties);
39+
return determine_result(properties);
40+
}
41+
42+
void report() override
43+
{
44+
switch(determine_result(properties))
45+
{
46+
case resultt::PASS:
47+
report_success(ui_message_handler);
48+
incremental_goto_checker.output_proof();
49+
break;
50+
51+
case resultt::FAIL:
52+
{
53+
goto_tracet goto_trace = incremental_goto_checker.build_trace();
54+
output_error_trace(
55+
goto_trace,
56+
incremental_goto_checker.get_namespace(),
57+
trace_optionst(options),
58+
ui_message_handler);
59+
report_failure(ui_message_handler);
60+
incremental_goto_checker.output_error_witness(goto_trace);
61+
break;
62+
}
63+
64+
case resultt::UNKNOWN:
65+
report_inconclusive(ui_message_handler);
66+
break;
67+
68+
case resultt::ERROR:
69+
report_error(ui_message_handler);
70+
break;
71+
}
72+
}
73+
74+
protected:
75+
abstract_goto_modelt &goto_model;
76+
incremental_goto_checkerT incremental_goto_checker;
77+
};
78+
79+
#endif // CPROVER_GOTO_CHECKER_STOP_ON_FAIL_VERIFIER_H

0 commit comments

Comments
 (0)