+static void register_test(struct list_head *h, struct ccanlint *test, ...)
+{
+ va_list ap;
+ struct ccanlint *depends;
+ struct dependent *dchild;
+
+ list_add(h, &test->list);
+
+ va_start(ap, test);
+ /* Careful: we might have been initialized by a dependent. */
+ if (test->dependencies.n.next == NULL)
+ list_head_init(&test->dependencies);
+
+ //dependent(s) args (if any), last one is NULL
+ while ((depends = va_arg(ap, struct ccanlint *)) != NULL) {
+ dchild = malloc(sizeof(*dchild));
+ dchild->dependent = test;
+ /* The thing we depend on might not be initialized yet! */
+ if (depends->dependencies.n.next == NULL)
+ list_head_init(&depends->dependencies);
+ list_add_tail(&depends->dependencies, &dchild->node);
+ test->num_depends++;
+ }
+ va_end(ap);
+}
+
+/**
+ * get_next_test - retrieves the next test to be processed
+ **/
+static inline struct ccanlint *get_next_test(struct list_head *test)
+{
+ struct ccanlint *i;
+
+ if (list_empty(test))
+ return NULL;
+
+ list_for_each(test, i, list) {
+ if (i->num_depends == 0)
+ return i;
+ }
+ errx(1, "Can't make process; test dependency cycle");
+}
+
+static void init_tests(void)
+{
+ const struct ccanlint *i;
+
+#undef REGISTER_TEST
+#define REGISTER_TEST(name, ...) register_test(&normal_tests, &name, __VA_ARGS__)
+#include "generated-normal-tests"
+#undef REGISTER_TEST
+#define REGISTER_TEST(name, ...) register_test(&compulsory_tests, &name, __VA_ARGS__)
+#include "generated-compulsory-tests"
+
+ if (!verbose)
+ return;
+
+ printf("\nCompulsory Tests\n");
+ list_for_each(&compulsory_tests, i, list) {
+ printf("%s depends on %u others\n", i->name, i->num_depends);
+ if (!list_empty(&i->dependencies)) {
+ const struct dependent *d;
+ printf("These depend on us:\n");
+ list_for_each(&i->dependencies, d, node)
+ printf("\t%s\n", d->dependent->name);
+ }
+ }
+
+ printf("\nNormal Tests\n");
+ list_for_each(&normal_tests, i, list) {
+ printf("%s depends on %u others\n", i->name, i->num_depends);
+ if (!list_empty(&i->dependencies)) {
+ const struct dependent *d;
+ printf("These depend on us:\n");
+ list_for_each(&i->dependencies, d, node)
+ printf("\t%s\n", d->dependent->name);
+ }
+ }
+}
+