Skip to content
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
44 changes: 44 additions & 0 deletions integration-tests/c-example/lib/linked-list/linked-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,48 @@ int cycle_list3(struct Node *head) {
if (head->next->next->next == NULL) {
return -3;
}
return 17;
}

int len_bound(struct Node *head, int bound) {
int len = 0;
while (head != NULL && bound > 0) {
++len;
--bound;
head = head->next;
}
return head != NULL ? -1 : len;
}

#define SIZE 4

int sort_list(struct Node *head) {
int n = len_bound(head, SIZE);
if (n == SIZE) {
for (int i = 0; i < n - 2; i++) {
struct Node *cop = head;
while (cop->next != NULL) {
if (cop->x > cop->next->x) {
int t = cop->x;
cop->x = cop->next->x;
cop->next->x = t;
}
cop = cop->next;
}
}
int fl = 1;
struct Node *cop = head;
while (cop->next != NULL) {
if (cop->x > cop->next->x) {
fl = -1;
}
cop = cop->next;
}
if (fl == 1) {
return 1;
} else {
return -1;
}
}
return 0;
}
4 changes: 4 additions & 0 deletions integration-tests/c-example/lib/linked-list/linked-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ int middle_length2(struct Kuku *head);

int cycle_list3(struct Node *head);

int len_bound(struct Node *head, int bound);

int sort_list(struct Node *head);

