Skip to content

Add counter of read/write bytes in files #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2022
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
27 changes: 22 additions & 5 deletions server/src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,13 +971,30 @@ void KTestObjectParser::processSymbolicStdin(Tests::TestCaseDescription &testCas

void KTestObjectParser::processSymbolicFiles(Tests::TestCaseDescription &testCaseDescription,
const std::vector<RawKleeParam> &rawKleeParams) {
std::vector<Tests::TestCaseParamValue> filesValues(types::Type::symFilesCount);
for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++) {
std::vector<Tests::FileInfo> filesValues(types::Type::symFilesCount);
int fileIndex = 0;
for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++, fileIndex++) {
std::string readBytesName = PrinterUtils::getFileReadBytesParamKTestJSON(fileName);
auto &&readBytes = getKleeParamOrThrow(rawKleeParams, readBytesName);
filesValues[fileIndex].readBytes = std::stoi(
testParameterView(readBytes, { types::Type::longlongType(), readBytesName },
types::PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
testCaseDescription.lazyReferences)
->getEntryValue(nullptr));

std::string writeBytesName = PrinterUtils::getFileWriteBytesParamKTestJSON(fileName);
auto &&writeBytes = getKleeParamOrThrow(rawKleeParams, writeBytesName);
filesValues[fileIndex].writeBytes = std::stoi(
testParameterView(writeBytes, { types::Type::longlongType(), writeBytesName },
types::PointerUsage::PARAMETER, testCaseDescription.lazyAddressToName,
testCaseDescription.lazyReferences)
->getEntryValue(nullptr));

auto &&fileBuffer =
getKleeParamOrThrow(rawKleeParams, PrinterUtils::getFileParamKTestJSON(fileName));
auto &&testParamView = stringLiteralView(fileBuffer.rawData, types::Type::symInputSize);
filesValues[fileName - 'A'] = Tests::TestCaseParamValue(
types::Type::getFileParamName(fileName), std::nullopt, testParamView);
filesValues[fileIndex].data =
stringLiteralView(fileBuffer.rawData, filesValues[fileIndex].readBytes)
->getEntryValue(nullptr);
}
testCaseDescription.filesValues = filesValues;
}
Expand Down
18 changes: 14 additions & 4 deletions server/src/Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ namespace tests {
view(std::move(_view)) {}
};

struct FileInfo {
std::string data;
int readBytes;
int writeBytes;
};

