Skip to content

Commit 3969dee

Browse files
committed
Some fixes
1 parent 3447d19 commit 3969dee

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

server/src/Tests.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,14 @@ void KTestObjectParser::addToOrder(const std::vector<UTBotKTestObject> &objects,
587587
const types::Type &paramType,
588588
Tests::TestCaseParamValue &paramValue,
589589
std::vector<bool> &visited,
590+
std::vector<PointerUsage> &usages,
590591
std::queue<JsonIndAndParam> &order) {
591592
auto it = std::find_if(objects.begin(), objects.end(),
592593
[paramName](const UTBotKTestObject &obj) { return obj.name == paramName; });
593594
if (it != objects.end()) {
594595
size_t jsonInd = it - objects.begin();
595596
visited[jsonInd] = true;
597+
usages[jsonInd] = types::PointerUsage::PARAMETER;
596598
Tests::MethodParam param = { paramType.isObjectPointer() && !paramType.isPointerToPointer()
597599
? paramType.baseTypeObj()
598600
: paramType,
@@ -615,16 +617,17 @@ bool KTestObjectParser::pointToStruct(const types::Type &pointerType,
615617
void KTestObjectParser::assignTypeUnnamedVar(
616618
Tests::MethodTestCase &testCase,
617619
const Tests::MethodDescription &methodDescription,
618-
std::vector<std::optional<Tests::TypeAndVarName>> &objects) {
620+
std::vector<std::optional<Tests::TypeAndVarName>> &objects,
621+
std::vector<PointerUsage> &usages) {
619622
std::queue<JsonIndAndParam> order;
620623
std::vector<bool> visited(testCase.objects.size(), false);
621624
for (size_t paramInd = 0; paramInd < testCase.paramValues.size(); paramInd++) {
622625
addToOrder(testCase.objects, methodDescription.params[paramInd].name,
623626
methodDescription.params[paramInd].type, testCase.paramValues[paramInd], visited,
624-
order);
627+
usages, order);
625628
}
626629
addToOrder(testCase.objects, KleeUtils::RESULT_VARIABLE_NAME, methodDescription.returnType,
627-
testCase.returnValue, visited, order);
630+
testCase.returnValue, visited, usages, order);
628631

629632
while (!order.empty()) {
630633
auto curType = order.front();
@@ -638,6 +641,7 @@ void KTestObjectParser::assignTypeUnnamedVar(
638641
throw UnImplementedException("Lazy variable has baseType=void");
639642
}
640643

644+
usages[curType.jsonInd] = types::PointerUsage::LAZY;
641645
std::vector<char> byteValue = testCase.objects[curType.jsonInd].bytes;
642646
Tests::TypeAndVarName typeAndVarName{ paramType, name };
643647
std::shared_ptr<AbstractValueView> testParamView = testParameterView(
@@ -655,7 +659,8 @@ void KTestObjectParser::assignTypeUnnamedVar(
655659
continue;
656660
}
657661
Tests::TypeAndVarName typeAndName = { paramType, "" };
658-
size_t offsetInStruct = getOffsetInStruct(typeAndName, SizeUtils::bytesToBits(offset));
662+
size_t offsetInStruct =
663+
getOffsetInStruct(typeAndName, SizeUtils::bytesToBits(offset), usages[indObj]);
659664
types::Type fieldType = traverseLazyInStruct(typeAndName.type, offsetInStruct).type;
660665
if (!pointToStruct(fieldType, testCase.objects[indObj])) {
661666
continue;
@@ -700,11 +705,13 @@ Tests::TypeAndVarName KTestObjectParser::traverseLazyInStruct(const types::Type
700705
}
701706
}
702707

703-
size_t KTestObjectParser::getOffsetInStruct(Tests::TypeAndVarName &objTypeAndName, size_t offsetInBits) const {
704-
if (!objTypeAndName.type.isPointerToPointer()) {
708+
size_t KTestObjectParser::getOffsetInStruct(Tests::TypeAndVarName &objTypeAndName,
709+
size_t offsetInBits,
710+
types::PointerUsage usage) const {
711+
if (!objTypeAndName.type.isPointerToPointer() || usage != types::PointerUsage::PARAMETER) {
705712
return offsetInBits;
706713
}
707-
std::vector<size_t> sizes = objTypeAndName.type.arraysSizes(types::PointerUsage::PARAMETER);
714+
std::vector<size_t> sizes = objTypeAndName.type.arraysSizes(usage);
708715
size_t dimension = sizes.size();
709716
objTypeAndName.type = objTypeAndName.type.baseTypeObj();
710717
size_t sizeInBits = typesHandler.typeSize(objTypeAndName.type);
@@ -739,16 +746,18 @@ void KTestObjectParser::assignTypeStubVar(Tests::MethodTestCase &testCase,
739746

740747
void KTestObjectParser::assignAllLazyPointers(
741748
Tests::MethodTestCase &testCase,
742-
const std::vector<std::optional<Tests::TypeAndVarName>> &objTypeAndName) const {
749+
const std::vector<std::optional<Tests::TypeAndVarName>> &objTypeAndName,
750+
const std::vector<PointerUsage> &usages) const {
743751
for (size_t ind = 0; ind < testCase.objects.size(); ind++) {
744752
const auto &object = testCase.objects[ind];
745753
if (!objTypeAndName[ind].has_value()) {
746754
continue;
747755
}
748756
for (const auto &pointer : object.pointers) {
749757
Tests::TypeAndVarName typeAndName = objTypeAndName[ind].value();
750-
size_t offset =
751-
getOffsetInStruct(typeAndName, SizeUtils::bytesToBits(pointer.offset));
758+
size_t offset = getOffsetInStruct(typeAndName,
759+
SizeUtils::bytesToBits(pointer.offset),
760+
usages[ind]);
752761
Tests::TypeAndVarName fromPtr =
753762
traverseLazyInStruct(typeAndName.type, offset, typeAndName.varName);
754763
if (!objTypeAndName[pointer.index].has_value()) {
@@ -757,8 +766,9 @@ void KTestObjectParser::assignAllLazyPointers(
757766

758767
std::string toPtrName;
759768
Tests::TypeAndVarName pointerTypeAndName = objTypeAndName[pointer.index].value();
760-
size_t indexOffset =
761-
getOffsetInStruct(pointerTypeAndName, SizeUtils::bytesToBits(pointer.indexOffset));
769+
size_t indexOffset = getOffsetInStruct(pointerTypeAndName,
770+
SizeUtils::bytesToBits(pointer.indexOffset),
771+
usages[pointer.index]);
762772
if (indexOffset == 0 &&
763773
pointToStruct(fromPtr.type, testCase.objects[pointer.index])) {
764774
toPtrName = pointerTypeAndName.varName;
@@ -852,11 +862,11 @@ void KTestObjectParser::parseTestCases(const UTBotKTestList &cases,
852862
traceStream << "\treturn: " << testCase.returnValue.view->getEntryValue(nullptr);
853863
LOG_S(MAX) << traceStream.str();
854864

855-
std::vector<std::optional<Tests::TypeAndVarName>> objectsValues(
856-
testCase.objects.size());
857-
assignTypeUnnamedVar(testCase, methodDescription, objectsValues);
865+
std::vector<std::optional<Tests::TypeAndVarName>> objectsValues(testCase.objects.size());
866+
std::vector<PointerUsage> usages(testCase.objects.size());
867+
assignTypeUnnamedVar(testCase, methodDescription, objectsValues, usages);
858868
assignTypeStubVar(testCase, methodDescription);
859-
assignAllLazyPointers(testCase, objectsValues);
869+
assignAllLazyPointers(testCase, objectsValues, usages);
860870

861871
methodDescription.testCases.push_back(testCase);
862872
methodDescription.suiteTestCases[testCase.suiteName].push_back(testCase.testIndex);

server/src/Tests.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,26 +824,31 @@ namespace tests {
824824
const types::Type &paramType,
825825
Tests::TestCaseParamValue &paramValue,
826826
std::vector<bool> &visited,
827+
std::vector<types::PointerUsage> &usages,
827828
std::queue<JsonIndAndParam> &order);
828829

829830
void assignTypeUnnamedVar(Tests::MethodTestCase &testCase,
830831
const Tests::MethodDescription &methodDescription,
831-
std::vector<std::optional<Tests::TypeAndVarName>> &objects);
832+
std::vector<std::optional<Tests::TypeAndVarName>> &objects,
833+
std::vector<types::PointerUsage> &usages);
832834

833835
void assignTypeStubVar(Tests::MethodTestCase &testCase,
834836
const Tests::MethodDescription &methodDescription);
835837

836838
void assignAllLazyPointers(
837839
Tests::MethodTestCase &testCase,
838-
const std::vector<std::optional<Tests::TypeAndVarName>> &objTypeAndName) const;
840+
const std::vector<std::optional<Tests::TypeAndVarName>> &objTypeAndName,
841+
const std::vector<types::PointerUsage> &usages) const;
839842

840843
size_t findFieldIndex(const types::StructInfo &structInfo, size_t offsetInBits) const;
841844

842845
Tests::TypeAndVarName traverseLazyInStruct(const types::Type &curVarType,
843846
size_t offsetInBits,
844847
const std::string &curVarName = "") const;
845848

846-
size_t getOffsetInStruct(Tests::TypeAndVarName &objTypeAndName, size_t offsetInBits) const;
849+
size_t getOffsetInStruct(Tests::TypeAndVarName &objTypeAndName,
850+
size_t offsetInBits,
851+
types::PointerUsage usage) const;
847852

848853
std::shared_ptr<AbstractValueView>
849854
getLazyPointerView(const std::vector<UTBotKTestObject> &objects,

0 commit comments

Comments
 (0)