Skip to content

Commit daf5c3c

Browse files
Saveliy Grigoryevladisgin
authored andcommitted
Set lazy pointers to NULL, change order of linking files and add test for wrong bubble sort
1 parent e1a96d9 commit daf5c3c

File tree

11 files changed

+274
-53
lines changed

11 files changed

+274
-53
lines changed

integration-tests/c-example/lib/linked-list/linked-list.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,48 @@ int cycle_list3(struct Node *head) {
102102
if (head->next->next->next == NULL) {
103103
return -3;
104104
}
105+
return 17;
106+
}
107+
108+
int len_bound(struct Node *head, int bound) {
109+
int len = 0;
110+
while (head != NULL && bound > 0) {
111+
++len;
112+
--bound;
113+
head = head->next;
114+
}
115+
return head != NULL ? -1 : len;
116+
}
117+
118+
#define SIZE 4
119+
120+
int sort_list(struct Node *head) {
121+
int n = len_bound(head, SIZE);
122+
if (n == SIZE) {
123+
for (int i = 0; i < n - 2; i++) {
124+
struct Node *cop = head;
125+
while (cop->next != NULL) {
126+
if (cop->x > cop->next->x) {
127+
int t = cop->x;
128+
cop->x = cop->next->x;
129+
cop->next->x = t;
130+
}
131+
cop = cop->next;
132+
}
133+
}
134+
int fl = 1;
135+
struct Node *cop = head;
136+
while (cop->next != NULL) {
137+
if (cop->x > cop->next->x) {
138+
fl = -1;
139+
}
140+
cop = cop->next;
141+
}
142+
if (fl == 1) {
143+
return 1;
144+
} else {
145+
return -1;
146+
}
147+
}
148+
return 0;
105149
}

integration-tests/c-example/lib/linked-list/linked-list.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ int middle_length2(struct Kuku *head);
4848

4949
int cycle_list3(struct Node *head);
5050

51+
int len_bound(struct Node *head, int bound);
52+
53+
int sort_list(struct Node *head);
54+
5155
#endif

