Skip to content

Commit b27059d

Browse files
luluu9Compute-Runtime-Automation
authored andcommitted
fix: add debug messages when graph export fails
Related-To: NEO-15377 Signed-off-by: Naklicki, Mateusz <mateusz.naklicki@intel.com>
1 parent 0cf5b36 commit b27059d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

level_zero/core/test/unit_tests/experimental/test_graph_export.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "level_zero/core/test/unit_tests/experimental/test_graph_export.h"
99

10+
#include "shared/test/common/helpers/stream_capture.h"
1011
#include "shared/test/common/mocks/mock_io_functions.h"
1112

1213
#include "level_zero/core/test/unit_tests/fixtures/module_fixture.h"
@@ -690,26 +691,46 @@ TEST_F(GraphDotExporterFileTest, GivenEmptyGraphWhenExportToFileThenWritesValidD
690691
}
691692

692693
TEST_F(GraphDotExporterFileTest, GivenFailedFileOpenWhenExportToFileThenReturnsUnknownError) {
694+
DebugManagerStateRestore restorer;
695+
NEO::debugManager.flags.PrintDebugMessages.set(true);
696+
693697
Graph testGraph{&ctx, true};
694698
setupFailedOpen();
695699

700+
StreamCapture capture;
701+
capture.captureStderr();
702+
696703
auto result = exporter.exportToFile(testGraph, testFilePath.c_str());
697704
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, result);
698705

699706
EXPECT_EQ(mockFopenCalledBefore + 1, NEO::IoFunctions::mockFopenCalled);
700707
EXPECT_EQ(mockFwriteCalledBefore, NEO::IoFunctions::mockFwriteCalled);
708+
709+
auto errorMessage = capture.getCapturedStderr();
710+
auto expectedErrorMessage = "Failed to open file " + testFilePath + " for writing graph content\n";
711+
EXPECT_EQ(expectedErrorMessage, errorMessage);
701712
}
702713

703714
TEST_F(GraphDotExporterFileTest, GivenFailedFileWriteWhenExportToFileThenReturnsUnknownError) {
715+
DebugManagerStateRestore restorer;
716+
NEO::debugManager.flags.PrintDebugMessages.set(true);
717+
704718
Graph testGraph{&ctx, true};
705719
setupFailedWrite();
706720

721+
StreamCapture capture;
722+
capture.captureStderr();
723+
707724
auto result = exporter.exportToFile(testGraph, testFilePath.c_str());
708725
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, result);
709726

710727
EXPECT_EQ(mockFopenCalledBefore + 1, NEO::IoFunctions::mockFopenCalled);
711728
EXPECT_EQ(mockFwriteCalledBefore + 1, NEO::IoFunctions::mockFwriteCalled);
712729
EXPECT_EQ(mockFcloseCalledBefore + 1, NEO::IoFunctions::mockFcloseCalled);
730+
731+
auto errorMessage = capture.getCapturedStderr();
732+
auto expectedErrorMessage = "Failed to write graph content to file " + testFilePath + "\n";
733+
EXPECT_EQ(expectedErrorMessage, errorMessage);
713734
}
714735

715736
TEST(GraphDumpHelperTest, GivenNullptrAndPtrWhenFormatPointerIsCalledThenReturnsFormattedString) {

level_zero/experimental/source/graph/graph_export.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ ze_result_t GraphDotExporter::exportToFile(const Graph &graph, const char *fileP
3333

3434
FILE *file = NEO::IoFunctions::fopenPtr(filePath, "w");
3535
if (nullptr == file) {
36+
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Failed to open file %s for writing graph content\n", filePath);
3637
return ZE_RESULT_ERROR_UNKNOWN;
3738
}
3839

3940
std::string dotContent = exportToString(graph);
40-
size_t bytesWritten = NEO::IoFunctions::fwritePtr(dotContent.c_str(), 1, dotContent.size(), file);
41+
size_t bytesWritten = NEO::IoFunctions::fwritePtr(dotContent.c_str(), sizeof(char), dotContent.size(), file);
4142
NEO::IoFunctions::fclosePtr(file);
4243

4344
if (bytesWritten != dotContent.size()) {
45+
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Failed to write graph content to file %s\n", filePath);
4446
return ZE_RESULT_ERROR_UNKNOWN;
4547
}
4648

0 commit comments

Comments
 (0)