Skip to content

Commit fb2da2e

Browse files
author
Daniel Kroening
committed
more work on MC/DC
1 parent 014d9ec commit fb2da2e

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

src/goto-instrument/cover.cpp

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,20 +366,21 @@ void instrument_cover_goals(
366366
case coverage_criteriont::CONDITION:
367367
// Conditions are all atomic predicates in the programs.
368368
{
369-
std::set<exprt> conditions=
370-
collect_conditions(i_it);
369+
const std::set<exprt> conditions=collect_conditions(i_it);
371370

372-
source_locationt source_location=i_it->source_location;
371+
const source_locationt source_location=i_it->source_location;
373372

374373
for(const auto & c : conditions)
375374
{
376-
std::string comment_t="condition `"+from_expr(ns, "", c)+"' true";
375+
const std::string c_string=from_expr(ns, "", c);
376+
377+
const std::string comment_t="condition `"+c_string+"' true";
377378
goto_program.insert_before_swap(i_it);
378379
i_it->make_assertion(c);
379380
i_it->source_location=source_location;
380381
i_it->source_location.set_comment(comment_t);
381382

382-
std::string comment_f="condition `"+from_expr(ns, "", c)+"' false";
383+
const std::string comment_f="condition `"+c_string+"' false";
383384
goto_program.insert_before_swap(i_it);
384385
i_it->make_assertion(not_exprt(c));
385386
i_it->source_location=source_location;
@@ -394,20 +395,21 @@ void instrument_cover_goals(
394395
case coverage_criteriont::DECISION:
395396
// Decisions are maximal Boolean combinations of conditions.
396397
{
397-
std::set<exprt> decisions=
398-
collect_decisions(i_it);
398+
const std::set<exprt> decisions=collect_decisions(i_it);
399399

400-
source_locationt source_location=i_it->source_location;
400+
const source_locationt source_location=i_it->source_location;
401401

402402
for(const auto & d : decisions)
403403
{
404-
std::string comment_t="decision `"+from_expr(ns, "", d)+"' true";
404+
const std::string d_string=from_expr(ns, "", d);
405+
406+
const std::string comment_t="decision `"+d_string+"' true";
405407
goto_program.insert_before_swap(i_it);
406408
i_it->make_assertion(d);
407409
i_it->source_location=source_location;
408410
i_it->source_location.set_comment(comment_t);
409411

410-
std::string comment_f="decision `"+from_expr(ns, "", d)+"' false";
412+
const std::string comment_f="decision `"+d_string+"' false";
411413
goto_program.insert_before_swap(i_it);
412414
i_it->make_assertion(not_exprt(d));
413415
i_it->source_location=source_location;
@@ -418,14 +420,51 @@ void instrument_cover_goals(
418420
i_it++;
419421
}
420422
break;
421-
422423

423424
case coverage_criteriont::MCDC:
424425
// 1. Each entry and exit point is invoked
425426
// 2. Each decision takes every possible outcome
426427
// 3. Each condition in a decision takes every possible outcome
427428
// 4. Each condition in a decision is shown to independently
428429
// affect the outcome of the decision.
430+
{
431+
const std::set<exprt> conditions=collect_conditions(i_it);
432+
const std::set<exprt> decisions=collect_decisions(i_it);
433+
434+
std::set<exprt> both;
435+
std::set_union(conditions.begin(), conditions.end(),
436+
decisions.begin(), decisions.end(),
437+
inserter(both, both.end()));
438+
439+
const source_locationt source_location=i_it->source_location;
440+
441+
for(const auto & p : both)
442+
{
443+
bool is_decision=decisions.find(p)!=decisions.end();
444+
bool is_condition=conditions.find(p)!=conditions.end();
445+
446+
std::string description=
447+
(is_decision && is_condition)?"decision/condition":
448+
is_decision?"decision":"condition";
449+
450+
std::string p_string=from_expr(ns, "", p);
451+
452+
std::string comment_t=description+" `"+p_string+"' true";
453+
goto_program.insert_before_swap(i_it);
454+
i_it->make_assertion(p);
455+
i_it->source_location=source_location;
456+
i_it->source_location.set_comment(comment_t);
457+
458+
std::string comment_f=description+" `"+p_string+"' false";
459+
goto_program.insert_before_swap(i_it);
460+
i_it->make_assertion(not_exprt(p));
461+
i_it->source_location=source_location;
462+
i_it->source_location.set_comment(comment_f);
463+
}
464+
465+
for(unsigned i=0; i<both.size()*2; i++)
466+
i_it++;
467+
}
429468
break;
430469

431470
case coverage_criteriont::PATH:

0 commit comments

Comments
 (0)