1 2 #include <string.h> 3 #include <assert.h> 4 5 #include <libmctp.h> 6 #include <libmctp-alloc.h> 7 8 #include "test-utils.h" 9 10 struct mctp_binding_test { 11 struct mctp_binding binding; 12 }; 13 14 static int mctp_binding_test_tx(struct mctp_binding *b __attribute__((unused)), 15 struct mctp_pktbuf *pkt __attribute__((unused))) 16 { 17 /* we are not expecting TX packets */ 18 assert(0); 19 } 20 21 struct mctp_binding_test *mctp_binding_test_init(void) 22 { 23 struct mctp_binding_test *test; 24 25 test = __mctp_alloc(sizeof(*test)); 26 test->binding.name = "test"; 27 test->binding.version = 1; 28 test->binding.tx = mctp_binding_test_tx; 29 return test; 30 } 31 32 void mctp_binding_test_rx_raw(struct mctp_binding_test *test, 33 void *buf, size_t len) 34 { 35 struct mctp_pktbuf *pkt; 36 37 pkt = mctp_pktbuf_alloc(len); 38 assert(pkt); 39 memcpy(mctp_pktbuf_hdr(pkt), buf, len); 40 mctp_bus_rx(&test->binding, pkt); 41 mctp_pktbuf_free(pkt); 42 } 43 44 void mctp_binding_test_register_bus(struct mctp_binding_test *binding, 45 struct mctp *mctp, mctp_eid_t eid) 46 { 47 mctp_register_bus(mctp, &binding->binding, eid); 48 } 49 50 void mctp_test_stack_init(struct mctp **mctp, 51 struct mctp_binding_test **binding, 52 mctp_eid_t eid) 53 { 54 *mctp = mctp_init(); 55 assert(*mctp); 56 57 *binding = mctp_binding_test_init(); 58 assert(*binding); 59 60 mctp_binding_test_register_bus(*binding, *mctp, eid); 61 } 62