Author: jelmer
Date: 2007-09-02 16:17:12 +0000 (Sun, 02 Sep 2007)
New Revision: 24898

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=24898

Log:
Fix LOCAL-REGISTRY, do not silently ignore testcase setup failures.
Modified:
   branches/SAMBA_4_0/
   branches/SAMBA_4_0/source/lib/registry/ldb.c
   branches/SAMBA_4_0/source/lib/registry/tests/registry.c
   branches/SAMBA_4_0/source/selftest/selftest.pl
   branches/SAMBA_4_0/source/torture/ui.c


Changeset:

Property changes on: branches/SAMBA_4_0
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/SAMBA_4_0/source/lib/registry/ldb.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/ldb.c        2007-09-02 16:12:49 UTC 
(rev 24897)
+++ branches/SAMBA_4_0/source/lib/registry/ldb.c        2007-09-02 16:17:12 UTC 
(rev 24898)
@@ -327,8 +327,7 @@
        if (location == NULL) 
                return WERR_INVALID_PARAM;
 
-       wrap = ldb_wrap_connect(parent_ctx, location, session_info, 
-                                                       credentials, 0, NULL);
+       wrap = ldb_wrap_connect(parent_ctx, location, session_info, 
credentials, 0, NULL);
 
        if (wrap == NULL) {
                DEBUG(1, (__FILE__": unable to connect\n"));

Modified: branches/SAMBA_4_0/source/lib/registry/tests/registry.c
===================================================================
--- branches/SAMBA_4_0/source/lib/registry/tests/registry.c     2007-09-02 
16:12:49 UTC (rev 24897)
+++ branches/SAMBA_4_0/source/lib/registry/tests/registry.c     2007-09-02 
16:17:12 UTC (rev 24898)
@@ -132,7 +132,7 @@
        error = reg_key_add_name(rctx, root, "Hamburg", NULL, NULL, 
                                                         &newkey1);
        torture_assert_werr_ok(tctx, error, "Creating key return code");
-       torture_assert(tctx, newkey2 != NULL, "Creating new key");
+       torture_assert(tctx, newkey1 != NULL, "Creating new key");
 
        error = reg_key_add_name(rctx, root, "Hamburg\\Hamburg", NULL, NULL, 
                                                         &newkey2);
@@ -374,7 +374,6 @@
        const struct registry_context *rctx = _data;
        struct registry_key *subkey = NULL, *root;
        WERROR error;
-       uint32_t data = 42;
        struct security_descriptor *osd, *nsd;
 
        if (!create_test_key(tctx, rctx, "Düsseldorf", &root, &subkey))
@@ -511,26 +510,20 @@
        const char *tempdir;
        NTSTATUS status;
        struct hive_key *hive_key;
+       const char *filename;
 
        error = reg_open_local(tctx, &rctx, NULL, NULL);
-       if (!W_ERROR_IS_OK(error))
-               return false;
+       torture_assert_werr_ok(tctx, error, "Opening local registry failed");
 
        status = torture_temp_dir(tctx, "registry-local", &tempdir);
-       if (!NT_STATUS_IS_OK(status))
-               return false;
+       torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed");
 
-       error = reg_open_ldb_file(tctx, 
-                                         talloc_asprintf(tctx, 
"%s/classes_root.ldb", tempdir),
-                                         NULL,
-                                         NULL,
-                                         &hive_key);
-       if (!W_ERROR_IS_OK(error))
-               return false;
+       filename = talloc_asprintf(tctx, "%s/classes_root.ldb", tempdir);
+       error = reg_open_ldb_file(tctx, filename, NULL, NULL, &hive_key);
+       torture_assert_werr_ok(tctx, error, "Opening classes_root file failed");
 
        error = reg_mount_hive(rctx, hive_key, HKEY_CLASSES_ROOT, NULL);
-       if (!W_ERROR_IS_OK(error))
-               return false;
+       torture_assert_werr_ok(tctx, error, "Mounting hive failed");
 
        *data = rctx;
 
@@ -540,13 +533,10 @@
 static void tcase_add_tests(struct torture_tcase *tcase)
 {
        torture_tcase_add_simple_test(tcase, "list_subkeys", test_list_subkeys);
-       torture_tcase_add_simple_test(tcase, "get_predefined_key",
-                                                                       
test_get_predefined);
-       torture_tcase_add_simple_test(tcase, "get_predefined_key",
-                                                                       
test_get_predefined_unknown);
+       torture_tcase_add_simple_test(tcase, "get_predefined_key", 
test_get_predefined);
+       torture_tcase_add_simple_test(tcase, "get_predefined_key", 
test_get_predefined_unknown);
        torture_tcase_add_simple_test(tcase, "create_key", test_create_subkey);
-       torture_tcase_add_simple_test(tcase, "create_key", 
-                                                                 
test_create_nested_subkey);
+       torture_tcase_add_simple_test(tcase, "create_key", 
test_create_nested_subkey);
        torture_tcase_add_simple_test(tcase, "key_add_abs", test_key_add_abs);
        torture_tcase_add_simple_test(tcase, "key_add_abs_top", 
test_key_add_abs_top);
        torture_tcase_add_simple_test(tcase, "set_value", test_set_value);
@@ -558,18 +548,16 @@
        torture_tcase_add_simple_test(tcase, "query_key", test_query_key);
        torture_tcase_add_simple_test(tcase, "query_key_nums", 
test_query_key_nums);
        torture_tcase_add_simple_test(tcase, "test_predef_key_by_name", 
-                                                                 
test_predef_key_by_name);
-       torture_tcase_add_simple_test(tcase, "security", 
-                                                                 
test_security);
+                                     test_predef_key_by_name);
+       torture_tcase_add_simple_test(tcase, "security", test_security);
        torture_tcase_add_simple_test(tcase, "test_predef_key_by_name_invalid", 
-                                                                 
test_predef_key_by_name_invalid);
+                                     test_predef_key_by_name_invalid);
 }
 
 struct torture_suite *torture_registry_registry(TALLOC_CTX *mem_ctx) 
 {
        struct torture_tcase *tcase;
-       struct torture_suite *suite = torture_suite_create(mem_ctx, 
-                                                                               
                           "REGISTRY");
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "REGISTRY");
        
        tcase = torture_suite_add_tcase(suite, "local");
        torture_tcase_set_fixture(tcase, setup_local_registry, NULL);

