PEL: Remove callout data file after testcases
Delete the temporary /tmp/phalPELCalloutsJson.* files used by some
testcases after they are done with it.
Tested:
No longer see files like '/tmp/phalPELCalloutsJson.MbM31h' when unit
tests are complete.
Change-Id: Iff2efac1391da7e5c22727a39b8a8b4d98816da5
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index 18be5db..6cc036b 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -1237,7 +1237,7 @@
checkDeconfigured(true);
}
-int createHWIsolatedCalloutFile()
+std::pair<int, std::filesystem::path> createHWIsolatedCalloutFile()
{
json jsonCalloutDataList(nlohmann::json::value_t::array);
json jsonDimmCallout;
@@ -1259,7 +1259,7 @@
if (fileFD == -1)
{
perror("Failed to create PELCallouts file");
- return -1;
+ return {-1, {}};
}
ssize_t rc = write(fileFD, calloutData.c_str(), calloutData.size());
@@ -1267,7 +1267,7 @@
{
perror("Failed to write PELCallouts file");
close(fileFD);
- return -1;
+ return {-1, {}};
}
// Ensure we seek to the beginning of the file
@@ -1276,9 +1276,9 @@
{
perror("Failed to set SEEK_SET for PELCallouts file");
close(fileFD);
- return -1;
+ return {-1, {}};
}
- return fileFD;
+ return {fileFD, calloutFile};
}
void appendFFDCEntry(int fd, uint8_t subTypeJson, uint8_t version,
@@ -1370,7 +1370,7 @@
manager.erase(42);
EXPECT_FALSE(findAnyPELInRepo());
- int fd = createHWIsolatedCalloutFile();
+ auto [fd, calloutFile] = createHWIsolatedCalloutFile();
ASSERT_NE(fd, -1);
uint8_t subTypeJson = 0xCA;
uint8_t version = 0x01;
@@ -1380,6 +1380,7 @@
phosphor::logging::Entry::Level::Error, additionalData,
associations, ffdcEntries);
close(fd);
+ std::filesystem::remove(calloutFile);
auto pelPathInRepo = findAnyPELInRepo();
auto unguardedData = readPELFile(*pelPathInRepo);
@@ -1452,7 +1453,7 @@
std::map<std::string, std::string> additionalData;
std::vector<std::string> associations;
- int fd = createHWIsolatedCalloutFile();
+ auto [fd, calloutFile] = createHWIsolatedCalloutFile();
ASSERT_NE(fd, -1);
uint8_t subTypeJson = 0xCA;
uint8_t version = 0x01;
@@ -1462,6 +1463,7 @@
phosphor::logging::Entry::Level::Error, additionalData,
associations, ffdcEntries);
close(fd);
+ std::filesystem::remove(calloutFile);
auto pelFile = findAnyPELInRepo();
EXPECT_TRUE(pelFile);