test_astlpc: Introduce astlpc_assert_tx_packet()

astlpc_assert_tx_packet() is a quick test to ensure the expected packet
has been enqueued on the interface.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I5ef818bcfc4537329a590e0c3023eb3d22db2c05
diff --git a/tests/test_astlpc.c b/tests/test_astlpc.c
index e95673a..a014ac3 100644
--- a/tests/test_astlpc.c
+++ b/tests/test_astlpc.c
@@ -19,8 +19,6 @@
 #undef NDEBUG
 #endif
 
-#define RX_BUFFER_DATA	0x100 + 4 + 4
-
 #include <assert.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -160,7 +158,7 @@
 	ep->mmio.lpc = lpc_mem;
 
 	/* Initialise the binding */
-	ep->astlpc = mctp_astlpc_init(mode, MCTP_BTU, NULL,
+	ep->astlpc = mctp_astlpc_init(mode, MCTP_BTU, lpc_mem,
 				      &mctp_binding_astlpc_mmio_ops, &ep->mmio);
 
 	mctp_register_bus(ep->mctp, &ep->astlpc->binding, eid);
@@ -210,6 +208,14 @@
 	free(ctx->lpc_mem);
 }
 
+static void astlpc_assert_tx_packet(struct astlpc_endpoint *src,
+				    const void *expected, size_t len)
+{
+	const size_t tx_body = src->astlpc->layout.tx.offset + 4 + 4;
+	const void *test = ((char *)src->astlpc->lpc_map) + tx_body;
+	assert(!memcmp(test, expected, len));
+}
+
 static void astlpc_test_packetised_message_bmc_to_host(void)
 {
 	struct astlpc_test ctx = { 0 };
@@ -229,10 +235,9 @@
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
 
-	/* Verify it's the packet we expect */
-	assert(!memcmp(ctx.lpc_mem + RX_BUFFER_DATA, &msg[0], MCTP_BTU));
+	astlpc_assert_tx_packet(&ctx.bmc, &msg[0], MCTP_BTU);
 
-	/* Host receives a packet */
+	/* Host receives the first packet */
 	mctp_astlpc_poll(ctx.host.astlpc);
 
 	/* Host returns Rx area ownership to BMC */
@@ -244,12 +249,11 @@
 	rc = mctp_astlpc_poll(ctx.bmc.astlpc);
 	assert(rc == 0);
 
-	/* Host receives a message */
+	/* Host receives the next packet */
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_STATUS] & KCS_STATUS_OBF);
 	assert(ctx.kcs[MCTP_ASTLPC_KCS_REG_DATA] == 0x01);
 
-	/* Verify it's the packet we expect */
-	assert(!memcmp(ctx.lpc_mem + RX_BUFFER_DATA, &msg[MCTP_BTU], MCTP_BTU));
+	astlpc_assert_tx_packet(&ctx.bmc, &msg[MCTP_BTU], MCTP_BTU);
 
 	network_destroy(&ctx);
 }