1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | SMB torture UI functions
|
---|
4 |
|
---|
5 | Copyright (C) Jelmer Vernooij 2006-2008
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 3 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "source4/include/includes.h"
|
---|
22 | #include "../torture/torture.h"
|
---|
23 | #include "../lib/util/dlinklist.h"
|
---|
24 | #include "param/param.h"
|
---|
25 | #include "system/filesys.h"
|
---|
26 | #include "system/dir.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops)
|
---|
30 | {
|
---|
31 | struct torture_results *results = talloc_zero(mem_ctx, struct torture_results);
|
---|
32 |
|
---|
33 | results->ui_ops = ui_ops;
|
---|
34 | results->returncode = true;
|
---|
35 |
|
---|
36 | if (ui_ops->init)
|
---|
37 | ui_ops->init(results);
|
---|
38 |
|
---|
39 | return results;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Initialize a torture context
|
---|
44 | */
|
---|
45 | struct torture_context *torture_context_init(struct tevent_context *event_ctx,
|
---|
46 | struct torture_results *results)
|
---|
47 | {
|
---|
48 | struct torture_context *torture = talloc_zero(event_ctx,
|
---|
49 | struct torture_context);
|
---|
50 |
|
---|
51 | if (torture == NULL)
|
---|
52 | return NULL;
|
---|
53 |
|
---|
54 | torture->ev = event_ctx;
|
---|
55 | torture->results = talloc_reference(torture, results);
|
---|
56 |
|
---|
57 | return torture;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Create a sub torture context
|
---|
62 | */
|
---|
63 | struct torture_context *torture_context_child(struct torture_context *parent)
|
---|
64 | {
|
---|
65 | struct torture_context *subtorture = talloc_zero(parent, struct torture_context);
|
---|
66 |
|
---|
67 | if (subtorture == NULL)
|
---|
68 | return NULL;
|
---|
69 |
|
---|
70 | subtorture->ev = talloc_reference(subtorture, parent->ev);
|
---|
71 | subtorture->lp_ctx = talloc_reference(subtorture, parent->lp_ctx);
|
---|
72 | subtorture->outputdir = talloc_reference(subtorture, parent->outputdir);
|
---|
73 | subtorture->results = talloc_reference(subtorture, parent->results);
|
---|
74 |
|
---|
75 | return subtorture;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | create a temporary directory under the output dir
|
---|
80 | */
|
---|
81 | _PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx,
|
---|
82 | const char *prefix, char **tempdir)
|
---|
83 | {
|
---|
84 | SMB_ASSERT(tctx->outputdir != NULL);
|
---|
85 |
|
---|
86 | *tempdir = talloc_asprintf(tctx, "%s/%s.XXXXXX", tctx->outputdir,
|
---|
87 | prefix);
|
---|
88 | NT_STATUS_HAVE_NO_MEMORY(*tempdir);
|
---|
89 |
|
---|
90 | if (mkdtemp(*tempdir) == NULL) {
|
---|
91 | return map_nt_error_from_unix(errno);
|
---|
92 | }
|
---|
93 |
|
---|
94 | return NT_STATUS_OK;
|
---|
95 | }
|
---|
96 |
|
---|
97 | static int local_deltree(const char *path)
|
---|
98 | {
|
---|
99 | int ret = 0;
|
---|
100 | struct dirent *dirent;
|
---|
101 | DIR *dir = opendir(path);
|
---|
102 | if (!dir) {
|
---|
103 | char *error = talloc_asprintf(NULL, "Could not open directory %s", path);
|
---|
104 | perror(error);
|
---|
105 | talloc_free(error);
|
---|
106 | return -1;
|
---|
107 | }
|
---|
108 | while ((dirent = readdir(dir))) {
|
---|
109 | char *name;
|
---|
110 | if ((strcmp(dirent->d_name, ".") == 0) || (strcmp(dirent->d_name, "..") == 0)) {
|
---|
111 | continue;
|
---|
112 | }
|
---|
113 | name = talloc_asprintf(NULL, "%s/%s", path,
|
---|
114 | dirent->d_name);
|
---|
115 | if (name == NULL) {
|
---|
116 | closedir(dir);
|
---|
117 | return -1;
|
---|
118 | }
|
---|
119 | DEBUG(0, ("About to remove %s\n", name));
|
---|
120 | ret = remove(name);
|
---|
121 | if (ret == 0) {
|
---|
122 | talloc_free(name);
|
---|
123 | continue;
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (errno == ENOTEMPTY) {
|
---|
127 | ret = local_deltree(name);
|
---|
128 | if (ret == 0) {
|
---|
129 | ret = remove(name);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | talloc_free(name);
|
---|
133 | if (ret != 0) {
|
---|
134 | char *error = talloc_asprintf(NULL, "Could not remove %s", path);
|
---|
135 | perror(error);
|
---|
136 | talloc_free(error);
|
---|
137 | break;
|
---|
138 | }
|
---|
139 | }
|
---|
140 | closedir(dir);
|
---|
141 | rmdir(path);
|
---|
142 | return ret;
|
---|
143 | }
|
---|
144 |
|
---|
145 | _PUBLIC_ NTSTATUS torture_deltree_outputdir(struct torture_context *tctx)
|
---|
146 | {
|
---|
147 | if (tctx->outputdir == NULL) {
|
---|
148 | return NT_STATUS_OK;
|
---|
149 | }
|
---|
150 | if ((strcmp(tctx->outputdir, "/") == 0)
|
---|
151 | || (strcmp(tctx->outputdir, "") == 0)) {
|
---|
152 | return NT_STATUS_INVALID_PARAMETER;
|
---|
153 | }
|
---|
154 |
|
---|
155 | if (local_deltree(tctx->outputdir) == -1) {
|
---|
156 | if (errno != 0) {
|
---|
157 | return map_nt_error_from_unix(errno);
|
---|
158 | }
|
---|
159 | return NT_STATUS_UNSUCCESSFUL;
|
---|
160 | }
|
---|
161 | return NT_STATUS_OK;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Comment on the status/progress of a test
|
---|
166 | */
|
---|
167 | void torture_comment(struct torture_context *context, const char *comment, ...)
|
---|
168 | {
|
---|
169 | va_list ap;
|
---|
170 | char *tmp;
|
---|
171 |
|
---|
172 | if (!context->results->ui_ops->comment)
|
---|
173 | return;
|
---|
174 |
|
---|
175 | va_start(ap, comment);
|
---|
176 | tmp = talloc_vasprintf(context, comment, ap);
|
---|
177 | va_end(ap);
|
---|
178 |
|
---|
179 | context->results->ui_ops->comment(context, tmp);
|
---|
180 |
|
---|
181 | talloc_free(tmp);
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Print a warning about the current test
|
---|
186 | */
|
---|
187 | void torture_warning(struct torture_context *context, const char *comment, ...)
|
---|
188 | {
|
---|
189 | va_list ap;
|
---|
190 | char *tmp;
|
---|
191 |
|
---|
192 | if (!context->results->ui_ops->warning)
|
---|
193 | return;
|
---|
194 |
|
---|
195 | va_start(ap, comment);
|
---|
196 | tmp = talloc_vasprintf(context, comment, ap);
|
---|
197 | va_end(ap);
|
---|
198 |
|
---|
199 | context->results->ui_ops->warning(context, tmp);
|
---|
200 |
|
---|
201 | talloc_free(tmp);
|
---|
202 | }
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Store the result of a torture test.
|
---|
206 | */
|
---|
207 | void torture_result(struct torture_context *context,
|
---|
208 | enum torture_result result, const char *fmt, ...)
|
---|
209 | {
|
---|
210 | va_list ap;
|
---|
211 |
|
---|
212 | va_start(ap, fmt);
|
---|
213 |
|
---|
214 | if (context->last_reason) {
|
---|
215 | torture_warning(context, "%s", context->last_reason);
|
---|
216 | talloc_free(context->last_reason);
|
---|
217 | }
|
---|
218 |
|
---|
219 | context->last_result = result;
|
---|
220 | context->last_reason = talloc_vasprintf(context, fmt, ap);
|
---|
221 | va_end(ap);
|
---|
222 | }
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Create a new torture suite
|
---|
226 | */
|
---|
227 | struct torture_suite *torture_suite_create(TALLOC_CTX *ctx, const char *name)
|
---|
228 | {
|
---|
229 | struct torture_suite *suite = talloc_zero(ctx, struct torture_suite);
|
---|
230 |
|
---|
231 | suite->name = talloc_strdup(suite, name);
|
---|
232 | suite->testcases = NULL;
|
---|
233 | suite->children = NULL;
|
---|
234 |
|
---|
235 | return suite;
|
---|
236 | }
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Set the setup() and teardown() functions for a testcase.
|
---|
240 | */
|
---|
241 | void torture_tcase_set_fixture(struct torture_tcase *tcase,
|
---|
242 | bool (*setup) (struct torture_context *, void **),
|
---|
243 | bool (*teardown) (struct torture_context *, void *))
|
---|
244 | {
|
---|
245 | tcase->setup = setup;
|
---|
246 | tcase->teardown = teardown;
|
---|
247 | }
|
---|
248 |
|
---|
249 | static bool wrap_test_with_testcase_const(struct torture_context *torture_ctx,
|
---|
250 | struct torture_tcase *tcase,
|
---|
251 | struct torture_test *test)
|
---|
252 | {
|
---|
253 | bool (*fn) (struct torture_context *,
|
---|
254 | const void *tcase_data,
|
---|
255 | const void *test_data);
|
---|
256 |
|
---|
257 | fn = test->fn;
|
---|
258 |
|
---|
259 | return fn(torture_ctx, tcase->data, test->data);
|
---|
260 | }
|
---|
261 |
|
---|
262 | /**
|
---|
263 | * Add a test that uses const data to a testcase
|
---|
264 | */
|
---|
265 | struct torture_test *torture_tcase_add_test_const(struct torture_tcase *tcase,
|
---|
266 | const char *name,
|
---|
267 | bool (*run) (struct torture_context *, const void *tcase_data,
|
---|
268 | const void *test_data),
|
---|
269 | const void *data)
|
---|
270 | {
|
---|
271 | struct torture_test *test = talloc(tcase, struct torture_test);
|
---|
272 |
|
---|
273 | test->name = talloc_strdup(test, name);
|
---|
274 | test->description = NULL;
|
---|
275 | test->run = wrap_test_with_testcase_const;
|
---|
276 | test->fn = run;
|
---|
277 | test->dangerous = false;
|
---|
278 | test->data = data;
|
---|
279 |
|
---|
280 | DLIST_ADD_END(tcase->tests, test, struct torture_test *);
|
---|
281 |
|
---|
282 | return test;
|
---|
283 | }
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Add a new testcase
|
---|
287 | */
|
---|
288 | bool torture_suite_init_tcase(struct torture_suite *suite,
|
---|
289 | struct torture_tcase *tcase,
|
---|
290 | const char *name)
|
---|
291 | {
|
---|
292 | tcase->name = talloc_strdup(tcase, name);
|
---|
293 | tcase->description = NULL;
|
---|
294 | tcase->setup = NULL;
|
---|
295 | tcase->teardown = NULL;
|
---|
296 | tcase->fixture_persistent = true;
|
---|
297 | tcase->tests = NULL;
|
---|
298 |
|
---|
299 | DLIST_ADD_END(suite->testcases, tcase, struct torture_tcase *);
|
---|
300 |
|
---|
301 | return true;
|
---|
302 | }
|
---|
303 |
|
---|
304 |
|
---|
305 | struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
|
---|
306 | const char *name)
|
---|
307 | {
|
---|
308 | struct torture_tcase *tcase = talloc(suite, struct torture_tcase);
|
---|
309 |
|
---|
310 | if (!torture_suite_init_tcase(suite, tcase, name))
|
---|
311 | return NULL;
|
---|
312 |
|
---|
313 | return tcase;
|
---|
314 | }
|
---|
315 |
|
---|
316 | int torture_suite_children_count(const struct torture_suite *suite)
|
---|
317 | {
|
---|
318 | int ret = 0;
|
---|
319 | struct torture_tcase *tcase;
|
---|
320 | struct torture_test *test;
|
---|
321 | struct torture_suite *tsuite;
|
---|
322 | for (tcase = suite->testcases; tcase; tcase = tcase->next) {
|
---|
323 | for (test = tcase->tests; test; test = test->next) {
|
---|
324 | ret++;
|
---|
325 | }
|
---|
326 | }
|
---|
327 | for (tsuite = suite->children; tsuite; tsuite = tsuite->next) {
|
---|
328 | ret ++;
|
---|
329 | }
|
---|
330 | return ret;
|
---|
331 | }
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Run a torture test suite.
|
---|
335 | */
|
---|
336 | bool torture_run_suite(struct torture_context *context,
|
---|
337 | struct torture_suite *suite)
|
---|
338 | {
|
---|
339 | return torture_run_suite_restricted(context, suite, NULL);
|
---|
340 | }
|
---|
341 |
|
---|
342 | bool torture_run_suite_restricted(struct torture_context *context,
|
---|
343 | struct torture_suite *suite, const char **restricted)
|
---|
344 | {
|
---|
345 | bool ret = true;
|
---|
346 | struct torture_tcase *tcase;
|
---|
347 | struct torture_suite *tsuite;
|
---|
348 |
|
---|
349 | if (context->results->ui_ops->suite_start)
|
---|
350 | context->results->ui_ops->suite_start(context, suite);
|
---|
351 |
|
---|
352 | /* FIXME: Adjust torture_suite_children_count if restricted != NULL */
|
---|
353 | context->results->ui_ops->progress(context,
|
---|
354 | torture_suite_children_count(suite), TORTURE_PROGRESS_SET);
|
---|
355 |
|
---|
356 | for (tcase = suite->testcases; tcase; tcase = tcase->next) {
|
---|
357 | ret &= torture_run_tcase_restricted(context, tcase, restricted);
|
---|
358 | }
|
---|
359 |
|
---|
360 | for (tsuite = suite->children; tsuite; tsuite = tsuite->next) {
|
---|
361 | context->results->ui_ops->progress(context, 0, TORTURE_PROGRESS_PUSH);
|
---|
362 | ret &= torture_run_suite_restricted(context, tsuite, restricted);
|
---|
363 | context->results->ui_ops->progress(context, 0, TORTURE_PROGRESS_POP);
|
---|
364 | }
|
---|
365 |
|
---|
366 | if (context->results->ui_ops->suite_finish)
|
---|
367 | context->results->ui_ops->suite_finish(context, suite);
|
---|
368 |
|
---|
369 | return ret;
|
---|
370 | }
|
---|
371 |
|
---|
372 | void torture_ui_test_start(struct torture_context *context,
|
---|
373 | struct torture_tcase *tcase,
|
---|
374 | struct torture_test *test)
|
---|
375 | {
|
---|
376 | if (context->results->ui_ops->test_start)
|
---|
377 | context->results->ui_ops->test_start(context, tcase, test);
|
---|
378 | }
|
---|
379 |
|
---|
380 | void torture_ui_test_result(struct torture_context *context,
|
---|
381 | enum torture_result result,
|
---|
382 | const char *comment)
|
---|
383 | {
|
---|
384 | if (context->results->ui_ops->test_result)
|
---|
385 | context->results->ui_ops->test_result(context, result, comment);
|
---|
386 |
|
---|
387 | if (result == TORTURE_ERROR || result == TORTURE_FAIL)
|
---|
388 | context->results->returncode = false;
|
---|
389 | }
|
---|
390 |
|
---|
391 | static bool test_needs_running(const char *name, const char **restricted)
|
---|
392 | {
|
---|
393 | int i;
|
---|
394 | if (restricted == NULL)
|
---|
395 | return true;
|
---|
396 | for (i = 0; restricted[i]; i++) {
|
---|
397 | if (!strcmp(name, restricted[i]))
|
---|
398 | return true;
|
---|
399 | }
|
---|
400 | return false;
|
---|
401 | }
|
---|
402 |
|
---|
403 | static bool internal_torture_run_test(struct torture_context *context,
|
---|
404 | struct torture_tcase *tcase,
|
---|
405 | struct torture_test *test,
|
---|
406 | bool already_setup,
|
---|
407 | const char **restricted)
|
---|
408 | {
|
---|
409 | bool success;
|
---|
410 | char *subunit_testname = NULL;
|
---|
411 |
|
---|
412 | if (tcase == NULL || strcmp(test->name, tcase->name) != 0) {
|
---|
413 | subunit_testname = talloc_asprintf(context, "%s.%s", tcase->name, test->name);
|
---|
414 | } else {
|
---|
415 | subunit_testname = talloc_strdup(context, test->name);
|
---|
416 | }
|
---|
417 |
|
---|
418 | if (!test_needs_running(subunit_testname, restricted))
|
---|
419 | return true;
|
---|
420 |
|
---|
421 | context->active_tcase = tcase;
|
---|
422 | context->active_test = test;
|
---|
423 |
|
---|
424 | torture_ui_test_start(context, tcase, test);
|
---|
425 |
|
---|
426 | context->last_reason = NULL;
|
---|
427 | context->last_result = TORTURE_OK;
|
---|
428 |
|
---|
429 | if (!already_setup && tcase->setup &&
|
---|
430 | !tcase->setup(context, &(tcase->data))) {
|
---|
431 | if (context->last_reason == NULL)
|
---|
432 | context->last_reason = talloc_strdup(context, "Setup failure");
|
---|
433 | context->last_result = TORTURE_ERROR;
|
---|
434 | success = false;
|
---|
435 | } else if (test->dangerous &&
|
---|
436 | !torture_setting_bool(context, "dangerous", false)) {
|
---|
437 | context->last_result = TORTURE_SKIP;
|
---|
438 | context->last_reason = talloc_asprintf(context,
|
---|
439 | "disabled %s - enable dangerous tests to use", test->name);
|
---|
440 | success = true;
|
---|
441 | } else {
|
---|
442 | success = test->run(context, tcase, test);
|
---|
443 |
|
---|
444 | if (!success && context->last_result == TORTURE_OK) {
|
---|
445 | if (context->last_reason == NULL)
|
---|
446 | context->last_reason = talloc_strdup(context, "Unknown error/failure");
|
---|
447 | context->last_result = TORTURE_ERROR;
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | if (!already_setup && tcase->teardown && !tcase->teardown(context, tcase->data)) {
|
---|
452 | if (context->last_reason == NULL)
|
---|
453 | context->last_reason = talloc_strdup(context, "Setup failure");
|
---|
454 | context->last_result = TORTURE_ERROR;
|
---|
455 | success = false;
|
---|
456 | }
|
---|
457 |
|
---|
458 | torture_ui_test_result(context, context->last_result,
|
---|
459 | context->last_reason);
|
---|
460 |
|
---|
461 | talloc_free(context->last_reason);
|
---|
462 |
|
---|
463 | context->active_test = NULL;
|
---|
464 | context->active_tcase = NULL;
|
---|
465 |
|
---|
466 | return success;
|
---|
467 | }
|
---|
468 |
|
---|
469 | bool torture_run_tcase(struct torture_context *context,
|
---|
470 | struct torture_tcase *tcase)
|
---|
471 | {
|
---|
472 | return torture_run_tcase_restricted(context, tcase, NULL);
|
---|
473 | }
|
---|
474 |
|
---|
475 | bool torture_run_tcase_restricted(struct torture_context *context,
|
---|
476 | struct torture_tcase *tcase, const char **restricted)
|
---|
477 | {
|
---|
478 | bool ret = true;
|
---|
479 | struct torture_test *test;
|
---|
480 | bool setup_succeeded = true;
|
---|
481 | const char * setup_reason = "Setup failed";
|
---|
482 |
|
---|
483 | context->active_tcase = tcase;
|
---|
484 | if (context->results->ui_ops->tcase_start)
|
---|
485 | context->results->ui_ops->tcase_start(context, tcase);
|
---|
486 |
|
---|
487 | if (tcase->fixture_persistent && tcase->setup) {
|
---|
488 | setup_succeeded = tcase->setup(context, &tcase->data);
|
---|
489 | }
|
---|
490 |
|
---|
491 | if (!setup_succeeded) {
|
---|
492 | /* Uh-oh. The setup failed, so we can't run any of the tests
|
---|
493 | * in this testcase. The subunit format doesn't specify what
|
---|
494 | * to do here, so we keep the failure reason, and manually
|
---|
495 | * use it to fail every test.
|
---|
496 | */
|
---|
497 | if (context->last_reason != NULL) {
|
---|
498 | setup_reason = talloc_asprintf(context,
|
---|
499 | "Setup failed: %s", context->last_reason);
|
---|
500 | }
|
---|
501 | }
|
---|
502 |
|
---|
503 | for (test = tcase->tests; test; test = test->next) {
|
---|
504 | if (setup_succeeded) {
|
---|
505 | ret &= internal_torture_run_test(context, tcase, test,
|
---|
506 | tcase->fixture_persistent, restricted);
|
---|
507 | } else {
|
---|
508 | context->active_tcase = tcase;
|
---|
509 | context->active_test = test;
|
---|
510 | torture_ui_test_start(context, tcase, test);
|
---|
511 | torture_ui_test_result(context, TORTURE_FAIL, setup_reason);
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | if (setup_succeeded && tcase->fixture_persistent && tcase->teardown &&
|
---|
516 | !tcase->teardown(context, tcase->data)) {
|
---|
517 | ret = false;
|
---|
518 | }
|
---|
519 |
|
---|
520 | context->active_tcase = NULL;
|
---|
521 | context->active_test = NULL;
|
---|
522 |
|
---|
523 | if (context->results->ui_ops->tcase_finish)
|
---|
524 | context->results->ui_ops->tcase_finish(context, tcase);
|
---|
525 |
|
---|
526 | return (!setup_succeeded) ? false : ret;
|
---|
527 | }
|
---|
528 |
|
---|
529 | bool torture_run_test(struct torture_context *context,
|
---|
530 | struct torture_tcase *tcase,
|
---|
531 | struct torture_test *test)
|
---|
532 | {
|
---|
533 | return internal_torture_run_test(context, tcase, test, false, NULL);
|
---|
534 | }
|
---|
535 |
|
---|
536 | bool torture_run_test_restricted(struct torture_context *context,
|
---|
537 | struct torture_tcase *tcase,
|
---|
538 | struct torture_test *test,
|
---|
539 | const char **restricted)
|
---|
540 | {
|
---|
541 | return internal_torture_run_test(context, tcase, test, false, restricted);
|
---|
542 | }
|
---|
543 |
|
---|
544 | int torture_setting_int(struct torture_context *test, const char *name,
|
---|
545 | int default_value)
|
---|
546 | {
|
---|
547 | return lpcfg_parm_int(test->lp_ctx, NULL, "torture", name, default_value);
|
---|
548 | }
|
---|
549 |
|
---|
550 | unsigned long torture_setting_ulong(struct torture_context *test,
|
---|
551 | const char *name,
|
---|
552 | unsigned long default_value)
|
---|
553 | {
|
---|
554 | return lpcfg_parm_ulong(test->lp_ctx, NULL, "torture", name,
|
---|
555 | default_value);
|
---|
556 | }
|
---|
557 |
|
---|
558 | double torture_setting_double(struct torture_context *test, const char *name,
|
---|
559 | double default_value)
|
---|
560 | {
|
---|
561 | return lpcfg_parm_double(test->lp_ctx, NULL, "torture", name, default_value);
|
---|
562 | }
|
---|
563 |
|
---|
564 | bool torture_setting_bool(struct torture_context *test, const char *name,
|
---|
565 | bool default_value)
|
---|
566 | {
|
---|
567 | return lpcfg_parm_bool(test->lp_ctx, NULL, "torture", name, default_value);
|
---|
568 | }
|
---|
569 |
|
---|
570 | const char *torture_setting_string(struct torture_context *test,
|
---|
571 | const char *name,
|
---|
572 | const char *default_value)
|
---|
573 | {
|
---|
574 | const char *ret;
|
---|
575 |
|
---|
576 | SMB_ASSERT(test != NULL);
|
---|
577 | SMB_ASSERT(test->lp_ctx != NULL);
|
---|
578 |
|
---|
579 | ret = lpcfg_parm_string(test->lp_ctx, NULL, "torture", name);
|
---|
580 |
|
---|
581 | if (ret == NULL)
|
---|
582 | return default_value;
|
---|
583 |
|
---|
584 | return ret;
|
---|
585 | }
|
---|
586 |
|
---|
587 | static bool wrap_test_with_simple_tcase_const (
|
---|
588 | struct torture_context *torture_ctx,
|
---|
589 | struct torture_tcase *tcase,
|
---|
590 | struct torture_test *test)
|
---|
591 | {
|
---|
592 | bool (*fn) (struct torture_context *, const void *tcase_data);
|
---|
593 |
|
---|
594 | fn = test->fn;
|
---|
595 |
|
---|
596 | return fn(torture_ctx, test->data);
|
---|
597 | }
|
---|
598 |
|
---|
599 | struct torture_tcase *torture_suite_add_simple_tcase_const(
|
---|
600 | struct torture_suite *suite, const char *name,
|
---|
601 | bool (*run) (struct torture_context *test, const void *),
|
---|
602 | const void *data)
|
---|
603 | {
|
---|
604 | struct torture_tcase *tcase;
|
---|
605 | struct torture_test *test;
|
---|
606 |
|
---|
607 | tcase = torture_suite_add_tcase(suite, name);
|
---|
608 |
|
---|
609 | test = talloc(tcase, struct torture_test);
|
---|
610 |
|
---|
611 | test->name = talloc_strdup(test, name);
|
---|
612 | test->description = NULL;
|
---|
613 | test->run = wrap_test_with_simple_tcase_const;
|
---|
614 | test->fn = run;
|
---|
615 | test->data = data;
|
---|
616 | test->dangerous = false;
|
---|
617 |
|
---|
618 | DLIST_ADD_END(tcase->tests, test, struct torture_test *);
|
---|
619 |
|
---|
620 | return tcase;
|
---|
621 | }
|
---|
622 |
|
---|
623 | static bool wrap_simple_test(struct torture_context *torture_ctx,
|
---|
624 | struct torture_tcase *tcase,
|
---|
625 | struct torture_test *test)
|
---|
626 | {
|
---|
627 | bool (*fn) (struct torture_context *);
|
---|
628 |
|
---|
629 | fn = test->fn;
|
---|
630 |
|
---|
631 | return fn(torture_ctx);
|
---|
632 | }
|
---|
633 |
|
---|
634 | struct torture_tcase *torture_suite_add_simple_test(
|
---|
635 | struct torture_suite *suite,
|
---|
636 | const char *name,
|
---|
637 | bool (*run) (struct torture_context *test))
|
---|
638 | {
|
---|
639 | struct torture_test *test;
|
---|
640 | struct torture_tcase *tcase;
|
---|
641 |
|
---|
642 | tcase = torture_suite_add_tcase(suite, name);
|
---|
643 |
|
---|
644 | test = talloc(tcase, struct torture_test);
|
---|
645 |
|
---|
646 | test->name = talloc_strdup(test, name);
|
---|
647 | test->description = NULL;
|
---|
648 | test->run = wrap_simple_test;
|
---|
649 | test->fn = run;
|
---|
650 | test->dangerous = false;
|
---|
651 |
|
---|
652 | DLIST_ADD_END(tcase->tests, test, struct torture_test *);
|
---|
653 |
|
---|
654 | return tcase;
|
---|
655 | }
|
---|
656 |
|
---|
657 | /**
|
---|
658 | * Add a child testsuite to a testsuite.
|
---|
659 | */
|
---|
660 | bool torture_suite_add_suite(struct torture_suite *suite,
|
---|
661 | struct torture_suite *child)
|
---|
662 | {
|
---|
663 | if (child == NULL)
|
---|
664 | return false;
|
---|
665 |
|
---|
666 | DLIST_ADD_END(suite->children, child, struct torture_suite *);
|
---|
667 |
|
---|
668 | /* FIXME: Check for duplicates and return false if the
|
---|
669 | * added suite already exists as a child */
|
---|
670 |
|
---|
671 | return true;
|
---|
672 | }
|
---|
673 |
|
---|
674 | /**
|
---|
675 | * Find the child testsuite with the specified name.
|
---|
676 | */
|
---|
677 | struct torture_suite *torture_find_suite(struct torture_suite *parent,
|
---|
678 | const char *name)
|
---|
679 | {
|
---|
680 | struct torture_suite *child;
|
---|
681 |
|
---|
682 | for (child = parent->children; child; child = child->next)
|
---|
683 | if (!strcmp(child->name, name))
|
---|
684 | return child;
|
---|
685 |
|
---|
686 | return NULL;
|
---|
687 | }
|
---|
688 |
|
---|
689 | static bool wrap_test_with_simple_test_const(struct torture_context *torture_ctx,
|
---|
690 | struct torture_tcase *tcase,
|
---|
691 | struct torture_test *test)
|
---|
692 | {
|
---|
693 | bool (*fn) (struct torture_context *, const void *tcase_data);
|
---|
694 |
|
---|
695 | fn = test->fn;
|
---|
696 |
|
---|
697 | return fn(torture_ctx, tcase->data);
|
---|
698 | }
|
---|
699 |
|
---|
700 | struct torture_test *torture_tcase_add_simple_test_const(
|
---|
701 | struct torture_tcase *tcase,
|
---|
702 | const char *name,
|
---|
703 | bool (*run) (struct torture_context *test,
|
---|
704 | const void *tcase_data))
|
---|
705 | {
|
---|
706 | struct torture_test *test;
|
---|
707 |
|
---|
708 | test = talloc(tcase, struct torture_test);
|
---|
709 |
|
---|
710 | test->name = talloc_strdup(test, name);
|
---|
711 | test->description = NULL;
|
---|
712 | test->run = wrap_test_with_simple_test_const;
|
---|
713 | test->fn = run;
|
---|
714 | test->data = NULL;
|
---|
715 | test->dangerous = false;
|
---|
716 |
|
---|
717 | DLIST_ADD_END(tcase->tests, test, struct torture_test *);
|
---|
718 |
|
---|
719 | return test;
|
---|
720 | }
|
---|
721 |
|
---|
722 | static bool wrap_test_with_simple_test(struct torture_context *torture_ctx,
|
---|
723 | struct torture_tcase *tcase,
|
---|
724 | struct torture_test *test)
|
---|
725 | {
|
---|
726 | bool (*fn) (struct torture_context *, void *tcase_data);
|
---|
727 |
|
---|
728 | fn = test->fn;
|
---|
729 |
|
---|
730 | return fn(torture_ctx, tcase->data);
|
---|
731 | }
|
---|
732 |
|
---|
733 | struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
|
---|
734 | const char *name,
|
---|
735 | bool (*run) (struct torture_context *test, void *tcase_data))
|
---|
736 | {
|
---|
737 | struct torture_test *test;
|
---|
738 |
|
---|
739 | test = talloc(tcase, struct torture_test);
|
---|
740 |
|
---|
741 | test->name = talloc_strdup(test, name);
|
---|
742 | test->description = NULL;
|
---|
743 | test->run = wrap_test_with_simple_test;
|
---|
744 | test->fn = run;
|
---|
745 | test->data = NULL;
|
---|
746 | test->dangerous = false;
|
---|
747 |
|
---|
748 | DLIST_ADD_END(tcase->tests, test, struct torture_test *);
|
---|
749 |
|
---|
750 | return test;
|
---|
751 | }
|
---|
752 |
|
---|
753 | void torture_ui_report_time(struct torture_context *context)
|
---|
754 | {
|
---|
755 | if (context->results->ui_ops->report_time)
|
---|
756 | context->results->ui_ops->report_time(context);
|
---|
757 | }
|
---|