dsp: platform: Add sensor enable responder
Add responder definitions and decode routines for
SetStateSensorEnables and SetNumericSensorEnable
Change-Id: Ic93da95f6b3cda4a99951943ebba1b1e20b95d79
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/tests/dsp/platform.cpp b/tests/dsp/platform.cpp
index 1cfdb0a..4427cbc 100644
--- a/tests/dsp/platform.cpp
+++ b/tests/dsp/platform.cpp
@@ -3594,6 +3594,175 @@
}
#ifdef LIBPLDM_API_TESTING
+TEST(SetNumericSensorEnable, testDecodeRequest)
+{
+ int rc;
+ struct pldm_set_numeric_sensor_enable_req decoded;
+
+ const std::array<uint8_t, hdrSize + 5> req
+ // PLDM header
+ {
+ PLDM_PLATFORM, 0x80, PLDM_SET_NUMERIC_SENSOR_ENABLE,
+ 0x67, 0x45, // sensor ID 0x4567
+ 0x00, // sensorOperationalState
+ 0x01, // sensorEventMessageEnable
+ 0x00, // extra
+ };
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ auto msg = reinterpret_cast<const pldm_msg*>(req.data());
+
+ // Good decode
+ rc = decode_set_numeric_sensor_enable_req(msg, 4, &decoded);
+ EXPECT_EQ(rc, 0);
+ EXPECT_EQ(decoded.sensor_id, 0x4567);
+ EXPECT_EQ(decoded.op_state, PLDM_SENSOR_ENABLED);
+ EXPECT_EQ(decoded.event_enable, PLDM_EVENTS_DISABLED);
+
+ // Fail short
+ rc = decode_set_numeric_sensor_enable_req(msg, 3, &decoded);
+ EXPECT_EQ(rc, -EOVERFLOW);
+ // Fail long
+ rc = decode_set_numeric_sensor_enable_req(msg, 5, &decoded);
+ EXPECT_EQ(rc, -EBADMSG);
+}
+#endif // LIBPLDM_API_TESTING
+
+#ifdef LIBPLDM_API_TESTING
+TEST(SetNumericSensorEnable, testDecodeInvalidOpRequest)
+{
+ int rc;
+ struct pldm_set_numeric_sensor_enable_req decoded;
+
+ const std::array<uint8_t, hdrSize + 4> req
+ // PLDM header
+ {
+ PLDM_PLATFORM, 0x80, PLDM_SET_NUMERIC_SENSOR_ENABLE,
+ 0x67, 0x45, // sensor ID 0x4567
+ 0x30, // Invalid sensorOperationalState
+ 0x01, // sensorEventMessageEnable
+ };
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ auto msg = reinterpret_cast<const pldm_msg*>(req.data());
+
+ rc = decode_set_numeric_sensor_enable_req(msg, 4, &decoded);
+ EXPECT_EQ(rc, -EPROTO);
+}
+#endif // LIBPLDM_API_TESTING
+
+#ifdef LIBPLDM_API_TESTING
+TEST(SetNumericSensorEnable, testDecodeInvalidEventRequest)
+{
+ int rc;
+ struct pldm_set_numeric_sensor_enable_req decoded;
+
+ const std::array<uint8_t, hdrSize + 4> req
+ // PLDM header
+ {
+ PLDM_PLATFORM, 0x80, PLDM_SET_NUMERIC_SENSOR_ENABLE,
+ 0x67, 0x45, // sensor ID 0x4567
+ 0x00, // sensorOperationalState
+ 0x77, // Invalid sensorEventMessageEnable
+ };
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ auto msg = reinterpret_cast<const pldm_msg*>(req.data());
+
+ rc = decode_set_numeric_sensor_enable_req(msg, 4, &decoded);
+ EXPECT_EQ(rc, -EPROTO);
+}
+#endif // LIBPLDM_API_TESTING
+
+#ifdef LIBPLDM_API_TESTING
+TEST(SetStateSensorEnables, testDecodeRequest)
+{
+ int rc;
+ struct pldm_set_state_sensor_enables_req decoded;
+
+ const std::array<uint8_t, hdrSize + 8> req
+ // PLDM header
+ {
+ PLDM_PLATFORM, 0x80, PLDM_SET_STATE_SENSOR_ENABLES,
+ 0x67, 0x45, // sensor ID 0x4567
+ 0x02, // count
+ 0x01, 0x00, // field 0
+ 0x02, 0x01, // field 1
+ 0x00, // extra byte
+ };
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ auto msg = reinterpret_cast<const pldm_msg*>(req.data());
+
+ // Good decode
+ rc = decode_set_state_sensor_enables_req(msg, 7, &decoded);
+ EXPECT_EQ(rc, 0);
+ EXPECT_EQ(decoded.sensor_id, 0x4567);
+ EXPECT_EQ(decoded.field_count, 2);
+ EXPECT_EQ(decoded.fields[0].op_state, PLDM_SET_SENSOR_DISABLED);
+ EXPECT_EQ(decoded.fields[0].event_enable, PLDM_NO_EVENT_GENERATION);
+ EXPECT_EQ(decoded.fields[1].op_state, PLDM_SET_SENSOR_UNAVAILABLE);
+ EXPECT_EQ(decoded.fields[1].event_enable, PLDM_EVENTS_DISABLED);
+
+ // Short message
+ rc = decode_set_state_sensor_enables_req(msg, 6, &decoded);
+ EXPECT_EQ(rc, -EOVERFLOW);
+
+ // Overlength message
+ rc = decode_set_state_sensor_enables_req(msg, 8, &decoded);
+ EXPECT_EQ(rc, -EBADMSG);
+}
+#endif // LIBPLDM_API_TESTING
+
+#ifdef LIBPLDM_API_TESTING
+TEST(SetStateSensorEnables, testDecodeInvalidOpRequest)
+{
+ int rc;
+ struct pldm_set_state_sensor_enables_req decoded;
+
+ const std::array<uint8_t, hdrSize + 7> req
+ // PLDM header
+ {
+ PLDM_PLATFORM, 0x80, PLDM_SET_STATE_SENSOR_ENABLES,
+ 0x67, 0x45, // sensor ID 0x4567
+ 0x02, // count
+ 0x01, 0x00, // field 0
+ 0x99, 0x01, // field 1 invalid op
+ };
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ auto msg = reinterpret_cast<const pldm_msg*>(req.data());
+
+ rc = decode_set_state_sensor_enables_req(msg, 7, &decoded);
+ EXPECT_EQ(rc, -EPROTO);
+}
+#endif // LIBPLDM_API_TESTING
+
+#ifdef LIBPLDM_API_TESTING
+TEST(SetStateSensorEnables, testDecodeInvalidEventRequest)
+{
+ int rc;
+ struct pldm_set_state_sensor_enables_req decoded;
+
+ const std::array<uint8_t, hdrSize + 7> req
+ // PLDM header
+ {
+ PLDM_PLATFORM, 0x80, PLDM_SET_STATE_SENSOR_ENABLES,
+ 0x67, 0x45, // sensor ID 0x4567
+ 0x02, // count
+ 0x01, 0x00, // field 0
+ 0x00, 0x77, // field 1 invalid event
+ };
+
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ auto msg = reinterpret_cast<const pldm_msg*>(req.data());
+
+ rc = decode_set_state_sensor_enables_req(msg, 7, &decoded);
+ EXPECT_EQ(rc, -EPROTO);
+}
+#endif // LIBPLDM_API_TESTING
+
+#ifdef LIBPLDM_API_TESTING
TEST(GetEventReceiver, testGoodEncodeRequest)
{
std::array<uint8_t, hdrSize> requestMsg{};