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"
22 #include <subunit/child.h>
24 static void torture_subunit_suite_start(struct torture_context
*ctx
,
25 struct torture_suite
*suite
)
29 static char *torture_subunit_test_name(struct torture_context
*ctx
,
30 struct torture_tcase
*tcase
,
31 struct torture_test
*test
)
33 if (!strcmp(tcase
->name
, test
->name
)) {
34 return talloc_strdup(ctx
, test
->name
);
36 return talloc_asprintf(ctx
, "%s.%s", tcase
->name
, test
->name
);
40 static void torture_subunit_report_time(struct torture_context
*tctx
)
45 if (clock_gettime(CLOCK_REALTIME
, &tp
) != 0) {
46 perror("clock_gettime");
50 tmp
= localtime(&tp
.tv_sec
);
56 if (strftime(timestr
, sizeof(timestr
), "%Y-%m-%d %H:%M:%S", tmp
) <= 0) {
61 printf("time: %s.%06ld\n", timestr
, tp
.tv_nsec
/ 1000);
64 static void torture_subunit_test_start(struct torture_context
*context
,
65 struct torture_tcase
*tcase
,
66 struct torture_test
*test
)
68 char *fullname
= torture_subunit_test_name(context
, context
->active_tcase
, context
->active_test
);
69 subunit_test_start(fullname
);
70 torture_subunit_report_time(context
);
71 talloc_free(fullname
);
74 static void torture_subunit_test_result(struct torture_context
*context
,
75 enum torture_result res
, const char *reason
)
77 char *fullname
= torture_subunit_test_name(context
, context
->active_tcase
, context
->active_test
);
78 torture_subunit_report_time(context
);
81 subunit_test_pass(fullname
);
84 subunit_test_fail(fullname
, reason
);
87 subunit_test_error(fullname
, reason
);
90 subunit_test_skip(fullname
, reason
);
93 talloc_free(fullname
);
96 static void torture_subunit_comment(struct torture_context
*test
,
99 fprintf(stderr
, "%s", comment
);
102 static void torture_subunit_warning(struct torture_context
*test
,
105 fprintf(stderr
, "WARNING!: %s\n", comment
);
108 static void torture_subunit_progress(struct torture_context
*tctx
, int offset
, enum torture_progress_whence whence
)
111 case TORTURE_PROGRESS_SET
:
112 printf("progress: %d\n", offset
);
114 case TORTURE_PROGRESS_CUR
:
115 printf("progress: %+-d\n", offset
);
117 case TORTURE_PROGRESS_POP
:
118 printf("progress: pop\n");
120 case TORTURE_PROGRESS_PUSH
:
121 printf("progress: push\n");
124 fprintf(stderr
, "Invalid call to progress()\n");
129 const struct torture_ui_ops torture_subunit_ui_ops
= {
130 .comment
= torture_subunit_comment
,
131 .warning
= torture_subunit_warning
,
132 .test_start
= torture_subunit_test_start
,
133 .test_result
= torture_subunit_test_result
,
134 .suite_start
= torture_subunit_suite_start
,
135 .progress
= torture_subunit_progress
,
136 .report_time
= torture_subunit_report_time
,