Refactor the dns_open_connection code so that duplicate code is removed and ensure...
[sfrench/samba-autobuild/.git] / lib / torture / torture.h
index af61ac189f8dfffb62c2381ed2c7d543daffa253..e710873fb39423c7297192eca7cf558eeaa366eb 100644 (file)
@@ -60,6 +60,7 @@ struct torture_ui_ops
        void (*test_result) (struct torture_context *, 
                                                 enum torture_result, const char *reason);
        void (*progress) (struct torture_context *, int offset, enum torture_progress_whence whence);
+       void (*report_time) (struct torture_context *);
 };
 
 void torture_ui_test_start(struct torture_context *context,
@@ -70,6 +71,8 @@ void torture_ui_test_result(struct torture_context *context,
                                                                enum torture_result result,
                                                                const char *comment);
 
+void torture_ui_report_time(struct torture_context *context);
+
 /*
  * Holds information about a specific run of the testsuite. 
  * The data in this structure should be considered private to 
@@ -84,7 +87,6 @@ struct torture_context
 {
        struct torture_results *results;
 
-       char *active_testname;
        struct torture_test *active_test;
        struct torture_tcase *active_tcase;
 
@@ -93,7 +95,7 @@ struct torture_context
 
        /** Directory used for temporary test data */
        const char *outputdir;
-       
+
        /** Event context */
        struct tevent_context *ev;
 
@@ -218,15 +220,28 @@ bool torture_suite_add_suite(struct torture_suite *suite,
 bool torture_run_suite(struct torture_context *context,
                                           struct torture_suite *suite);
 
+/* Run the specified testsuite recursively, but only the specified 
+ * tests */
+bool torture_run_suite_restricted(struct torture_context *context, 
+                      struct torture_suite *suite, const char **restricted);
+
 /* Run the specified testcase */
 bool torture_run_tcase(struct torture_context *context,
                                           struct torture_tcase *tcase);
 
+bool torture_run_tcase_restricted(struct torture_context *context, 
+                      struct torture_tcase *tcase, const char **restricted);
+
 /* Run the specified test */
 bool torture_run_test(struct torture_context *context,
                                          struct torture_tcase *tcase,
                                          struct torture_test *test);
 
+bool torture_run_test_restricted(struct torture_context *context,
+                                         struct torture_tcase *tcase,
+                                         struct torture_test *test,
+                                         const char **restricted);
+
 void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
 void torture_warning(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
 void torture_result(struct torture_context *test,
@@ -273,11 +288,19 @@ void torture_result(struct torture_context *test,
 #define torture_assert_ndr_err_equal(torture_ctx,got,expected,cmt) \
        do { enum ndr_err_code __got = got, __expected = expected; \
        if (__got != __expected) { \
-               torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d, expected %d (%s): %s", __got, __expected, __STRING(expected), cmt); \
+               torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
                return false; \
        }\
        } while(0)
 
+#define torture_assert_hresult_equal(torture_ctx, got, expected, cmt) \
+       do { HRESULT __got = got, __expected = expected; \
+       if (!HRES_IS_EQUAL(__got, __expected)) { \
+               torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", hresult_errstr(__got), hresult_errstr(__expected), cmt); \
+               return false; \
+       } \
+       } while (0)
+
 #define torture_assert_casestr_equal(torture_ctx,got,expected,cmt) \
        do { const char *__got = (got), *__expected = (expected); \
        if (!strequal(__got, __expected)) { \
@@ -296,6 +319,16 @@ void torture_result(struct torture_context *test,
        } \
        } while(0)
 
+#define torture_assert_strn_equal(torture_ctx,got,expected,len,cmt)\
+       do { const char *__got = (got), *__expected = (expected); \
+       if (strncmp(__got, __expected, len) != 0) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                                          __location__": "#got" %s of len %d did not match "#expected" %s: %s", \
+                                          __got, (int)len, __expected, cmt); \
+               return false; \
+       } \
+       } while(0)
+
 #define torture_assert_str_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
        do { const char *__got = (got), *__expected = (expected); \
        if (strcmp_safe(__got, __expected) != 0) { \
@@ -372,8 +405,8 @@ void torture_result(struct torture_context *test,
        do { int __got = (got), __expected = (expected); \
        if (__got != __expected) { \
                torture_result(torture_ctx, TORTURE_FAIL, \
-                       __location__": "#got" was %d, expected %d: %s", \
-                       __got, __expected, cmt); \
+                       __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
+                       __got, __got, __expected, __expected, cmt); \
                return false; \
        } \
        } while(0)
@@ -382,8 +415,29 @@ void torture_result(struct torture_context *test,
        do { int __got = (got), __expected = (expected); \
        if (__got != __expected) { \
                torture_result(torture_ctx, TORTURE_FAIL, \
-                       __location__": "#got" was %d, expected %d: %s", \
-                       __got, __expected, cmt); \
+                       __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
+                       __got, __got, __expected, __expected, cmt); \
+               ret = false; \
+               goto label; \
+       } \
+       } while(0)
+
+#define torture_assert_int_not_equal(torture_ctx,got,not_expected,cmt)\
+       do { int __got = (got), __not_expected = (not_expected); \
+       if (__got == __not_expected) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %d (0x%X), expected a different number: %s", \
+                       __got, __got, cmt); \
+               return false; \
+       } \
+       } while(0)
+
+#define torture_assert_int_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
+       do { int __got = (got), __not_expected = (not_expected); \
+       if (__got == __not_expected) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %d (0x%X), expected a different number: %s", \
+                       __got, __got, cmt); \
                ret = false; \
                goto label; \
        } \
@@ -393,12 +447,50 @@ void torture_result(struct torture_context *test,
        do { uint64_t __got = (got), __expected = (expected); \
        if (__got != __expected) { \
                torture_result(torture_ctx, TORTURE_FAIL, \
-                       __location__": "#got" was %llu, expected %llu: %s", \
-                       (unsigned long long)__got, (unsigned long long)__expected, cmt); \
+                       __location__": "#got" was %llu (0x%llX), expected %llu (0x%llX): %s", \
+                       (unsigned long long)__got, (unsigned long long)__got, \
+                       (unsigned long long)__expected, (unsigned long long)__expected, \
+                       cmt); \
                return false; \
        } \
        } while(0)
 
+#define torture_assert_u64_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
+       do { uint64_t __got = (got), __expected = (expected); \
+       if (__got != __expected) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %llu (0x%llX), expected %llu (0x%llX): %s", \
+                       (unsigned long long)__got, (unsigned long long)__got, \
+                       (unsigned long long)__expected, (unsigned long long)__expected, \
+                       cmt); \
+               ret = false; \
+               goto label; \
+       } \
+       } while(0)
+
+#define torture_assert_u64_not_equal(torture_ctx,got,not_expected,cmt)\
+       do { uint64_t __got = (got), __not_expected = (not_expected); \
+       if (__got == __not_expected) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %llu (0x%llX), expected a different number: %s", \
+                       (unsigned long long)__got, (unsigned long long)__got, \
+                       cmt); \
+               return false; \
+       } \
+       } while(0)
+
+#define torture_assert_u64_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
+       do { uint64_t __got = (got), __not_expected = (not_expected); \
+       if (__got == __not_expected) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %llu (0x%llX), expected a different number: %s", \
+                       (unsigned long long)__got, (unsigned long long)__got, \
+                       cmt); \
+               ret = false; \
+               goto label; \
+       } \
+       } while(0)
+
 #define torture_assert_errno_equal(torture_ctx,expected,cmt)\
        do { int __expected = (expected); \
        if (errno != __expected) { \
@@ -410,7 +502,54 @@ void torture_result(struct torture_context *test,
        } \
        } while(0)
 
+#define torture_assert_guid_equal(torture_ctx,got,expected,cmt)\
+       do { struct GUID __got = (got), __expected = (expected); \
+       if (!GUID_equal(&__got, &__expected)) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was %s, expected %s: %s", \
+                       GUID_string(torture_ctx, &__got), GUID_string(torture_ctx, &__expected), cmt); \
+               return false; \
+       } \
+       } while(0)
+
+#define torture_assert_nttime_equal(torture_ctx,got,expected,cmt) \
+       do { NTTIME __got = got, __expected = expected; \
+       if (!nt_time_equal(&__got, &__expected)) { \
+               torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_time_string(tctx, __got), nt_time_string(tctx, __expected), cmt); \
+               return false; \
+       }\
+       } while(0)
+
+#define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
+       do { struct dom_sid *__got = (got), *__expected = (expected); \
+       if (!dom_sid_equal(__got, __expected)) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                                          __location__": "#got" was %s, expected %s: %s", \
+                                          dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
+               return false; \
+       } \
+       } while(0)
+
+#define torture_assert_not_null(torture_ctx,got,cmt)\
+       do { void *__got = (got); \
+       if (__got == NULL) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was NULL, expected != NULL: %s", \
+                       cmt); \
+               return false; \
+       } \
+       } while(0)
 
+#define torture_assert_not_null_goto(torture_ctx,got,ret,label,cmt)\
+       do { void *__got = (got); \
+       if (__got == NULL) { \
+               torture_result(torture_ctx, TORTURE_FAIL, \
+                       __location__": "#got" was NULL, expected != NULL: %s", \
+                       cmt); \
+               ret = false; \
+               goto label; \
+       } \
+       } while(0)
 
 #define torture_skip(torture_ctx,cmt) do {\
                torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
@@ -444,6 +583,9 @@ void torture_result(struct torture_context *test,
 #define torture_assert_ndr_success(torture_ctx,expr,cmt) \
                torture_assert_ndr_err_equal(torture_ctx,expr,NDR_ERR_SUCCESS,cmt)
 
+#define torture_assert_hresult_ok(torture_ctx,expr,cmt) \
+               torture_assert_hresult_equal(torture_ctx,expr,HRES_ERROR(0), cmt)
+
 /* Getting settings */
 const char *torture_setting_string(struct torture_context *test, \
                                                                   const char *name, 
@@ -471,6 +613,7 @@ unsigned long torture_setting_ulong(struct torture_context *test,
 NTSTATUS torture_temp_dir(struct torture_context *tctx, 
                                   const char *prefix, 
                                   char **tempdir);
+NTSTATUS torture_deltree_outputdir(struct torture_context *tctx);
 
 struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
                const char *name,
@@ -489,5 +632,6 @@ struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct t
 struct torture_context *torture_context_child(struct torture_context *tctx);
 
 extern const struct torture_ui_ops torture_subunit_ui_ops;
+extern const struct torture_ui_ops torture_simple_ui_ops;
 
 #endif /* __TORTURE_UI_H__ */