server/src/Tests.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ shared_ptr<StructValueView> KTestObjectParser::structView(const vector<char> &by
280280
PointerUsage usage,
281281
const std::optional<const Tests::MethodDescription> &testingMethod,
282282
const std::string &name,
283-
const std::optional<MapAddressName> &fromAddressToName,
283+
const MapAddressName &fromAddressToName,
284284
std::vector<InitReference> &initReferences) {
285285
vector<shared_ptr<AbstractValueView>> subViews;
286286
unsigned int curPos = offset;
@@ -342,13 +342,13 @@ shared_ptr<StructValueView> KTestObjectParser::structView(const vector<char> &by
342342
case TypeKind::OBJECT_POINTER:
343343
res = readBytesAsValueForType(byteArray, PointerWidthType, curPos + offsetField,
344344
PointerWidthSize);
345-
if (fromAddressToName.has_value()) {
346-
if (fromAddressToName->find(std::stoull(res)) != fromAddressToName->end()) {
347-
initReferences.emplace_back(PrinterUtils::getFieldAccess(name, field.name), fromAddressToName->at(std::stoull(res)));
348-
}
345+
if (fromAddressToName.find(std::stoull(res)) != fromAddressToName.end()) {
346+
initReferences.emplace_back(PrinterUtils::getFieldAccess(name, field.name),
347+
fromAddressToName.at(std::stoull(res)));
348+
res = PrinterUtils::C_NULL;
349349
}
350-
subViews.push_back(std::make_shared<JustValueView>(PrinterUtils::initializePointer(
351-
field.type.typeName(), res)));
350+
351+
subViews.push_back(std::make_shared<JustValueView>(PrinterUtils::initializePointer(field.type.typeName(), res)));
352352
break;
353353
case TypeKind::FUNCTION_POINTER:
354354
subViews.push_back(functionPointerView(curStruct.name, field.name));
@@ -606,8 +606,8 @@ void KTestObjectParser::assignTypeUnnamedVar(Tests::MethodTestCase &testCase,
606606

607607
testCase.lazyVariables.emplace_back(curVar.type, name);
608608
shared_ptr<AbstractValueView> testParamView = testParameterView({name, byteValue}, {paramType, name},
609-
PointerUsage::PARAMETER, methodDescription,
610-
testCase.fromAddressToName, testCase.lazyReferences);
609+
PointerUsage::PARAMETER, testCase.fromAddressToName,
610+
testCase.lazyReferences, methodDescription);
611611
testCase.lazyValues.emplace_back(testCase.objects[curVar.num].name, 0, testParamView);
612612
}
613613

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

786-
testParamView = testParameterView(kleeParam, {paramType, methodParam.name }, PointerUsage::PARAMETER, methodDescription,
787-
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
786+
testParamView = testParameterView(kleeParam, {paramType, methodParam.name }, PointerUsage::PARAMETER,
787+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences,
788+
methodDescription);
788789
}
789790
testCaseDescription.funcParamValues.push_back(
790791
{ methodParam.name, methodParam.alignment, testParamView });
@@ -805,7 +806,9 @@ KTestObjectParser::parseTestCaseParams(const UTBotKTest &ktest,
805806
auto paramType = methodDescription.returnType.maybeReturnArray() ? methodDescription.returnType :
806807
methodDescription.returnType.baseTypeObj();
807808
const Tests::TypeAndVarName returnParam = { paramType, KleeUtils::RESULT_VARIABLE_NAME };
808-
const auto testReturnView = testParameterView(kleeResParam, returnParam, PointerUsage::RETURN, methodDescription);
809+
const auto testReturnView = testParameterView(kleeResParam, returnParam, PointerUsage::RETURN,
810+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences,
811+
methodDescription);
809812
testCaseDescription.returnValue = {
810813
KleeUtils::RESULT_VARIABLE_NAME, types::TypesHandler::isObjectPointerType(methodDescription.returnType), testReturnView
811814
};
@@ -818,13 +821,15 @@ KTestObjectParser::parseTestCaseParams(const UTBotKTest &ktest,
818821
const auto kleePathFlagSymbolicIterator = getKleeParam(rawKleeParams, KLEE_PATH_FLAG_SYMBOLIC);
819822
if (kleePathFlagSymbolicIterator != rawKleeParams.end()) {
820823
const Tests::TypeAndVarName kleePathParam = {types::Type::intType(), KLEE_PATH_FLAG_SYMBOLIC};
821-
const auto kleePathFlagSymbolicView = testParameterView(*kleePathFlagSymbolicIterator, kleePathParam, types::PointerUsage::PARAMETER);
824+
const auto kleePathFlagSymbolicView = testParameterView(*kleePathFlagSymbolicIterator, kleePathParam, types::PointerUsage::PARAMETER,
825+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
822826
testCaseDescription.kleePathFlagSymbolicValue = {KLEE_PATH_FLAG_SYMBOLIC, false, kleePathFlagSymbolicView};
823827
}
824828
const auto functionReturnNotNullIterator = getKleeParam(rawKleeParams, KleeUtils::NOT_NULL_VARIABLE_NAME);
825829
if (functionReturnNotNullIterator != rawKleeParams.end()) {
826830
const Tests::TypeAndVarName functionReturnNotNull = {types::Type::intType(), KleeUtils::NOT_NULL_VARIABLE_NAME};
827-
const auto functionReturnNotNullView = testParameterView(*functionReturnNotNullIterator, functionReturnNotNull, types::PointerUsage::PARAMETER);
831+
const auto functionReturnNotNullView = testParameterView(*functionReturnNotNullIterator, functionReturnNotNull, types::PointerUsage::PARAMETER,
832+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
828833
testCaseDescription.functionReturnNotNullValue = {KleeUtils::NOT_NULL_VARIABLE_NAME, false, functionReturnNotNullView};
829834
}
830835
return testCaseDescription;
@@ -835,13 +840,15 @@ void KTestObjectParser::processGlobalParamPreValue(Tests::TestCaseDescription &t
835840
vector<RawKleeParam> &rawKleeParams) {
836841
string kleeParamName = globalParam.name;
837842
auto kleeParam = getKleeParamOrThrow(rawKleeParams, kleeParamName);
838-
auto testParamView = testParameterView(kleeParam, { globalParam.type, globalParam.name }, types::PointerUsage::PARAMETER);
843+
auto testParamView = testParameterView(kleeParam, { globalParam.type, globalParam.name }, types::PointerUsage::PARAMETER,
844+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
839845
testCaseDescription.globalPreValues.emplace_back( globalParam.name, globalParam.alignment, testParamView );
840846
}
841847

842848
void KTestObjectParser::processSymbolicStdin(Tests::TestCaseDescription &testCaseDescription, vector<RawKleeParam> &rawKleeParams) {
843849
auto &&read = getKleeParamOrThrow(rawKleeParams, "stdin-read");
844-
string &&view = testParameterView(read, {types::Type::longlongType(), "stdin-read"}, types::PointerUsage::PARAMETER)->getEntryValue();
850+
string &&view = testParameterView(read, {types::Type::longlongType(), "stdin-read"}, types::PointerUsage::PARAMETER,
851+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences)->getEntryValue();
845852
if (view == "0LL") {
846853
return;
847854
} else {
@@ -865,7 +872,8 @@ void KTestObjectParser::processGlobalParamPostValue(Tests::TestCaseDescription &
865872
auto kleeParam = getKleeParamOrThrow(rawKleeParams, symbolicVariable);
866873
auto type = typesHandler.getReturnTypeToCheck(globalParam.type);
867874
Tests::TypeAndVarName typeAndVarName{ type, globalParam.name };
868-
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER);
875+
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER,
876+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
869877
testCaseDescription.globalPostValues.emplace_back( globalParam.name, globalParam.alignment, testParamView );
870878
}
871879

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

@@ -894,30 +903,21 @@ void KTestObjectParser::processStubParamValue(Tests::TestCaseDescription &testCa
894903
}
895904
auto type = typesHandler.getReturnTypeToCheck(methodNameToReturnTypeMap.at(methodName));
896905
Tests::TypeAndVarName typeAndVarName{ type, kleeParam.paramName };
897-
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER);
906+
auto testParamView = testParameterView(kleeParam, typeAndVarName, types::PointerUsage::PARAMETER,
907+
testCaseDescription.fromAddressToName, testCaseDescription.lazyReferences);
898908
testCaseDescription.stubValues.emplace_back( kleeParam.paramName, 0, testParamView );
899909
testCaseDescription.stubValuesTypes.emplace_back(type, kleeParam.paramName, 0);
900910
}
901911
}
902912
}
903913

904-
shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
905-
const RawKleeParam &kleeParam,
906-
const Tests::TypeAndVarName &param,
907-
types::PointerUsage usage,
908-
const std::optional<const Tests::MethodDescription> &testingMethod,
909-
const std::optional<MapAddressName> &fromAddressToName) {
910-
std::vector<InitReference> tmp;
911-
return testParameterView(kleeParam, param, usage, testingMethod, fromAddressToName, tmp);
912-
}
913-
914914
shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
915915
const KTestObjectParser::RawKleeParam &kleeParam,
916916
const Tests::TypeAndVarName &param,
917917
PointerUsage usage,
918-
const std::optional<const Tests::MethodDescription> &testingMethod,
919-
const std::optional<MapAddressName> &fromAddressToName,
920-
std::vector<InitReference> &initReferences) {
918+
const MapAddressName &fromAddressToName,
919+
std::vector<InitReference> &initReferences,
920+
const std::optional<const Tests::MethodDescription> &testingMethod) {
921921
EnumInfo enumInfo;
922922
StructInfo structInfo;
923923
UnionInfo unionInfo;

server/src/Tests.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,9 @@ namespace tests {
570570
testParameterView(const RawKleeParam &kleeParam,
571571
const Tests::TypeAndVarName &param,
572572
types::PointerUsage usage,
573-
const std::optional<const Tests::MethodDescription> &testingMethod = std::nullopt,
574-
const std::optional<MapAddressName> &fromAddressToName = std::nullopt);
575-
576-
shared_ptr<AbstractValueView>
577-
testParameterView(const RawKleeParam &kleeParam,
578-
const Tests::TypeAndVarName &param,
579-
types::PointerUsage usage,
580-
const std::optional<const Tests::MethodDescription> &testingMethod,
581-
const std::optional<MapAddressName> &fromAddressToName,
582-
std::vector<InitReference> &initReferences);
573+
const MapAddressName &fromAddressToName,
574+
std::vector<InitReference> &initReferences,
575+
const std::optional<const Tests::MethodDescription> &testingMethod = std::nullopt);
583576

584577
shared_ptr<ArrayValueView> multiArrayView(const vector<char> &byteArray,
585578
const types::Type &type,
@@ -618,7 +611,7 @@ namespace tests {
618611
types::PointerUsage usage,
619612
const std::optional<const Tests::MethodDescription> &testingMethod,
620613
const std::string &name,
621-
const std::optional<MapAddressName> &fromAddressToName,
614+
const MapAddressName &fromAddressToName,
622615
std::vector<InitReference> &initReferences);
623616

624617
shared_ptr<PrimitiveValueView> primitiveView(const vector<char> &byteArray,

server/src/building/Linker.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,18 @@ std::string getArchiveArgument(std::string const &argument,
533533
return argument;
534534
}
535535

536+
static void moveKleeTemporaryFileArgumentToBegin(std::vector<std::string> &arguments) {
537+
auto iteratorToCurrentFile = std::find_if(arguments.begin(), arguments.end(), [] (const std::string &argument) {
538+
return StringUtils::endsWith(argument, "_klee.bc");
539+
});
540+
if (iteratorToCurrentFile == arguments.end()) {
541+
LOG_S(ERROR) << "Don't find temporary klee file";
542+
return;
543+
}
544+
auto iteratorToSwap = std::find(arguments.begin(), arguments.end(), "-o");
545+
std::iter_swap(iteratorToSwap + 2, iteratorToCurrentFile);
546+
}
547+
536548
static std::vector<utbot::LinkCommand>
537549
getArchiveCommands(fs::path const &workingDir,
538550
CollectionUtils::MapFileTo<fs::path> const &dependencies,
@@ -547,6 +559,8 @@ getArchiveCommands(fs::path const &workingDir,
547559
output, linkCommand, hasArchiveOption);
548560
});
549561
arguments.erase(arguments.begin());
562+
moveKleeTemporaryFileArgumentToBegin(arguments);
563+
550564
if (hasArchiveOption) {
551565
arguments.insert(arguments.begin(), { "ar" });
552566
} else {

server/src/utils/PrinterUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ namespace PrinterUtils {
5151
}
5252

5353
std::string initializePointer(const std::string &type, const std::string &value) {
54-
return "(" + type + ") " + value;
54+
if (value == C_NULL || value == "0") {
55+
return C_NULL;
56+
} else {
57+
return "(" + type + ") " + value;
58+
}
59+
5560
}
5661

5762
std::string generateNewVar(int cnt) {

0 commit comments

Comments
 (0)