PEL: Skip purging PEL if it has associated hw isolation entry

When PELs reaches to certain limits, either in total size or
total number of them, the code starts removing older pels
based on certain criteria. During this process make sure
no pel is removed that has an associated hardware isolation
entry record or error_log event record.

Signed-off-by: Sumit Kumar <sumit_kumar@in.ibm.com>
Change-Id: Ia7c9af6911bcf2ac8f8ec046d4c7a7a12d9b2bbd
diff --git a/test/openpower-pels/repository_test.cpp b/test/openpower-pels/repository_test.cpp
index 7aa0d0d..73a24d8 100644
--- a/test/openpower-pels/repository_test.cpp
+++ b/test/openpower-pels/repository_test.cpp
@@ -624,6 +624,7 @@
 // Prune PELs, when no HMC/OS/PHYP acks
 TEST_F(RepositoryTest, TestPruneNoAcks)
 {
+    std::vector<uint32_t> id;
     Repository repo{repoPath, 4096 * 20, 100};
 
     // Add 10 4096B (on disk) PELs of BMC nonInfo, Info and nonBMC info,
@@ -663,7 +664,7 @@
     }
 
     // Prune down to 15%/30%/15%/30% = 90% total
-    auto IDs = repo.prune();
+    auto IDs = repo.prune(id);
 
     // Check the final sizes
     EXPECT_EQ(sizes.total, 4096 * 18);            // 90% of 20 PELs
@@ -689,6 +690,7 @@
 // pruning still works properly
 TEST_F(RepositoryTest, TestPruneInfoOnly)
 {
+    std::vector<uint32_t> id;
     Repository repo{repoPath, 4096 * 22, 100};
 
     // Fill 4096*23 bytes on disk of BMC info PELs
@@ -712,7 +714,7 @@
         EXPECT_TRUE(repo.getPELAttributes(id));
     }
 
-    auto IDs = repo.prune();
+    auto IDs = repo.prune(id);
 
     // Check the final sizes
     EXPECT_EQ(sizes.total, 4096 * 3);
@@ -736,6 +738,7 @@
 // pruning order.
 TEST_F(RepositoryTest, TestPruneWithAcks)
 {
+    std::vector<uint32_t> id;
     Repository repo{repoPath, 4096 * 20, 100};
 
     // Fill 30% worth of BMC non-info non-acked PELs
@@ -770,7 +773,7 @@
             repo.setPELHostTransState(pel->id(), TransmissionState::sent);
         }
 
-        auto IDs = repo.prune();
+        auto IDs = repo.prune(id);
         EXPECT_EQ(repo.getSizeStats().total, 4096 * 6);
 
         // The newest PEL should be the one deleted
@@ -782,6 +785,7 @@
 // Test that the total number of PELs limit is enforced.
 TEST_F(RepositoryTest, TestPruneTooManyPELs)
 {
+    std::vector<uint32_t> id;
     Repository repo{repoPath, 4096 * 100, 10};
 
     // Add 10, which is the limit and is still OK
@@ -792,7 +796,7 @@
         repo.add(pel);
     }
 
-    auto IDs = repo.prune();
+    auto IDs = repo.prune(id);
 
     // Nothing pruned yet
     EXPECT_TRUE(IDs.empty());
@@ -806,7 +810,7 @@
 
     // Now that's it's over the limit of 10, it will bring it down
     // to 80%, which is 8 after it removes 3.
-    IDs = repo.prune();
+    IDs = repo.prune(id);
     EXPECT_EQ(repo.getSizeStats().total, 4096 * 8);
     ASSERT_EQ(IDs.size(), 3);
 
@@ -1011,3 +1015,43 @@
     logID = repo.getLogID(idWithObmcLogId);
     ASSERT_TRUE(!logID.has_value());
 }
+
+// Test that OpenBMC log Id with hardware isolation entry is not removed.
+TEST_F(RepositoryTest, TestPruneWithIdHwIsoEntry)
+{
+    std::vector<uint32_t> id{502};
+    Repository repo{repoPath, 4096 * 100, 10};
+
+    // Add 10, which is the limit and is still OK
+    for (uint32_t i = 1; i <= 10; i++)
+    {
+        auto data = pelFactory(i, 'O', 0x20, 0x8800, 500);
+        auto pel = std::make_unique<PEL>(data);
+        repo.add(pel);
+    }
+
+    auto IDs = repo.prune(id);
+
+    // Nothing pruned yet
+    EXPECT_TRUE(IDs.empty());
+
+    // Add 1 more PEL which will be too many.
+    {
+        auto data = pelFactory(11, 'O', 0x20, 0x8800, 500);
+        auto pel = std::make_unique<PEL>(data);
+        repo.add(pel);
+    }
+
+    // Now that's it's over the limit of 10, it will bring it down
+    // to 80%, which is 8 after it removes 3.
+    IDs = repo.prune(id);
+    EXPECT_EQ(repo.getSizeStats().total, 4096 * 8);
+    ASSERT_EQ(IDs.size(), 3);
+
+    // Check that it deleted the oldest ones.
+    // And the Id with hw isolation entry is NOT removed.
+    // The OpenBMC log ID is the PEL ID + 500.
+    EXPECT_EQ(IDs[0], 500 + 1);
+    EXPECT_EQ(IDs[1], 500 + 3);
+    EXPECT_EQ(IDs[2], 500 + 4);
+}