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