platform: Support PLDM_CPER_EVENT in encode_platform_event_message_req()
DSP0248 v1.3.0 add CPEREvent for PLDM Event Types as Table 11 and add
it in `encode_platform_event_message_req` func.
Change-Id: I94e73938694ce8367489244b75c7e8e0a6d1d8ee
Signed-off-by: John Chung <john.chung@arm.com>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dcdd2fc..d904d46 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,8 @@
Register assignment for function parameters was changed with the removal of
some asserts in related implementations.
+4. platform: Support PLDM_CPER_EVENT in encode_platform_event_message_req()
+
### Deprecated
1. oem: meta: Deprecate `decode_oem_meta_file_io_req()`
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 4ecad13..755707a 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -1236,7 +1236,7 @@
return PLDM_ERROR_INVALID_LENGTH;
}
- if (event_class > PLDM_HEARTBEAT_TIMER_ELAPSED_EVENT &&
+ if (event_class > PLDM_CPER_EVENT &&
!(event_class >= 0xf0 && event_class <= 0xfe)) {
return PLDM_ERROR_INVALID_DATA;
}
diff --git a/tests/dsp/platform.cpp b/tests/dsp/platform.cpp
index 2f0240b..56e9fb3 100644
--- a/tests/dsp/platform.cpp
+++ b/tests/dsp/platform.cpp
@@ -2262,33 +2262,67 @@
TEST(PlatformEventMessage, testGoodEncodeRequest)
{
- uint8_t formatVersion = 0x01;
- uint8_t Tid = 0x03;
- uint8_t eventClass = 0x00;
- uint8_t eventData = 34;
+ static constexpr const uint8_t formatVersion = 0x01;
+ static constexpr const uint8_t eventClass = 0x00;
+ static constexpr const uint8_t eventData = 34;
+ static constexpr const uint8_t Tid = 0x03;
+ struct pldm_platform_event_message_req req;
+ struct pldm_msgbuf _buf;
+ struct pldm_msgbuf* buf = &_buf;
+ size_t len;
+ void* data;
- std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
- sizeof(eventData)>
- requestMsg{};
+ PLDM_MSG_DEFINE_P(request, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
+ sizeof(eventData));
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ /* Test with the minimum event type value */
auto rc = encode_platform_event_message_req(
- 0, formatVersion, Tid, eventClass,
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- reinterpret_cast<uint8_t*>(&eventData), sizeof(eventData), request,
- sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
+ 0, formatVersion, Tid, eventClass, &eventData, sizeof(eventData),
+ request, sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
+ ASSERT_EQ(rc, PLDM_SUCCESS);
- struct pldm_platform_event_message_req* req =
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- reinterpret_cast<struct pldm_platform_event_message_req*>(
- request->payload);
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES, request->payload,
+ PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(eventData));
+ ASSERT_EQ(rc, 0);
- EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(formatVersion, req->format_version);
- EXPECT_EQ(Tid, req->tid);
- EXPECT_EQ(eventClass, req->event_class);
- EXPECT_EQ(0, memcmp(&eventData, req->event_data, sizeof(eventData)));
+ pldm_msgbuf_extract_uint8(buf, req.format_version);
+ pldm_msgbuf_extract_uint8(buf, req.tid);
+ pldm_msgbuf_extract_uint8(buf, req.event_class);
+ data = nullptr;
+ pldm_msgbuf_span_remaining(buf, &data, &len);
+ ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
+
+ EXPECT_EQ(formatVersion, req.format_version);
+ EXPECT_EQ(Tid, req.tid);
+ EXPECT_EQ(eventClass, req.event_class);
+ ASSERT_EQ(sizeof(eventData), len);
+ EXPECT_EQ(0, memcmp(&eventData, data, len));
+
+ /* Test with the maximum event type value */
+ rc = encode_platform_event_message_req(
+ 0, formatVersion, Tid, PLDM_CPER_EVENT, &eventData, sizeof(eventData),
+ request, sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
+ ASSERT_EQ(rc, PLDM_SUCCESS);
+
+ rc = pldm_msgbuf_init_errno(
+ buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES, request->payload,
+ PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(eventData));
+ ASSERT_EQ(rc, 0);
+
+ pldm_msgbuf_extract_uint8(buf, req.format_version);
+ pldm_msgbuf_extract_uint8(buf, req.tid);
+ pldm_msgbuf_extract_uint8(buf, req.event_class);
+
+ data = nullptr;
+ pldm_msgbuf_span_remaining(buf, &data, &len);
+ ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
+
+ EXPECT_EQ(formatVersion, req.format_version);
+ EXPECT_EQ(Tid, req.tid);
+ EXPECT_EQ(PLDM_CPER_EVENT, req.event_class);
+ ASSERT_EQ(sizeof(eventData), len);
+ EXPECT_EQ(0, memcmp(&eventData, data, len));
}
TEST(PlatformEventMessage, testBadEncodeRequest)
@@ -2296,36 +2330,35 @@
uint8_t Tid = 0x03;
uint8_t eventClass = 0x00;
uint8_t eventData = 34;
- size_t sz_eventData = sizeof(eventData);
- size_t payloadLen =
- sz_eventData + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES;
uint8_t formatVersion = 0x01;
+ static constexpr const size_t payloadLen =
+ PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(eventData);
- std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
- sizeof(eventData)>
- requestMsg{};
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
+ PLDM_MSG_DEFINE_P(request, payloadLen);
auto rc = encode_platform_event_message_req(
- 0, formatVersion, Tid, eventClass,
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- reinterpret_cast<uint8_t*>(&eventData), sz_eventData, nullptr,
- payloadLen);
+ 0, formatVersion, Tid, eventClass, &eventData, sizeof(eventData),
+ nullptr, payloadLen);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- rc = encode_platform_event_message_req(
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- 0, 0, Tid, eventClass, reinterpret_cast<uint8_t*>(&eventData),
- sz_eventData, request, payloadLen);
+
+ rc = encode_platform_event_message_req(0, 0, Tid, eventClass, &eventData,
+ sizeof(eventData), request,
+ payloadLen);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass,
nullptr, 0, request, payloadLen);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
- rc = encode_platform_event_message_req(
- 0, formatVersion, Tid, eventClass,
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- reinterpret_cast<uint8_t*>(&eventData), sz_eventData, request, 0);
+
+ rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass,
+ &eventData, sizeof(eventData),
+ request, 0);
EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+
+ rc = encode_platform_event_message_req(
+ 0, formatVersion, Tid, PLDM_CPER_EVENT + 1, &eventData,
+ sizeof(eventData), request, payloadLen);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
}
TEST(PlatformEventMessage, testGoodDecodeResponse)