1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | Samba utility functions
|
---|
4 | Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 | #include "lib/torture/torture.h"
|
---|
22 | #include <subunit/child.h>
|
---|
23 |
|
---|
24 | static void torture_subunit_suite_start(struct torture_context *ctx,
|
---|
25 | struct torture_suite *suite)
|
---|
26 | {
|
---|
27 | }
|
---|
28 |
|
---|
29 | static char *torture_subunit_test_name(struct torture_context *ctx,
|
---|
30 | struct torture_tcase *tcase,
|
---|
31 | struct torture_test *test)
|
---|
32 | {
|
---|
33 | if (!strcmp(tcase->name, test->name)) {
|
---|
34 | return talloc_strdup(ctx, test->name);
|
---|
35 | } else {
|
---|
36 | return talloc_asprintf(ctx, "%s.%s", tcase->name, test->name);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | static void torture_subunit_report_time(struct torture_context *tctx)
|
---|
41 | {
|
---|
42 | struct timespec tp;
|
---|
43 | struct tm *tmp;
|
---|
44 | char timestr[200];
|
---|
45 | if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
|
---|
46 | perror("clock_gettime");
|
---|
47 | return;
|
---|
48 | }
|
---|
49 |
|
---|
50 | tmp = localtime(&tp.tv_sec);
|
---|
51 | if (!tmp) {
|
---|
52 | perror("localtime");
|
---|
53 | return;
|
---|
54 | }
|
---|
55 |
|
---|
56 | if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
|
---|
57 | perror("strftime");
|
---|
58 | return;
|
---|
59 | }
|
---|
60 |
|
---|
61 | printf("time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
|
---|
62 | }
|
---|
63 |
|
---|
64 | static void torture_subunit_test_start(struct torture_context *context,
|
---|
65 | struct torture_tcase *tcase,
|
---|
66 | struct torture_test *test)
|
---|
67 | {
|
---|
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);
|
---|
72 | }
|
---|
73 |
|
---|
74 | static void torture_subunit_test_result(struct torture_context *context,
|
---|
75 | enum torture_result res, const char *reason)
|
---|
76 | {
|
---|
77 | char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
|
---|
78 | torture_subunit_report_time(context);
|
---|
79 | switch (res) {
|
---|
80 | case TORTURE_OK:
|
---|
81 | subunit_test_pass(fullname);
|
---|
82 | break;
|
---|
83 | case TORTURE_FAIL:
|
---|
84 | subunit_test_fail(fullname, reason);
|
---|
85 | break;
|
---|
86 | case TORTURE_ERROR:
|
---|
87 | subunit_test_error(fullname, reason);
|
---|
88 | break;
|
---|
89 | case TORTURE_SKIP:
|
---|
90 | subunit_test_skip(fullname, reason);
|
---|
91 | break;
|
---|
92 | }
|
---|
93 | talloc_free(fullname);
|
---|
94 | }
|
---|
95 |
|
---|
96 | static void torture_subunit_comment(struct torture_context *test,
|
---|
97 | const char *comment)
|
---|
98 | {
|
---|
99 | fprintf(stderr, "%s", comment);
|
---|
100 | }
|
---|
101 |
|
---|
102 | static void torture_subunit_warning(struct torture_context *test,
|
---|
103 | const char *comment)
|
---|
104 | {
|
---|
105 | fprintf(stderr, "WARNING!: %s\n", comment);
|
---|
106 | }
|
---|
107 |
|
---|
108 | static void torture_subunit_progress(struct torture_context *tctx, int offset, enum torture_progress_whence whence)
|
---|
109 | {
|
---|
110 | switch (whence) {
|
---|
111 | case TORTURE_PROGRESS_SET:
|
---|
112 | printf("progress: %d\n", offset);
|
---|
113 | break;
|
---|
114 | case TORTURE_PROGRESS_CUR:
|
---|
115 | printf("progress: %+-d\n", offset);
|
---|
116 | break;
|
---|
117 | case TORTURE_PROGRESS_POP:
|
---|
118 | printf("progress: pop\n");
|
---|
119 | break;
|
---|
120 | case TORTURE_PROGRESS_PUSH:
|
---|
121 | printf("progress: push\n");
|
---|
122 | break;
|
---|
123 | default:
|
---|
124 | fprintf(stderr, "Invalid call to progress()\n");
|
---|
125 | break;
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
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,
|
---|
137 | };
|
---|