Skip to content

Commit

Permalink
Add more logs (#647)
Browse files Browse the repository at this point in the history
* Add more logs
  • Loading branch information
ladisgin authored Sep 25, 2023
1 parent db7c6de commit 7444333
Show file tree
Hide file tree
Showing 31 changed files with 265 additions and 134 deletions.
7 changes: 4 additions & 3 deletions server/src/FeaturesFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
}
LOG_S(DEBUG) << statsMessage.str();
if (!hasSupportedMethods && throwIfZeroFunctions) {
throw NoTestGeneratedException("Couldn't find any supported methods. "
"Please check if source directories are specified correctly. "
"See logs for more details about unsupported functions.");
std::string message = "Couldn't find any supported methods. "
"Please check if source directories are specified correctly.";
LOG_S(ERROR) << message;
throw NoTestGeneratedException(message);
}
}

Expand Down
15 changes: 12 additions & 3 deletions server/src/KleeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ KleeGenerator::KleeGenerator(BaseTestGen *testGen, types::TypesHandler &typesHan
fs::create_directories(this->testGen->serverBuildDir);
fs::create_directories(Paths::getLogDir(this->testGen->projectContext.projectName));
} catch (const fs::filesystem_error &e) {
throw FileSystemException("create_directories failed", e);
LOG_S(ERROR) << StringUtils::stringFormat("Create_directories failed: %s", e.what());
throw FileSystemException("Create_directories failed", e);
}
}