#endif
68 changes: 34 additions & 34 deletions server/src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ shared_ptr<StructValueView> KTestObjectParser::structView(const vector<char> &by
PointerUsage usage,
const std::optional<const Tests::MethodDescription> &testingMethod,
const std::string &name,
const std::optional<MapAddressName> &fromAddressToName,
const MapAddressName &fromAddressToName,
std::vector<InitReference> &initReferences) {
vector<shared_ptr<AbstractValueView>> subViews;
unsigned int curPos = offset;
Expand Down Expand Up @@ -342,13 +342,13 @@ shared_ptr<StructValueView> KTestObjectParser::structView(const vector<char> &by
case TypeKind::OBJECT_POINTER:
res = readBytesAsValueForType(byteArray, PointerWidthType, curPos + offsetField,
PointerWidthSize);
if (fromAddressToName.has_value()) {
if (fromAddressToName->find(std::stoull(res)) != fromAddressToName->end()) {
initReferences.emplace_back(PrinterUtils::getFieldAccess(name, field.name), fromAddressToName->at(std::stoull(res)));
}
if (fromAddressToName.find(std::stoull(res)) != fromAddressToName.end()) {
initReferences.emplace_back(PrinterUtils::getFieldAccess(name, field.name),
fromAddressToName.at(std::stoull(res)));
res = PrinterUtils::C_NULL;
}
subViews.push_back(std::make_shared<JustValueView>(PrinterUtils::initializePointer(
field.type.typeName(), res)));

subViews.push_back(std::make_shared<JustValueView>(PrinterUtils::initializePointer(field.type.typeName(), res)));
break;
case TypeKind::FUNCTION_POINTER:
subViews.push_back(functionPointerView(curStruct.name, field.name));
Expand Down Expand Up @@ -606,8 +606,8 @@ void KTestObjectParser::assignTypeUnnamedVar(Tests::MethodTestCase &testCase,

testCase.lazyVariables.emplace_back(curVar.type, name);
shared_ptr<AbstractValueView> testParamView = testParameterView({name, byteValue}, {paramType, name},
PointerUsage::PARAMETER, methodDescription,
testCase.fromAddressToName, testCase.lazyReferences);
PointerUsage::PARAMETER, testCase.fromAddressToName,
testCase.lazyReferences, methodDescription);
testCase.lazyValues.emplace_back(testCase.objects[curVar.num].name, 0, testParamView);
}

Expand Down Expand Up @@ -778,13 +778,14 @@ KTestObjectParser::parseTestCaseParams(const UTBotKTest &ktest,
auto paramType = methodParam.type.maybeJustPointer() ? methodParam.type.baseTypeObj() : methodParam.type;
if (CollectionUtils::containsKey(methodDescription.functionPointers, methodParam.name)) {
testParamView = testParameterView(
emptyKleeParam, { paramType, methodParam.name }, PointerUsage::PARAMETER, methodDescription,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
emptyKleeParam, { paramType, methodParam.name }, PointerUsage::PARAMETER, testCaseDescription.fromAddressToName,
testCaseDescription.lazyReferences, methodDescription);
} else {
const auto kleeParam = getKleeParamOrThrow(rawKleeParams, methodParam.name);

testParamView = testParameterView(kleeParam, {paramType, methodParam.name }, PointerUsage::PARAMETER, methodDescription,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
testParamView = testParameterView(kleeParam, {paramType, methodParam.name }, PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences,
methodDescription);
}
testCaseDescription.funcParamValues.push_back(
{ methodParam.name, methodParam.alignment, testParamView });
Expand All @@ -805,7 +806,9 @@ KTestObjectParser::parseTestCaseParams(const UTBotKTest &ktest,
auto paramType = methodDescription.returnType.maybeReturnArray() ? methodDescription.returnType :
methodDescription.returnType.baseTypeObj();
const Tests::TypeAndVarName returnParam = { paramType, KleeUtils::RESULT_VARIABLE_NAME };
const auto testReturnView = testParameterView(kleeResParam, returnParam, PointerUsage::RETURN, methodDescription);
const auto testReturnView = testParameterView(kleeResParam, returnParam, PointerUsage::RETURN,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences,
methodDescription);
testCaseDescription.returnValue = {
KleeUtils::RESULT_VARIABLE_NAME, types::TypesHandler::isObjectPointerType(methodDescription.returnType), testReturnView
};
Expand All @@ -818,13 +821,15 @@ KTestObjectParser::parseTestCaseParams(const UTBotKTest &ktest,
const auto kleePathFlagSymbolicIterator = getKleeParam(rawKleeParams, KLEE_PATH_FLAG_SYMBOLIC);
if (kleePathFlagSymbolicIterator != rawKleeParams.end()) {
const Tests::TypeAndVarName kleePathParam = {types::Type::intType(), KLEE_PATH_FLAG_SYMBOLIC};
const auto kleePathFlagSymbolicView = testParameterView(*kleePathFlagSymbolicIterator, kleePathParam, types::PointerUsage::PARAMETER);
const auto kleePathFlagSymbolicView = testParameterView(*kleePathFlagSymbolicIterator, kleePathParam, types::PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
testCaseDescription.kleePathFlagSymbolicValue = {KLEE_PATH_FLAG_SYMBOLIC, false, kleePathFlagSymbolicView};
}
const auto functionReturnNotNullIterator = getKleeParam(rawKleeParams, KleeUtils::NOT_NULL_VARIABLE_NAME);
if (functionReturnNotNullIterator != rawKleeParams.end()) {
const Tests::TypeAndVarName functionReturnNotNull = {types::Type::intType(), KleeUtils::NOT_NULL_VARIABLE_NAME};
const auto functionReturnNotNullView = testParameterView(*functionReturnNotNullIterator, functionReturnNotNull, types::PointerUsage::PARAMETER);
const auto functionReturnNotNullView = testParameterView(*functionReturnNotNullIterator, functionReturnNotNull, types::PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
testCaseDescription.functionReturnNotNullValue = {KleeUtils::NOT_NULL_VARIABLE_NAME, false, functionReturnNotNullView};
}
return testCaseDescription;
Expand All @@ -835,13 +840,15 @@ void KTestObjectParser::processGlobalParamPreValue(Tests::TestCaseDescription &t
vector<RawKleeParam> &rawKleeParams) {
string kleeParamName = globalParam.name;
auto kleeParam = getKleeParamOrThrow(rawKleeParams, kleeParamName);
auto testParamView = testParameterView(kleeParam, { globalParam.type, globalParam.name }, types::PointerUsage::PARAMETER);
auto testParamView = testParameterView(kleeParam, { globalParam.type, globalParam.name }, types::PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
testCaseDescription.globalPreValues.emplace_back( globalParam.name, globalParam.alignment, testParamView );
}

void KTestObjectParser::processSymbolicStdin(Tests::TestCaseDescription &testCaseDescription, vector<RawKleeParam> &rawKleeParams) {
auto &&read = getKleeParamOrThrow(rawKleeParams, "stdin-read");
string &&view = testParameterView(read, {types::Type::longlongType(), "stdin-read"}, types::PointerUsage::PARAMETER)->getEntryValue();
string &&view = testParameterView(read, {types::Type::longlongType(), "stdin-read"}, types::PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences)->getEntryValue();
if (view == "0LL") {
return;
} else {
Expand All @@ -865,7 +872,8 @@ void KTestObjectParser::processGlobalParamPostValue(Tests::TestCaseDescription &
auto kleeParam = getKleeParamOrThrow(rawKleeParams, symbolicVariable);
auto type = typesHandler.getReturnTypeToCheck(globalParam.type);
Tests::TypeAndVarName typeAndVarName{ type, globalParam.name };
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER);
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
testCaseDescription.globalPostValues.emplace_back( globalParam.name, globalParam.alignment, testParamView );
}

Expand All @@ -878,7 +886,8 @@ void KTestObjectParser::processParamPostValue(Tests::TestCaseDescription &testCa
types::Type paramType = param.type.arrayCloneMultiDim(usage);
auto type = typesHandler.getReturnTypeToCheck(paramType);
Tests::TypeAndVarName typeAndVarName{ type, param.name };
auto testParamView = testParameterView(kleeParam, typeAndVarName, usage);
auto testParamView = testParameterView(kleeParam, typeAndVarName, usage, testCaseDescription.fromAddressToName,
testCaseDescription.lazyReferences);
testCaseDescription.paramPostValues.emplace_back( param.name, param.alignment, testParamView );
}

Expand All @@ -894,30 +903,21 @@ void KTestObjectParser::processStubParamValue(Tests::TestCaseDescription &testCa
}
auto type = typesHandler.getReturnTypeToCheck(methodNameToReturnTypeMap.at(methodName));
Tests::TypeAndVarName typeAndVarName{ type, kleeParam.paramName };
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER);
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER,
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
testCaseDescription.stubValues.emplace_back( kleeParam.paramName, 0, testParamView );
testCaseDescription.stubValuesTypes.emplace_back(type, kleeParam.paramName, 0);
}
}
}

shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
const RawKleeParam &kleeParam,
const Tests::TypeAndVarName &param,
types::PointerUsage usage,
const std::optional<const Tests::MethodDescription> &testingMethod,
const std::optional<MapAddressName> &fromAddressToName) {
std::vector<InitReference> tmp;
return testParameterView(kleeParam, param, usage, testingMethod, fromAddressToName, tmp);
}

shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
const KTestObjectParser::RawKleeParam &kleeParam,
const Tests::TypeAndVarName &param,
PointerUsage usage,
const std::optional<const Tests::MethodDescription> &testingMethod,
const std::optional<MapAddressName> &fromAddressToName,
std::vector<InitReference> &initReferences) {
const MapAddressName &fromAddressToName,
std::vector<InitReference> &initReferences,
const std::optional<const Tests::MethodDescription> &testingMethod) {
EnumInfo enumInfo;
StructInfo structInfo;
UnionInfo unionInfo;
Expand Down
15 changes: 4 additions & 11 deletions server/src/Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,9 @@ namespace tests {
testParameterView(const RawKleeParam &kleeParam,
const Tests::TypeAndVarName &param,
types::PointerUsage usage,
const std::optional<const Tests::MethodDescription> &testingMethod = std::nullopt,
const std::optional<MapAddressName> &fromAddressToName = std::nullopt);

shared_ptr<AbstractValueView>
testParameterView(const RawKleeParam &kleeParam,
const Tests::TypeAndVarName &param,
types::PointerUsage usage,
const std::optional<const Tests::MethodDescription> &testingMethod,
const std::optional<MapAddressName> &fromAddressToName,
std::vector<InitReference> &initReferences);
const MapAddressName &fromAddressToName,
std::vector<InitReference> &initReferences,
const std::optional<const Tests::MethodDescription> &testingMethod = std::nullopt);

shared_ptr<ArrayValueView> multiArrayView(const vector<char> &byteArray,
const types::Type &type,
Expand Down Expand Up @@ -618,7 +611,7 @@ namespace tests {
types::PointerUsage usage,
const std::optional<const Tests::MethodDescription> &testingMethod,
const std::string &name,
const std::optional<MapAddressName> &fromAddressToName,
const MapAddressName &fromAddressToName,
std::vector<InitReference> &initReferences);

shared_ptr<PrimitiveValueView> primitiveView(const vector<char> &byteArray,
Expand Down
14 changes: 14 additions & 0 deletions server/src/building/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ std::string getArchiveArgument(std::string const &argument,
return argument;
}

static void moveKleeTemporaryFileArgumentToBegin(std::vector<std::string> &arguments) {
auto iteratorToCurrentFile = std::find_if(arguments.begin(), arguments.end(), [] (const std::string &argument) {
return StringUtils::endsWith(argument, "_klee.bc");
});
if (iteratorToCurrentFile == arguments.end()) {
LOG_S(ERROR) << "Don't find temporary klee file";
return;
}
auto iteratorToSwap = std::find(arguments.begin(), arguments.end(), "-o");
std::iter_swap(iteratorToSwap + 2, iteratorToCurrentFile);
}

static std::vector<utbot::LinkCommand>
getArchiveCommands(fs::path const &workingDir,
CollectionUtils::MapFileTo<fs::path> const &dependencies,
Expand All @@ -547,6 +559,8 @@ getArchiveCommands(fs::path const &workingDir,
output, linkCommand, hasArchiveOption);
});
arguments.erase(arguments.begin());
moveKleeTemporaryFileArgumentToBegin(arguments);

if (hasArchiveOption) {
arguments.insert(arguments.begin(), { "ar" });
} else {
Expand Down
7 changes: 6 additions & 1 deletion server/src/utils/PrinterUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ namespace PrinterUtils {
}

std::string initializePointer(const std::string &type, const std::string &value) {
return "(" + type + ") " + value;
if (value == C_NULL || value == "0") {
return C_NULL;
} else {
return "(" + type + ") " + value;
}

}

std::string generateNewVar(int cnt) {
Expand Down
Loading