Skip to content

Commit 2395ac0

Browse files
committed
Add counter of read/write bytes in files
1 parent 9bf4766 commit 2395ac0

File tree

9 files changed

+66
-25
lines changed

9 files changed

+66
-25
lines changed

Diff for: server/src/Tests.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -971,13 +971,29 @@ void KTestObjectParser::processSymbolicStdin(Tests::TestCaseDescription &testCas
971971

972972
void KTestObjectParser::processSymbolicFiles(Tests::TestCaseDescription &testCaseDescription,
973973
const std::vector<RawKleeParam> &rawKleeParams) {
974-
std::vector<Tests::TestCaseParamValue> filesValues(types::Type::symFilesCount);
974+
std::vector<Tests::FileInfo> filesValues(types::Type::symFilesCount);
975975
for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++) {
976+
std::string readBytesName = PrinterUtils::getFileReadBytesParamKTestJSON(fileName);
977+
auto &&readBytes = getKleeParamOrThrow(rawKleeParams, readBytesName);
978+
filesValues[fileName - 'A'].readBytes = std::stoi(
979+
testParameterView(readBytes, { types::Type::longlongType(), readBytesName },
980+
types::PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
981+
testCaseDescription.lazyReferences)
982+
->getEntryValue(nullptr));
983+
984+
std::string writeBytesName = PrinterUtils::getFileWriteBytesParamKTestJSON(fileName);
985+
auto &&writeBytes = getKleeParamOrThrow(rawKleeParams, writeBytesName);
986+
filesValues[fileName - 'A'].writeBytes = std::stoi(
987+
testParameterView(writeBytes, { types::Type::longlongType(), writeBytesName },
988+
types::PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
989+
testCaseDescription.lazyReferences)
990+
->getEntryValue(nullptr));
991+
976992
auto &&fileBuffer =
977993
getKleeParamOrThrow(rawKleeParams, PrinterUtils::getFileParamKTestJSON(fileName));
978-
auto &&testParamView = stringLiteralView(fileBuffer.rawData, types::Type::symInputSize);
979-
filesValues[fileName - 'A'] = Tests::TestCaseParamValue(
980-
types::Type::getFileParamName(fileName), std::nullopt, testParamView);
994+
filesValues[fileName - 'A'].data =
995+
stringLiteralView(fileBuffer.rawData, filesValues[fileName - 'A'].readBytes)
996+
->getEntryValue(nullptr);
981997
}
982998
testCaseDescription.filesValues = filesValues;
983999
}

Diff for: server/src/Tests.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ namespace tests {
390390
view(std::move(_view)) {}
391391
};
392392

