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 void torture_subunit_report_time(struct torture_context
*tctx
)
49 if (clock_gettime(CLOCK_REALTIME
, &tp
) != 0) {
50 perror("clock_gettime");
54 tmp
= gmtime(&tp
.tv_sec
);
60 if (strftime(timestr
, sizeof(timestr
), "%Y-%m-%d %H:%M:%S", tmp
) <= 0) {
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
);
86 result_str
= "success";
89 result_str
= "failure";
98 subunit_send_event(result_str
, fullname
, reason
);
99 talloc_free(fullname
);
102 static void torture_subunit_comment(struct torture_context
*test
,
105 fprintf(stderr
, "%s", comment
);
108 static void torture_subunit_warning(struct torture_context
*test
,
111 fprintf(stderr
, "WARNING!: %s\n", comment
);
114 static void torture_subunit_progress(struct torture_context
*tctx
, int offset
, enum torture_progress_whence whence
)
117 case TORTURE_PROGRESS_SET
:
118 printf("progress: %d\n", offset
);
120 case TORTURE_PROGRESS_CUR
:
121 printf("progress: %+-d\n", offset
);
123 case TORTURE_PROGRESS_POP
:
124 printf("progress: pop\n");
126 case TORTURE_PROGRESS_PUSH
:
127 printf("progress: push\n");
130 fprintf(stderr
, "Invalid call to progress()\n");
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
,