blob: 2123a85bc86a5e6044753053d7196fd283657c87 [file] [log] [blame]
Jeremy Kerr4dc8f952019-03-13 15:55:06 +08001
2#include <assert.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6
7#include <libmctp.h>
8
9#include "test-utils.h"
10
11
12struct test_ctx {
13 struct mctp *mctp;
14 struct mctp_binding_test *binding;
15 int rx_count;
16 mctp_eid_t src_eid;
17};
18
19static void test_rx(uint8_t eid, void *data, void *msg, size_t len)
20{
21 struct test_ctx *ctx = data;
22
23 (void)msg;
24 (void)len;
25
26 ctx->rx_count++;
27 ctx->src_eid = eid;
28}
29
30static void create_packet(struct mctp_hdr *pkt,
31 mctp_eid_t src, mctp_eid_t dest)
32{
33 memset(pkt, 0, sizeof(*pkt));
34 pkt->src = src;
35 pkt->dest = dest;
36 pkt->flags_seq_tag = MCTP_HDR_FLAG_SOM | MCTP_HDR_FLAG_EOM;
37}
38
39int main(void)
40{
41 struct test_ctx _ctx, *ctx = &_ctx;
42 const mctp_eid_t local_eid = 8;
43 const mctp_eid_t remote_eid = 9;
44 const mctp_eid_t other_eid = 10;
45 struct {
46 struct mctp_hdr hdr;
47 uint8_t payload[1];
48 } pktbuf;
49
50 mctp_test_stack_init(&ctx->mctp, &ctx->binding, local_eid);
51
52 mctp_set_rx_all(ctx->mctp, test_rx, ctx);
53
54 /* check a message addressed to us is received */
55 ctx->rx_count = 0;
56
57 create_packet(&pktbuf.hdr, remote_eid, local_eid);
58
59 mctp_binding_test_rx_raw(ctx->binding, &pktbuf, sizeof(pktbuf));
60
61 assert(ctx->rx_count == 1);
62 assert(ctx->src_eid == remote_eid);
63
64 /* check a message not addressed to us is not received */
65 ctx->rx_count = 0;
66
67 create_packet(&pktbuf.hdr, remote_eid, other_eid);
68
69 mctp_binding_test_rx_raw(ctx->binding, &pktbuf, sizeof(pktbuf));
70
71 assert(ctx->rx_count == 0);
72
73 return EXIT_SUCCESS;
74}