Skip to content

Commit 7444333

Browse files
authored
Add more logs (#647)
* Add more logs
1 parent db7c6de commit 7444333

31 files changed

+265
-134
lines changed

server/src/FeaturesFilter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ void FeaturesFilter::filter(utbot::SettingsContext const &settingsContext,
177177
}
178178
LOG_S(DEBUG) << statsMessage.str();
179179
if (!hasSupportedMethods && throwIfZeroFunctions) {
180-
throw NoTestGeneratedException("Couldn't find any supported methods. "
181-
"Please check if source directories are specified correctly. "
182-
"See logs for more details about unsupported functions.");
180+
std::string message = "Couldn't find any supported methods. "
181+
"Please check if source directories are specified correctly.";
182+
LOG_S(ERROR) << message;
183+
throw NoTestGeneratedException(message);
183184
}
184185
}
185186

server/src/KleeGenerator.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ KleeGenerator::KleeGenerator(BaseTestGen *testGen, types::TypesHandler &typesHan
2727
fs::create_directories(this->testGen->serverBuildDir);
2828
fs::create_directories(Paths::getLogDir(this->testGen->projectContext.projectName));
2929
} catch (const fs::filesystem_error &e) {
30-
throw FileSystemException("create_directories failed", e);
30+
LOG_S(ERROR) << StringUtils::stringFormat("Create_directories failed: %s", e.what());
31+
throw FileSystemException("Create_directories failed", e);
3132
}
3233
}
3334

@@ -208,6 +209,7 @@ Result<fs::path> KleeGenerator::defaultBuild(const fs::path &hintPath,
208209
"Couldn't get command for klee file: %s\n"
209210
"Please check if directory is in source directories in UTBot extension settings: %s",
210211
sourceFilePath, hintPath.parent_path().string());
212+
LOG_S(ERROR) << message;
211213
throw BaseException(std::move(message));
212214
}
213215
auto &command = optionalCommand.value();
@@ -287,7 +289,11 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
287289
LOG_S(MAX) << "Klee filepath: " << outFiles.back();
288290
} else {
289291
if (lineInfo) {
290-
throw BaseException("Couldn't compile klee file for current line.");
292+
std::string message = StringUtils::stringFormat(
293+
"Couldn't compile klee file for current line: %s:%d-%d", lineInfo->filePath,
294+
lineInfo->begin, lineInfo->end);
295+
LOG_S(ERROR) << message;
296+
throw BaseException(message);
291297
}
292298
auto tempKleeFilePath = Paths::addSuffix(kleeFilePath, "_temp");
293299
fs::copy(kleeFilePath, tempKleeFilePath, fs::copy_options::overwrite_existing);
@@ -327,7 +333,10 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
327333
if (kleeBitcodeFile.isSuccess()) {
328334
outFiles.emplace_back(kleeBitcodeFile.getOpt().value());
329335
} else {
330-
throw BaseException("Couldn't compile klee file from correct methods.");
336+
std::string message = StringUtils::stringFormat(
337+
"Couldn't compile klee file from correct methods");
338+
LOG_S(ERROR) << message;
339+
throw BaseException(message);
331340
}
332341
}
333342
});

server/src/KleeRunner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
7777
LOG_S(WARNING) << FileNotPresentedInCommandsException::createMessage(filePath);
7878
return;
7979
} else {
80+
LOG_S(ERROR) << FileNotPresentedInCommandsException::createMessage(filePath);
8081
throw FileNotPresentedInCommandsException(filePath);
8182
}
8283
}
@@ -85,6 +86,7 @@ void KleeRunner::runKlee(const std::vector<tests::TestMethod> &testMethods,
8586
LOG_S(WARNING) << FileNotPresentedInArtifactException::createMessage(filePath);
8687
return;
8788
} else {
89+
LOG_S(ERROR) << FileNotPresentedInArtifactException::createMessage(filePath);
8890
throw FileNotPresentedInArtifactException(filePath);
8991
}
9092
}

