cprover
cover_instrument_mcdc.cpp File Reference

Coverage Instrumentation for MC/DC. More...

#include "cover_instrument.h"
#include <langapi/language_util.h>
#include <algorithm>
#include <iterator>
#include "cover_util.h"
Include dependency graph for cover_instrument_mcdc.cpp:

Go to the source code of this file.

Functions

void collect_mcdc_controlling_rec (const exprt &src, const std::vector< exprt > &conditions, std::set< exprt > &result)
 To recursively collect controlling exprs for for mcdc coverage. More...
 
std::set< exprtcollect_mcdc_controlling (const std::set< exprt > &decisions)
 
std::set< exprtreplacement_conjunction (const std::set< exprt > &replacement_exprs, const std::vector< exprt > &operands, const std::size_t i)
 To replace the i-th expr of ''operands'' with each expr inside ''replacement_exprs''. More...
 
std::set< exprtcollect_mcdc_controlling_nested (const std::set< exprt > &decisions)
 This nested method iteratively applies ''collect_mcdc_controlling'' to every non-atomic expr within a decision. More...
 
std::set< signed > sign_of_expr (const exprt &e, const exprt &E)
 The sign of expr ''e'' within the super-expr ''E''. More...
 
void remove_repetition (std::set< exprt > &exprs)
 After the ''collect_mcdc_controlling_nested'', there can be the recurrence of the same expr in the resulted set of exprs, and this method will remove the repetitive ones. More...
 
bool eval_expr (const std::map< exprt, signed > &atomic_exprs, const exprt &src)
 To evaluate the value of expr ''src'', according to the atomic expr values. More...
 
std::map< exprt, signed > values_of_atomic_exprs (const exprt &e, const std::set< exprt > &conditions)
 To obtain values of atomic exprs within the super expr. More...
 
bool is_mcdc_pair (const exprt &e1, const exprt &e2, const exprt &c, const std::set< exprt > &conditions, const exprt &decision)
 To check if the two input controlling exprs are mcdc pairs regarding an atomic expr ''c''. More...
 
bool has_mcdc_pair (const exprt &c, const std::set< exprt > &expr_set, const std::set< exprt > &conditions, const exprt &decision)
 To check if we can find the mcdc pair of the input ''expr_set'' regarding the atomic expr ''c''. More...
 
void minimize_mcdc_controlling (std::set< exprt > &controlling, const exprt &decision)
 This method minimizes the controlling conditions for mcdc coverage. More...
 

Detailed Description

Coverage Instrumentation for MC/DC.

Definition in file cover_instrument_mcdc.cpp.

Function Documentation

◆ collect_mcdc_controlling()

std::set<exprt> collect_mcdc_controlling ( const std::set< exprt > &  decisions)

◆ collect_mcdc_controlling_nested()

std::set<exprt> collect_mcdc_controlling_nested ( const std::set< exprt > &  decisions)

This nested method iteratively applies ''collect_mcdc_controlling'' to every non-atomic expr within a decision.

The final controlling conditions resulted from ''src'' will be stored in ''s1''; ''s2'' is usd to hold the temporary expansion.

To expand an operand if it is not atomic, and label the ''changed'' flag; the resulted expansion of such an operand is stored in ''res''.

Definition at line 166 of file cover_instrument_mcdc.cpp.

References collect_mcdc_controlling(), collect_operands(), is_condition(), and replacement_conjunction().

Referenced by cover_mcdc_instrumentert::instrument().

◆ collect_mcdc_controlling_rec()

void collect_mcdc_controlling_rec ( const exprt src,
const std::vector< exprt > &  conditions,
std::set< exprt > &  result 
)

To recursively collect controlling exprs for for mcdc coverage.

It may happen that ''is_condition(src)'' is valid, but we ignore this case here as it can be handled by the routine decision/condition detection.

Definition at line 22 of file cover_instrument_mcdc.cpp.

References collect_operands(), conjunction(), irept::id(), is_condition(), unary_exprt::op(), and to_not_expr().

Referenced by collect_mcdc_controlling().

◆ eval_expr()

bool eval_expr ( const std::map< exprt, signed > &  atomic_exprs,
const exprt src 
)

To evaluate the value of expr ''src'', according to the atomic expr values.

Definition at line 405 of file cover_instrument_mcdc.cpp.

References collect_operands(), irept::id(), and exprt::make_not().

Referenced by is_mcdc_pair().