Expand Down Expand Up @@ -208,6 +209,7 @@ Result<fs::path> KleeGenerator::defaultBuild(const fs::path &hintPath,
"Couldn't get command for klee file: %s\n"
"Please check if directory is in source directories in UTBot extension settings: %s",
sourceFilePath, hintPath.parent_path().string());
LOG_S(ERROR) << message;
throw BaseException(std::move(message));
}
auto &command = optionalCommand.value();
Expand Down Expand Up @@ -287,7 +289,11 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
LOG_S(MAX) << "Klee filepath: " << outFiles.back();
} else {
if (lineInfo) {
throw BaseException("Couldn't compile klee file for current line.");
std::string message = StringUtils::stringFormat(
"Couldn't compile klee file for current line: %s:%d-%d", lineInfo->filePath,
lineInfo->begin, lineInfo->end);
LOG_S(ERROR) << message;
throw BaseException(message);
}
auto tempKleeFilePath = Paths::addSuffix(kleeFilePath, "_temp");
fs::copy(kleeFilePath, tempKleeFilePath, fs::copy_options::overwrite_existing);
Expand Down Expand Up @@ -327,7 +333,10 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
if (kleeBitcodeFile.isSuccess()) {
outFiles.emplace_back(kleeBitcodeFile.getOpt().value());
} else {
throw BaseException("Couldn't compile klee file from correct methods.");
std::string message = StringUtils::stringFormat(
"Couldn't compile klee file from correct methods");
LOG_S(ERROR) << message;
throw BaseException(message);
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions server/src/KleeRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
LOG_S(WARNING) << FileNotPresentedInCommandsException::createMessage(filePath);
return;
} else {
LOG_S(ERROR) << FileNotPresentedInCommandsException::createMessage(filePath);
throw FileNotPresentedInCommandsException(filePath);
}
}
Expand All @@ -85,6 +86,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
LOG_S(WARNING) << FileNotPresentedInArtifactException::createMessage(filePath);
return;
} else {
LOG_S(ERROR) << FileNotPresentedInArtifactException::createMessage(filePath);
throw FileNotPresentedInArtifactException(filePath);
}
}
Expand Down
5 changes: 3 additions & 2 deletions server/src/RequestEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace RequestEnvironment {

const std::string &getClientId() {
if (!clientId.has_value()) {
throw std::runtime_error(
"Client id was not initialized. Did you forget to call \"setThreadOptions\"?");
//TODO: Add more logs
std::string message = "Client id was not initialized. Did you forget to call \"setThreadOptions\"?";
throw std::runtime_error(message);
}
return clientId.value();
}
Expand Down
20 changes: 15 additions & 5 deletions server/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
if (lineTestGen->needToAddPathFlag()) {
LOG_S(DEBUG) << "Added test line flag for file " << lineInfo->filePath;
fs::path flagFilePath =
printer::KleePrinter(&typesHandler, nullptr, Paths::getSourceLanguage(lineInfo->filePath), &testGen)
printer::KleePrinter(&typesHandler, nullptr, Paths::getSourceLanguage(lineInfo->filePath),
&testGen)
.addTestLineFlag(lineInfo, lineInfo->forAssert, testGen.projectContext);
pathSubstitution = {lineTestGen->filePath, flagFilePath};
}
Expand All @@ -265,7 +266,7 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
auto selectedTargets = linker.getSelectedTargets();
SourceToHeaderRewriter(testGen.projectContext, testGen.getTargetBuildDatabase()->compilationDatabase,
fetcher.getStructsToDeclare(), testGen.serverBuildDir, typesHandler)
.generateTestHeaders(testGen.tests, stubGen, selectedTargets, testGen.progressWriter);
.generateTestHeaders(testGen.tests, stubGen, selectedTargets, testGen.progressWriter);
KleeRunner kleeRunner{testGen.projectContext, testGen.settingsContext};
bool interactiveMode = (dynamic_cast<ProjectTestGen *>(&testGen) != nullptr);
auto generationStartTime = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -315,11 +316,14 @@ std::shared_ptr<LineInfo> Server::TestsGenServiceImpl::getLineInfo(LineTestGen &
lineTestGen.compileCommandsJsonPath);
stmtFinder.findFunction();
if (!stmtFinder.getLineInfo().initialized) {
throw NoTestGeneratedException(
"Maybe you tried to generate tests placing cursor on invalid line.");
LOG_S(ERROR) << "Cant generate for this line\n"
<< stmtFinder.getLineInfo().stmtString;
throw NoTestGeneratedException("Maybe you tried to generate tests placing cursor on invalid line.");
}
if (isSameType<AssertionTestGen>(lineTestGen) &&
!StringUtils::contains(stmtFinder.getLineInfo().stmtString, "assert")) {
LOG_S(ERROR) << "No assert found on this line\n"
<< stmtFinder.getLineInfo().stmtString;
throw NoTestGeneratedException("No assert found on this line.");
}
auto lineInfo = std::make_shared<LineInfo>(stmtFinder.getLineInfo());
Expand All @@ -343,6 +347,7 @@ std::string extractMessage(const loguru::Message &message) {
void Server::logToClient(void *channel, const loguru::Message &message) {
auto data = reinterpret_cast<WriterData *>(channel);
if (data == nullptr) {
LOG_S(ERROR) << "Couldn't handle logging to client, data is null";
throw BaseException("Couldn't handle logging to client, data is null");
}
std::vector<char> thread_name(LOGURU_BUFFER_SIZE);
Expand All @@ -361,6 +366,7 @@ void Server::logToClient(void *channel, const loguru::Message &message) {
void Server::gtestLog(void *channel, const loguru::Message &message) {
auto data = reinterpret_cast<WriterData *>(channel);
if (data == nullptr) {
LOG_S(ERROR) << "Can't interpret gtest log channel";
throw BaseException("Can't interpret gtest log channel");
}
std::vector<char> thread_name(LOGURU_BUFFER_SIZE);
Expand Down Expand Up @@ -661,6 +667,10 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context,
} catch (CompilationDatabaseException const &e) {
LOG_S(ERROR) << "Compilation database error: " << e.what();
return failedToLoadCDbStatus(e);
} catch (std::exception const &e) {
std::string message = StringUtils::stringFormat("Error during construct compilation database: %s", e.what());
LOG_S(ERROR) << message;
return {StatusCode::UNKNOWN, message};
}
return Status::OK;
}
Expand Down Expand Up @@ -690,7 +700,7 @@ Status Server::TestsGenServiceImpl::GetFileTargets(ServerContext *context,

RequestLockMutex &Server::TestsGenServiceImpl::getLock() {
std::string const &client = RequestEnvironment::getClientId();
auto[iterator, inserted] = locks.try_emplace(client);
auto [iterator, inserted] = locks.try_emplace(client);
return iterator->second;
}

Expand Down
5 changes: 4 additions & 1 deletion server/src/Synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ bool Synchronizer::removeStubIfSourceAbsent(const StubOperator &stub) const {
fs::remove(stub.getStubPath(testGen->projectContext));
return true;
} catch (const fs::filesystem_error &e) {
std::string message = StringUtils::stringFormat("Failed to delete stub file '%s'", stub.getStubPath(testGen->projectContext));
std::string message = StringUtils::stringFormat("Failed to delete stub file: '%s'",
stub.getStubPath(testGen->projectContext));
LOG_S(ERROR) << message
<< e.what();
throw FileSystemException(message, e);
}
return false;
Expand Down
84 changes: 49 additions & 35 deletions server/src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,33 @@ std::shared_ptr<ArrayValueView> KTestObjectParser::multiArrayView(const std::vec

for (size_t curPos = offsetInBits; curPos < offsetInBits + arraySizeInBits; curPos += elementLenInBits) {
switch (typesHandler.getTypeKind(baseType)) {
case TypeKind::STRUCT_LIKE:
views.push_back(structView(byteArray, lazyPointersArray, typesHandler.getStructInfo(baseType), curPos, usage));
break;
case TypeKind::ENUM:
views.push_back(enumView(byteArray, typesHandler.getEnumInfo(type), curPos, elementLenInBits));
break;
case TypeKind::PRIMITIVE:
views.push_back(primitiveView(byteArray, baseType, curPos, elementLenInBits));
break;
case TypeKind::OBJECT_POINTER:
case TypeKind::ARRAY:
LOG_S(ERROR) << "Invariant ERROR: base type is pointer/array: " << type.typeName();
// No break here
case TypeKind::UNKNOWN:
throw UnImplementedException(
std::string("Arrays don't support element type: " + type.typeName())
);
default:
std::string message = "Missing case for this TypeKind in switch";
LOG_S(ERROR) << message;
throw NoSuchTypeException(message);
case TypeKind::STRUCT_LIKE: {
views.push_back(
structView(byteArray, lazyPointersArray, typesHandler.getStructInfo(baseType), curPos, usage));
break;
}
case TypeKind::ENUM: {
views.push_back(enumView(byteArray, typesHandler.getEnumInfo(type), curPos, elementLenInBits));
break;
}
case TypeKind::PRIMITIVE: {
views.push_back(primitiveView(byteArray, baseType, curPos, elementLenInBits));
break;
}
case TypeKind::OBJECT_POINTER:
case TypeKind::ARRAY:
LOG_S(ERROR) << "Invariant ERROR: base type is pointer/array: " << type.typeName();
// No break here
case TypeKind::UNKNOWN: {
std::string message = "Arrays don't support element type: " + type.typeName();
LOG_S(ERROR) << message;
throw UnImplementedException(message);
}
default: {
std::string message = "Missing case for this TypeKind in switch";
LOG_S(ERROR) << message;
throw NoSuchTypeException(message);
}
}
}

Expand Down Expand Up @@ -240,14 +246,16 @@ std::shared_ptr<ArrayValueView> KTestObjectParser::arrayView(const std::vector<c
break;
case TypeKind::OBJECT_POINTER:
case TypeKind::ARRAY:
case TypeKind::UNKNOWN:
throw UnImplementedException(
std::string("Arrays don't support element type: " + type.typeName())
);
default:
case TypeKind::UNKNOWN: {
std::string message = "Arrays don't support element type: " + type.typeName();
LOG_S(ERROR) << message;
throw UnImplementedException(message);
}
default: {
std::string message = "Missing case for this TypeKind in switch";
LOG_S(ERROR) << message;
throw NoSuchTypeException(message);
}
}
}
return std::make_shared<ArrayValueView>(subViews);
Expand Down Expand Up @@ -384,16 +392,17 @@ std::shared_ptr<StructValueView> KTestObjectParser::structView(const std::vector
case TypeKind::FUNCTION_POINTER:
subViews.push_back(functionPointerView(curStruct.name, field.name));
break;
case TypeKind::UNKNOWN:
case TypeKind::UNKNOWN: {
// TODO: pointers
throw UnImplementedException(
std::string("Structs don't support fields of type: " + field.type.typeName())
);

default:
std::string message = "Structs don't support fields of type: " + field.type.typeName();
LOG_S(ERROR) << message;
throw UnImplementedException(message);
}
default: {
std::string message = "Missing case for this TypeKind in switch";
LOG_S(ERROR) << message;
throw NoSuchTypeException(message);
}
}

if (!dirtyInitializedField && sizeOfFieldToInitUnion < fieldLen &&
Expand Down Expand Up @@ -646,7 +655,9 @@ void KTestObjectParser::assignTypeUnnamedVar(

if (testCase.objects[curType.jsonInd].is_lazy) {
if (types::TypesHandler::baseTypeIsVoid(paramType)) {
throw UnImplementedException("Lazy variable has baseType=void");
std::string message = "Lazy variable has baseType=void";
LOG_S(ERROR) << message;
throw UnImplementedException(message);
}

usages[curType.jsonInd] = types::PointerUsage::LAZY;
Expand Down Expand Up @@ -1220,8 +1231,11 @@ std::shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
return arrayView(rawData, kleeParam.pointers, paramType.baseTypeObj(),
SizeUtils::bytesToBits(rawData.size()), 0, usage);
}
case TypeKind::UNKNOWN:
throw UnImplementedException("No such type");
case TypeKind::UNKNOWN: {
std::string message = "No such type";
LOG_S(ERROR) << message;
throw UnImplementedException(message);
}
default: {
std::string message = "Missing case for this TypeKind in switch";
LOG_S(ERROR) << message;
Expand Down
Loading

0 comments on commit 7444333

Please sign in to comment.