blob: d1a306c7f1983bf132026bbc7c762b7fafd4681d [file] [log] [blame]
Jeremy Kerr3d36ee22019-05-30 11:15:37 +08001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Jeremy Kerr18925112019-03-13 15:43:08 +08002
3#include <string.h>
4#include <assert.h>
5
6#include <libmctp.h>
7#include <libmctp-alloc.h>
8
9#include "test-utils.h"
10
11struct mctp_binding_test {
12 struct mctp_binding binding;
13};
14
15static int mctp_binding_test_tx(struct mctp_binding *b __attribute__((unused)),
16 struct mctp_pktbuf *pkt __attribute__((unused)))
17{
18 /* we are not expecting TX packets */
19 assert(0);
Andrew Jefferya501a582020-03-10 22:25:16 +103020 return 0;
Jeremy Kerr18925112019-03-13 15:43:08 +080021}
22
23struct mctp_binding_test *mctp_binding_test_init(void)
24{
25 struct mctp_binding_test *test;
26
27 test = __mctp_alloc(sizeof(*test));
Andrew Jeffery225c46d2020-03-10 23:20:01 +103028 memset(test, '\0', sizeof(*test));
Jeremy Kerr18925112019-03-13 15:43:08 +080029 test->binding.name = "test";
30 test->binding.version = 1;
31 test->binding.tx = mctp_binding_test_tx;
Andrew Jeffery73c268e2020-01-30 10:16:09 +103032 test->binding.pkt_size = MCTP_PACKET_SIZE(MCTP_BTU);
Andrew Jeffery39da3d02021-03-12 16:51:26 +103033 test->binding.pkt_header = 0;
34 test->binding.pkt_trailer = 0;
Jeremy Kerr18925112019-03-13 15:43:08 +080035 return test;
36}
37
Andrew Jeffery5c5673b2020-03-10 23:23:58 +103038void mctp_binding_test_destroy(struct mctp_binding_test *test)
39{
40 __mctp_free(test);
41}
42
Jeremy Kerr18925112019-03-13 15:43:08 +080043void mctp_binding_test_rx_raw(struct mctp_binding_test *test,
44 void *buf, size_t len)
45{
46 struct mctp_pktbuf *pkt;
47
Jeremy Kerrdf15f7e2019-08-05 15:41:19 +080048 pkt = mctp_pktbuf_alloc(&test->binding, len);
Jeremy Kerr18925112019-03-13 15:43:08 +080049 assert(pkt);
50 memcpy(mctp_pktbuf_hdr(pkt), buf, len);
51 mctp_bus_rx(&test->binding, pkt);
Jeremy Kerr18925112019-03-13 15:43:08 +080052}
53
54void mctp_binding_test_register_bus(struct mctp_binding_test *binding,
55 struct mctp *mctp, mctp_eid_t eid)
56{
57 mctp_register_bus(mctp, &binding->binding, eid);
58}
59
60void mctp_test_stack_init(struct mctp **mctp,
61 struct mctp_binding_test **binding,
62 mctp_eid_t eid)
63{
64 *mctp = mctp_init();
65 assert(*mctp);
66
67 *binding = mctp_binding_test_init();
68 assert(*binding);
69
70 mctp_binding_test_register_bus(*binding, *mctp, eid);
71}