smbd: Use leases_db in lease_match()
[gd/samba-autobuild/.git] / lib / torture / subunit.c
index 0b63cca0536ac1bf1af8cec593d43cb5077bd14a..deb96ffa3a983d128d6bfdbe3ab78215858730b8 100644 (file)
 
 #include "includes.h"
 #include "lib/torture/torture.h"
-#include <subunit/child.h>
+
+static void subunit_send_event(char const * const event,
+               char const * const name,
+               char const * const details)
+{
+       if (NULL == details) {
+               printf("%s: %s\n", event, name);
+       } else {
+               printf("%s: %s [\n", event, name);
+               printf("%s", details);
+               if (details[strlen(details) - 1] != '\n')
+                       puts("");
+               puts("]");
+       }
+       fflush(stdout);
+}
 
 static void torture_subunit_suite_start(struct torture_context *ctx,
                                struct torture_suite *suite)
@@ -37,12 +52,37 @@ static char *torture_subunit_test_name(struct torture_context *ctx,
        }
 }
 
-static void torture_subunit_test_start(struct torture_context *ctx, 
+static void torture_subunit_report_time(struct torture_context *tctx)
+{
+       struct timespec tp;
+       struct tm *tmp;
+       char timestr[200];
+       if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
+               perror("clock_gettime");
+               return;
+       }
+
+       tmp = gmtime(&tp.tv_sec);
+       if (!tmp) {
+               perror("gmtime");
+               return;
+       }
+
+       if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
+               perror("strftime");
+               return;
+       }
+
+       printf("time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
+}
+
+static void torture_subunit_test_start(struct torture_context *context, 
                               struct torture_tcase *tcase,
                               struct torture_test *test)
 {
-       char *fullname = torture_subunit_test_name(ctx, ctx->active_tcase, ctx->active_test);
-       subunit_test_start(fullname);
+       char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
+       subunit_send_event("test", fullname, NULL);
+       torture_subunit_report_time(context);
        talloc_free(fullname);
 }
 
@@ -50,20 +90,23 @@ static void torture_subunit_test_result(struct torture_context *context,
                                enum torture_result res, const char *reason)
 {
        char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
+       const char *result_str = "unknown";
+       torture_subunit_report_time(context);
        switch (res) {
        case TORTURE_OK:
-               subunit_test_pass(fullname);
+               result_str = "success";
                break;
        case TORTURE_FAIL:
-               subunit_test_fail(fullname, reason);
+               result_str = "failure";
                break;
        case TORTURE_ERROR:
-               subunit_test_error(fullname, reason);
+               result_str = "error";
                break;
        case TORTURE_SKIP:
-               subunit_test_skip(fullname, reason);
+               result_str = "skip";
                break;
        }
+       subunit_send_event(result_str, fullname, reason);
        talloc_free(fullname);
 }
 
@@ -107,4 +150,5 @@ const struct torture_ui_ops torture_subunit_ui_ops = {
        .test_result = torture_subunit_test_result,
        .suite_start = torture_subunit_suite_start,
        .progress = torture_subunit_progress,
+       .report_time = torture_subunit_report_time,
 };