Skip to content

Commit 87e8440

Browse files
committed
CBMC --cover: only store traces with --show-test-suite
Not everyone needs test inputs, especially when programs lack INPUT instructions anyway. Test inputs are found via goto traces, and computing those is expensive in both time and memory required. On one benchmark, not building goto traces reduced the overall time from 36000 seconds to 2800 seconds (a saving of 92%).
1 parent e4d4ff4 commit 87e8440

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

doc/cprover-manual/test-suite.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ and outputs of interest for generating test suites.
128128
To demonstrate the automatic test suite generation in CBMC, we call the
129129
following command:
130130

131-
cbmc pid.c --cover mcdc --unwind 6 --xml-ui
131+
cbmc pid.c --cover mcdc --show-test-suite --unwind 6 --xml-ui
132132

133133
We'll describe those command line options one by one. The option `--cover mcdc`
134-
specifies the code coverage criterion. There
134+
specifies the code coverage criterion, and --show-test-suite requests that a
135+
test suite be printed. There
135136
are four conditional statements in the PID function: in lines 41,
136137
44, 48, and 49. To satisfy MC/DC, the test suite has to meet
137138
multiple requirements. For instance, each conditional statement needs to

regression/cbmc-cover/branch-loop1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--xml-ui --cover branch
3+
--xml-ui --cover branch --show-test-suite
44
activate-multi-line-match
55
^EXIT=0$
66
^SIGNAL=0$

regression/cbmc-cover/pointer-function-parameters-2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--function fun --cover branch
3+
--function fun --cover branch --show-test-suite
44
^\*\* 7 of 7 covered \(100.0%\)$
55
^Test suite:$
66
a=\(\(signed int \*\*\)NULL\)

regression/cbmc-cover/pointer-function-parameters/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--function fun --cover branch
3+
--function fun --cover branch --show-test-suite
44
^\*\* 5 of 5 covered \(100\.0%\)$
55
^Test suite:$
66
^(tmp(\$\d+)?=[^,]*, a=\(\(signed int \*\)NULL\))|(a=\(\(signed int \*\)NULL\), tmp(\$\d+)?=[^,]*)$

src/cbmc/cbmc_parse_options.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,11 @@ int cbmc_parse_optionst::doit()
726726
(void)verifier();
727727
verifier.report();
728728

729-
c_test_input_generatort test_generator(ui_message_handler, options);
730-
test_generator(verifier.get_traces());
729+
if(options.get_bool_option("show-test-suite"))
730+
{
731+
c_test_input_generatort test_generator(ui_message_handler, options);
732+
test_generator(verifier.get_traces());
733+
}
731734

732735
return CPROVER_EXIT_SUCCESS;
733736
}

src/goto-checker/cover_goals_verifier_with_trace_storage.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ class cover_goals_verifier_with_trace_storaget : public goto_verifiert
4141
while(incremental_goto_checker(properties).progress !=
4242
incremental_goto_checkert::resultt::progresst::DONE)
4343
{
44-
// we've got a trace; store it and link it to the covered goals
45-
message_building_error_trace(log);
46-
(void)traces.insert_all(incremental_goto_checker.build_full_trace());
44+
if(
45+
options.get_bool_option("show-test-suite") ||
46+
options.get_bool_option("trace"))
47+
{
48+
// we've got a trace; store it and link it to the covered goals
49+
message_building_error_trace(log);
50+
(void)traces.insert_all(incremental_goto_checker.build_full_trace());
51+
}
4752

4853
++iterations;
4954
}

src/goto-instrument/cover.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ void parse_cover_options(const cmdlinet &cmdline, optionst &options)
166166
cmdline.isset("cover-traces-must-terminate"));
167167
options.set_option(
168168
"cover-failed-assertions", cmdline.isset("cover-failed-assertions"));
169+
170+
options.set_option("show-test-suite", cmdline.isset("show-test-suite"));
169171
}
170172

171173
/// Build data structures controlling coverage from command-line options.

src/goto-instrument/cover.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ class optionst;
2424

2525
#define OPT_COVER \
2626
"(cover):" \
27-
"(cover-failed-assertions)"
27+
"(cover-failed-assertions)" \
28+
"(show-test-suite)"
2829

2930
#define HELP_COVER \
3031
" --cover CC create test-suite with coverage criterion " \
3132
"CC\n" \
3233
" --cover-failed-assertions do not stop coverage checking at failed " \
3334
"assertions\n" \
3435
" (this is the default for --cover " \
35-
"assertions)\n"
36+
"assertions)\n" \
37+
" --show-test-suite print test suite for coverage criterion " \
38+
"(requires --cover)"
3639

3740
enum class coverage_criteriont
3841
{

0 commit comments

Comments
 (0)