smbd: Use leases_db in lease_match()
[gd/samba-autobuild/.git] / lib / torture / subunit.c
index d5ee344596fb5a9cece742f52f80f7853a3a3afc..deb96ffa3a983d128d6bfdbe3ab78215858730b8 100644 (file)
 #include "includes.h"
 #include "lib/torture/torture.h"
 
-static void subunit_init(struct torture_results *results) 
+static void subunit_send_event(char const * const event,
+               char const * const name,
+               char const * const details)
 {
-       /* FIXME: register segv and bus handler */
+       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 subunit_suite_start(struct torture_context *ctx,
+static void torture_subunit_suite_start(struct torture_context *ctx,
                                struct torture_suite *suite)
 {
 }
 
-static void subunit_print_testname(struct torture_context *ctx, 
+static char *torture_subunit_test_name(struct torture_context *ctx,
                                   struct torture_tcase *tcase,
                                   struct torture_test *test)
 {
        if (!strcmp(tcase->name, test->name)) {
-               printf("%s", test->name);
+               return talloc_strdup(ctx, test->name);
        } else {
-               printf("%s.%s", tcase->name, test->name);
+               return talloc_asprintf(ctx, "%s.%s", tcase->name, test->name);
+       }
+}
+
+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 subunit_test_start(struct torture_context *ctx
+static void torture_subunit_test_start(struct torture_context *context
                               struct torture_tcase *tcase,
                               struct torture_test *test)
 {
-       printf("test: ");
-       subunit_print_testname(ctx, tcase, test);       
-       printf("\n");
+       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);
 }
 
-static void subunit_test_result(struct torture_context *context, 
+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:
-               printf("success: ");
+               result_str = "success";
                break;
        case TORTURE_FAIL:
-               printf("failure: ");
+               result_str = "failure";
                break;
        case TORTURE_ERROR:
-               printf("error: ");
+               result_str = "error";
                break;
        case TORTURE_SKIP:
-               printf("skip: ");
+               result_str = "skip";
                break;
        }
-       subunit_print_testname(context, context->active_tcase, context->active_test);   
-
-       if (reason)
-               printf(" [\n%s\n]", reason);
-       printf("\n");
+       subunit_send_event(result_str, fullname, reason);
+       talloc_free(fullname);
 }
 
-static void subunit_comment(struct torture_context *test,
+static void torture_subunit_comment(struct torture_context *test,
                            const char *comment)
 {
        fprintf(stderr, "%s", comment);
 }
 
-static void subunit_warning(struct torture_context *test,
+static void torture_subunit_warning(struct torture_context *test,
                            const char *comment)
 {
        fprintf(stderr, "WARNING!: %s\n", comment);
 }
 
+static void torture_subunit_progress(struct torture_context *tctx, int offset, enum torture_progress_whence whence)
+{
+       switch (whence) {
+       case TORTURE_PROGRESS_SET:
+               printf("progress: %d\n", offset);
+               break;
+       case TORTURE_PROGRESS_CUR:
+               printf("progress: %+-d\n", offset);
+               break;
+       case TORTURE_PROGRESS_POP:
+               printf("progress: pop\n");
+               break;
+       case TORTURE_PROGRESS_PUSH:
+               printf("progress: push\n");
+               break;
+       default:
+               fprintf(stderr, "Invalid call to progress()\n");
+               break;
+       }
+}
+
 const struct torture_ui_ops torture_subunit_ui_ops = {
-       .init = subunit_init,
-       .comment = subunit_comment,
-       .warning = subunit_warning,
-       .test_start = subunit_test_start,
-       .test_result = subunit_test_result,
-       .suite_start = subunit_suite_start
+       .comment = torture_subunit_comment,
+       .warning = torture_subunit_warning,
+       .test_start = torture_subunit_test_start,
+       .test_result = torture_subunit_test_result,
+       .suite_start = torture_subunit_suite_start,
+       .progress = torture_subunit_progress,
+       .report_time = torture_subunit_report_time,
 };