lib/util: Clean up includes for time.[ch]
[sfrench/samba-autobuild/.git] / lib / torture / torture.c
index ead89cdd5e353605e2d0642eae3d1921fb277fc8..ff2f8c89399affc20f1500e85e608649f1e7402a 100644 (file)
@@ -88,7 +88,7 @@ _PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx,
        NT_STATUS_HAVE_NO_MEMORY(*tempdir);
 
        if (mkdtemp(*tempdir) == NULL) {
-               return map_nt_error_from_unix(errno);
+               return map_nt_error_from_unix_common(errno);
        }
 
        return NT_STATUS_OK;
@@ -96,7 +96,7 @@ _PUBLIC_ NTSTATUS torture_temp_dir(struct torture_context *tctx,
 
 static int local_deltree(const char *path)
 {
-       int ret;
+       int ret = 0;
        struct dirent *dirent;
        DIR *dir = opendir(path);
        if (!dir) {
@@ -116,6 +116,7 @@ static int local_deltree(const char *path)
                        closedir(dir);
                        return -1;
                }
+               DEBUG(0, ("About to remove %s\n", name));
                ret = remove(name);
                if (ret == 0) {
                        talloc_free(name);
@@ -137,12 +138,15 @@ static int local_deltree(const char *path)
                }
        }
        closedir(dir);
+       rmdir(path);
        return ret;
 }
 
 _PUBLIC_ NTSTATUS torture_deltree_outputdir(struct torture_context *tctx)
 {
-       SMB_ASSERT(tctx->outputdir != NULL);
+       if (tctx->outputdir == NULL) {
+               return NT_STATUS_OK;
+       }
        if ((strcmp(tctx->outputdir, "/") == 0)
            || (strcmp(tctx->outputdir, "") == 0)) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -150,7 +154,7 @@ _PUBLIC_ NTSTATUS torture_deltree_outputdir(struct torture_context *tctx)
 
        if (local_deltree(tctx->outputdir) == -1) {
                if (errno != 0) {
-                       return map_nt_error_from_unix(errno);
+                       return map_nt_error_from_unix_common(errno);
                }
                return NT_STATUS_UNSUCCESSFUL;
        }
@@ -396,7 +400,7 @@ static bool test_needs_running(const char *name, const char **restricted)
        return 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,
@@ -405,7 +409,7 @@ static bool internal_torture_run_test(struct torture_context *context,
        bool success;
        char *subunit_testname = NULL;
 
-       if (tcase == NULL || strcmp(test->name, tcase->name) != 0) { 
+       if (tcase == NULL || strcmp(test->name, tcase->name) != 0) {
                subunit_testname = talloc_asprintf(context, "%s.%s", tcase->name, test->name);
        } else {
                subunit_testname = talloc_strdup(context, test->name);
@@ -422,38 +426,39 @@ static bool internal_torture_run_test(struct torture_context *context,
        context->last_reason = NULL;
        context->last_result = TORTURE_OK;
 
-       if (!already_setup && tcase->setup && 
-               !tcase->setup(context, &(tcase->data))) {
-               if (context->last_reason == NULL)
+       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);
-           success = true;
+       } 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);
+               success = true;
        } else {
-           success = test->run(context, tcase, test);
+               success = test->run(context, tcase, test);
 
-           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 (!success && context->last_result == TORTURE_OK) {
+                       if (context->last_reason == NULL)
+                               context->last_reason = talloc_strdup(context,
+                                       "Unknown error/failure. Missing torture_fail() or torture_assert_*() call?");
+                       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;
+               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, 
+       torture_ui_test_result(context, context->last_result,
                               context->last_reason);
-       
+
        talloc_free(context->last_reason);
 
        context->active_test = NULL;