◆ has_mcdc_pair()

bool has_mcdc_pair ( const exprt c,
const std::set< exprt > &  expr_set,
const std::set< exprt > &  conditions,
const exprt decision 
)

To check if we can find the mcdc pair of the input ''expr_set'' regarding the atomic expr ''c''.

Definition at line 539 of file cover_instrument_mcdc.cpp.

References is_mcdc_pair().

Referenced by minimize_mcdc_controlling().

◆ is_mcdc_pair()

bool is_mcdc_pair ( const exprt e1,
const exprt e2,
const exprt c,
const std::set< exprt > &  conditions,
const exprt decision 
)

To check if the two input controlling exprs are mcdc pairs regarding an atomic expr ''c''.

A mcdc pair of (e1, e2) regarding ''c'' means that ''e1'' and ''e2'' result in different ''decision'' values, and this is caused by the different choice of ''c'' value.

A mcdc pair of controlling exprs regarding ''c'' can have different values for only one atomic expr, i.e., ''c''. Otherwise, they are not a mcdc pair.

Definition at line 476 of file cover_instrument_mcdc.cpp.

References eval_expr(), and values_of_atomic_exprs().

Referenced by has_mcdc_pair().

◆ minimize_mcdc_controlling()

void minimize_mcdc_controlling ( std::set< exprt > &  controlling,
const exprt decision 
)

This method minimizes the controlling conditions for mcdc coverage.

The minimum is in a sense that by deleting any controlling condition in the set, the mcdc coverage for the decision will be not complete.

parameters: The input ''controlling'' should have been processed by
''collect_mcdc_controlling_nested'' and ''remove_repetition''

Iteratively, we test that after removing an item ''x'' from the ''controlling'', can a complete mcdc coverage over ''decision'' still be reserved?

If yes, we update ''controlling'' with the ''new_controlling'' without ''x''; otherwise, we should keep ''x'' within ''controlling''.

If in the end all elements ''x'' in ''controlling'' are reserved, this means that current ''controlling'' set is minimum and the ''while'' loop should be broken out of.

Note: implementation here for the above procedure is not (meant to be) optimal.

If there is no mcdc pair for an atomic condition ''c'', then ''x'' should not be removed from the original ''controlling'' set

Definition at line 564 of file cover_instrument_mcdc.cpp.

References collect_conditions(), and has_mcdc_pair().

Referenced by cover_mcdc_instrumentert::instrument().

◆ remove_repetition()

void remove_repetition ( std::set< exprt > &  exprs)

After the ''collect_mcdc_controlling_nested'', there can be the recurrence of the same expr in the resulted set of exprs, and this method will remove the repetitive ones.

To check if ''x'' is identical with some expr in ''new_exprs''. Two exprs ''x'' and ''y'' are identical iff they have the same sign for every atomic condition ''c''.

If ''x'' is found identical w.r.t some expr in ''new_conditions, we label it and break.

Definition at line 318 of file cover_instrument_mcdc.cpp.

References collect_conditions(), and sign_of_expr().

Referenced by cover_mcdc_instrumentert::instrument().

◆ replacement_conjunction()

std::set<exprt> replacement_conjunction ( const std::set< exprt > &  replacement_exprs,
const std::vector< exprt > &  operands,
const std::size_t  i 
)

To replace the i-th expr of ''operands'' with each expr inside ''replacement_exprs''.

Definition at line 143 of file cover_instrument_mcdc.cpp.

References conjunction().

Referenced by collect_mcdc_controlling_nested().

◆ sign_of_expr()

std::set<signed> sign_of_expr ( const exprt e,
const exprt E 
)

The sign of expr ''e'' within the super-expr ''E''.

parameters: E should be the pre-processed output by
''collect_mcdc_controlling_nested''
Returns
+1 : not negated -1 : negated

In the general case, we analyze each operand of ''E''.

Definition at line 261 of file cover_instrument_mcdc.cpp.

References collect_operands(), irept::id(), is_condition(), exprt::make_not(), and exprt::op0().

Referenced by remove_repetition(), and values_of_atomic_exprs().

◆ values_of_atomic_exprs()

std::map<exprt, signed> values_of_atomic_exprs ( const exprt e,
const std::set< exprt > &  conditions 
)

To obtain values of atomic exprs within the super expr.

Definition at line 451 of file cover_instrument_mcdc.cpp.

References sign_of_expr().

Referenced by is_mcdc_pair().