Fix code to consume the secondary code
- The snooping daemon was coded to fill the Raw Value dbus
property with uint64_t signature.
- The intent behind this commit is to work with the changed
dbus backend from uint64_t to struct[uint64_t,array[byte]].
- The phosphor dbus interface change is documented in the below
commit :
https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-dbus-interfaces/+/40903
Tested By:
- As the ibm systems does not a snooping port, i have done the
unittesting & all the unit tests are PASSED with a system that
has the above mentioned dbus interface change.
root@witherspoon:/tmp# ./post_reporter_test
[==========] Running 5 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 5 tests from PostReporterTest
[ RUN ] PostReporterTest.EmitsObjectsOnExpectedDbusPath
[ OK ] PostReporterTest.EmitsObjectsOnExpectedDbusPath (17 ms)
[ RUN ] PostReporterTest.AddsObjectWithExpectedName
[ OK ] PostReporterTest.AddsObjectWithExpectedName (5 ms)
[ RUN ] PostReporterTest.ValueReadsDefaultToZero
[ OK ] PostReporterTest.ValueReadsDefaultToZero (1 ms)
[ RUN ] PostReporterTest.SetValueToPositiveValueWorks
[ OK ] PostReporterTest.SetValueToPositiveValueWorks (2 ms)
[ RUN ] PostReporterTest.SetValueMultipleTimesWorks
[ OK ] PostReporterTest.SetValueMultipleTimesWorks (2 ms)
[----------] 5 tests from PostReporterTest (34 ms total)
[----------] Global test environment tear-down
[==========] 5 tests from 1 test suite ran. (40 ms total)
[ PASSED ] 5 tests.
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: Id0a79fcddc827d34f9d2a61ab14d8c9c4be522b5
diff --git a/example.cpp b/example.cpp
index bfd28ad..9bec1b9 100644
--- a/example.cpp
+++ b/example.cpp
@@ -22,10 +22,11 @@
#include <memory>
/* Example PostCode handler which simply prints them */
-static void printPostcode(uint64_t postcode)
+static void printPostcode(postcode_t postcode)
{
/* Print output to verify the example program is receiving values. */
- std::printf("recv: 0x%" PRIx64 "\n", postcode);
+ std::printf("recv: 0x%" PRIx64 "\n",
+ std::get<primary_post_code_t>(postcode));
}
/*
diff --git a/lpcsnoop/snoop.hpp b/lpcsnoop/snoop.hpp
index 2c89127..68d51b4 100644
--- a/lpcsnoop/snoop.hpp
+++ b/lpcsnoop/snoop.hpp
@@ -13,6 +13,9 @@
using ServerObject = typename sdbusplus::server::object::object<T...>;
using PostInterface = sdbusplus::xyz::openbmc_project::State::Boot::server::Raw;
using PostObject = ServerObject<PostInterface>;
+using primary_post_code_t = uint64_t;
+using secondary_post_code_t = std::vector<uint8_t>;
+using postcode_t = std::tuple<primary_post_code_t, secondary_post_code_t>;
class PostReporter : public PostObject
{
diff --git a/lpcsnoop/snoop_listen.hpp b/lpcsnoop/snoop_listen.hpp
index 1ff189d..475028f 100644
--- a/lpcsnoop/snoop_listen.hpp
+++ b/lpcsnoop/snoop_listen.hpp
@@ -36,7 +36,7 @@
class SnoopListen
{
using message_handler_t = std::function<void(sdbusplus::message::message&)>;
- using postcode_handler_t = std::function<void(uint64_t)>;
+ using postcode_handler_t = std::function<void(postcode_t)>;
public:
SnoopListen(sdbusplus::bus::bus& busIn, sd_bus_message_handler_t handler) :
@@ -74,7 +74,7 @@
sdbusplus::message::message& m)
{
std::string messageBusName;
- std::map<std::string, std::variant<uint64_t>> messageData;
+ std::map<std::string, std::variant<postcode_t>> messageData;
constexpr char propertyKey[] = "Value";
m.read(messageBusName, messageData);
@@ -82,7 +82,7 @@
if (messageBusName == SNOOP_BUSNAME &&
messageData.find(propertyKey) != messageData.end())
{
- handler(get<uint64_t>(messageData[propertyKey]));
+ handler(get<postcode_t>(messageData[propertyKey]));
}
}
};
diff --git a/main.cpp b/main.cpp
index db0532d..d25fd6f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -64,8 +64,8 @@
// HACK: Always send property changed signal even for the same code
// since we are single threaded, external users will never see the
// first value.
- reporter->value(~code, true);
- reporter->value(code);
+ reporter->value(std::make_tuple(~code, secondary_post_code_t{}), true);
+ reporter->value(std::make_tuple(code, secondary_post_code_t{}));
// read depends on old data being cleared since it doens't always read
// the full code size
diff --git a/test/post_reporter_test.cpp b/test/post_reporter_test.cpp
index 0dbbcfe..5213593 100644
--- a/test/post_reporter_test.cpp
+++ b/test/post_reporter_test.cpp
@@ -55,29 +55,51 @@
TEST_F(PostReporterTest, ValueReadsDefaultToZero)
{
PostReporter testReporter(bus, SNOOP_OBJECTPATH, true);
- EXPECT_EQ(0, testReporter.value());
+ EXPECT_EQ(0, std::get<primary_post_code_t>(testReporter.value()));
}
TEST_F(PostReporterTest, SetValueToPositiveValueWorks)
{
PostReporter testReporter(bus, SNOOP_OBJECTPATH, true);
- testReporter.value(65537);
- EXPECT_EQ(65537, testReporter.value());
+ secondary_post_code_t secondaryCode = {123, 124, 125};
+ testReporter.value(std::make_tuple(65537, secondaryCode));
+ EXPECT_EQ(65537, std::get<primary_post_code_t>(testReporter.value()));
+ EXPECT_EQ(secondaryCode,
+ std::get<secondary_post_code_t>(testReporter.value()));
}
TEST_F(PostReporterTest, SetValueMultipleTimesWorks)
{
PostReporter testReporter(bus, SNOOP_OBJECTPATH, true);
- testReporter.value(123);
- EXPECT_EQ(123, testReporter.value());
- testReporter.value(456);
- EXPECT_EQ(456, testReporter.value());
- testReporter.value(0);
- EXPECT_EQ(0, testReporter.value());
- testReporter.value(456);
- EXPECT_EQ(456, testReporter.value());
- testReporter.value(456);
- EXPECT_EQ(456, testReporter.value());
+ secondary_post_code_t secondaryCode = {10, 40, 0, 245, 56};
+ testReporter.value(std::make_tuple(123, secondaryCode));
+ EXPECT_EQ(123, std::get<primary_post_code_t>(testReporter.value()));
+ EXPECT_EQ(secondaryCode,
+ std::get<secondary_post_code_t>(testReporter.value()));
+
+ secondaryCode = {0, 0, 0, 0, 0};
+ testReporter.value(std::make_tuple(45, secondaryCode));
+ EXPECT_EQ(45, std::get<primary_post_code_t>(testReporter.value()));
+ EXPECT_EQ(secondaryCode,
+ std::get<secondary_post_code_t>(testReporter.value()));
+
+ secondaryCode = {23, 200, 0, 45, 2};
+ testReporter.value(std::make_tuple(0, secondaryCode));
+ EXPECT_EQ(0, std::get<primary_post_code_t>(testReporter.value()));
+ EXPECT_EQ(secondaryCode,
+ std::get<secondary_post_code_t>(testReporter.value()));
+
+ secondaryCode = {10, 40, 0, 35, 78};
+ testReporter.value(std::make_tuple(46, secondaryCode));
+ EXPECT_EQ(46, std::get<primary_post_code_t>(testReporter.value()));
+ EXPECT_EQ(secondaryCode,
+ std::get<secondary_post_code_t>(testReporter.value()));
+
+ secondaryCode = {10, 40, 0, 35, 78};
+ testReporter.value(std::make_tuple(46, secondaryCode));
+ EXPECT_EQ(46, std::get<primary_post_code_t>(testReporter.value()));
+ EXPECT_EQ(secondaryCode,
+ std::get<secondary_post_code_t>(testReporter.value()));
}
} // namespace