tests: Add simple test infrastructure

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/Makefile b/Makefile
index 86b6c2f..bdfe6a0 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,22 @@
 utils/%: utils/%.o libmctp.a
 	$(LINK.o) -o $@ $^
 
+test_util_objs = tests/test-utils.o
+
+tests =
+
+test_targets = $(tests:%=tests/%)
+
+$(test_targets): $(test_util_objs) libmctp.a
+
+$(test_targets): %: %.o
+	$(LINK.o) -o $@ $^
+
+check: $(test_targets)
+	for t in $(test_targets); do echo $$t; $$t || exit 1; done
+
+.PHONY: check
+
 clean:
 	rm -f $(LIBMCTP)
 	rm -f $(LIBMCTP_OBJS)
diff --git a/tests/test-utils.c b/tests/test-utils.c
new file mode 100644
index 0000000..205393c
--- /dev/null
+++ b/tests/test-utils.c
@@ -0,0 +1,61 @@
+
+#include <string.h>
+#include <assert.h>
+
+#include <libmctp.h>
+#include <libmctp-alloc.h>
+
+#include "test-utils.h"
+
+struct mctp_binding_test {
+	struct mctp_binding	binding;
+};
+
+static int mctp_binding_test_tx(struct mctp_binding *b __attribute__((unused)),
+		struct mctp_pktbuf *pkt __attribute__((unused)))
+{
+	/* we are not expecting TX packets */
+	assert(0);
+}
+
+struct mctp_binding_test *mctp_binding_test_init(void)
+{
+	struct mctp_binding_test *test;
+
+	test = __mctp_alloc(sizeof(*test));
+	test->binding.name = "test";
+	test->binding.version = 1;
+	test->binding.tx = mctp_binding_test_tx;
+	return test;
+}
+
+void mctp_binding_test_rx_raw(struct mctp_binding_test *test,
+		void *buf, size_t len)
+{
+	struct mctp_pktbuf *pkt;
+
+	pkt = mctp_pktbuf_alloc(len);
+	assert(pkt);
+	memcpy(mctp_pktbuf_hdr(pkt), buf, len);
+	mctp_bus_rx(&test->binding, pkt);
+	mctp_pktbuf_free(pkt);
+}
+
+void mctp_binding_test_register_bus(struct mctp_binding_test *binding,
+		struct mctp *mctp, mctp_eid_t eid)
+{
+	mctp_register_bus(mctp, &binding->binding, eid);
+}
+
+void mctp_test_stack_init(struct mctp **mctp,
+		struct mctp_binding_test **binding,
+		mctp_eid_t eid)
+{
+	*mctp = mctp_init();
+	assert(*mctp);
+
+	*binding = mctp_binding_test_init();
+	assert(*binding);
+
+	mctp_binding_test_register_bus(*binding, *mctp, eid);
+}
diff --git a/tests/test-utils.h b/tests/test-utils.h
new file mode 100644
index 0000000..b565876
--- /dev/null
+++ b/tests/test-utils.h
@@ -0,0 +1,24 @@
+#ifndef _MCTP_TESTS_TEST_UTILS_H
+#define _MCTP_TESTS_TEST_UTILS_H
+
+#include <libmctp.h>
+
+/* test binding implementation */
+
+/* standard binding interface */
+struct mctp_binding_test *mctp_binding_test_init(void);
+void mctp_binding_test_register_bus(struct mctp_binding_test *binding,
+		struct mctp *mctp, mctp_eid_t eid);
+
+/* internal test binding interface */
+void mctp_binding_test_rx_raw(struct mctp_binding_test *test,
+		void *buf, size_t len);
+
+/* gerneral utility functions */
+
+/* create a MCTP stack, and add a test binding, using the specified EID */
+void mctp_test_stack_init(struct mctp **mctp,
+		struct mctp_binding_test **binding,
+		mctp_eid_t eid);
+
+#endif /* _MCTP_TESTS_TEST_UTILS_H */