LCOV - code coverage report
Current view: top level - lib/torture - torture.h (source / functions) Hit Total Coverage
Test: coverage report for smb2.twrp.listdir_fix f886ca1c Lines: 0 4 0.0 %
Date: 2023-11-07 19:11:32 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    SMB torture UI functions
       4             : 
       5             :    Copyright (C) Jelmer Vernooij 2006
       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             : #ifndef __TORTURE_UI_H__
      22             : #define __TORTURE_UI_H__
      23             : 
      24             : struct torture_test;
      25             : struct torture_context;
      26             : struct torture_suite;
      27             : struct torture_tcase;
      28             : struct torture_results;
      29             : 
      30             : /*
      31             :  * Arranged in precedence order. TORTURE_ERROR has the highest priority;
      32             :  * TORTURE_OK the lowest.
      33             :  */
      34             : enum torture_result { 
      35             :         TORTURE_OK=0, 
      36             :         TORTURE_SKIP=1,
      37             :         TORTURE_FAIL=2,
      38             :         TORTURE_ERROR=3
      39             : };
      40             : 
      41             : enum torture_progress_whence {
      42             :         TORTURE_PROGRESS_SET,
      43             :         TORTURE_PROGRESS_CUR,
      44             :         TORTURE_PROGRESS_POP,
      45             :         TORTURE_PROGRESS_PUSH,
      46             : };
      47             : 
      48             : /* 
      49             :  * These callbacks should be implemented by any backend that wishes 
      50             :  * to listen to reports from the torture tests.
      51             :  */
      52             : struct torture_ui_ops
      53             : {
      54             :         void (*init) (struct torture_results *);
      55             :         void (*comment) (struct torture_context *, const char *);
      56             :         void (*warning) (struct torture_context *, const char *);
      57             :         void (*suite_start) (struct torture_context *, struct torture_suite *);
      58             :         void (*suite_finish) (struct torture_context *, struct torture_suite *);
      59             :         void (*tcase_start) (struct torture_context *, struct torture_tcase *); 
      60             :         void (*tcase_finish) (struct torture_context *, struct torture_tcase *);
      61             :         void (*test_start) (struct torture_context *, 
      62             :                                                 struct torture_tcase *,
      63             :                                                 struct torture_test *);
      64             :         void (*test_result) (struct torture_context *, 
      65             :                                                  enum torture_result, const char *reason);
      66             :         void (*progress) (struct torture_context *, int offset, enum torture_progress_whence whence);
      67             :         void (*report_time) (struct torture_context *);
      68             : };
      69             : 
      70             : void torture_ui_test_start(struct torture_context *context,
      71             :                                                            struct torture_tcase *tcase,
      72             :                                                            struct torture_test *test);
      73             : 
      74             : void torture_ui_test_result(struct torture_context *context,
      75             :                                                                 enum torture_result result,
      76             :                                                                 const char *comment);
      77             : 
      78             : void torture_ui_report_time(struct torture_context *context);
      79             : 
      80             : /*
      81             :  * Holds information about a specific run of the testsuite. 
      82             :  * The data in this structure should be considered private to 
      83             :  * the torture tests and should only be used directly by the torture 
      84             :  * code and the ui backends.
      85             :  *
      86             :  * Torture tests should instead call the torture_*() macros and functions 
      87             :  * specified below.
      88             :  */
      89             : 
      90             : struct torture_subunit_prefix {
      91             :         const struct torture_subunit_prefix *parent;
      92             :         char subunit_prefix[256];
      93             : };
      94             : 
      95             : struct torture_context
      96             : {
      97             :         struct torture_results *results;
      98             : 
      99             :         struct torture_test *active_test;
     100             :         struct torture_tcase *active_tcase;
     101             :         struct torture_subunit_prefix _initial_prefix;
     102             :         const struct torture_subunit_prefix *active_prefix;
     103             : 
     104             :         enum torture_result last_result;
     105             :         char *last_reason;
     106             : 
     107             :         /** Directory used for temporary test data */
     108             :         const char *outputdir;
     109             : 
     110             :         /** Event context */
     111             :         struct tevent_context *ev;
     112             : 
     113             :         /** Loadparm context (will go away in favor of torture_setting_ at some point) */
     114             :         struct loadparm_context *lp_ctx;
     115             : 
     116             :         int conn_index;
     117             : };
     118             : 
     119             : struct torture_results
     120             : {
     121             :         const struct torture_ui_ops *ui_ops;
     122             :         void *ui_data;
     123             : 
     124             :         /** Whether tests should avoid writing output to stdout */
     125             :         bool quiet;
     126             : 
     127             :         bool returncode;
     128             : };
     129             : 
     130             : /* 
     131             :  * Describes a particular torture test
     132             :  */
     133             : struct torture_test {
     134             :         /** Short unique name for the test. */
     135             :         const char *name;
     136             : 
     137             :         /** Long description for the test. */
     138             :         const char *description;
     139             : 
     140             :         /** Whether this is a dangerous test 
     141             :          * (can corrupt the remote servers data or bring it down). */
     142             :         bool dangerous;
     143             : 
     144             :         /** Function to call to run this test */
     145             :         bool (*run) (struct torture_context *torture_ctx, 
     146             :                                  struct torture_tcase *tcase,
     147             :                                  struct torture_test *test);
     148             : 
     149             :         struct torture_test *prev, *next;
     150             : 
     151             :         /** Pointer to the actual test function. This is run by the 
     152             :           * run() function above. */
     153             :         void *fn;
     154             : 
     155             :         /** Use data for this test */
     156             :         const void *data;
     157             : 
     158             :         struct torture_tcase *tcase;
     159             : };
     160             : 
     161             : /* 
     162             :  * Describes a particular test case.
     163             :  */
     164             : struct torture_tcase {
     165             :     const char *name;
     166             :         const char *description;
     167             :         bool (*setup) (struct torture_context *tcase, void **data);
     168             :         bool (*teardown) (struct torture_context *tcase, void *data); 
     169             :         bool fixture_persistent;
     170             :         void *data;
     171             :         struct torture_test *tests;
     172             :         struct torture_tcase *prev, *next;
     173             :         const struct torture_suite *suite;
     174             : };
     175             : 
     176             : struct torture_suite
     177             : {
     178             :         const char *name;
     179             :         const char *description;
     180             :         struct torture_tcase *testcases;
     181             :         struct torture_suite *children;
     182             :         const struct torture_suite *parent;
     183             : 
     184             :         /* Pointers to siblings of this torture suite */
     185             :         struct torture_suite *prev, *next;
     186             : };
     187             : 
     188             : /** Create a new torture suite */
     189             : struct torture_suite *torture_suite_create(TALLOC_CTX *mem_ctx,
     190             :                 const char *name);
     191             : 
     192             : /** Change the setup and teardown functions for a testcase */
     193             : void torture_tcase_set_fixture(struct torture_tcase *tcase,
     194             :                 bool (*setup) (struct torture_context *, void **),
     195             :                 bool (*teardown) (struct torture_context *, void *));
     196             : 
     197             : /* Add another test to run for a particular testcase */
     198             : struct torture_test *torture_tcase_add_test_const(struct torture_tcase *tcase,
     199             :                 const char *name,
     200             :                 bool (*run) (struct torture_context *test,
     201             :                         const void *tcase_data, const void *test_data),
     202             :                 const void *test_data);
     203             : 
     204             : /* Add a testcase to a testsuite */
     205             : struct torture_tcase *torture_suite_add_tcase(struct torture_suite *suite,
     206             :                                                          const char *name);
     207             : 
     208             : /* Convenience wrapper that adds a testcase against only one
     209             :  * test will be run */
     210             : struct torture_tcase *torture_suite_add_simple_tcase_const(
     211             :                 struct torture_suite *suite,
     212             :                 const char *name,
     213             :                 bool (*run) (struct torture_context *test,
     214             :                         const void *test_data),
     215             :                 const void *data);
     216             : 
     217             : /* Convenience function that adds a test which only
     218             :  * gets the test case data */
     219             : struct torture_test *torture_tcase_add_simple_test_const(
     220             :                 struct torture_tcase *tcase,
     221             :                 const char *name,
     222             :                 bool (*run) (struct torture_context *test,
     223             :                         const void *tcase_data));
     224             : 
     225             : /* Convenience wrapper that adds a test that doesn't need any
     226             :  * testcase data */
     227             : struct torture_tcase *torture_suite_add_simple_test(
     228             :                 struct torture_suite *suite,
     229             :                 const char *name,
     230             :                 bool (*run) (struct torture_context *test));
     231             : 
     232             : /* Add a child testsuite to an existing testsuite */
     233             : bool torture_suite_add_suite(struct torture_suite *suite,
     234             :                 struct torture_suite *child);
     235             : 
     236             : char *torture_subunit_test_name(struct torture_context *ctx,
     237             :                                 struct torture_tcase *tcase,
     238             :                                 struct torture_test *test);
     239             : void torture_subunit_prefix_reset(struct torture_context *ctx,
     240             :                                   const char *name);
     241             : 
     242             : /* Run the specified testsuite recursively */
     243             : bool torture_run_suite(struct torture_context *context,
     244             :                                            struct torture_suite *suite);
     245             : 
     246             : /* Run the specified testsuite recursively, but only the specified 
     247             :  * tests */
     248             : bool torture_run_suite_restricted(struct torture_context *context, 
     249             :                        struct torture_suite *suite, const char **restricted);
     250             : 
     251             : /* Run the specified testcase */
     252             : bool torture_run_tcase(struct torture_context *context,
     253             :                                            struct torture_tcase *tcase);
     254             : 
     255             : bool torture_run_tcase_restricted(struct torture_context *context, 
     256             :                        struct torture_tcase *tcase, const char **restricted);
     257             : 
     258             : /* Run the specified test */
     259             : bool torture_run_test(struct torture_context *context,
     260             :                                           struct torture_tcase *tcase,
     261             :                                           struct torture_test *test);
     262             : 
     263             : bool torture_run_test_restricted(struct torture_context *context,
     264             :                                           struct torture_tcase *tcase,
     265             :                                           struct torture_test *test,
     266             :                                           const char **restricted);
     267             : 
     268             : void torture_comment(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
     269             : void torture_warning(struct torture_context *test, const char *comment, ...) PRINTF_ATTRIBUTE(2,3);
     270             : void torture_result(struct torture_context *test,
     271             :                         enum torture_result, const char *reason, ...) PRINTF_ATTRIBUTE(3,4);
     272             : 
     273             : #define torture_assert(torture_ctx,expr,cmt) do { \
     274             :         if (!(expr)) { \
     275             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
     276             :                 return false; \
     277             :         } \
     278             : } while(0)
     279             : 
     280             : #define torture_assertf(torture_ctx, expr, format, ...) do {            \
     281             :         if (!(expr)) {                                                  \
     282             :                 char *_msg = talloc_asprintf(torture_ctx,               \
     283             :                                              format,                    \
     284             :                                              __VA_ARGS__);              \
     285             :                 torture_result(torture_ctx,                             \
     286             :                                TORTURE_FAIL,                            \
     287             :                                __location__": Expression `%s' failed: %s", \
     288             :                                __STRING(expr), _msg);                   \
     289             :                 talloc_free(_msg);                                      \
     290             :                 return false;                                           \
     291             :         }                                                               \
     292             : } while(0)
     293             : 
     294             : #define torture_assert_goto(torture_ctx,expr,ret,label,cmt) do { \
     295             :         if (!(expr)) { \
     296             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
     297             :                 ret = false; \
     298             :                 goto label; \
     299             :         } \
     300             : } while(0)
     301             : 
     302             : #define torture_assert_werr_equal(torture_ctx, got, expected, cmt) \
     303             :         do { WERROR __got = got, __expected = expected; \
     304             :         if (!W_ERROR_EQUAL(__got, __expected)) { \
     305             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", win_errstr(__got), win_errstr(__expected), cmt); \
     306             :                 return false; \
     307             :         } \
     308             :         } while (0)
     309             : 
     310             : #define torture_assert_ntstatus_equal(torture_ctx,got,expected,cmt) \
     311             :         do { NTSTATUS __got = got, __expected = expected; \
     312             :         if (!NT_STATUS_EQUAL(__got, __expected)) { \
     313             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_errstr(__got), nt_errstr(__expected), cmt); \
     314             :                 return false; \
     315             :         }\
     316             :         } while(0)
     317             : 
     318             : #define torture_assert_ntstatus_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
     319             :         do { NTSTATUS __got = got, __expected = expected; \
     320             :         if (!NT_STATUS_EQUAL(__got, __expected)) { \
     321             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_errstr(__got), nt_errstr(__expected), cmt); \
     322             :                 ret = false; \
     323             :                 goto label; \
     324             :         }\
     325             :         } while(0)
     326             : 
     327             : #define torture_assert_ndr_err_equal(torture_ctx,got,expected,cmt) \
     328             :         do { enum ndr_err_code __got = got, __expected = expected; \
     329             :         if (__got != __expected) { \
     330             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
     331             :                 return false; \
     332             :         }\
     333             :         } while(0)
     334             : 
     335             : #define torture_assert_ndr_err_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
     336             :         do { enum ndr_err_code __got = got, __expected = expected; \
     337             :         if (__got != __expected) { \
     338             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
     339             :                 ret = false; \
     340             :                 goto label; \
     341             :         }\
     342             :         } while(0)
     343             : 
     344             : #define torture_assert_hresult_equal(torture_ctx, got, expected, cmt) \
     345             :         do { HRESULT __got = got, __expected = expected; \
     346             :         if (!HRES_IS_EQUAL(__got, __expected)) { \
     347             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", hresult_errstr(__got), hresult_errstr(__expected), cmt); \
     348             :                 return false; \
     349             :         } \
     350             :         } while (0)
     351             : 
     352             : #define torture_assert_krb5_error_equal(torture_ctx, got, expected, cmt) \
     353             :         do { krb5_error_code __got = got, __expected = expected; \
     354             :         if (__got != __expected) { \
     355             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, error_message(__got), __expected, error_message(__expected), cmt); \
     356             :                 return false; \
     357             :         } \
     358             :         } while (0)
     359             : 
     360             : #define torture_assert_casestr_equal(torture_ctx,got,expected,cmt) \
     361             :         do { const char *__got = (got), *__expected = (expected); \
     362             :         if (!strequal(__got, __expected)) { \
     363             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     364             :                                __location__": "#got" was %s, expected %s: %s", \
     365             :                                __got, __expected == NULL ? "null" : __expected, cmt); \
     366             :                 return false; \
     367             :         } \
     368             :         } while(0)
     369             : 
     370             : #define torture_assert_str_equal(torture_ctx,got,expected,cmt)\
     371             :         do { const char *__got = (got), *__expected = (expected); \
     372             :         if (strcmp_safe(__got, __expected) != 0) { \
     373             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     374             :                                __location__": "#got" was %s, expected %s: %s", \
     375             :                                __got, __expected == NULL ? "NULL" : __expected, cmt); \
     376             :                 return false; \
     377             :         } \
     378             :         } while(0)
     379             : 
     380             : #define torture_assert_strn_equal(torture_ctx,got,expected,len,cmt)\
     381             :         do { const char *__got = (got), *__expected = (expected); \
     382             :         if (strncmp(__got, __expected, len) != 0) { \
     383             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     384             :                                            __location__": "#got" %s of len %d did not match "#expected" %s: %s", \
     385             :                                            __got, (int)len, __expected, cmt); \
     386             :                 return false; \
     387             :         } \
     388             :         } while(0)
     389             : 
     390             : #define torture_assert_str_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
     391             :         do { const char *__got = (got), *__expected = (expected); \
     392             :         if (strcmp_safe(__got, __expected) != 0) { \
     393             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     394             :                                            __location__": "#got" was %s, expected %s: %s", \
     395             :                                            __got, __expected, cmt); \
     396             :                 ret = false; \
     397             :                 goto label; \
     398             :         } \
     399             :         } while(0)
     400             : 
     401             : #define torture_assert_mem_equal(torture_ctx,got,expected,len,cmt)\
     402             :         do { const void *__got = (got), *__expected = (expected); \
     403             :         if (memcmp(__got, __expected, len) != 0) { \
     404             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     405             :                                __location__": "#got" of len %d did not match "#expected": %s", (int)len, cmt); \
     406             :                 return false; \
     407             :         } \
     408             :         } while(0)
     409             : 
     410             : #define torture_assert_mem_equal_goto(torture_ctx,got,expected,len,ret,label,cmt) \
     411             :         do { const void *__got = (got), *__expected = (expected); \
     412             :         if (memcmp(__got, __expected, len) != 0) { \
     413             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     414             :                                __location__": "#got" of len %d did not match "#expected": %s", (int)len, cmt); \
     415             :                 ret = false; \
     416             :                 goto label; \
     417             :         } \
     418             :         } while(0)
     419             : 
     420             : #define torture_assert_mem_not_equal_goto(torture_ctx,got,expected,len,ret,label,cmt) \
     421             :         do { const void *__got = (got), *__expected = (expected); \
     422             :         if (memcmp(__got, __expected, len) == 0) { \
     423             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     424             :                                __location__": "#got" of len %d unexpectedly matches "#expected": %s", (int)len, cmt); \
     425             :                 ret = false; \
     426             :                 goto label; \
     427             :         } \
     428             :         } while(0)
     429             : 
     430           0 : static inline void torture_dump_data_str_cb(const char *buf, void *private_data)
     431             : {
     432           0 :         char **dump = (char **)private_data;
     433           0 :         *dump = talloc_strdup_append_buffer(*dump, buf);
     434           0 : }
     435             : 
     436             : #define torture_assert_data_blob_equal(torture_ctx,got,expected,cmt)\
     437             :         do { const DATA_BLOB __got = (got), __expected = (expected); \
     438             :         if (__got.length != __expected.length) { \
     439             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     440             :                                __location__": "#got".len %d did not match "#expected" len %d: %s", \
     441             :                                (int)__got.length, (int)__expected.length, cmt); \
     442             :                 return false; \
     443             :         } \
     444             :         if (memcmp(__got.data, __expected.data, __got.length) != 0) { \
     445             :                 char *__dump = NULL; \
     446             :                 uint8_t __byte_a = 0x00;\
     447             :                 uint8_t __byte_b = 0x00;\
     448             :                 size_t __i;\
     449             :                 for (__i=0; __i < __expected.length; __i++) {\
     450             :                         __byte_a = __expected.data[__i];\
     451             :                         if (__i == __got.length) {\
     452             :                                 __byte_b = 0x00;\
     453             :                                 break;\
     454             :                         }\
     455             :                         __byte_b = __got.data[__i];\
     456             :                         if (__byte_a != __byte_b) {\
     457             :                                 break;\
     458             :                         }\
     459             :                 }\
     460             :                 torture_warning(torture_ctx, "blobs differ at byte 0x%02X (%zu)", (unsigned int)__i, __i);\
     461             :                 torture_warning(torture_ctx, "expected byte[0x%02X] = 0x%02X got byte[0x%02X] = 0x%02X",\
     462             :                                 (unsigned int)__i, __byte_a, (unsigned int)__i, __byte_b);\
     463             :                 __dump = talloc_strdup(torture_ctx, ""); \
     464             :                 dump_data_cb(__got.data, __got.length, true, \
     465             :                              torture_dump_data_str_cb, &__dump); \
     466             :                 torture_warning(torture_ctx, "got[0x%02X]: \n%s", \
     467             :                                 (unsigned int)__got.length, __dump); \
     468             :                 TALLOC_FREE(__dump); \
     469             :                 __dump = talloc_strdup(torture_ctx, ""); \
     470             :                 dump_data_cb(__expected.data, __expected.length, true, \
     471             :                              torture_dump_data_str_cb, &__dump); \
     472             :                 torture_warning(torture_ctx, "expected[0x%02X]: \n%s", \
     473             :                                 (int)__expected.length, __dump); \
     474             :                 TALLOC_FREE(__dump); \
     475             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     476             :                                __location__": "#got" of len %d did not match "#expected": %s", (int)__got.length, cmt); \
     477             :                 return false; \
     478             :         } \
     479             :         } while(0)
     480             : 
     481             : #define torture_assert_file_contains_text(torture_ctx,filename,expected,cmt)\
     482             :         do { \
     483             :         char *__got; \
     484             :         const char *__expected = (expected); \
     485             :         size_t __size; \
     486             :         __got = file_load(filename, &__size, 0, torture_ctx); \
     487             :         if (__got == NULL) { \
     488             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     489             :                                __location__": unable to open %s: %s\n", \
     490             :                                filename, cmt); \
     491             :                 return false; \
     492             :         } \
     493             :         \
     494             :         if (strcmp_safe(__got, __expected) != 0) { \
     495             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     496             :                         __location__": %s contained:\n%sExpected: %s%s\n", \
     497             :                         filename, __got, __expected, cmt); \
     498             :                 talloc_free(__got); \
     499             :                 return false; \
     500             :         } \
     501             :         talloc_free(__got); \
     502             :         } while(0)
     503             : 
     504             : #define torture_assert_file_contains(torture_ctx,filename,expected,cmt)\
     505             :         do { const char *__got, *__expected = (expected); \
     506             :         size_t __size; \
     507             :         __got = file_load(filename, *size, 0, torture_ctx); \
     508             :         if (strcmp_safe(__got, __expected) != 0) { \
     509             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     510             :                                            __location__": %s contained:\n%sExpected: %s%s\n", \
     511             :                                            __got, __expected, cmt); \
     512             :                 talloc_free(__got); \
     513             :                 return false; \
     514             :         } \
     515             :         talloc_free(__got); \
     516             :         } while(0)
     517             : 
     518             : #define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
     519             :         do { int __got = (got), __expected = (expected); \
     520             :         if (__got != __expected) { \
     521             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     522             :                         __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
     523             :                         __got, __got, __expected, __expected, cmt); \
     524             :                 return false; \
     525             :         } \
     526             :         } while(0)
     527             : 
     528             : #define torture_assert_int_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
     529             :         do { int __got = (got), __expected = (expected); \
     530             :         if (__got != __expected) { \
     531             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     532             :                         __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
     533             :                         __got, __got, __expected, __expected, cmt); \
     534             :                 ret = false; \
     535             :                 goto label; \
     536             :         } \
     537             :         } while(0)
     538             : 
     539             : #define torture_assert_int_not_equal(torture_ctx,got,not_expected,cmt)\
     540             :         do { int __got = (got), __not_expected = (not_expected); \
     541             :         if (__got == __not_expected) { \
     542             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     543             :                         __location__": "#got" was %d (0x%X), expected a different number: %s", \
     544             :                         __got, __got, cmt); \
     545             :                 return false; \
     546             :         } \
     547             :         } while(0)
     548             : 
     549             : #define torture_assert_int_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
     550             :         do { int __got = (got), __not_expected = (not_expected); \
     551             :         if (__got == __not_expected) { \
     552             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     553             :                         __location__": "#got" was %d (0x%X), expected a different number: %s", \
     554             :                         __got, __got, cmt); \
     555             :                 ret = false; \
     556             :                 goto label; \
     557             :         } \
     558             :         } while(0)
     559             : 
     560             : #define torture_assert_u32_equal(torture_ctx,got,expected,cmt)\
     561             :         do { uint32_t __got = (got), __expected = (expected); \
     562             :         if (__got != __expected) { \
     563             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     564             :                         __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected %"PRIu32" (0x%"PRIX32"): %s", \
     565             :                         __got, __got, \
     566             :                         __expected, __expected, \
     567             :                         cmt); \
     568             :                 return false; \
     569             :         } \
     570             :         } while(0)
     571             : 
     572             : #define torture_assert_u32_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
     573             :         do { uint32_t __got = (got), __expected = (expected); \
     574             :         if (__got != __expected) { \
     575             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     576             :                         __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected %"PRIu32" (0x%"PRIX32"): %s", \
     577             :                         __got, __got, \
     578             :                         __expected, __expected, \
     579             :                         cmt); \
     580             :                 ret = false; \
     581             :                 goto label; \
     582             :         } \
     583             :         } while(0)
     584             : 
     585             : #define torture_assert_u32_not_equal(torture_ctx,got,not_expected,cmt)\
     586             :         do { uint32_t __got = (got), __not_expected = (not_expected); \
     587             :         if (__got == __not_expected) { \
     588             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     589             :                         __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected a different number: %s", \
     590             :                         __got, __got, \
     591             :                         cmt); \
     592             :                 return false; \
     593             :         } \
     594             :         } while(0)
     595             : 
     596             : #define torture_assert_u32_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
     597             :         do { uint32_t __got = (got), __not_expected = (not_expected); \
     598             :         if (__got == __not_expected) { \
     599             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     600             :                         __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected a different number: %s", \
     601             :                         __got, __got, \
     602             :                         cmt); \
     603             :                 ret = false; \
     604             :                 goto label; \
     605             :         } \
     606             :         } while(0)
     607             : 
     608             : #define torture_assert_u64_equal(torture_ctx,got,expected,cmt)\
     609             :         do { uint64_t __got = (got), __expected = (expected); \
     610             :         if (__got != __expected) { \
     611             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     612             :                         __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected %"PRIu64" (0x%"PRIX64"): %s", \
     613             :                         __got, __got, \
     614             :                         __expected, __expected, \
     615             :                         cmt); \
     616             :                 return false; \
     617             :         } \
     618             :         } while(0)
     619             : 
     620             : #define torture_assert_u64_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
     621             :         do { uint64_t __got = (got), __expected = (expected); \
     622             :         if (__got != __expected) { \
     623             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     624             :                         __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected %"PRIu64" (0x%"PRIX64"): %s", \
     625             :                         __got, __got, \
     626             :                         __expected, __expected, \
     627             :                         cmt); \
     628             :                 ret = false; \
     629             :                 goto label; \
     630             :         } \
     631             :         } while(0)
     632             : 
     633             : #define torture_assert_u64_not_equal(torture_ctx,got,not_expected,cmt)\
     634             :         do { uint64_t __got = (got), __not_expected = (not_expected); \
     635             :         if (__got == __not_expected) { \
     636             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     637             :                         __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected a different number: %s", \
     638             :                         __got, __got, \
     639             :                         cmt); \
     640             :                 return false; \
     641             :         } \
     642             :         } while(0)
     643             : 
     644             : #define torture_assert_u64_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
     645             :         do { uint64_t __got = (got), __not_expected = (not_expected); \
     646             :         if (__got == __not_expected) { \
     647             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     648             :                         __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected a different number: %s", \
     649             :                         __got, __got, \
     650             :                         cmt); \
     651             :                 ret = false; \
     652             :                 goto label; \
     653             :         } \
     654             :         } while(0)
     655             : 
     656             : #define torture_assert_size_equal(torture_ctx,got,expected,cmt)\
     657             :         do { size_t __got = (got), __expected = (expected); \
     658             :         if (__got != __expected) { \
     659             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     660             :                         __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \
     661             :                         __got, __got, \
     662             :                         __expected, __expected, \
     663             :                         cmt); \
     664             :                 return false; \
     665             :         } \
     666             :         } while(0)
     667             : 
     668             : #define torture_assert_size_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
     669             :         do { size_t __got = (got), __expected = (expected); \
     670             :         if (__got != __expected) { \
     671             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     672             :                         __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \
     673             :                         __got, __got, \
     674             :                         __expected, __expected, \
     675             :                         cmt); \
     676             :                 ret = false; \
     677             :                 goto label; \
     678             :         } \
     679             :         } while(0)
     680             : 
     681             : #define torture_assert_size_not_equal(torture_ctx,got,not_expected,cmt)\
     682             :         do { size_t __got = (got), __not_expected = (not_expected); \
     683             :         if (__got == __not_expected) { \
     684             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     685             :                         __location__": "#got" was %zu (0x%zX), expected a different number: %s", \
     686             :                         __got, __got, \
     687             :                         cmt); \
     688             :                 return false; \
     689             :         } \
     690             :         } while(0)
     691             : 
     692             : #define torture_assert_size_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
     693             :         do { size_t __got = (got), __not_expected = (not_expected); \
     694             :         if (__got == __not_expected) { \
     695             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     696             :                         __location__": "#got" was %zu (0x%zX), expected a different number: %s", \
     697             :                         __got, __got, \
     698             :                         cmt); \
     699             :                 ret = false; \
     700             :                 goto label; \
     701             :         } \
     702             :         } while(0)
     703             : 
     704             : #define torture_assert_errno_equal(torture_ctx,expected,cmt)\
     705             :         do { int __expected = (expected); \
     706             :         if (errno != __expected) { \
     707             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     708             :                         __location__": errno was %d (%s), expected %d: %s: %s", \
     709             :                                            errno, strerror(errno), __expected, \
     710             :                                            strerror(__expected), cmt); \
     711             :                 return false; \
     712             :         } \
     713             :         } while(0)
     714             : 
     715             : #define torture_assert_errno_equal_goto(torture_ctx,expected,ret,label,cmt)\
     716             :         do { int __expected = (expected); \
     717             :         if (errno != __expected) { \
     718             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     719             :                         __location__": errno was %d (%s), expected %d: %s: %s", \
     720             :                                            errno, strerror(errno), __expected, \
     721             :                                            strerror(__expected), cmt); \
     722             :                 ret = false; \
     723             :                 goto label; \
     724             :         } \
     725             :         } while(0)
     726             : 
     727             : #define torture_assert_guid_equal(torture_ctx,got,expected,cmt)\
     728             :         do {const struct GUID __got = (got), __expected = (expected); \
     729             :         if (!GUID_equal(&__got, &__expected)) { \
     730             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     731             :                         __location__": "#got" was %s, expected %s: %s", \
     732             :                         GUID_string(torture_ctx, &__got), GUID_string(torture_ctx, &__expected), cmt); \
     733             :                 return false; \
     734             :         } \
     735             :         } while(0)
     736             : 
     737             : #define torture_assert_nttime_equal(torture_ctx,got,expected,cmt) \
     738             :         do { NTTIME __got = got, __expected = expected; \
     739             :         if (!nt_time_equal(&__got, &__expected)) { \
     740             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_time_string(torture_ctx, __got), nt_time_string(torture_ctx, __expected), cmt); \
     741             :                 return false; \
     742             :         }\
     743             :         } while(0)
     744             : 
     745             : #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
     746             :         do {const struct dom_sid *__got = (got), *__expected = (expected); \
     747             :         if (!dom_sid_equal(__got, __expected)) { \
     748             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     749             :                                            __location__": "#got" was %s, expected %s: %s", \
     750             :                                            dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
     751             :                 return false; \
     752             :         } \
     753             :         } while(0)
     754             : 
     755             : #define torture_assert_not_null(torture_ctx,got,cmt)\
     756             :         do {const void *__got = (got); \
     757             :         if (__got == NULL) { \
     758             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     759             :                         __location__": "#got" was NULL, expected != NULL: %s", \
     760             :                         cmt); \
     761             :                 return false; \
     762             :         } \
     763             :         } while(0)
     764             : 
     765             : #define torture_assert_not_null_goto(torture_ctx,got,ret,label,cmt)\
     766             :         do {const void *__got = (got); \
     767             :         if (__got == NULL) { \
     768             :                 torture_result(torture_ctx, TORTURE_FAIL, \
     769             :                         __location__": "#got" was NULL, expected != NULL: %s", \
     770             :                         cmt); \
     771             :                 ret = false; \
     772             :                 goto label; \
     773             :         } \
     774             :         } while(0)
     775             : 
     776             : #define torture_skip(torture_ctx,cmt) do {\
     777             :                 torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
     778             :                 return true; \
     779             :         } while(0)
     780             : #define torture_skip_goto(torture_ctx,label,cmt) do {\
     781             :                 torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
     782             :                 goto label; \
     783             :         } while(0)
     784             : #define torture_fail(torture_ctx,cmt) do {\
     785             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
     786             :                 return false; \
     787             :         } while (0)
     788             : #define torture_fail_goto(torture_ctx,label,cmt) do {\
     789             :                 torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
     790             :                 goto label; \
     791             :         } while (0)
     792             : 
     793             : #define torture_out stderr
     794             : 
     795             : /* Convenience macros */
     796             : #define torture_assert_ntstatus_ok(torture_ctx,expr,cmt) \
     797             :                 torture_assert_ntstatus_equal(torture_ctx,expr,NT_STATUS_OK,cmt)
     798             : 
     799             : #define torture_assert_ntstatus_ok_goto(torture_ctx,expr,ret,label,cmt) \
     800             :                 torture_assert_ntstatus_equal_goto(torture_ctx,expr,NT_STATUS_OK,ret,label,cmt)
     801             : 
     802             : #define torture_assert_werr_ok(torture_ctx,expr,cmt) \
     803             :                 torture_assert_werr_equal(torture_ctx,expr,WERR_OK,cmt)
     804             : 
     805             : #define torture_assert_ndr_success(torture_ctx,expr,cmt) \
     806             :                 torture_assert_ndr_err_equal(torture_ctx,expr,NDR_ERR_SUCCESS,cmt)
     807             : 
     808             : #define torture_assert_ndr_success_goto(torture_ctx,expr,ret,label,cmt) \
     809             :                 torture_assert_ndr_err_equal_goto(torture_ctx,expr,NDR_ERR_SUCCESS,ret,label,cmt)
     810             : 
     811             : #define torture_assert_hresult_ok(torture_ctx,expr,cmt) \
     812             :                 torture_assert_hresult_equal(torture_ctx,expr,HRES_ERROR(0), cmt)
     813             : 
     814             : /* Getting settings */
     815             : const char *torture_setting_string(struct torture_context *test, \
     816             :                                                                    const char *name, 
     817             :                                                                    const char *default_value);
     818             : 
     819             : int torture_setting_int(struct torture_context *test, 
     820             :                                                 const char *name, 
     821             :                                                 int default_value);
     822             : 
     823             : double torture_setting_double(struct torture_context *test, 
     824             :                                                 const char *name, 
     825             :                                                 double default_value);
     826             : 
     827             : bool torture_setting_bool(struct torture_context *test, 
     828             :                                                   const char *name, 
     829             :                                                   bool default_value);
     830             : 
     831             : struct torture_suite *torture_find_suite(struct torture_suite *parent, 
     832             :                                                                                  const char *name);
     833             : 
     834             : unsigned long torture_setting_ulong(struct torture_context *test,
     835             :                                     const char *name,
     836             :                                     unsigned long default_value);
     837             : 
     838             : NTSTATUS torture_temp_dir(struct torture_context *tctx, 
     839             :                                    const char *prefix, 
     840             :                                    char **tempdir);
     841             : NTSTATUS torture_deltree_outputdir(struct torture_context *tctx);
     842             : 
     843             : struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
     844             :                 const char *name,
     845             :                 bool (*run) (struct torture_context *test, void *tcase_data));
     846             : 
     847             : 
     848             : bool torture_suite_init_tcase(struct torture_suite *suite, 
     849             :                               struct torture_tcase *tcase, 
     850             :                               const char *name);
     851             : int torture_suite_children_count(const struct torture_suite *suite);
     852             : 
     853             : struct torture_context *torture_context_init(struct tevent_context *event_ctx, struct torture_results *results);
     854             : 
     855             : struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops);
     856             : 
     857             : struct torture_context *torture_context_child(struct torture_context *tctx);
     858             : 
     859             : extern const struct torture_ui_ops torture_subunit_ui_ops;
     860             : extern const struct torture_ui_ops torture_simple_ui_ops;
     861             : 
     862             : #endif /* __TORTURE_UI_H__ */

Generated by: LCOV version 1.14