smbd: Remove "st" from struct open_symlink_err
[Samba.git] / lib / torture / subunit.c
blob693d9038bba8617231bc473306ed8af79e228a49
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "lib/torture/torture.h"
23 static void subunit_send_event(char const * const event,
24 char const * const name,
25 char const * const details)
27 if (NULL == details) {
28 printf("%s: %s\n", event, name);
29 } else {
30 printf("%s: %s [\n", event, name);
31 printf("%s", details);
32 if (details[strlen(details) - 1] != '\n')
33 puts("");
34 puts("]");
36 fflush(stdout);
39 static void torture_subunit_suite_start(struct torture_context *ctx,
40 struct torture_suite *suite)
44 static void torture_subunit_report_time(struct torture_context *tctx)
46 struct timespec tp;
47 struct tm *tmp;
48 char timestr[200];
49 if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
50 perror("clock_gettime");
51 return;
54 tmp = gmtime(&tp.tv_sec);
55 if (!tmp) {
56 perror("gmtime");
57 return;
60 if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
61 perror("strftime");
62 return;
65 printf("time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
68 static void torture_subunit_test_start(struct torture_context *context,
69 struct torture_tcase *tcase,
70 struct torture_test *test)
72 char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
73 subunit_send_event("test", fullname, NULL);
74 torture_subunit_report_time(context);
75 talloc_free(fullname);
78 static void torture_subunit_test_result(struct torture_context *context,
79 enum torture_result res, const char *reason)
81 char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
82 const char *result_str = "unknown";
83 torture_subunit_report_time(context);
84 switch (res) {
85 case TORTURE_OK:
86 result_str = "success";
87 break;
88 case TORTURE_FAIL:
89 result_str = "failure";
90 break;
91 case TORTURE_ERROR:
92 result_str = "error";
93 break;
94 case TORTURE_SKIP:
95 result_str = "skip";
96 break;
98 subunit_send_event(result_str, fullname, reason);
99 talloc_free(fullname);
102 static void torture_subunit_comment(struct torture_context *test,
103 const char *comment)
105 fprintf(stderr, "%s", comment);
108 static void torture_subunit_warning(struct torture_context *test,
109 const char *comment)
111 fprintf(stderr, "WARNING!: %s\n", comment);
114 static void torture_subunit_progress(struct torture_context *tctx, int offset, enum torture_progress_whence whence)
116 switch (whence) {
117 case TORTURE_PROGRESS_SET:
118 printf("progress: %d\n", offset);
119 break;
120 case TORTURE_PROGRESS_CUR:
121 printf("progress: %+-d\n", offset);
122 break;
123 case TORTURE_PROGRESS_POP:
124 printf("progress: pop\n");
125 break;
126 case TORTURE_PROGRESS_PUSH:
127 printf("progress: push\n");
128 break;
129 default:
130 fprintf(stderr, "Invalid call to progress()\n");
131 break;
135 const struct torture_ui_ops torture_subunit_ui_ops = {
136 .comment = torture_subunit_comment,
137 .warning = torture_subunit_warning,
138 .test_start = torture_subunit_test_start,
139 .test_result = torture_subunit_test_result,
140 .suite_start = torture_subunit_suite_start,
141 .progress = torture_subunit_progress,
142 .report_time = torture_subunit_report_time,