PEL: Fix for error - unable to read PEL ID file
This is a case when PEL daemon can't read pelID file to get the next
pel Id to use. It could be that the file got corrupted during code
update or factory reset leading to zeros data in file. The fix is to
delete the file as there is already code later to recreate file if
not available.
Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
Change-Id: I42372cc1d79ece5914e7fdb51f3fa2a2d9cb07e7
diff --git a/test/openpower-pels/log_id_test.cpp b/test/openpower-pels/log_id_test.cpp
index 7167dd7..9588b07 100644
--- a/test/openpower-pels/log_id_test.cpp
+++ b/test/openpower-pels/log_id_test.cpp
@@ -20,6 +20,7 @@
#include <chrono>
#include <filesystem>
+#include <fstream>
#include <thread>
#include <gtest/gtest.h>
@@ -58,3 +59,39 @@
fs::remove_all(fs::path{backingFile}.parent_path());
}
+
+TEST(LogIdTest, PELIDTest)
+{
+ // Get PEL ID file updated with binary zeros
+ auto backingFile = getPELIDFile();
+ std::ofstream wf{backingFile, std::ios::binary};
+ char id = '\0';
+ for (int i = 0; i < 4; i++)
+ {
+ wf.write(&id, sizeof(id));
+ }
+ wf.close();
+
+ // Expect existing PEL ID file to be deleted and
+ // new PEL ID regenerated
+ EXPECT_EQ(generatePELID(), 0x50000001);
+ EXPECT_EQ(generatePELID(), 0x50000002);
+ EXPECT_EQ(generatePELID(), 0x50000003);
+ EXPECT_EQ(generatePELID(), 0x50000004);
+ EXPECT_EQ(generatePELID(), 0x50000005);
+
+ // Get PEL ID file updated with binary zeros again
+ std::ofstream fw{backingFile, std::ios::binary};
+ for (int i = 0; i < 4; i++)
+ {
+ fw.write(&id, sizeof(id));
+ }
+ fw.close();
+
+ // This time PEL IDs are random generated
+ EXPECT_NE(generatePELID(), 0x50000001);
+ EXPECT_NE(generatePELID(), 0x50000002);
+ EXPECT_NE(generatePELID(), 0x50000003);
+ EXPECT_NE(generatePELID(), 0x50000004);
+ EXPECT_NE(generatePELID(), 0x50000005);
+}