PEL: Don't allow duplicate callouts

When adding callouts, check if the callout being added already exists.
If it does, don't add it and rather just update the priority of the
existing one to be the highest of the two.

Callouts are considered to be equal if their location code matches, or
if they have the same maintenance procedure, or if they have the same
symbolic FRU.

The change entails adding an operator== on the Callout object, as well
as an operator> so that the callout with the highest priority can be
determined.  Also use this new operator> in the sort of the callout list
that happens after a callout is added or changed.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I5ee148cc12e92f67fb3da233c3615e9665e95355
diff --git a/test/openpower-pels/src_callouts_test.cpp b/test/openpower-pels/src_callouts_test.cpp
index 69c26b8..f13462d 100644
--- a/test/openpower-pels/src_callouts_test.cpp
+++ b/test/openpower-pels/src_callouts_test.cpp
@@ -16,6 +16,8 @@
 #include "extensions/openpower-pels/callouts.hpp"
 #include "pel_utils.hpp"
 
+#include <format>
+
 #include <gtest/gtest.h>
 
 using namespace openpower::pels;
@@ -99,8 +101,9 @@
 
     for (size_t i = 0; i < maxNumberOfCallouts; i++)
     {
+        auto loc = std::format("U1-P{}", i);
         auto callout = std::make_unique<Callout>(
-            CalloutPriority::high, "U1-P1", "1234567", "ABCD", "123456789ABC");
+            CalloutPriority::high, loc, "1234567", "ABCD", "123456789ABC");
         auto calloutSize = callout->flattenedSize();
 
         callouts.addCallout(std::move(callout));
@@ -200,3 +203,65 @@
     EXPECT_EQ(calloutObjects[9]->locationCode(), "U1-P10");
     EXPECT_EQ(calloutObjects[9]->priority(), 'L');
 }
+
+TEST(CalloutsTest, TestDupCallouts)
+{
+    {
+        // Duplicate callouts, keep the high priority one
+        Callouts callouts;
+        auto c0 = std::make_unique<Callout>(CalloutPriority::medium, "U1-P1",
+                                            "1234567", "ABC", "123456789ABC");
+        callouts.addCallout(std::move(c0));
+
+        auto c1 = std::make_unique<Callout>(CalloutPriority::high, "U1-P1",
+                                            "1234567", "ABCD", "123456789ABC");
+        callouts.addCallout(std::move(c1));
+
+        EXPECT_EQ(callouts.callouts().size(), 1);
+        const auto& calloutObjects = callouts.callouts();
+        EXPECT_EQ(calloutObjects[0]->priority(), 'H');
+    }
+
+    {
+        // Different callouts, keep them both
+        Callouts callouts;
+        auto c0 = std::make_unique<Callout>(CalloutPriority::high, "U1-P1",
+                                            "1234567", "ABC", "123456789ABC");
+        callouts.addCallout(std::move(c0));
+
+        auto c1 = std::make_unique<Callout>(CalloutPriority::medium, "U1-P2",
+                                            "1234567", "ABCD", "123456789ABC");
+        callouts.addCallout(std::move(c1));
+
+        EXPECT_EQ(callouts.callouts().size(), 2);
+    }
+
+    {
+        // Two duplicates and two unique.  Needs sorting.
+        Callouts callouts;
+        auto c0 = std::make_unique<Callout>(CalloutPriority::low, "U1-P9",
+                                            "1234567", "ABCD", "123456789ABC");
+        callouts.addCallout(std::move(c0));
+
+        auto c1 = std::make_unique<Callout>(CalloutPriority::low, "U1-P1",
+                                            "1234567", "ABC", "123456789ABC");
+        callouts.addCallout(std::move(c1));
+
+        auto c2 = std::make_unique<Callout>(CalloutPriority::high, "U1-P1",
+                                            "1234567", "ABC", "123456789ABC");
+        callouts.addCallout(std::move(c2));
+
+        auto c3 = std::make_unique<Callout>(CalloutPriority::medium, "U1-P5",
+                                            "1234567", "ABCD", "123456789ABC");
+        callouts.addCallout(std::move(c3));
+
+        const auto& calloutObjects = callouts.callouts();
+        EXPECT_EQ(callouts.callouts().size(), 3);
+        EXPECT_EQ(calloutObjects[0]->priority(), 'H');
+        EXPECT_EQ(calloutObjects[0]->locationCode(), "U1-P1");
+        EXPECT_EQ(calloutObjects[1]->priority(), 'M');
+        EXPECT_EQ(calloutObjects[1]->locationCode(), "U1-P5");
+        EXPECT_EQ(calloutObjects[2]->priority(), 'L');
+        EXPECT_EQ(calloutObjects[2]->locationCode(), "U1-P9");
+    }
+}