xref: /openbmc/libmctp/tests/test_core.c (revision 133df7ab)
169f545f7SSumanth Bhat /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
269f545f7SSumanth Bhat 
369f545f7SSumanth Bhat #define _GNU_SOURCE
469f545f7SSumanth Bhat 
569f545f7SSumanth Bhat #ifdef NDEBUG
669f545f7SSumanth Bhat #undef NDEBUG
769f545f7SSumanth Bhat #endif
869f545f7SSumanth Bhat 
969f545f7SSumanth Bhat #if HAVE_CONFIG_H
1069f545f7SSumanth Bhat #include "config.h"
1169f545f7SSumanth Bhat #endif
1269f545f7SSumanth Bhat 
1369f545f7SSumanth Bhat #include <assert.h>
1469f545f7SSumanth Bhat #include <fcntl.h>
1569f545f7SSumanth Bhat #include <stdbool.h>
1669f545f7SSumanth Bhat #include <stdint.h>
1769f545f7SSumanth Bhat #include <stdio.h>
1869f545f7SSumanth Bhat #include <stdlib.h>
1969f545f7SSumanth Bhat #include <string.h>
2069f545f7SSumanth Bhat #include <unistd.h>
2169f545f7SSumanth Bhat 
225ab78259SAndrew Jeffery #include "compiler.h"
2369f545f7SSumanth Bhat #include "libmctp-alloc.h"
2469f545f7SSumanth Bhat #include "libmctp-log.h"
2569f545f7SSumanth Bhat #include "range.h"
2669f545f7SSumanth Bhat #include "test-utils.h"
2769f545f7SSumanth Bhat 
2869f545f7SSumanth Bhat #define TEST_DEST_EID		9
29*133df7abSJohn Chung #define TEST_DEST_NULL_EID	0
30*133df7abSJohn Chung #define TEST_DEST_BROADCAST_EID 255
3169f545f7SSumanth Bhat #define TEST_SRC_EID		10
3269f545f7SSumanth Bhat 
3369f545f7SSumanth Bhat #ifndef ARRAY_SIZE
3469f545f7SSumanth Bhat #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
3569f545f7SSumanth Bhat #endif
3669f545f7SSumanth Bhat 
3769f545f7SSumanth Bhat #define MAX_PAYLOAD_SIZE 50000
3869f545f7SSumanth Bhat 
3969f545f7SSumanth Bhat struct pktbuf {
4069f545f7SSumanth Bhat 	struct mctp_hdr hdr;
4169f545f7SSumanth Bhat 	uint8_t *payload;
4269f545f7SSumanth Bhat };
4369f545f7SSumanth Bhat 
4469f545f7SSumanth Bhat struct test_params {
4569f545f7SSumanth Bhat 	bool seen;
4669f545f7SSumanth Bhat 	size_t message_size;
47f39c3857SSumanth Bhat 	uint8_t msg_tag;
48f39c3857SSumanth Bhat 	bool tag_owner;
4969f545f7SSumanth Bhat };
5069f545f7SSumanth Bhat 
rx_message(uint8_t eid __unused,bool tag_owner,uint8_t msg_tag,void * data,void * msg __unused,size_t len)51f39c3857SSumanth Bhat static void rx_message(uint8_t eid __unused, bool tag_owner, uint8_t msg_tag,
52f39c3857SSumanth Bhat 		       void *data, void *msg __unused, size_t len)
5369f545f7SSumanth Bhat {
5469f545f7SSumanth Bhat 	struct test_params *param = (struct test_params *)data;
5569f545f7SSumanth Bhat 
56f39c3857SSumanth Bhat 	mctp_prdebug("MCTP message received: len %zd, tag %u", len, msg_tag);
5769f545f7SSumanth Bhat 
5869f545f7SSumanth Bhat 	param->seen = true;
5969f545f7SSumanth Bhat 	param->message_size = len;
60f39c3857SSumanth Bhat 	param->msg_tag = msg_tag;
61f39c3857SSumanth Bhat 	param->tag_owner = tag_owner;
6269f545f7SSumanth Bhat }
6369f545f7SSumanth Bhat 
get_sequence()6469f545f7SSumanth Bhat static uint8_t get_sequence()
6569f545f7SSumanth Bhat {
6669f545f7SSumanth Bhat 	static uint8_t pkt_seq = 0;
6769f545f7SSumanth Bhat 
6869f545f7SSumanth Bhat 	return (pkt_seq++ % 4);
6969f545f7SSumanth Bhat }
7069f545f7SSumanth Bhat 
get_tag()7169f545f7SSumanth Bhat static uint8_t get_tag()
7269f545f7SSumanth Bhat {
7369f545f7SSumanth Bhat 	static uint8_t tag = 0;
7469f545f7SSumanth Bhat 
7569f545f7SSumanth Bhat 	return (tag++ % 8);
7669f545f7SSumanth Bhat }
7769f545f7SSumanth Bhat 
7869f545f7SSumanth Bhat /*
7969f545f7SSumanth Bhat  * receive_pktbuf bypasses all bindings and directly invokes mctp_bus_rx.
8069f545f7SSumanth Bhat  * This is necessary in order invoke test cases on the core functionality.
8169f545f7SSumanth Bhat  * The memory allocated for the mctp packet is capped at MCTP_BTU
8269f545f7SSumanth Bhat  * size, however, the mimiced rx pkt still retains the len parameter.
8369f545f7SSumanth Bhat  * This allows to mimic packets larger than a sane memory allocator can
8469f545f7SSumanth Bhat  * provide.
8569f545f7SSumanth Bhat  */
receive_ptkbuf(struct mctp_binding_test * binding,const struct pktbuf * pktbuf,size_t len)8669f545f7SSumanth Bhat static void receive_ptkbuf(struct mctp_binding_test *binding,
8769f545f7SSumanth Bhat 			   const struct pktbuf *pktbuf, size_t len)
8869f545f7SSumanth Bhat {
8969f545f7SSumanth Bhat 	size_t alloc_size = MIN((size_t)MCTP_BTU, len);
9069f545f7SSumanth Bhat 	struct mctp_pktbuf *rx_pkt;
9169f545f7SSumanth Bhat 
9269f545f7SSumanth Bhat 	rx_pkt = __mctp_alloc(sizeof(*rx_pkt) + MCTP_PACKET_SIZE(alloc_size));
9369f545f7SSumanth Bhat 	assert(rx_pkt);
9469f545f7SSumanth Bhat 
9569f545f7SSumanth Bhat 	/* Preserve passed len parameter */
9669f545f7SSumanth Bhat 	rx_pkt->size = MCTP_PACKET_SIZE(len);
9769f545f7SSumanth Bhat 	rx_pkt->start = 0;
9869f545f7SSumanth Bhat 	rx_pkt->end = MCTP_PACKET_SIZE(len);
9969f545f7SSumanth Bhat 	rx_pkt->mctp_hdr_off = 0;
10069f545f7SSumanth Bhat 	rx_pkt->next = NULL;
10169f545f7SSumanth Bhat 	memcpy(rx_pkt->data, &pktbuf->hdr, sizeof(pktbuf->hdr));
10269f545f7SSumanth Bhat 	memcpy(rx_pkt->data + sizeof(pktbuf->hdr), pktbuf->payload, alloc_size);
10369f545f7SSumanth Bhat 
10469f545f7SSumanth Bhat 	mctp_bus_rx((struct mctp_binding *)binding, rx_pkt);
10569f545f7SSumanth Bhat }
10669f545f7SSumanth Bhat 
receive_one_fragment(struct mctp_binding_test * binding,uint8_t * payload,size_t fragment_size,uint8_t flags_seq_tag,struct pktbuf * pktbuf)10769f545f7SSumanth Bhat static void receive_one_fragment(struct mctp_binding_test *binding,
10869f545f7SSumanth Bhat 				 uint8_t *payload, size_t fragment_size,
10969f545f7SSumanth Bhat 				 uint8_t flags_seq_tag, struct pktbuf *pktbuf)
11069f545f7SSumanth Bhat {
11169f545f7SSumanth Bhat 	pktbuf->hdr.flags_seq_tag = flags_seq_tag;
11269f545f7SSumanth Bhat 	pktbuf->payload = payload;
11369f545f7SSumanth Bhat 	receive_ptkbuf(binding, pktbuf, fragment_size);
11469f545f7SSumanth Bhat }
11569f545f7SSumanth Bhat 
receive_two_fragment_message(struct mctp_binding_test * binding,uint8_t * payload,size_t fragment1_size,size_t fragment2_size,struct pktbuf * pktbuf)11669f545f7SSumanth Bhat static void receive_two_fragment_message(struct mctp_binding_test *binding,
11769f545f7SSumanth Bhat 					 uint8_t *payload,
11869f545f7SSumanth Bhat 					 size_t fragment1_size,
11969f545f7SSumanth Bhat 					 size_t fragment2_size,
12069f545f7SSumanth Bhat 					 struct pktbuf *pktbuf)
12169f545f7SSumanth Bhat {
12269f545f7SSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
12369f545f7SSumanth Bhat 	uint8_t flags_seq_tag;
12469f545f7SSumanth Bhat 
12569f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
12669f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
12769f545f7SSumanth Bhat 	receive_one_fragment(binding, payload, fragment1_size, flags_seq_tag,
12869f545f7SSumanth Bhat 			     pktbuf);
12969f545f7SSumanth Bhat 
13069f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
13169f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
13269f545f7SSumanth Bhat 	receive_one_fragment(binding, payload + fragment1_size, fragment2_size,
13369f545f7SSumanth Bhat 			     flags_seq_tag, pktbuf);
13469f545f7SSumanth Bhat }
13569f545f7SSumanth Bhat 
mctp_core_test_simple_rx()13669f545f7SSumanth Bhat static void mctp_core_test_simple_rx()
13769f545f7SSumanth Bhat {
13869f545f7SSumanth Bhat 	struct mctp *mctp = NULL;
13969f545f7SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
14069f545f7SSumanth Bhat 	struct test_params test_param;
14169f545f7SSumanth Bhat 	uint8_t test_payload[2 * MCTP_BTU];
14269f545f7SSumanth Bhat 	struct pktbuf pktbuf;
14369f545f7SSumanth Bhat 
14469f545f7SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
14569f545f7SSumanth Bhat 	test_param.seen = false;
14669f545f7SSumanth Bhat 	test_param.message_size = 0;
14769f545f7SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
14869f545f7SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
14969f545f7SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
15069f545f7SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
15169f545f7SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
15269f545f7SSumanth Bhat 
15369f545f7SSumanth Bhat 	/* Receive 2 fragments of equal size */
15469f545f7SSumanth Bhat 	receive_two_fragment_message(binding, test_payload, MCTP_BTU, MCTP_BTU,
15569f545f7SSumanth Bhat 				     &pktbuf);
15669f545f7SSumanth Bhat 
15769f545f7SSumanth Bhat 	assert(test_param.seen);
15869f545f7SSumanth Bhat 	assert(test_param.message_size == 2 * MCTP_BTU);
15969f545f7SSumanth Bhat 
16069f545f7SSumanth Bhat 	mctp_binding_test_destroy(binding);
16169f545f7SSumanth Bhat 	mctp_destroy(mctp);
16269f545f7SSumanth Bhat }
16369f545f7SSumanth Bhat 
mctp_core_test_receive_equal_length_fragments()16469f545f7SSumanth Bhat static void mctp_core_test_receive_equal_length_fragments()
16569f545f7SSumanth Bhat {
16669f545f7SSumanth Bhat 	struct mctp *mctp = NULL;
16769f545f7SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
16869f545f7SSumanth Bhat 	struct test_params test_param;
16969f545f7SSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
17069f545f7SSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
17169f545f7SSumanth Bhat 	struct pktbuf pktbuf;
17269f545f7SSumanth Bhat 	uint8_t flags_seq_tag;
17369f545f7SSumanth Bhat 
17469f545f7SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
17569f545f7SSumanth Bhat 	test_param.seen = false;
17669f545f7SSumanth Bhat 	test_param.message_size = 0;
17769f545f7SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
17869f545f7SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
17969f545f7SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
18069f545f7SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
18169f545f7SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
18269f545f7SSumanth Bhat 
18369f545f7SSumanth Bhat 	/* Receive 3 fragments, each of size MCTP_BTU */
18469f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
18569f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
18669f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
18769f545f7SSumanth Bhat 			     &pktbuf);
18869f545f7SSumanth Bhat 
18969f545f7SSumanth Bhat 	flags_seq_tag = (get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
19069f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + MCTP_BTU, MCTP_BTU,
19169f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
19269f545f7SSumanth Bhat 
19369f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
19469f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
19569f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + (2 * MCTP_BTU), MCTP_BTU,
19669f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
19769f545f7SSumanth Bhat 
19869f545f7SSumanth Bhat 	assert(test_param.seen);
19969f545f7SSumanth Bhat 	assert(test_param.message_size == 3 * MCTP_BTU);
20069f545f7SSumanth Bhat 
20169f545f7SSumanth Bhat 	mctp_binding_test_destroy(binding);
20269f545f7SSumanth Bhat 	mctp_destroy(mctp);
20369f545f7SSumanth Bhat }
20469f545f7SSumanth Bhat 
mctp_core_test_receive_unexpected_smaller_middle_fragment()20569f545f7SSumanth Bhat static void mctp_core_test_receive_unexpected_smaller_middle_fragment()
20669f545f7SSumanth Bhat {
20769f545f7SSumanth Bhat 	struct mctp *mctp = NULL;
20869f545f7SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
20969f545f7SSumanth Bhat 	struct test_params test_param;
21069f545f7SSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
21169f545f7SSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
21269f545f7SSumanth Bhat 	struct pktbuf pktbuf;
21369f545f7SSumanth Bhat 	uint8_t flags_seq_tag;
21469f545f7SSumanth Bhat 
21569f545f7SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
21669f545f7SSumanth Bhat 	test_param.seen = false;
21769f545f7SSumanth Bhat 	test_param.message_size = 0;
21869f545f7SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
21969f545f7SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
22069f545f7SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
22169f545f7SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
22269f545f7SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
22369f545f7SSumanth Bhat 
22469f545f7SSumanth Bhat 	/* Middle fragment with size MCTP_BTU - 1 */
22569f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
22669f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
22769f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
22869f545f7SSumanth Bhat 			     &pktbuf);
22969f545f7SSumanth Bhat 
23069f545f7SSumanth Bhat 	flags_seq_tag = (get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
23169f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + MCTP_BTU, MCTP_BTU - 1,
23269f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
23369f545f7SSumanth Bhat 
23469f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
23569f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
23669f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + (2 * MCTP_BTU), MCTP_BTU,
23769f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
23869f545f7SSumanth Bhat 
23969f545f7SSumanth Bhat 	assert(!test_param.seen);
24069f545f7SSumanth Bhat 
24169f545f7SSumanth Bhat 	mctp_binding_test_destroy(binding);
24269f545f7SSumanth Bhat 	mctp_destroy(mctp);
24369f545f7SSumanth Bhat }
24469f545f7SSumanth Bhat 
mctp_core_test_receive_unexpected_bigger_middle_fragment()24569f545f7SSumanth Bhat static void mctp_core_test_receive_unexpected_bigger_middle_fragment()
24669f545f7SSumanth Bhat {
24769f545f7SSumanth Bhat 	struct mctp *mctp = NULL;
24869f545f7SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
24969f545f7SSumanth Bhat 	struct test_params test_param;
25069f545f7SSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
25169f545f7SSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
25269f545f7SSumanth Bhat 	struct pktbuf pktbuf;
25369f545f7SSumanth Bhat 	uint8_t flags_seq_tag;
25469f545f7SSumanth Bhat 
25569f545f7SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
25669f545f7SSumanth Bhat 	test_param.seen = false;
25769f545f7SSumanth Bhat 	test_param.message_size = 0;
25869f545f7SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
25969f545f7SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
26069f545f7SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
26169f545f7SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
26269f545f7SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
26369f545f7SSumanth Bhat 
26469f545f7SSumanth Bhat 	/* Middle fragment with size MCTP_BTU + 1 */
26569f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
26669f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
26769f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
26869f545f7SSumanth Bhat 			     &pktbuf);
26969f545f7SSumanth Bhat 
27069f545f7SSumanth Bhat 	flags_seq_tag = (get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
27169f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + MCTP_BTU, MCTP_BTU + 1,
27269f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
27369f545f7SSumanth Bhat 
27469f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
27569f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
27669f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + (2 * MCTP_BTU), MCTP_BTU,
27769f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
27869f545f7SSumanth Bhat 
27969f545f7SSumanth Bhat 	assert(!test_param.seen);
28069f545f7SSumanth Bhat 
28169f545f7SSumanth Bhat 	mctp_binding_test_destroy(binding);
28269f545f7SSumanth Bhat 	mctp_destroy(mctp);
28369f545f7SSumanth Bhat }
28469f545f7SSumanth Bhat 
mctp_core_test_receive_smaller_end_fragment()28569f545f7SSumanth Bhat static void mctp_core_test_receive_smaller_end_fragment()
28669f545f7SSumanth Bhat {
28769f545f7SSumanth Bhat 	struct mctp *mctp = NULL;
28869f545f7SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
28969f545f7SSumanth Bhat 	struct test_params test_param;
29069f545f7SSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
29169f545f7SSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
29269f545f7SSumanth Bhat 	uint8_t end_frag_size = MCTP_BTU - 10;
29369f545f7SSumanth Bhat 	struct pktbuf pktbuf;
29469f545f7SSumanth Bhat 	uint8_t flags_seq_tag;
29569f545f7SSumanth Bhat 
29669f545f7SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
29769f545f7SSumanth Bhat 	test_param.seen = false;
29869f545f7SSumanth Bhat 	test_param.message_size = 0;
29969f545f7SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
30069f545f7SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
30169f545f7SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
30269f545f7SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
30369f545f7SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
30469f545f7SSumanth Bhat 
30569f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
30669f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
30769f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
30869f545f7SSumanth Bhat 			     &pktbuf);
30969f545f7SSumanth Bhat 
31069f545f7SSumanth Bhat 	flags_seq_tag = (get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
31169f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + MCTP_BTU, MCTP_BTU,
31269f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
31369f545f7SSumanth Bhat 
31469f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
31569f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
31669f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + (2 * MCTP_BTU),
31769f545f7SSumanth Bhat 			     end_frag_size, flags_seq_tag, &pktbuf);
31869f545f7SSumanth Bhat 
31969f545f7SSumanth Bhat 	assert(test_param.seen);
32069f545f7SSumanth Bhat 	assert(test_param.message_size ==
32169f545f7SSumanth Bhat 	       (size_t)(2 * MCTP_BTU + end_frag_size));
32269f545f7SSumanth Bhat 
32369f545f7SSumanth Bhat 	mctp_binding_test_destroy(binding);
32469f545f7SSumanth Bhat 	mctp_destroy(mctp);
32569f545f7SSumanth Bhat }
32669f545f7SSumanth Bhat 
mctp_core_test_receive_bigger_end_fragment()32769f545f7SSumanth Bhat static void mctp_core_test_receive_bigger_end_fragment()
32869f545f7SSumanth Bhat {
32969f545f7SSumanth Bhat 	struct mctp *mctp = NULL;
33069f545f7SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
33169f545f7SSumanth Bhat 	struct test_params test_param;
33269f545f7SSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
33369f545f7SSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
33469f545f7SSumanth Bhat 	uint8_t end_frag_size = MCTP_BTU + 10;
33569f545f7SSumanth Bhat 	struct pktbuf pktbuf;
33669f545f7SSumanth Bhat 	uint8_t flags_seq_tag;
33769f545f7SSumanth Bhat 
33869f545f7SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
33969f545f7SSumanth Bhat 	test_param.seen = false;
34069f545f7SSumanth Bhat 	test_param.message_size = 0;
34169f545f7SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
34269f545f7SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
34369f545f7SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
34469f545f7SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
34569f545f7SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
34669f545f7SSumanth Bhat 
34769f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
34869f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
34969f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
35069f545f7SSumanth Bhat 			     &pktbuf);
35169f545f7SSumanth Bhat 
35269f545f7SSumanth Bhat 	flags_seq_tag = (get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
35369f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + MCTP_BTU, MCTP_BTU,
35469f545f7SSumanth Bhat 			     flags_seq_tag, &pktbuf);
35569f545f7SSumanth Bhat 
35669f545f7SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
35769f545f7SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
35869f545f7SSumanth Bhat 	receive_one_fragment(binding, test_payload + (2 * MCTP_BTU),
35969f545f7SSumanth Bhat 			     end_frag_size, flags_seq_tag, &pktbuf);
36069f545f7SSumanth Bhat 
36169f545f7SSumanth Bhat 	assert(!test_param.seen);
36269f545f7SSumanth Bhat 
36369f545f7SSumanth Bhat 	mctp_binding_test_destroy(binding);
36469f545f7SSumanth Bhat 	mctp_destroy(mctp);
36569f545f7SSumanth Bhat }
36669f545f7SSumanth Bhat 
mctp_core_test_drop_large_fragments()367bc79c24eSSumanth Bhat static void mctp_core_test_drop_large_fragments()
368bc79c24eSSumanth Bhat {
369bc79c24eSSumanth Bhat 	struct mctp *mctp = NULL;
370bc79c24eSSumanth Bhat 	struct mctp_binding_test *binding = NULL;
371bc79c24eSSumanth Bhat 	struct test_params test_param;
372bc79c24eSSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
373bc79c24eSSumanth Bhat 	struct pktbuf pktbuf;
374bc79c24eSSumanth Bhat 
375bc79c24eSSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
376bc79c24eSSumanth Bhat 	test_param.seen = false;
377bc79c24eSSumanth Bhat 	test_param.message_size = 0;
378bc79c24eSSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
379bc79c24eSSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
380bc79c24eSSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
381bc79c24eSSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
382bc79c24eSSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
383bc79c24eSSumanth Bhat 
384bc79c24eSSumanth Bhat 	/* Receive a large payload - first fragment with MCTP_BTU bytes,
385bc79c24eSSumanth Bhat 	* 2nd fragment of SIZE_MAX */
386bc79c24eSSumanth Bhat 
387bc79c24eSSumanth Bhat 	receive_two_fragment_message(binding, test_payload, MCTP_BTU,
38831b01e0dSAndrew Jeffery 				     SIZE_MAX - sizeof(struct mctp_hdr),
38931b01e0dSAndrew Jeffery 				     &pktbuf);
390bc79c24eSSumanth Bhat 
391bc79c24eSSumanth Bhat 	assert(!test_param.seen);
392bc79c24eSSumanth Bhat 
393bc79c24eSSumanth Bhat 	mctp_binding_test_destroy(binding);
394bc79c24eSSumanth Bhat 	mctp_destroy(mctp);
395bc79c24eSSumanth Bhat }
396bc79c24eSSumanth Bhat 
mctp_core_test_exhaust_context_buffers()39734d4c96fSSumanth Bhat static void mctp_core_test_exhaust_context_buffers()
39834d4c96fSSumanth Bhat {
39934d4c96fSSumanth Bhat 	struct mctp *mctp = NULL;
40034d4c96fSSumanth Bhat 	struct mctp_binding_test *binding = NULL;
40134d4c96fSSumanth Bhat 	struct test_params test_param;
40234d4c96fSSumanth Bhat 	static uint8_t test_payload[MAX_PAYLOAD_SIZE];
40334d4c96fSSumanth Bhat 	uint8_t tag = MCTP_HDR_FLAG_TO | get_tag();
40434d4c96fSSumanth Bhat 	uint8_t i = 0;
40534d4c96fSSumanth Bhat 	const uint8_t max_context_buffers = 16;
40634d4c96fSSumanth Bhat 	struct pktbuf pktbuf;
40734d4c96fSSumanth Bhat 	uint8_t flags_seq_tag;
40834d4c96fSSumanth Bhat 
40934d4c96fSSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
41034d4c96fSSumanth Bhat 	test_param.seen = false;
41134d4c96fSSumanth Bhat 	test_param.message_size = 0;
41234d4c96fSSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
41334d4c96fSSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
41434d4c96fSSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
41534d4c96fSSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
41634d4c96fSSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
41734d4c96fSSumanth Bhat 
41834d4c96fSSumanth Bhat 	/* Exhaust all 16 context buffers*/
41934d4c96fSSumanth Bhat 	for (i = 0; i < max_context_buffers; i++) {
42034d4c96fSSumanth Bhat 		flags_seq_tag = MCTP_HDR_FLAG_SOM |
42134d4c96fSSumanth Bhat 				(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
42234d4c96fSSumanth Bhat 		receive_one_fragment(binding, test_payload, MCTP_BTU,
42334d4c96fSSumanth Bhat 				     flags_seq_tag, &pktbuf);
42434d4c96fSSumanth Bhat 
42534d4c96fSSumanth Bhat 		/* Change source EID so that different contexts are created */
42634d4c96fSSumanth Bhat 		pktbuf.hdr.src++;
42734d4c96fSSumanth Bhat 	}
42834d4c96fSSumanth Bhat 
42934d4c96fSSumanth Bhat 	/* Send a full message from a different EID */
43034d4c96fSSumanth Bhat 	pktbuf.hdr.src++;
43134d4c96fSSumanth Bhat 	receive_two_fragment_message(binding, test_payload, MCTP_BTU, MCTP_BTU,
43234d4c96fSSumanth Bhat 				     &pktbuf);
43334d4c96fSSumanth Bhat 
43434d4c96fSSumanth Bhat 	/* Message assembly should fail */
43534d4c96fSSumanth Bhat 	assert(!test_param.seen);
43634d4c96fSSumanth Bhat 
43734d4c96fSSumanth Bhat 	/* Complete message assembly for one of the messages */
43834d4c96fSSumanth Bhat 	pktbuf.hdr.src -= max_context_buffers;
43934d4c96fSSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
44034d4c96fSSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) | tag;
44131b01e0dSAndrew Jeffery 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
44231b01e0dSAndrew Jeffery 			     &pktbuf);
44334d4c96fSSumanth Bhat 
44434d4c96fSSumanth Bhat 	assert(test_param.seen);
44534d4c96fSSumanth Bhat 	assert(test_param.message_size == (2 * MCTP_BTU));
44634d4c96fSSumanth Bhat 
44734d4c96fSSumanth Bhat 	mctp_binding_test_destroy(binding);
44834d4c96fSSumanth Bhat 	mctp_destroy(mctp);
44934d4c96fSSumanth Bhat }
45034d4c96fSSumanth Bhat 
mctp_core_test_rx_with_tag()451f39c3857SSumanth Bhat static void mctp_core_test_rx_with_tag()
452f39c3857SSumanth Bhat {
453f39c3857SSumanth Bhat 	struct mctp *mctp = NULL;
454f39c3857SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
455f39c3857SSumanth Bhat 	struct test_params test_param;
456f39c3857SSumanth Bhat 	static uint8_t test_payload[MCTP_BTU];
457f39c3857SSumanth Bhat 	uint8_t tag = get_tag();
458f39c3857SSumanth Bhat 	struct pktbuf pktbuf;
459f39c3857SSumanth Bhat 	uint8_t flags_seq_tag;
460f39c3857SSumanth Bhat 
461f39c3857SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
462f39c3857SSumanth Bhat 	test_param.seen = false;
463f39c3857SSumanth Bhat 	test_param.message_size = 0;
464f39c3857SSumanth Bhat 	test_param.msg_tag = 0;
465f39c3857SSumanth Bhat 	test_param.tag_owner = false;
466f39c3857SSumanth Bhat 
467f39c3857SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
468f39c3857SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
469f39c3857SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
470f39c3857SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
471f39c3857SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
472f39c3857SSumanth Bhat 
473f39c3857SSumanth Bhat 	/* Set tag and tag owner fields for a recieve packet */
474f39c3857SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM | MCTP_HDR_FLAG_EOM |
475f39c3857SSumanth Bhat 			(1 << MCTP_HDR_TO_SHIFT) | tag;
476f39c3857SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
477f39c3857SSumanth Bhat 			     &pktbuf);
478f39c3857SSumanth Bhat 
479f39c3857SSumanth Bhat 	assert(test_param.seen);
480f39c3857SSumanth Bhat 	assert(test_param.message_size == (MCTP_BTU));
481f39c3857SSumanth Bhat 	assert(test_param.msg_tag == tag);
482f39c3857SSumanth Bhat 	assert(test_param.tag_owner);
483f39c3857SSumanth Bhat 
484f39c3857SSumanth Bhat 	mctp_binding_test_destroy(binding);
485f39c3857SSumanth Bhat 	mctp_destroy(mctp);
486f39c3857SSumanth Bhat }
487f39c3857SSumanth Bhat 
mctp_core_test_rx_with_tag_multifragment()488f39c3857SSumanth Bhat static void mctp_core_test_rx_with_tag_multifragment()
489f39c3857SSumanth Bhat {
490f39c3857SSumanth Bhat 	struct mctp *mctp = NULL;
491f39c3857SSumanth Bhat 	struct mctp_binding_test *binding = NULL;
492f39c3857SSumanth Bhat 	struct test_params test_param;
493f39c3857SSumanth Bhat 	static uint8_t test_payload[MCTP_BTU];
494f39c3857SSumanth Bhat 	uint8_t tag = get_tag();
495f39c3857SSumanth Bhat 	struct pktbuf pktbuf;
496f39c3857SSumanth Bhat 	uint8_t flags_seq_tag;
497f39c3857SSumanth Bhat 
498f39c3857SSumanth Bhat 	memset(test_payload, 0, sizeof(test_payload));
499f39c3857SSumanth Bhat 	test_param.seen = false;
500f39c3857SSumanth Bhat 	test_param.message_size = 0;
501f39c3857SSumanth Bhat 	test_param.msg_tag = 0;
502f39c3857SSumanth Bhat 	test_param.tag_owner = false;
503f39c3857SSumanth Bhat 
504f39c3857SSumanth Bhat 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
505f39c3857SSumanth Bhat 	mctp_set_rx_all(mctp, rx_message, &test_param);
506f39c3857SSumanth Bhat 	memset(&pktbuf, 0, sizeof(pktbuf));
507f39c3857SSumanth Bhat 	pktbuf.hdr.dest = TEST_DEST_EID;
508f39c3857SSumanth Bhat 	pktbuf.hdr.src = TEST_SRC_EID;
509f39c3857SSumanth Bhat 
510f39c3857SSumanth Bhat 	/* Set tag and tag owner fields for a 3 fragment packet */
511f39c3857SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_SOM |
512f39c3857SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) |
513f39c3857SSumanth Bhat 			(1 << MCTP_HDR_TO_SHIFT) | tag;
514f39c3857SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
515f39c3857SSumanth Bhat 			     &pktbuf);
516f39c3857SSumanth Bhat 
517f39c3857SSumanth Bhat 	flags_seq_tag = (get_sequence() << MCTP_HDR_SEQ_SHIFT) |
518f39c3857SSumanth Bhat 			(1 << MCTP_HDR_TO_SHIFT) | tag;
519f39c3857SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
520f39c3857SSumanth Bhat 			     &pktbuf);
521f39c3857SSumanth Bhat 
522f39c3857SSumanth Bhat 	flags_seq_tag = MCTP_HDR_FLAG_EOM |
523f39c3857SSumanth Bhat 			(get_sequence() << MCTP_HDR_SEQ_SHIFT) |
524f39c3857SSumanth Bhat 			(1 << MCTP_HDR_TO_SHIFT) | tag;
525f39c3857SSumanth Bhat 	receive_one_fragment(binding, test_payload, MCTP_BTU, flags_seq_tag,
526f39c3857SSumanth Bhat 			     &pktbuf);
527f39c3857SSumanth Bhat 
528f39c3857SSumanth Bhat 	assert(test_param.seen);
529f39c3857SSumanth Bhat 	assert(test_param.message_size == (3 * MCTP_BTU));
530f39c3857SSumanth Bhat 	assert(test_param.msg_tag == tag);
531f39c3857SSumanth Bhat 	assert(test_param.tag_owner);
532f39c3857SSumanth Bhat 
533f39c3857SSumanth Bhat 	mctp_binding_test_destroy(binding);
534f39c3857SSumanth Bhat 	mctp_destroy(mctp);
535f39c3857SSumanth Bhat }
536f39c3857SSumanth Bhat 
537*133df7abSJohn Chung /*
538*133df7abSJohn Chung  * This test case covers null destination eid. MCTP
539*133df7abSJohn Chung  * daemon might query endpoint (i.e., Get Endpoint
540*133df7abSJohn Chung  * ID command) by physical address requests and
541*133df7abSJohn Chung  * destination eid as 0. Endpoint shall accept and
542*133df7abSJohn Chung  * handle this request.
543*133df7abSJohn Chung  */
mctp_core_test_rx_with_null_dst_eid()544*133df7abSJohn Chung static void mctp_core_test_rx_with_null_dst_eid()
545*133df7abSJohn Chung {
546*133df7abSJohn Chung 	struct mctp *mctp = NULL;
547*133df7abSJohn Chung 	struct mctp_binding_test *binding = NULL;
548*133df7abSJohn Chung 	struct test_params test_param;
549*133df7abSJohn Chung 	uint8_t test_payload[2 * MCTP_BTU];
550*133df7abSJohn Chung 	struct pktbuf pktbuf;
551*133df7abSJohn Chung 
552*133df7abSJohn Chung 	memset(test_payload, 0, sizeof(test_payload));
553*133df7abSJohn Chung 	test_param.seen = false;
554*133df7abSJohn Chung 	test_param.message_size = 0;
555*133df7abSJohn Chung 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
556*133df7abSJohn Chung 	mctp_set_rx_all(mctp, rx_message, &test_param);
557*133df7abSJohn Chung 	memset(&pktbuf, 0, sizeof(pktbuf));
558*133df7abSJohn Chung 	pktbuf.hdr.dest = TEST_DEST_NULL_EID;
559*133df7abSJohn Chung 	pktbuf.hdr.src = TEST_SRC_EID;
560*133df7abSJohn Chung 
561*133df7abSJohn Chung 	/* Receive 2 fragments of equal size */
562*133df7abSJohn Chung 	receive_two_fragment_message(binding, test_payload, MCTP_BTU, MCTP_BTU,
563*133df7abSJohn Chung 				     &pktbuf);
564*133df7abSJohn Chung 
565*133df7abSJohn Chung 	assert(test_param.seen);
566*133df7abSJohn Chung 	assert(test_param.message_size == 2 * MCTP_BTU);
567*133df7abSJohn Chung 
568*133df7abSJohn Chung 	mctp_binding_test_destroy(binding);
569*133df7abSJohn Chung 	mctp_destroy(mctp);
570*133df7abSJohn Chung }
571*133df7abSJohn Chung 
572*133df7abSJohn Chung /*
573*133df7abSJohn Chung  * This test case covers Broadcast Request message (i.e.,
574*133df7abSJohn Chung  * `Endpoint Discovery` command). Endpoint shall accept
575*133df7abSJohn Chung  * and handle this request.
576*133df7abSJohn Chung  */
mctp_core_test_rx_with_broadcast_dst_eid()577*133df7abSJohn Chung static void mctp_core_test_rx_with_broadcast_dst_eid()
578*133df7abSJohn Chung {
579*133df7abSJohn Chung 	struct mctp *mctp = NULL;
580*133df7abSJohn Chung 	struct mctp_binding_test *binding = NULL;
581*133df7abSJohn Chung 	struct test_params test_param;
582*133df7abSJohn Chung 	uint8_t test_payload[2 * MCTP_BTU];
583*133df7abSJohn Chung 	struct pktbuf pktbuf;
584*133df7abSJohn Chung 
585*133df7abSJohn Chung 	memset(test_payload, 0, sizeof(test_payload));
586*133df7abSJohn Chung 	test_param.seen = false;
587*133df7abSJohn Chung 	test_param.message_size = 0;
588*133df7abSJohn Chung 	mctp_test_stack_init(&mctp, &binding, TEST_DEST_EID);
589*133df7abSJohn Chung 	mctp_set_rx_all(mctp, rx_message, &test_param);
590*133df7abSJohn Chung 	memset(&pktbuf, 0, sizeof(pktbuf));
591*133df7abSJohn Chung 	pktbuf.hdr.dest = TEST_DEST_BROADCAST_EID;
592*133df7abSJohn Chung 	pktbuf.hdr.src = TEST_SRC_EID;
593*133df7abSJohn Chung 
594*133df7abSJohn Chung 	/* Receive 2 fragments of equal size */
595*133df7abSJohn Chung 	receive_two_fragment_message(binding, test_payload, MCTP_BTU, MCTP_BTU,
596*133df7abSJohn Chung 				     &pktbuf);
597*133df7abSJohn Chung 
598*133df7abSJohn Chung 	assert(test_param.seen);
599*133df7abSJohn Chung 	assert(test_param.message_size == 2 * MCTP_BTU);
600*133df7abSJohn Chung 
601*133df7abSJohn Chung 	mctp_binding_test_destroy(binding);
602*133df7abSJohn Chung 	mctp_destroy(mctp);
603*133df7abSJohn Chung }
604*133df7abSJohn Chung 
60569f545f7SSumanth Bhat /* clang-format off */
60669f545f7SSumanth Bhat #define TEST_CASE(test) { #test, test }
60769f545f7SSumanth Bhat static const struct {
60869f545f7SSumanth Bhat 	const char *name;
60969f545f7SSumanth Bhat 	void (*test)(void);
61069f545f7SSumanth Bhat } mctp_core_tests[] = {
61169f545f7SSumanth Bhat 	TEST_CASE(mctp_core_test_simple_rx),
61269f545f7SSumanth Bhat 	TEST_CASE(mctp_core_test_receive_equal_length_fragments),
61369f545f7SSumanth Bhat 	TEST_CASE(mctp_core_test_receive_unexpected_smaller_middle_fragment),
61469f545f7SSumanth Bhat 	TEST_CASE(mctp_core_test_receive_unexpected_bigger_middle_fragment),
61569f545f7SSumanth Bhat 	TEST_CASE(mctp_core_test_receive_smaller_end_fragment),
61669f545f7SSumanth Bhat 	TEST_CASE(mctp_core_test_receive_bigger_end_fragment),
617bc79c24eSSumanth Bhat 	TEST_CASE(mctp_core_test_drop_large_fragments),
61834d4c96fSSumanth Bhat 	TEST_CASE(mctp_core_test_exhaust_context_buffers),
619f39c3857SSumanth Bhat 	TEST_CASE(mctp_core_test_rx_with_tag),
620f39c3857SSumanth Bhat 	TEST_CASE(mctp_core_test_rx_with_tag_multifragment),
621*133df7abSJohn Chung 	TEST_CASE(mctp_core_test_rx_with_null_dst_eid),
622*133df7abSJohn Chung 	TEST_CASE(mctp_core_test_rx_with_broadcast_dst_eid),
62369f545f7SSumanth Bhat };
62469f545f7SSumanth Bhat /* clang-format on */
62569f545f7SSumanth Bhat 
62669f545f7SSumanth Bhat #ifndef BUILD_ASSERT
62769f545f7SSumanth Bhat #define BUILD_ASSERT(x)                                                        \
62869f545f7SSumanth Bhat 	do {                                                                   \
62969f545f7SSumanth Bhat 		(void)sizeof(char[0 - (!(x))]);                                \
63069f545f7SSumanth Bhat 	} while (0)
63169f545f7SSumanth Bhat #endif
63269f545f7SSumanth Bhat 
main(void)63369f545f7SSumanth Bhat int main(void)
63469f545f7SSumanth Bhat {
63569f545f7SSumanth Bhat 	uint8_t i;
63669f545f7SSumanth Bhat 
63769f545f7SSumanth Bhat 	mctp_set_log_stdio(MCTP_LOG_DEBUG);
63869f545f7SSumanth Bhat 
63969f545f7SSumanth Bhat 	BUILD_ASSERT(ARRAY_SIZE(mctp_core_tests) < SIZE_MAX);
64069f545f7SSumanth Bhat 	for (i = 0; i < ARRAY_SIZE(mctp_core_tests); i++) {
64169f545f7SSumanth Bhat 		mctp_prlog(MCTP_LOG_DEBUG, "begin: %s",
64269f545f7SSumanth Bhat 			   mctp_core_tests[i].name);
64369f545f7SSumanth Bhat 		mctp_core_tests[i].test();
64469f545f7SSumanth Bhat 		mctp_prlog(MCTP_LOG_DEBUG, "end: %s\n",
64569f545f7SSumanth Bhat 			   mctp_core_tests[i].name);
64669f545f7SSumanth Bhat 	}
64769f545f7SSumanth Bhat 
64869f545f7SSumanth Bhat 	return 0;
64969f545f7SSumanth Bhat }
650