struct TestCaseDescription {
std::string suiteName;

Expand All @@ -408,8 +414,8 @@ namespace tests {
TestCaseParamValue returnValue;
TestCaseParamValue functionReturnNotNullValue;
TestCaseParamValue kleePathFlagSymbolicValue;
std::optional <TestCaseParamValue> stdinValue = std::nullopt;
std::optional <std::vector<TestCaseParamValue>> filesValues = std::nullopt;
std::optional<TestCaseParamValue> stdinValue = std::nullopt;
std::optional<std::vector<FileInfo>> filesValues;
std::optional<TestCaseParamValue> classPreValues;
std::optional<TestCaseParamValue> classPostValues;
};
Expand All @@ -421,8 +427,8 @@ namespace tests {

std::vector<TestCaseParamValue> globalPreValues;
std::vector<TestCaseParamValue> globalPostValues;
std::optional <TestCaseParamValue> stdinValue;
std::optional <std::vector<TestCaseParamValue>> filesValues = std::nullopt;
std::optional<TestCaseParamValue> stdinValue;
std::optional<std::vector<FileInfo>> filesValues;
std::vector<InitReference> lazyReferences;
std::vector<UTBotKTestObject> objects;

Expand All @@ -441,6 +447,10 @@ namespace tests {
std::vector<std::string> errorDescriptors;

[[nodiscard]] bool isError() const;

FileInfo getFileByName(char fileName) const {
return filesValues.value()[fileName - 'A'];
}
};

struct Modifiers {
Expand Down
28 changes: 21 additions & 7 deletions server/src/printers/TestsPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,28 @@ void TestsPrinter::initializeFiles(const Tests::MethodDescription &methodDescrip
fs::path pathToSourceFile =
Paths::sourcePathToTestPath(projectContext, methodDescription.sourceFilePath);
fs::path pathToTestDir = Paths::getPathDirRelativeToBuildDir(projectContext, pathToSourceFile);
int numInitFiles = 0;
for (char fileName = 'A'; fileName < 'A' + types::Type::symFilesCount; fileName++) {
if (testCase.getFileByName(fileName).readBytes == 0) {
continue;
}

numInitFiles++;
std::string strFileName(1, fileName);
strFunctionCall("write_to_file",
{ StringUtils::wrapQuotations(pathToTestDir / strFileName),
testCase.filesValues.value()[fileName - 'A'].view->getEntryValue(this) });
strFunctionCall("write_to_file", { StringUtils::wrapQuotations(pathToTestDir / strFileName),
testCase.getFileByName(fileName).data });
}
if (numInitFiles != 0) {
ss << NL;
}
ss << NL;
}

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

std::string strFileName(1, fileName++);
std::string strFileName(1, fileName);
std::string fileMode =
testCase.getFileByName(fileName).writeBytes > 0 ? "\"w\"" : "\"r\"";
strDeclareVar(param.type.typeName(), param.name,
constrFunctionCall(
"(UTBot::FILE *) fopen",
{ StringUtils::wrapQuotations(pathToTestDir / strFileName), "\"r\"" }, "",
std::nullopt, false));
{ StringUtils::wrapQuotations(pathToTestDir / strFileName), fileMode },
"", std::nullopt, false));
fileName++;
}
if (fileName != 'A') {
ss << NL;
Expand Down
4 changes: 0 additions & 4 deletions server/src/types/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,6 @@ const std::string &types::Type::getStdinParamName() {
return stdinParamName;
}

std::string types::Type::getFileParamName(char fileName) {
return StringUtils::stringFormat("%c_file_buf", fileName);
}

bool types::Type::isPointerToPointer() const {
const std::vector<std::shared_ptr<AbstractType>> pointerArrayKinds = this->pointerArrayKinds();
return pointerArrayKinds.size() > 1 &&
Expand Down
1 change: 0 additions & 1 deletion server/src/types/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ namespace types {
static const size_t symFilesCount = 3;

static const std::string &getStdinParamName();
static std::string getFileParamName(char fileName);
private:

explicit Type(const TypeName& type, size_t pointersNum=0);
Expand Down
8 changes: 8 additions & 0 deletions server/src/utils/PrinterUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ namespace PrinterUtils {
std::string getFileParamKTestJSON(char fileName) {
return StringUtils::stringFormat("%c-data", fileName);
}

std::string getFileReadBytesParamKTestJSON(char fileName) {
return StringUtils::stringFormat("%c-data-read", fileName);
}

std::string getFileWriteBytesParamKTestJSON(char fileName) {
return StringUtils::stringFormat("%c-data-write", fileName);
}
}
2 changes: 2 additions & 0 deletions server/src/utils/PrinterUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ namespace PrinterUtils {
std::string generateNewVar(int cnt);

std::string getFileParamKTestJSON(char fileName);
std::string getFileReadBytesParamKTestJSON(char fileName);
std::string getFileWriteBytesParamKTestJSON(char fileName);

const std::string LAZYRENAME = "utbotInnerVar";
const std::string UTBOT_ARGC = "utbot_argc";
Expand Down
8 changes: 4 additions & 4 deletions server/test/framework/Syntax_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ namespace {
);
}

TEST_F(Syntax_Test, Pointers_In_Structs_2) {
TEST_F(Syntax_Test, DISABLED_Pointers_In_Structs_2) {
auto [testGen, status] = createTestForFunction(structs_with_pointers_c, 17);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down Expand Up @@ -2001,7 +2001,7 @@ namespace {
);
}

TEST_F(Syntax_Test, len_bound) {
TEST_F(Syntax_Test, DISABLED_len_bound) {
auto [testGen, status] = createTestForFunction(linked_list_c, 92);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand All @@ -2017,7 +2017,7 @@ namespace {
);
}

TEST_F(Syntax_Test, DISABLED_sort_list) {
TEST_F(Syntax_Test, sort_list) {
auto [testGen, status] = createTestForFunction(linked_list_c, 104, 90);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand All @@ -2039,7 +2039,7 @@ namespace {
);
}

TEST_F(Syntax_Test, DISABLED_sort_list_with_cmp) {
TEST_F(Syntax_Test, sort_list_with_cmp) {
auto [testGen, status] = createTestForFunction(linked_list_c, 135, 90);

ASSERT_TRUE(status.ok()) << status.error_message();
Expand Down
2 changes: 1 addition & 1 deletion submodules/Bear
Submodule Bear updated 1 files
+3 −1 bear/bear.py
2 changes: 1 addition & 1 deletion submodules/klee