Skip to content

Invariant with diagnostics #2906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions regression/invariants/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ class structured_error_testt: public invariant_failedt
}
};

struct DiagnosticA
{
};
struct DiagnosticB
{
};

template <>
struct diagnostics_helpert<DiagnosticA>
{
static std::string diagnostics_as_string(const DiagnosticA &)
{
return "Diagnostic A";
}
};

template <>
struct diagnostics_helpert<DiagnosticB>
{
static std::string diagnostics_as_string(const DiagnosticB &)
{
return "Diagnostic B";
}
};

/// Causes an invariant failure dependent on first argument value.
/// One ignored argument is accepted to conform with the test.pl script,
/// which would be the input source file for other cbmc driver programs.
Expand Down Expand Up @@ -92,21 +117,38 @@ int main(int argc, char** argv)
else if(arg=="irep")
INVARIANT_WITH_IREP(false, "error with irep", pointer_type(void_typet()));
else if(arg == "invariant-diagnostics")
INVARIANT(
INVARIANT_WITH_DIAGNOSTICS(
false,
"invariant with diagnostics failure",
"invariant diagnostics information");
else if(arg == "precondition-diagnostics")
PRECONDITION(false, "precondition diagnostics information");
PRECONDITION_WITH_DIAGNOSTICS(
false, "precondition diagnostics information");
else if(arg == "postcondition-diagnostics")
POSTCONDITION(false, "postcondition diagnostics information");
POSTCONDITION_WITH_DIAGNOSTICS(
false, "postcondition diagnostics information");
else if(arg == "check-return-diagnostics")
CHECK_RETURN(false, "check return diagnostics information");
CHECK_RETURN_WITH_DIAGNOSTICS(
false, "check return diagnostics information");
else if(arg == "data-invariant-diagnostics")
DATA_INVARIANT(
DATA_INVARIANT_WITH_DIAGNOSTICS(
false,
"data invariant with diagnostics failure",
"data invariant diagnostics information");
else if(arg == "invariant-with-lots-of-diagnostics")
INVARIANT_WITH_DIAGNOSTICS(
false,
"an invariant that fails",
"diagnostic 1",
"diagnostic 2",
"diagnostic 3",
"diagnostic 4");
else if(arg == "invariant-with-custom-diagnostics")
INVARIANT_WITH_DIAGNOSTICS(
false,
"an invariant with some custom diagnostics",
DiagnosticA{},
DiagnosticB{});
else
return 1;
}
11 changes: 11 additions & 0 deletions regression/invariants/invariant-failure19/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
dummy_parameter.c
invariant-with-lots-of-diagnostics
^EXIT=(0|127|134|137)$
^SIGNAL=0$
--- begin invariant violation report ---
Invariant check failed
diagnostic 1
diagnostic 2
diagnostic 3
diagnostic 4
9 changes: 9 additions & 0 deletions regression/invariants/invariant-failure20/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
dummy_parameter.c
invariant-with-custom-diagnostics
^EXIT=(0|127|134|137)$
^SIGNAL=0$
--- begin invariant violation report ---
Invariant check failed
Diagnostic A
Diagnostic B
11 changes: 11 additions & 0 deletions src/util/dstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Author: Daniel Kroening, [email protected]
#define CPROVER_UTIL_DSTRING_H

#include <iosfwd>
#include <string>

#include "invariant.h"
#include "string_container.h"

/// \ref dstringt has one field, an unsigned integer \ref no which is an index
Expand Down Expand Up @@ -198,4 +200,13 @@ struct hash<dstringt> // NOLINT(readability/identifiers)
};
}

template <>
struct diagnostics_helpert<dstringt>
{
static std::string diagnostics_as_string(const dstringt &dstring)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm considering making this a function that takes a std::ostream& and writes some string representation of its argument there rather than returning string. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave this for future work I'd say :)

{
return as_string(dstring);
}
};

#endif // CPROVER_UTIL_DSTRING_H
Loading