393+
struct FileInfo {
394+
std::string data;
395+
int readBytes;
396+
int writeBytes;
397+
};
398+
393399
struct TestCaseDescription {
394400
std::string suiteName;
395401

@@ -408,8 +414,8 @@ namespace tests {
408414
TestCaseParamValue returnValue;
409415
TestCaseParamValue functionReturnNotNullValue;
410416
TestCaseParamValue kleePathFlagSymbolicValue;
411-
std::optional <TestCaseParamValue> stdinValue = std::nullopt;
412-
std::optional <std::vector<TestCaseParamValue>> filesValues = std::nullopt;
417+
std::optional<TestCaseParamValue> stdinValue = std::nullopt;
418+
std::optional<std::vector<FileInfo>> filesValues;
413419
std::optional<TestCaseParamValue> classPreValues;
414420
std::optional<TestCaseParamValue> classPostValues;
415421
};
@@ -421,8 +427,8 @@ namespace tests {
421427

422428
std::vector<TestCaseParamValue> globalPreValues;
423429
std::vector<TestCaseParamValue> globalPostValues;
424-
std::optional <TestCaseParamValue> stdinValue;
425-
std::optional <std::vector<TestCaseParamValue>> filesValues = std::nullopt;
430+
std::optional<TestCaseParamValue> stdinValue;
431+
std::optional<std::vector<FileInfo>> filesValues;
426432
std::vector<InitReference> lazyReferences;
427433
std::vector<UTBotKTestObject> objects;
428434

Diff for: server/src/printers/TestsPrinter.cpp

+21-7
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,28 @@ void TestsPrinter::initializeFiles(const Tests::MethodDescription &methodDescrip
256256
fs::path pathToSourceFile =
257257
Paths::sourcePathToTestPath(projectContext, methodDescription.sourceFilePath);
258258
fs::path pathToTestDir = Paths::getPathDirRelativeToBuildDir(projectContext, pathToSourceFile);
259+
int numInitFiles = 0;
259260
for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++) {
261+
if (testCase.filesValues.value()[fileName - 'A'].readBytes == 0) {
262+
continue;
263+
}
264+
265+
numInitFiles++;
260266
std::string strFileName(1, fileName);
261-
strFunctionCall("write_to_file",
262-
{ StringUtils::wrapQuotations(pathToTestDir / strFileName),
263-
testCase.filesValues.value()[fileName - 'A'].view->getEntryValue(this) });
267+
strFunctionCall("write_to_file", { StringUtils::wrapQuotations(pathToTestDir / strFileName),
268+
testCase.filesValues.value()[fileName - 'A'].data });
269+
}
270+
if (numInitFiles != 0) {
271+
ss << NL;
264272
}
265-
ss << NL;
266273
}
267274

268275
void TestsPrinter::openFiles(const Tests::MethodDescription &methodDescription,
269276
const Tests::MethodTestCase &testCase) {
277+
if (!testCase.filesValues.has_value()) {
278+
LOG_S(WARNING) << "There are not symbolic files in the test.";
279+
return;
280+
}
270281
char fileName = 'A';
271282
fs::path pathToSourceFile =
272283
Paths::sourcePathToTestPath(projectContext, methodDescription.sourceFilePath);
@@ -277,12 +288,15 @@ void TestsPrinter::openFiles(const Tests::MethodDescription &methodDescription,
277288
continue;
278289
}
279290

280-
std::string strFileName(1, fileName++);
291+
std::string strFileName(1, fileName);
292+
std::string fileMode =
293+
testCase.filesValues.value()[fileName - 'A'].writeBytes > 0 ? "\"w\"" : "\"r\"";
281294
strDeclareVar(param.type.typeName(), param.name,
282295
constrFunctionCall(
283296
"(UTBot::FILE *) fopen",
284-
{ StringUtils::wrapQuotations(pathToTestDir / strFileName), "\"r\"" }, "",
285-
std::nullopt, false));
297+
{ StringUtils::wrapQuotations(pathToTestDir / strFileName), fileMode },
298+
"", std::nullopt, false));
299+
fileName++;
286300
}
287301
if (fileName != 'A') {
288302
ss << NL;

Diff for: server/src/types/Types.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ const std::string &types::Type::getStdinParamName() {
284284
return stdinParamName;
285285
}
286286

287-
std::string types::Type::getFileParamName(char fileName) {
288-
return StringUtils::stringFormat("%c_file_buf", fileName);
289-
}
290-
291287
bool types::Type::isPointerToPointer() const {
292288
const std::vector<std::shared_ptr<AbstractType>> pointerArrayKinds = this->pointerArrayKinds();
293289
return pointerArrayKinds.size() > 1 &&

Diff for: server/src/types/Types.h

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ namespace types {
242242
static const size_t symFilesCount = 3;
243243

244244
static const std::string &getStdinParamName();
245-
static std::string getFileParamName(char fileName);
246245
private:
247246

248247
explicit Type(const TypeName& type, size_t pointersNum=0);

Diff for: server/src/utils/PrinterUtils.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,12 @@ namespace PrinterUtils {
136136
std::string getFileParamKTestJSON(char fileName) {
137137
return StringUtils::stringFormat("%c-data", fileName);
138138
}
139+
140+
std::string getFileReadBytesParamKTestJSON(char fileName) {
141+
return StringUtils::stringFormat("%c-data-read", fileName);
142+
}
143+
144+
std::string getFileWriteBytesParamKTestJSON(char fileName) {
145+
return StringUtils::stringFormat("%c-data-write", fileName);
146+
}
139147
}

Diff for: server/src/utils/PrinterUtils.h

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ namespace PrinterUtils {
103103
std::string generateNewVar(int cnt);
104104

105105
std::string getFileParamKTestJSON(char fileName);
106+
std::string getFileReadBytesParamKTestJSON(char fileName);
107+
std::string getFileWriteBytesParamKTestJSON(char fileName);
106108

107109
const std::string LAZYRENAME = "utbotInnerVar";
108110
const std::string UTBOT_ARGC = "utbot_argc";

Diff for: server/test/framework/Syntax_Tests.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ namespace {
12831283
);
12841284
}
12851285

1286-
TEST_F(Syntax_Test, Pointers_In_Structs_2) {
1286+
TEST_F(Syntax_Test, DISABLED_Pointers_In_Structs_2) {
12871287
auto [testGen, status] = createTestForFunction(structs_with_pointers_c, 17);
12881288

12891289
ASSERT_TRUE(status.ok()) << status.error_message();
@@ -2001,7 +2001,7 @@ namespace {
20012001
);
20022002
}
20032003

2004-
TEST_F(Syntax_Test, len_bound) {
2004+
TEST_F(Syntax_Test, DISABLED_len_bound) {
20052005
auto [testGen, status] = createTestForFunction(linked_list_c, 92);
20062006

20072007
ASSERT_TRUE(status.ok()) << status.error_message();
@@ -2017,7 +2017,7 @@ namespace {
20172017
);
20182018
}
20192019

2020-
TEST_F(Syntax_Test, DISABLED_sort_list) {
2020+
TEST_F(Syntax_Test, sort_list) {
20212021
auto [testGen, status] = createTestForFunction(linked_list_c, 104, 90);
20222022

20232023
ASSERT_TRUE(status.ok()) << status.error_message();
@@ -2039,7 +2039,7 @@ namespace {
20392039
);
20402040
}
20412041

2042-
TEST_F(Syntax_Test, DISABLED_sort_list_with_cmp) {
2042+
TEST_F(Syntax_Test, sort_list_with_cmp) {
20432043
auto [testGen, status] = createTestForFunction(linked_list_c, 135, 90);
20442044

20452045
ASSERT_TRUE(status.ok()) << status.error_message();

0 commit comments

Comments
 (0)