Skip to content

Commit 8991cbc

Browse files
committed
[fix] Generate test only for successful solution found
1 parent ecfca38 commit 8991cbc

2 files changed

Lines changed: 73 additions & 75 deletions

File tree

lib/Core/Executor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7180,7 +7180,6 @@ bool Executor::getSymbolicSolution(const ExecutionState &state, KTest &res) {
71807180
}
71817181
bool success = solver->getInitialValues(extendedConstraints.cs(), objects,
71827182
values, state.queryMetaData);
7183-
Assignment assignment(objects, values);
71847183
solver->setTimeout(time::Span());
71857184
if (!success) {
71867185
klee_warning("unable to compute initial values (invalid constraints?)!");

tools/klee/main.cpp

Lines changed: 73 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ DISABLE_WARNING_DEPRECATED_DECLARATIONS
3434
#include "llvm/Bitcode/BitcodeReader.h"
3535
#include "llvm/IR/Constants.h"
3636
#include "llvm/IR/IRBuilder.h"
37+
#include "llvm/IR/InstIterator.h"
3738
#include "llvm/IR/Instruction.h"
3839
#include "llvm/IR/LLVMContext.h"
3940
#include "llvm/IR/Type.h"
@@ -62,7 +63,6 @@ DISABLE_WARNING_POP
6263
#include <fstream>
6364
#include <iomanip>
6465
#include <iterator>
65-
#include <llvm/IR/InstIterator.h>
6666
#include <sstream>
6767

6868
using json = nlohmann::json;
@@ -601,9 +601,8 @@ void KleeHandler::processTestCase(const ExecutionState &state,
601601
const auto start_time = time::getWallTime();
602602
bool atLeastOneGenerated = false;
603603

604-
if (WriteKTests) {
605-
606-
if (success) {
604+
if (success) {
605+
if (WriteKTests) {
607606
for (unsigned i = 0; i < ktest.uninitCoeff + 1; ++i) {
608607
if (!kTest_toFile(
609608
&ktest,
@@ -620,49 +619,36 @@ void KleeHandler::processTestCase(const ExecutionState &state,
620619
}
621620
}
622621

623-
if (message) {
624-
auto f = openTestFile(suffix, id);
625-
if (f)
626-
*f << message;
627-
}
628-
629-
if (m_pathWriter) {
630-
std::vector<unsigned char> concreteBranches;
631-
m_pathWriter->readStream(m_interpreter->getPathStreamID(state),
632-
concreteBranches);
633-
auto f = openTestFile("path", id);
634-
if (f) {
635-
for (const auto &branch : concreteBranches) {
636-
*f << branch << '\n';
637-
}
622+
if (WriteXMLTests) {
623+
for (unsigned i = 0; i < ktest.uninitCoeff + 1; ++i) {
624+
writeTestCaseXML(message != nullptr, ktest, id, i);
625+
atLeastOneGenerated = true;
638626
}
639627
}
640-
}
641628

642-
if (message || WriteKQueries) {
643-
std::string constraints;
644-
m_interpreter->getConstraintLog(state, constraints, Interpreter::KQUERY);
645-
auto f = openTestFile("kquery", id);
646-
if (f)
647-
*f << constraints;
629+
for (unsigned i = 0; i < ktest.numObjects; i++) {
630+
delete[] ktest.objects[i].bytes;
631+
delete[] ktest.objects[i].pointers;
632+
}
633+
delete[] ktest.objects;
648634
}
649635

650-
if (WriteCVCs) {
651-
// FIXME: If using Z3 as the core solver the emitted file is actually
652-
// SMT-LIBv2 not CVC which is a bit confusing
653-
std::string constraints;
654-
m_interpreter->getConstraintLog(state, constraints, Interpreter::STP);
655-
auto f = openTestFile("cvc", id);
636+
if (message) {
637+
auto f = openTestFile(suffix, id);
656638
if (f)
657-
*f << constraints;
639+
*f << message;
658640
}
659641

660-
if (WriteSMT2s) {
661-
std::string constraints;
662-
m_interpreter->getConstraintLog(state, constraints, Interpreter::SMTLIB2);
663-
auto f = openTestFile("smt2", id);
664-
if (f)
665-
*f << constraints;
642+
if (m_pathWriter) {
643+
std::vector<unsigned char> concreteBranches;
644+
m_pathWriter->readStream(m_interpreter->getPathStreamID(state),
645+
concreteBranches);
646+
auto f = openTestFile("path", id);
647+
if (f) {
648+
for (const auto &branch : concreteBranches) {
649+
*f << branch << '\n';
650+
}
651+
}
666652
}
667653

668654
if (m_symPathWriter) {
@@ -677,55 +663,68 @@ void KleeHandler::processTestCase(const ExecutionState &state,
677663
}
678664
}
679665

680-
if (WriteKPaths) {
681-
std::string blockPath;
682-
m_interpreter->getBlockPath(state, blockPath);
683-
auto f = openTestFile("kpath", id);
684-
if (f)
685-
*f << blockPath;
686-
}
687-
688-
if (WriteCov) {
689-
std::map<std::string, std::set<unsigned>> cov;
690-
m_interpreter->getCoveredLines(state, cov);
691-
auto f = openTestFile("cov", id);
692-
if (f) {
693-
for (const auto &entry : cov) {
694-
for (const auto &line : entry.second) {
695-
*f << entry.first << ':' << line << '\n';
696-
}
697-
}
698-
}
699-
}
700-
701-
if (WriteXMLTests) {
702-
for (unsigned i = 0; i < ktest.uninitCoeff + 1; ++i) {
703-
writeTestCaseXML(message != nullptr, ktest, id, i);
704-
atLeastOneGenerated = true;
705-
}
706-
}
707-
708666
if (atLeastOneGenerated) {
709667
++m_numGeneratedTests;
710668
}
711669

712-
for (unsigned i = 0; i < ktest.numObjects; i++) {
713-
delete[] ktest.objects[i].bytes;
714-
delete[] ktest.objects[i].pointers;
715-
}
716-
delete[] ktest.objects;
717-
718670
if (m_numGeneratedTests == MaxTests)
719671
m_interpreter->setHaltExecution(HaltExecution::MaxTests);
720672

721-
if (!WriteXMLTests && WriteTestInfo) {
673+
if (WriteTestInfo) {
722674
time::Span elapsed_time(time::getWallTime() - start_time);
723675
auto f = openTestFile("info", id);
724676
if (f)
725677
*f << "Time to generate test case: " << elapsed_time << '\n';
726678
}
727679
} // if (!WriteNone)
728680

681+
if (WriteKQueries) {
682+
std::string constraints;
683+
m_interpreter->getConstraintLog(state, constraints, Interpreter::KQUERY);
684+
auto f = openTestFile("kquery", id);
685+
if (f)
686+
*f << constraints;
687+
}
688+
689+
if (WriteCVCs) {
690+
// FIXME: If using Z3 as the core solver the emitted file is actually
691+
// SMT-LIBv2 not CVC which is a bit confusing
692+
std::string constraints;
693+
m_interpreter->getConstraintLog(state, constraints, Interpreter::STP);
694+
auto f = openTestFile("cvc", id);
695+
if (f)
696+
*f << constraints;
697+
}
698+
699+
if (WriteSMT2s) {
700+
std::string constraints;
701+
m_interpreter->getConstraintLog(state, constraints, Interpreter::SMTLIB2);
702+
auto f = openTestFile("smt2", id);
703+
if (f)
704+
*f << constraints;
705+
}
706+
707+
if (WriteKPaths) {
708+
std::string blockPath;
709+
m_interpreter->getBlockPath(state, blockPath);
710+
auto f = openTestFile("kpath", id);
711+
if (f)
712+
*f << blockPath;
713+
}
714+
715+
if (WriteCov) {
716+
std::map<std::string, std::set<unsigned>> cov;
717+
m_interpreter->getCoveredLines(state, cov);
718+
auto f = openTestFile("cov", id);
719+
if (f) {
720+
for (const auto &entry : cov) {
721+
for (const auto &line : entry.second) {
722+
*f << entry.first << ':' << line << '\n';
723+
}
724+
}
725+
}
726+
}
727+
729728
if (isError && OptExitOnError) {
730729
m_interpreter->prepareForEarlyExit();
731730
klee_error("EXITING ON ERROR:\n%s\n", message);

0 commit comments

Comments
 (0)