Andrew Jeffery | efb4006 | 2023-11-10 13:48:39 +1030 | [diff] [blame^] | 1 | #include <libpldm/transport.h> |
| 2 | |
Andrew Jeffery | 2aa237d | 2023-09-22 18:21:06 +0930 | [diff] [blame] | 3 | #include "array.h" |
Andrew Jeffery | 2aa237d | 2023-09-22 18:21:06 +0930 | [diff] [blame] | 4 | #include "transport/test.h" |
| 5 | |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | TEST(Transport, send_recv_one) |
| 9 | { |
| 10 | uint8_t req[] = {0x81, 0x00, 0x01, 0x01}; |
| 11 | uint8_t resp[] = {0x01, 0x00, 0x01, 0x00}; |
| 12 | const struct pldm_transport_test_descriptor seq[] = { |
| 13 | { |
| 14 | .type = PLDM_TRANSPORT_TEST_ELEMENT_MSG_SEND, |
| 15 | .send_msg = |
| 16 | { |
| 17 | .dst = 1, |
| 18 | .msg = req, |
| 19 | .len = sizeof(req), |
| 20 | }, |
| 21 | }, |
| 22 | { |
| 23 | .type = PLDM_TRANSPORT_TEST_ELEMENT_LATENCY, |
| 24 | .latency = |
| 25 | { |
| 26 | .it_interval = {0, 0}, |
| 27 | .it_value = {1, 0}, |
| 28 | }, |
| 29 | }, |
| 30 | { |
| 31 | .type = PLDM_TRANSPORT_TEST_ELEMENT_MSG_RECV, |
| 32 | .recv_msg = |
| 33 | { |
| 34 | .src = 1, |
| 35 | .msg = resp, |
| 36 | .len = sizeof(resp), |
| 37 | }, |
| 38 | }, |
| 39 | }; |
| 40 | struct pldm_transport_test* test = NULL; |
| 41 | struct pldm_transport* ctx; |
| 42 | size_t len; |
| 43 | void* msg; |
| 44 | int rc; |
| 45 | |
| 46 | EXPECT_EQ(pldm_transport_test_init(&test, seq, ARRAY_SIZE(seq)), 0); |
| 47 | ctx = pldm_transport_test_core(test); |
| 48 | rc = pldm_transport_send_recv_msg(ctx, 1, req, sizeof(req), &msg, &len); |
| 49 | EXPECT_EQ(rc, PLDM_REQUESTER_SUCCESS); |
| 50 | EXPECT_EQ(len, sizeof(resp)); |
| 51 | EXPECT_EQ(memcmp(msg, resp, len), 0); |
| 52 | free(msg); |
| 53 | pldm_transport_test_destroy(test); |
| 54 | } |