test_serial: Fix assert triggered in core.c

    $ ./tests/test_serial
    test_serial: core.c:252: mctp_register_bus: Assertion `mctp->n_busses == 0' failed.
    Aborted (core dumped)

I'm not sure how this slipped through the cracks, and CI didn't catch it
either.  However, the scenario wasn't correctly modelled, so do the proper
thing and instantiate two mctp contexts and assign a binding instance to each,
connected by the pipes.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ib5382a45cd0042c840fdb01b2038e9a531bf2384
diff --git a/tests/test_serial.c b/tests/test_serial.c
index 9c4da34..905f664 100644
--- a/tests/test_serial.c
+++ b/tests/test_serial.c
@@ -13,6 +13,7 @@
 
 #include <assert.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -35,6 +36,8 @@
 
 uint8_t mctp_msg_src[2 * MCTP_BTU];
 
+static bool seen;
+
 static void rx_message(uint8_t eid, void *data, void *msg, size_t len)
 {
 	uint8_t type;
@@ -45,13 +48,21 @@
 
 	assert(sizeof(mctp_msg_src) == len);
 	assert(!memcmp(mctp_msg_src, msg, len));
+
+	seen = true;
 }
 
+struct serial_test {
+	struct mctp_binding_serial_pipe binding;
+	struct mctp *mctp;
+};
+
 int main(void)
 {
-	struct mctp_binding_serial_pipe _a, *a = &_a;
-	struct mctp_binding_serial_pipe _b, *b = &_b;
-	struct mctp *mctp;
+	struct serial_test scenario[2];
+
+	struct mctp_binding_serial_pipe *a = &scenario[0].binding;
+	struct mctp_binding_serial_pipe *b = &scenario[1].binding;
 	int p[2][2];
 	int rc;
 
@@ -66,35 +77,37 @@
 	rc = pipe(p[1]);
 	assert(!rc);
 
-	mctp = mctp_init();
-	assert(mctp);
-
-	mctp_set_rx_all(mctp, rx_message, NULL);
-
 	/* Instantiate the A side of the serial pipe */
+	scenario[0].mctp = mctp_init();
+	assert(scenario[0].mctp);
 	a->serial = mctp_serial_init();
 	assert(a->serial);
 	a->ingress = p[0][0];
 	a->egress = p[1][1];
 	mctp_serial_open_fd(a->serial, a->ingress);
 	mctp_serial_set_tx_fn(a->serial, mctp_binding_serial_pipe_tx, a);
-	mctp_register_bus(mctp, mctp_binding_serial_core(a->serial), 8);
+	mctp_register_bus(scenario[0].mctp, mctp_binding_serial_core(a->serial), 8);
 
 	/* Instantiate the B side of the serial pipe */
+	scenario[1].mctp = mctp_init();
+	assert(scenario[1].mctp);
+	mctp_set_rx_all(scenario[1].mctp, rx_message, NULL);
 	b->serial = mctp_serial_init();
 	assert(b->serial);
 	b->ingress = p[1][0];
 	b->egress = p[0][1];
 	mctp_serial_open_fd(b->serial, b->ingress);
 	mctp_serial_set_tx_fn(b->serial, mctp_binding_serial_pipe_tx, a);
-	mctp_register_bus(mctp, mctp_binding_serial_core(b->serial), 9);
+	mctp_register_bus(scenario[1].mctp, mctp_binding_serial_core(b->serial), 9);
 
 	/* Transmit a message from A to B */
-	rc = mctp_message_tx(mctp, 9, mctp_msg_src, sizeof(mctp_msg_src));
+	rc = mctp_message_tx(scenario[0].mctp, 9, mctp_msg_src, sizeof(mctp_msg_src));
 	assert(rc == 0);
 
 	/* Read the message at B from A */
+	seen = false;
 	mctp_serial_read(b->serial);
+	assert(seen);
 
 	return 0;
 }