Changeset 740 for vendor/current/lib/torture/torture.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified vendor/current/lib/torture/torture.c ¶
r414 r740 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 SMB torture UI functions 4 4 5 5 Copyright (C) Jelmer Vernooij 2006-2008 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 24 24 #include "param/param.h" 25 25 #include "system/filesys.h" 26 #include "system/dir.h" 27 26 28 27 29 struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops) … … 72 74 73 75 return subtorture; 74 } 75 76 /** 77 create a temporary directory .76 } 77 78 /** 79 create a temporary directory under the output dir 78 80 */ 79 _PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx, 80 const char *prefix, 81 char **tempdir) 81 _PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx, 82 const char *prefix, char **tempdir) 82 83 { 83 84 SMB_ASSERT(tctx->outputdir != NULL); 84 85 85 *tempdir = talloc_asprintf(tctx, "%s/%s.XXXXXX", tctx->outputdir, 86 *tempdir = talloc_asprintf(tctx, "%s/%s.XXXXXX", tctx->outputdir, 86 87 prefix); 87 88 NT_STATUS_HAVE_NO_MEMORY(*tempdir); … … 91 92 } 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 } 93 161 return NT_STATUS_OK; 94 162 } … … 108 176 tmp = talloc_vasprintf(context, comment, ap); 109 177 va_end(ap); 110 178 111 179 context->results->ui_ops->comment(context, tmp); 112 180 113 181 talloc_free(tmp); 114 182 } … … 246 314 } 247 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 248 333 /** 249 334 * Run a torture test suite. … … 251 336 bool torture_run_suite(struct torture_context *context, 252 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) 253 344 { 254 345 bool ret = true; 255 346 struct torture_tcase *tcase; 256 347 struct torture_suite *tsuite; 257 char *old_testname;258 348 259 349 if (context->results->ui_ops->suite_start) 260 350 context->results->ui_ops->suite_start(context, suite); 261 351 262 old_testname = context->active_testname; 263 if (old_testname != NULL) 264 context->active_testname = talloc_asprintf(context, "%s-%s", 265 old_testname, suite->name); 266 else 267 context->active_testname = talloc_strdup(context, suite->name); 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); 268 355 269 356 for (tcase = suite->testcases; tcase; tcase = tcase->next) { 270 ret &= torture_run_tcase (context, tcase);357 ret &= torture_run_tcase_restricted(context, tcase, restricted); 271 358 } 272 359 273 360 for (tsuite = suite->children; tsuite; tsuite = tsuite->next) { 274 ret &= torture_run_suite(context, tsuite); 275 } 276 277 talloc_free(context->active_testname); 278 context->active_testname = old_testname; 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 } 279 365 280 366 if (context->results->ui_ops->suite_finish) … … 303 389 } 304 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 305 403 static bool internal_torture_run_test(struct torture_context *context, 306 404 struct torture_tcase *tcase, 307 405 struct torture_test *test, 308 bool already_setup) 406 bool already_setup, 407 const char **restricted) 309 408 { 310 409 bool success; 311 char * old_testname = NULL;410 char *subunit_testname = NULL; 312 411 313 412 if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 314 old_testname = context->active_testname; 315 context->active_testname = talloc_asprintf(context, "%s-%s", old_testname, test->name); 316 } 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; 317 420 318 421 context->active_tcase = tcase; … … 358 461 talloc_free(context->last_reason); 359 462 360 if (tcase == NULL || strcmp(test->name, tcase->name) != 0) {361 talloc_free(context->active_testname);362 context->active_testname = old_testname;363 }364 463 context->active_test = NULL; 365 464 context->active_tcase = NULL; … … 368 467 } 369 468 370 bool torture_run_tcase(struct torture_context *context, 469 bool torture_run_tcase(struct torture_context *context, 371 470 struct torture_tcase *tcase) 372 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 { 373 478 bool ret = true; 374 char *old_testname;375 479 struct torture_test *test; 480 bool setup_succeeded = true; 481 const char * setup_reason = "Setup failed"; 376 482 377 483 context->active_tcase = tcase; … … 379 485 context->results->ui_ops->tcase_start(context, tcase); 380 486 381 if (tcase->fixture_persistent && tcase->setup 382 && !tcase->setup(context, &tcase->data)) { 383 /* FIXME: Use torture ui ops for reporting this error */ 384 fprintf(stderr, "Setup failed: "); 385 if (context->last_reason != NULL) 386 fprintf(stderr, "%s", context->last_reason); 387 fprintf(stderr, "\n"); 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)) { 388 517 ret = false; 389 goto done; 390 } 391 392 old_testname = context->active_testname; 393 context->active_testname = talloc_asprintf(context, "%s-%s", 394 old_testname, tcase->name); 395 for (test = tcase->tests; test; test = test->next) { 396 ret &= internal_torture_run_test(context, tcase, test, 397 tcase->fixture_persistent); 398 } 399 talloc_free(context->active_testname); 400 context->active_testname = old_testname; 401 402 if (tcase->fixture_persistent && tcase->teardown && 403 !tcase->teardown(context, tcase->data)) 404 ret = false; 405 406 done: 518 } 519 407 520 context->active_tcase = NULL; 521 context->active_test = NULL; 408 522 409 523 if (context->results->ui_ops->tcase_finish) 410 524 context->results->ui_ops->tcase_finish(context, tcase); 411 525 412 return ret;526 return (!setup_succeeded) ? false : ret; 413 527 } 414 528 … … 417 531 struct torture_test *test) 418 532 { 419 return internal_torture_run_test(context, tcase, test, false); 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); 420 542 } 421 543 … … 423 545 int default_value) 424 546 { 425 return lp_parm_int(test->lp_ctx, NULL, "torture", name, default_value); 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); 426 556 } 427 557 … … 429 559 double default_value) 430 560 { 431 return lp _parm_double(test->lp_ctx, NULL, "torture", name, default_value);561 return lpcfg_parm_double(test->lp_ctx, NULL, "torture", name, default_value); 432 562 } 433 563 … … 435 565 bool default_value) 436 566 { 437 return lp _parm_bool(test->lp_ctx, NULL, "torture", name, default_value);567 return lpcfg_parm_bool(test->lp_ctx, NULL, "torture", name, default_value); 438 568 } 439 569 … … 447 577 SMB_ASSERT(test->lp_ctx != NULL); 448 578 449 ret = lp _parm_string(test->lp_ctx, NULL, "torture", name);579 ret = lpcfg_parm_string(test->lp_ctx, NULL, "torture", name); 450 580 451 581 if (ret == NULL) … … 620 750 return test; 621 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 }
Note:
See TracChangeset
for help on using the changeset viewer.