Modified: branches/SAMBA_4_0/source/selftest/selftest.pl
===================================================================
--- branches/SAMBA_4_0/source/selftest/selftest.pl      2007-09-02 16:12:49 UTC 
(rev 24897)
+++ branches/SAMBA_4_0/source/selftest/selftest.pl      2007-09-02 16:17:12 UTC 
(rev 24898)
@@ -528,7 +528,7 @@
 # ensure any one smbtorture call doesn't run too long
 push (@torture_options, "--maximum-runtime=$torture_maxtime");
 push (@torture_options, "--target=$opt_target");
-push (@torture_options, "--basedir=$prefix");
+push (@torture_options, "--basedir=$prefix_abs");
 push (@torture_options, "--option=torture:progress=no") if ($opt_format eq 
"buildfarm");
 push (@torture_options, "--format=subunit");
 push (@torture_options, "--option=torture:quick=yes") if ($opt_quick);

Modified: branches/SAMBA_4_0/source/torture/ui.c
===================================================================
--- branches/SAMBA_4_0/source/torture/ui.c      2007-09-02 16:12:49 UTC (rev 
24897)
+++ branches/SAMBA_4_0/source/torture/ui.c      2007-09-02 16:17:12 UTC (rev 
24898)
@@ -164,7 +164,7 @@
        old_testname = context->active_testname;
        if (old_testname != NULL)
                context->active_testname = talloc_asprintf(context, "%s-%s", 
-                                                                               
           old_testname, suite->name);
+                                                          old_testname, 
suite->name);
        else
                context->active_testname = talloc_strdup(context, suite->name);
 
@@ -219,22 +219,17 @@
                context->returncode = false;
 }
 
