PEL: Logic to enqueue a PEL to send to host

Fill in the function to determine if a PEL needs to be placed on the
qeueue to be sent up to the host.  It involves checking both the host
and HMC transmission states, as well as the PEL action flags field.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I9f1a9fba1b7e6dc7a167f1c7e9dfd6c40d90883f
diff --git a/test/openpower-pels/host_notifier_test.cpp b/test/openpower-pels/host_notifier_test.cpp
index 2d50dcf..2f2e1f0 100644
--- a/test/openpower-pels/host_notifier_test.cpp
+++ b/test/openpower-pels/host_notifier_test.cpp
@@ -38,6 +38,20 @@
 
 class HostNotifierTest : public CleanPELFiles
 {
+  public:
+    HostNotifierTest()
+    {
+        auto r = sd_event_default(&event);
+        EXPECT_TRUE(r >= 0);
+    }
+
+    ~HostNotifierTest()
+    {
+        sd_event_unref(event);
+    }
+
+  protected:
+    sd_event* event;
 };
 
 /**
@@ -100,6 +114,112 @@
     EXPECT_FALSE(called);
 }
 
+// Test dealing with how acked PELs are put on the
+// notification queue.
+TEST_F(HostNotifierTest, TestPolicyAckedPEL)
+{
+    Repository repo{repoPath};
+    MockDataInterface dataIface;
+
+    std::unique_ptr<HostInterface> hostIface =
+        std::make_unique<MockHostInterface>(event, dataIface);
+
+    HostNotifier notifier{repo, dataIface, std::move(hostIface)};
+
+    auto pel = makePEL();
+    repo.add(pel);
+
+    // This is required
+    EXPECT_TRUE(notifier.enqueueRequired(pel->id()));
+
+    // Not in the repo
+    EXPECT_FALSE(notifier.enqueueRequired(42));
+
+    // Now set this PEL to host acked
+    repo.setPELHostTransState(pel->id(), TransmissionState::acked);
+
+    // Since it's acked, doesn't need to be enqueued or transmitted
+    EXPECT_FALSE(notifier.enqueueRequired(pel->id()));
+}
+
+// Test the 'don't report' PEL flag
+TEST_F(HostNotifierTest, TestPolicyDontReport)
+{
+    Repository repo{repoPath};
+    MockDataInterface dataIface;
+
+    std::unique_ptr<HostInterface> hostIface =
+        std::make_unique<MockHostInterface>(event, dataIface);
+
+    HostNotifier notifier{repo, dataIface, std::move(hostIface)};
+
+    // dontReportToHostFlagBit
+    auto pel = makePEL(0x1000);
+
+    // Double check the action flag is still set
+    std::bitset<16> actionFlags = pel->userHeader().actionFlags();
+    EXPECT_TRUE(actionFlags.test(dontReportToHostFlagBit));
+
+    repo.add(pel);
+
+    // Don't need to send this to the host
+    EXPECT_FALSE(notifier.enqueueRequired(pel->id()));
+}
+
+// Test that hidden PELs need notification when there
+// is no HMC.
+TEST_F(HostNotifierTest, TestPolicyHiddenNoHMC)
+{
+    Repository repo{repoPath};
+    MockDataInterface dataIface;
+
+    std::unique_ptr<HostInterface> hostIface =
+        std::make_unique<MockHostInterface>(event, dataIface);
+
+    HostNotifier notifier{repo, dataIface, std::move(hostIface)};
+
+    // hiddenFlagBit
+    auto pel = makePEL(0x4000);
+
+    // Double check the action flag is still set
+    std::bitset<16> actionFlags = pel->userHeader().actionFlags();
+    EXPECT_TRUE(actionFlags.test(hiddenFlagBit));
+
+    repo.add(pel);
+
+    // Still need to enqueue this
+    EXPECT_TRUE(notifier.enqueueRequired(pel->id()));
+}
+
+// Don't need to enqueue a hidden log already acked by the HMC
+TEST_F(HostNotifierTest, TestPolicyHiddenWithHMCAcked)
+{
+    Repository repo{repoPath};
+    MockDataInterface dataIface;
+
+    std::unique_ptr<HostInterface> hostIface =
+        std::make_unique<MockHostInterface>(event, dataIface);
+
+    HostNotifier notifier{repo, dataIface, std::move(hostIface)};
+
+    // hiddenFlagBit
+    auto pel = makePEL(0x4000);
+
+    // Double check the action flag is still set
+    std::bitset<16> actionFlags = pel->userHeader().actionFlags();
+    EXPECT_TRUE(actionFlags.test(hiddenFlagBit));
+
+    repo.add(pel);
+
+    // No HMC yet, so required
+    EXPECT_TRUE(notifier.enqueueRequired(pel->id()));
+
+    repo.setPELHMCTransState(pel->id(), TransmissionState::acked);
+
+    // Not required anymore
+    EXPECT_FALSE(notifier.enqueueRequired(pel->id()));
+}
+
 // Test that PELs are enqueued on startup
 TEST_F(HostNotifierTest, TestStartup)
 {
@@ -113,10 +233,6 @@
         repo.add(pel);
     }
 
-    sd_event* event = nullptr;
-    auto r = sd_event_default(&event);
-    ASSERT_TRUE(r >= 0);
-
     std::unique_ptr<HostInterface> hostIface =
         std::make_unique<MockHostInterface>(event, dataIface);