server/src/RequestEnvironment.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ namespace RequestEnvironment {
66

77
const std::string &getClientId() {
88
if (!clientId.has_value()) {
9-
throw std::runtime_error(
10-
"Client id was not initialized. Did you forget to call \"setThreadOptions\"?");
9+
//TODO: Add more logs
10+
std::string message = "Client id was not initialized. Did you forget to call \"setThreadOptions\"?";
11+
throw std::runtime_error(message);
1112
}
1213
return clientId.value();
1314
}

server/src/Server.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
246246
if (lineTestGen->needToAddPathFlag()) {
247247
LOG_S(DEBUG) << "Added test line flag for file " << lineInfo->filePath;
248248
fs::path flagFilePath =
249-
printer::KleePrinter(&typesHandler, nullptr, Paths::getSourceLanguage(lineInfo->filePath), &testGen)
249+
printer::KleePrinter(&typesHandler, nullptr, Paths::getSourceLanguage(lineInfo->filePath),
250+
&testGen)
250251
.addTestLineFlag(lineInfo, lineInfo->forAssert, testGen.projectContext);
251252
pathSubstitution = {lineTestGen->filePath, flagFilePath};
252253
}
@@ -265,7 +266,7 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
265266
auto selectedTargets = linker.getSelectedTargets();
266267
SourceToHeaderRewriter(testGen.projectContext, testGen.getTargetBuildDatabase()->compilationDatabase,
267268
fetcher.getStructsToDeclare(), testGen.serverBuildDir, typesHandler)
268-
.generateTestHeaders(testGen.tests, stubGen, selectedTargets, testGen.progressWriter);
269+
.generateTestHeaders(testGen.tests, stubGen, selectedTargets, testGen.progressWriter);
269270
KleeRunner kleeRunner{testGen.projectContext, testGen.settingsContext};
270271
bool interactiveMode = (dynamic_cast<ProjectTestGen *>(&testGen) != nullptr);
271272
auto generationStartTime = std::chrono::steady_clock::now();
@@ -315,11 +316,14 @@ std::shared_ptr<LineInfo> Server::TestsGenServiceImpl::getLineInfo(LineTestGen &
315316
lineTestGen.compileCommandsJsonPath);
316317
stmtFinder.findFunction();
317318
if (!stmtFinder.getLineInfo().initialized) {
318-
throw NoTestGeneratedException(
319-
"Maybe you tried to generate tests placing cursor on invalid line.");
319+
LOG_S(ERROR) << "Cant generate for this line\n"
320+
<< stmtFinder.getLineInfo().stmtString;
321+
throw NoTestGeneratedException("Maybe you tried to generate tests placing cursor on invalid line.");
320322
}
321323
if (isSameType<AssertionTestGen>(lineTestGen) &&
322324
!StringUtils::contains(stmtFinder.getLineInfo().stmtString, "assert")) {
325+
LOG_S(ERROR) << "No assert found on this line\n"
326+
<< stmtFinder.getLineInfo().stmtString;
323327
throw NoTestGeneratedException("No assert found on this line.");
324328
}
325329
auto lineInfo = std::make_shared<LineInfo>(stmtFinder.getLineInfo());
@@ -343,6 +347,7 @@ std::string extractMessage(const loguru::Message &message) {
343347
void Server::logToClient(void *channel, const loguru::Message &message) {
344348
auto data = reinterpret_cast<WriterData *>(channel);
345349
if (data == nullptr) {
350+
LOG_S(ERROR) << "Couldn't handle logging to client, data is null";
346351
throw BaseException("Couldn't handle logging to client, data is null");
347352
}
348353
std::vector<char> thread_name(LOGURU_BUFFER_SIZE);
@@ -361,6 +366,7 @@ void Server::logToClient(void *channel, const loguru::Message &message) {
361366
void Server::gtestLog(void *channel, const loguru::Message &message) {
362367
auto data = reinterpret_cast<WriterData *>(channel);
363368
if (data == nullptr) {
369+
LOG_S(ERROR) << "Can't interpret gtest log channel";
364370
throw BaseException("Can't interpret gtest log channel");
365371
}
366372
std::vector<char> thread_name(LOGURU_BUFFER_SIZE);
@@ -661,6 +667,10 @@ Status Server::TestsGenServiceImpl::GetProjectTargets(ServerContext *context,
661667
} catch (CompilationDatabaseException const &e) {
662668
LOG_S(ERROR) << "Compilation database error: " << e.what();
663669
return failedToLoadCDbStatus(e);
670+
} catch (std::exception const &e) {
671+
std::string message = StringUtils::stringFormat("Error during construct compilation database: %s", e.what());
672+
LOG_S(ERROR) << message;
673+
return {StatusCode::UNKNOWN, message};
664674
}
665675
return Status::OK;
666676
}
@@ -690,7 +700,7 @@ Status Server::TestsGenServiceImpl::GetFileTargets(ServerContext *context,
690700

691701
RequestLockMutex &Server::TestsGenServiceImpl::getLock() {
692702
std::string const &client = RequestEnvironment::getClientId();
693-
auto[iterator, inserted] = locks.try_emplace(client);
703+
auto [iterator, inserted] = locks.try_emplace(client);
694704
return iterator->second;
695705
}
696706

server/src/Synchronizer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ bool Synchronizer::removeStubIfSourceAbsent(const StubOperator &stub) const {
109109
fs::remove(stub.getStubPath(testGen->projectContext));
110110
return true;
111111
} catch (const fs::filesystem_error &e) {
112-
std::string message = StringUtils::stringFormat("Failed to delete stub file '%s'", stub.getStubPath(testGen->projectContext));
112+
std::string message = StringUtils::stringFormat("Failed to delete stub file: '%s'",
113+
stub.getStubPath(testGen->projectContext));
114+
LOG_S(ERROR) << message
115+
<< e.what();
113116
throw FileSystemException(message, e);
114117
}
115118
return false;

server/src/Tests.cpp

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,33 @@ std::shared_ptr<ArrayValueView> KTestObjectParser::multiArrayView(const std::vec
164164

165165
for (size_t curPos = offsetInBits; curPos < offsetInBits + arraySizeInBits; curPos += elementLenInBits) {
166166
switch (typesHandler.getTypeKind(baseType)) {
167-
case TypeKind::STRUCT_LIKE:
168-
views.push_back(structView(byteArray, lazyPointersArray, typesHandler.getStructInfo(baseType), curPos, usage));
169-
break;
170-
case TypeKind::ENUM:
171-
views.push_back(enumView(byteArray, typesHandler.getEnumInfo(type), curPos, elementLenInBits));
172-
break;
173-
case TypeKind::PRIMITIVE:
174-
views.push_back(primitiveView(byteArray, baseType, curPos, elementLenInBits));
175-
break;
176-
case TypeKind::OBJECT_POINTER:
177-
case TypeKind::ARRAY:
178-
LOG_S(ERROR) << "Invariant ERROR: base type is pointer/array: " << type.typeName();
179-
// No break here
180-
case TypeKind::UNKNOWN:
181-
throw UnImplementedException(
182-
std::string("Arrays don't support element type: " + type.typeName())
183-
);
184-
default:
185-
std::string message = "Missing case for this TypeKind in switch";
186-
LOG_S(ERROR) << message;
187-
throw NoSuchTypeException(message);
167+
case TypeKind::STRUCT_LIKE: {
168+
views.push_back(
169+
structView(byteArray, lazyPointersArray, typesHandler.getStructInfo(baseType), curPos, usage));
170+
break;
171+
}
172+
case TypeKind::ENUM: {
173+
views.push_back(enumView(byteArray, typesHandler.getEnumInfo(type), curPos, elementLenInBits));
174+
break;
175+
}
176+
case TypeKind::PRIMITIVE: {
177+
views.push_back(primitiveView(byteArray, baseType, curPos, elementLenInBits));
178+
break;
179+
}
180+
case TypeKind::OBJECT_POINTER:
181+
case TypeKind::ARRAY:
182+
LOG_S(ERROR) << "Invariant ERROR: base type is pointer/array: " << type.typeName();
183+
// No break here
184+
case TypeKind::UNKNOWN: {
185+
std::string message = "Arrays don't support element type: " + type.typeName();
186+
LOG_S(ERROR) << message;
187+
throw UnImplementedException(message);
188+
}
189+
default: {
190+
std::string message = "Missing case for this TypeKind in switch";
191+
LOG_S(ERROR) << message;
192+
throw NoSuchTypeException(message);
193+
}
188194
}
189195
}
190196

@@ -240,14 +246,16 @@ std::shared_ptr<ArrayValueView> KTestObjectParser::arrayView(const std::vector<c
240246
break;
241247
case TypeKind::OBJECT_POINTER:
242248
case TypeKind::ARRAY:
243-
case TypeKind::UNKNOWN:
244-
throw UnImplementedException(
245-
std::string("Arrays don't support element type: " + type.typeName())
246-
);
247-
default:
249+
case TypeKind::UNKNOWN: {
250+
std::string message = "Arrays don't support element type: " + type.typeName();
251+
LOG_S(ERROR) << message;
252+
throw UnImplementedException(message);
253+
}
254+
default: {
248255
std::string message = "Missing case for this TypeKind in switch";
249256
LOG_S(ERROR) << message;
250257
throw NoSuchTypeException(message);
258+
}
251259
}
252260
}
253261
return std::make_shared<ArrayValueView>(subViews);
@@ -384,16 +392,17 @@ std::shared_ptr<StructValueView> KTestObjectParser::structView(const std::vector
384392
case TypeKind::FUNCTION_POINTER:
385393
subViews.push_back(functionPointerView(curStruct.name, field.name));
386394
break;
387-
case TypeKind::UNKNOWN:
395+
case TypeKind::UNKNOWN: {
388396
// TODO: pointers
389-
throw UnImplementedException(
390-
std::string("Structs don't support fields of type: " + field.type.typeName())
391-
);
392-
393-
default:
397+
std::string message = "Structs don't support fields of type: " + field.type.typeName();
398+
LOG_S(ERROR) << message;
399+
throw UnImplementedException(message);
400+
}
401+
default: {
394402
std::string message = "Missing case for this TypeKind in switch";
395403
LOG_S(ERROR) << message;
396404
throw NoSuchTypeException(message);
405+
}
397406
}
398407

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

647656
if (testCase.objects[curType.jsonInd].is_lazy) {
648657
if (types::TypesHandler::baseTypeIsVoid(paramType)) {
649-
throw UnImplementedException("Lazy variable has baseType=void");
658+
std::string message = "Lazy variable has baseType=void";
659+
LOG_S(ERROR) << message;
660+
throw UnImplementedException(message);
650661
}
651662

652663
usages[curType.jsonInd] = types::PointerUsage::LAZY;
@@ -1220,8 +1231,11 @@ std::shared_ptr<AbstractValueView> KTestObjectParser::testParameterView(
12201231
return arrayView(rawData, kleeParam.pointers, paramType.baseTypeObj(),
12211232
SizeUtils::bytesToBits(rawData.size()), 0, usage);
12221233
}
1223-
case TypeKind::UNKNOWN:
1224-
throw UnImplementedException("No such type");
1234+
case TypeKind::UNKNOWN: {
1235+
std::string message = "No such type";
1236+
LOG_S(ERROR) << message;
1237+
throw UnImplementedException(message);
1238+
}
12251239
default: {
12261240
std::string message = "Missing case for this TypeKind in switch";
12271241
LOG_S(ERROR) << message;

0 commit comments

Comments
 (0)