-static BOOL internal_torture_run_test(struct torture_context *context, 
+static bool internal_torture_run_test(struct torture_context *context, 
                                          struct torture_tcase *tcase,
                                          struct torture_test *test,
-                                         BOOL already_setup)
+                                         bool already_setup)
 {
-       BOOL ret;
+       bool success;
        char *old_testname;
 
-       if (!already_setup && tcase->setup && 
-               !tcase->setup(context, &(tcase->data)))
-               return false;
-
        if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 
                old_testname = context->active_testname;
-               context->active_testname = talloc_asprintf(context, "%s-%s", 
-                                                                               
           old_testname, test->name);
+               context->active_testname = talloc_asprintf(context, "%s-%s", 
old_testname, test->name);
        }
 
        context->active_tcase = tcase;
@@ -245,21 +240,34 @@
        context->last_reason = NULL;
        context->last_result = TORTURE_OK;
 
-       if (test->dangerous && 
+       if (!already_setup && tcase->setup && 
+               !tcase->setup(context, &(tcase->data))) {
+               if (context->last_reason == NULL)
+                       context->last_reason = talloc_strdup(context, "Setup 
failure");
+               context->last_result = TORTURE_ERROR;
+               success = false;
+       } else if (test->dangerous && 
            !torture_setting_bool(context, "dangerous", false)) {
            context->last_result = TORTURE_SKIP;
            context->last_reason = talloc_asprintf(context, 
                "disabled %s - enable dangerous tests to use", test->name);
        } else {
-           ret = test->run(context, tcase, test);
+           success = test->run(context, tcase, test);
 
-           if (!ret && context->last_result == TORTURE_OK) {
+           if (!success && context->last_result == TORTURE_OK) {
                    if (context->last_reason == NULL)
                            context->last_reason = talloc_strdup(context, 
"Unknown error/failure");
                    context->last_result = TORTURE_ERROR;
            }
        }
 
+       if (!already_setup && tcase->teardown && !tcase->teardown(context, 
tcase->data)) {
+               if (context->last_reason == NULL)
+                   context->last_reason = talloc_strdup(context, "Setup 
failure");
+               context->last_result = TORTURE_ERROR;
+               success = false;
+       }
+
        torture_ui_test_result(context, context->last_result, 
                               context->last_reason);
        
@@ -272,10 +280,7 @@
        context->active_test = NULL;
        context->active_tcase = NULL;
 
-       if (!already_setup && tcase->teardown && !tcase->teardown(context, 
tcase->data))
-               return False;
-
-       return ret;
+       return success;
 }
 
 BOOL torture_run_tcase(struct torture_context *context, 
@@ -288,18 +293,22 @@
        context->level++;
 
        context->active_tcase = tcase;
-       if (context->ui_ops->tcase_start)
+       if (context->ui_ops->tcase_start) 
                context->ui_ops->tcase_start(context, tcase);
 
        if (tcase->fixture_persistent && tcase->setup 
                && !tcase->setup(context, &tcase->data)) {
-               ret = False;
+               /* FIXME: Use torture ui ops for reporting this error */
+               fprintf(stderr, "Setup failed: ");
+               if (context->last_reason != NULL)
+                       fprintf(stderr, "%s", context->last_reason);
+               fprintf(stderr, "\n");
+               ret = false;
                goto done;
        }
 
        old_testname = context->active_testname;
-       context->active_testname = talloc_asprintf(context, "%s-%s", 
-                                                                               
           old_testname, tcase->name);
+       context->active_testname = talloc_asprintf(context, "%s-%s", 
old_testname, tcase->name);
        for (test = tcase->tests; test; test = test->next) {
                ret &= internal_torture_run_test(context, tcase, test, 
                                tcase->fixture_persistent);
@@ -309,7 +318,7 @@
 
        if (tcase->fixture_persistent && tcase->teardown &&
                !tcase->teardown(context, tcase->data))
-               ret = False;
+               ret = false;
 
 done:
        context->active_tcase = NULL;
@@ -326,7 +335,7 @@
                                          struct torture_tcase *tcase,
                                          struct torture_test *test)
 {
-       return internal_torture_run_test(context, tcase, test, False);
+       return internal_torture_run_test(context, tcase, test, false);
 }
 
 int torture_setting_int(struct torture_context *test, const char *name, 

Reply via email to