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/>.
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
);
30 printf("%s: %s [\n", event
, name
);
31 printf("%s", details
);
32 if (details
[strlen(details
) - 1] != '\n')
39 static void torture_subunit_suite_start(struct torture_context
*ctx
,
40 struct torture_suite
*suite
)
44 static char *torture_subunit_test_name(struct torture_context
*ctx
,
45 struct torture_tcase
*tcase
,
46 struct torture_test
*test
)
48 if (!strcmp(tcase
->name
, test
->name
)) {
49 return talloc_strdup(ctx
, test
->name
);
51 return talloc_asprintf(ctx
, "%s.%s", tcase
->name
, test
->name
);
55 static void torture_subunit_report_time(struct torture_context
*tctx
)
60 if (clock_gettime(CLOCK_REALTIME
, &tp
) != 0) {
61 perror("clock_gettime");
65 tmp
= localtime(&tp
.tv_sec
);
71 if (strftime(timestr
, sizeof(timestr
), "%Y-%m-%d %H:%M:%S", tmp
) <= 0) {
76 printf("time: %s.%06ld\n", timestr
, tp
.tv_nsec
/ 1000);
79 static void torture_subunit_test_start(struct torture_context
*context
,
80 struct torture_tcase
*tcase
,
81 struct torture_test
*test
)
83 char *fullname
= torture_subunit_test_name(context
, context
->active_tcase
, context
->active_test
);
84 subunit_send_event("test", fullname
, NULL
);
85 torture_subunit_report_time(context
);
86 talloc_free(fullname
);
89 static void torture_subunit_test_result(struct torture_context
*context
,
90 enum torture_result res
, const char *reason
)
92 char *fullname
= torture_subunit_test_name(context
, context
->active_tcase
, context
->active_test
);
93 const char *result_str
= "unknown";
94 torture_subunit_report_time(context
);
97 result_str
= "success";
100 result_str
= "failure";
103 result_str
= "error";
109 subunit_send_event(result_str
, fullname
, reason
);
110 talloc_free(fullname
);
113 static void torture_subunit_comment(struct torture_context
*test
,
116 fprintf(stderr
, "%s", comment
);
119 static void torture_subunit_warning(struct torture_context
*test
,
122 fprintf(stderr
, "WARNING!: %s\n", comment
);
125 static void torture_subunit_progress(struct torture_context
*tctx
, int offset
, enum torture_progress_whence whence
)
128 case TORTURE_PROGRESS_SET
:
129 printf("progress: %d\n", offset
);
131 case TORTURE_PROGRESS_CUR
:
132 printf("progress: %+-d\n", offset
);
134 case TORTURE_PROGRESS_POP
:
135 printf("progress: pop\n");
137 case TORTURE_PROGRESS_PUSH
:
138 printf("progress: push\n");
141 fprintf(stderr
, "Invalid call to progress()\n");
146 const struct torture_ui_ops torture_subunit_ui_ops
= {
147 .comment
= torture_subunit_comment
,
148 .warning
= torture_subunit_warning
,
149 .test_start
= torture_subunit_test_start
,
150 .test_result
= torture_subunit_test_result
,
151 .suite_start
= torture_subunit_suite_start
,
152 .progress
= torture_subunit_progress
,
153 .report_time
= torture_subunit_report_time
,