blob: dc0a5f3bb0c669b27a6fc0ebc8860c66a5cdf001 [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);
20}
21
22struct mctp_binding_test *mctp_binding_test_init(void)
23{
24 struct mctp_binding_test *test;
25
26 test = __mctp_alloc(sizeof(*test));
27 test->binding.name = "test";
28 test->binding.version = 1;
29 test->binding.tx = mctp_binding_test_tx;
Jeremy Kerrdf15f7e2019-08-05 15:41:19 +080030 test->binding.pkt_size = MCTP_BMTU;
31 test->binding.pkt_pad = 0;
Jeremy Kerr18925112019-03-13 15:43:08 +080032 return test;
33}
34
35void mctp_binding_test_rx_raw(struct mctp_binding_test *test,
36 void *buf, size_t len)
37{
38 struct mctp_pktbuf *pkt;
39
Jeremy Kerrdf15f7e2019-08-05 15:41:19 +080040 pkt = mctp_pktbuf_alloc(&test->binding, len);
Jeremy Kerr18925112019-03-13 15:43:08 +080041 assert(pkt);
42 memcpy(mctp_pktbuf_hdr(pkt), buf, len);
43 mctp_bus_rx(&test->binding, pkt);
Jeremy Kerr18925112019-03-13 15:43:08 +080044}
45
46void mctp_binding_test_register_bus(struct mctp_binding_test *binding,
47 struct mctp *mctp, mctp_eid_t eid)
48{
49 mctp_register_bus(mctp, &binding->binding, eid);
50}
51
52void mctp_test_stack_init(struct mctp **mctp,
53 struct mctp_binding_test **binding,
54 mctp_eid_t eid)
55{
56 *mctp = mctp_init();
57 assert(*mctp);
58
59 *binding = mctp_binding_test_init();
60 assert(*binding);
61
62 mctp_binding_test_register_bus(*binding, *mctp, eid);
63}