+static int
+exec_and_report_test(const struct weston_test *t, void *test_data, int iteration)
+{
+ int success = 0;
+ int hardfail = 0;
+ siginfo_t info;
+
+ pid_t pid = fork();
+ assert(pid >= 0);
+
+ if (pid == 0)
+ run_test(t, test_data); /* never returns */
+
+ if (waitid(P_ALL, 0, &info, WEXITED)) {
+ fprintf(stderr, "waitid failed: %m\n");
+ abort();
+ }
+
+ if (test_data)
+ fprintf(stderr, "test \"%s/%i\":\t", t->name, iteration);
+ else
+ fprintf(stderr, "test \"%s\":\t", t->name);
+
+ switch (info.si_code) {
+ case CLD_EXITED:
+ fprintf(stderr, "exit status %d", info.si_status);
+ if (info.si_status == EXIT_SUCCESS)
+ success = 1;
+ break;
+ case CLD_KILLED:
+ case CLD_DUMPED:
+ fprintf(stderr, "signal %d", info.si_status);
+ if (info.si_status != SIGABRT)
+ hardfail = 1;
+ break;
+ }
+
+ if (t->must_fail)
+ success = !success;
+
+ if (success && !hardfail) {
+ fprintf(stderr, ", pass.\n");
+ return 1;
+ } else {
+ fprintf(stderr, ", fail.\n");
+ return 0;
+ }
+}
+
+/* Returns number of tests and number of pass / fail in param args */
+static int
+iterate_test(const struct weston_test *t, int *passed)
+{
+ int i;
+ void *current_test_data = (void *) t->table_data;
+ for (i = 0; i < t->n_elements; ++i, current_test_data += t->element_size)
+ {
+ if (exec_and_report_test(t, current_test_data, i))
+ ++(*passed);
+ }
+
+ return t->n_elements;
+}
+