commit | f0315a3e6c5ff834d16c920869e896910ab79064 | [log] [tgz] |
---|---|---|
author | Andrew Jeffery <andrew@aj.id.au> | Tue Mar 10 23:49:41 2020 +1030 |
committer | Andrew Jeffery <andrew@aj.id.au> | Tue Mar 10 23:17:06 2020 +0000 |
tree | c37de39a54219f8730f671a82e271f53173f5968 | |
parent | f8b4749a92338f89e2a23c38c4ddce1c26663bd1 [diff] |
test_serial: Clean up after test case Free all allocated memory to avoid false-positives from leak sanitizers. Resolves: ==15807==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934f1e in __interceptor_realloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10df1e) #1 0x7fb35b7f3065 in __mctp_realloc /home/andrew/src/openbmc/libmctp/alloc.c:48 #2 0x7fb35b7ed979 in mctp_msg_ctx_add_pkt /home/andrew/src/openbmc/libmctp/core.c:213 #3 0x7fb35b7f0a09 in mctp_bus_rx /home/andrew/src/openbmc/libmctp/core.c:383 #4 0x7fb35b7f467d in mctp_serial_finish_packet /home/andrew/src/openbmc/libmctp/serial.c:169 #5 0x7fb35b7f6071 in mctp_rx_consume_one /home/andrew/src/openbmc/libmctp/serial.c:254 #6 0x7fb35b7f6409 in mctp_rx_consume /home/andrew/src/openbmc/libmctp/serial.c:271 #7 0x7fb35b7f668a in mctp_serial_read /home/andrew/src/openbmc/libmctp/serial.c:288 #8 0x559680986cc7 in main tests/test_serial.c:113 #9 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Indirect leak of 1384 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934ae8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dae8) #1 0x7fb35b7f2cf0 in __mctp_alloc /home/andrew/src/openbmc/libmctp/alloc.c:28 #2 0x7fb35b7f6cad in mctp_serial_init /home/andrew/src/openbmc/libmctp/serial.c:343 #3 0x559680986553 in main tests/test_serial.c:99 #4 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Indirect leak of 552 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934ae8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dae8) #1 0x7fb35b7f2cf0 in __mctp_alloc /home/andrew/src/openbmc/libmctp/alloc.c:28 #2 0x7fb35b7ededc in mctp_init /home/andrew/src/openbmc/libmctp/core.c:234 #3 0x559680986485 in main tests/test_serial.c:96 #4 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Indirect leak of 40 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934ae8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dae8) #1 0x7fb35b7f2cf0 in __mctp_alloc /home/andrew/src/openbmc/libmctp/alloc.c:28 #2 0x7fb35b7ee55f in mctp_register_bus /home/andrew/src/openbmc/libmctp/core.c:277 #3 0x559680986b64 in main tests/test_serial.c:105 #4 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Signed-off-by: Andrew Jeffery <andrew@aj.id.au> Change-Id: I9f95104545cc6f633ee134fffc90cb0ea2c46eeb
This library is intended to be a portable implementation of the Management Component Transport Protocol (MCTP), as defined by DMTF standard "DSP0236", plus transport binding specifications.
Currently, the library is is only at prototyping stage. Interfaces will likely change, and are missing lots of components of the standard.
To initialise the MCTP stack with a single hardware bus:
mctp = mctp_init()
: Initialise the MCTP corebinding = mctp_<binding>_init()
: Initialise a hardware bindingmctp_register_bus(mctp, binding, eid)
: Register the hardware binding with the core, using a predefined EIDThen, register a function call to be invoked when a message is received:
mctp_set_rx_all(mctp, function)
: Provide a callback to be invoked when a MCTP message is receivedOr transmit a message:
mctp_message_tx(mctp, message, len)
: Transmit a MCTP messageThe binding may require you to notify it to receive packets. For example, for the serial binding, the mctp_serial_read()
function should be invoked when the file-descriptor for the serial device has data available.
libmctp implements basic support for bridging between two hardware bindings. In this mode, bindings may have different MTUs, so packets are reassembled into their messages, then the messages are re-packetised for the outgoing binding.
For bridging between two endpoints, use the mctp_bridge_busses()
function:
mctp = mctp_init()
: Initialise the MCTP coreb1 = mctp_<binding>_init(); b2 = mctp_<binding>_init()
: Initialise two hardware bindingsmctp_bridge_busses(mctp, b1, b2)
: Setup bridgeNote that no EIDs are defined here; the bridge does not deliver any messages to a local rx callback, and messages are bridged as-is.
Hardware bindings provide a method for libmctp to send and receive packets to/from hardware. A binding defines a hardware specific structure (struct mctp_binding_<name>
), which wraps the generic binding (struct mctp_binding
):
struct mctp_binding_foo { struct mctp_binding binding; /* hardware-specific members here... */ };
The binding code then provides a method (_init
) to allocate and initialise the binding; this may be of any prototype (calling code will know what arguments to pass):
struct mctp_binding_foo *mctp_binding_foo_init(void);
or maybe the foo
binding needs a path argument:
struct mctp_binding_foo *mctp_binding_foo_init(const char *path);
The binding then needs to provide a function (_core
) to convert the hardware-specific struct to the libmctp generic core struct
struct mctp_binding *mctp_binding_foo_core(struct mctp_binding_foo *b);
(Implementations of this will usually be fairly consistent, just returning b->binding
). Callers can then use that generic pointer to register the binding with the core:
struct mctp_binding *binding = mctp_binding_foo_core(foo); mctp_register_bus(mctp, binding, 8);
The libmctp code is intended to be integrated into other codebases by two methods:
as a simple library (libmctp.{a,so}
) which can be compiled separately and linked into the containing project
as a set of sources to be included into the containing project (either imported, or as a git subtree/submodule)
For (1), you can use the top-level makefile to produce libmtcp.a
.
For (2), the Makefile.inc
file provides the minimum set of dependencies to either build libmctp.a, or just the actual object files (LIBMCTP_OBS
), which you can include into your existing make definitions. You'll want to set LIBMTCP_DIR
to refer to the subdirectory that contains that makefile, so we can set the correct paths to sources.
This library is intended to be portable to be used in a range of environments, but the main targets are:
For the latter, we need to support customisation of the functions that libmctp uses (for example, POSIX file IO is not available).
In order to support these, we have a few compile-time definitions:
MCTP_HAVE_FILEIO
: define if POSIX file io is available, allowing the serial hardware binding to access char devices for IO.
MCTP_HAVE_SYSLOG
: allow logging to syslog, through the vsyslog
call.
MCTP_DEFAULT_ALLOC
: set default allocator functions (malloc, free, realloc), so that applications do not have to provide their own.