2 Unix SMB/CIFS implementation.
3 SMB torture UI functions
5 Copyright (C) Jelmer Vernooij 2006
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.
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.
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/>.
21 #ifndef __TORTURE_UI_H__
22 #define __TORTURE_UI_H__
25 struct torture_context
;
28 struct torture_results
;
31 * Arranged in precedence order. TORTURE_ERROR has the highest priority;
32 * TORTURE_OK the lowest.
41 enum torture_progress_whence
{
45 TORTURE_PROGRESS_PUSH
,
49 * These callbacks should be implemented by any backend that wishes
50 * to listen to reports from the torture tests.
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
*);
70 void torture_ui_test_start(struct torture_context
*context
,
71 struct torture_tcase
*tcase
,
72 struct torture_test
*test
);
74 void torture_ui_test_result(struct torture_context
*context
,
75 enum torture_result result
,
78 void torture_ui_report_time(struct torture_context
*context
);
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.
86 * Torture tests should instead call the torture_*() macros and functions
90 struct torture_subunit_prefix
{
91 const struct torture_subunit_prefix
*parent
;
92 char subunit_prefix
[256];
95 struct torture_context
97 struct torture_results
*results
;
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
;
104 enum torture_result last_result
;
107 /** Directory used for temporary test data */
108 const char *outputdir
;
111 struct tevent_context
*ev
;
113 /** Loadparm context (will go away in favor of torture_setting_ at some point) */
114 struct loadparm_context
*lp_ctx
;
119 struct torture_results
121 const struct torture_ui_ops
*ui_ops
;
124 /** Whether tests should avoid writing output to stdout */
131 * Describes a particular torture test
133 struct torture_test
{
134 /** Short unique name for the test. */
137 /** Long description for the test. */
138 const char *description
;
140 /** Whether this is a dangerous test
141 * (can corrupt the remote servers data or bring it down). */
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
);
149 struct torture_test
*prev
, *next
;
151 /** Pointer to the actual test function. This is run by the
152 * run() function above. */
155 /** Use data for this test */
158 struct torture_tcase
*tcase
;
162 * Describes a particular test case.
164 struct torture_tcase
{
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
;
171 struct torture_test
*tests
;
172 struct torture_tcase
*prev
, *next
;
173 const struct torture_suite
*suite
;
179 const char *description
;
180 struct torture_tcase
*testcases
;
181 struct torture_suite
*children
;
182 const struct torture_suite
*parent
;
184 /* Pointers to siblings of this torture suite */
185 struct torture_suite
*prev
, *next
;
188 /** Create a new torture suite */
189 struct torture_suite
*torture_suite_create(TALLOC_CTX
*mem_ctx
,
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 *));
197 /* Add another test to run for a particular testcase */
198 struct torture_test
*torture_tcase_add_test_const(struct torture_tcase
*tcase
,
200 bool (*run
) (struct torture_context
*test
,
201 const void *tcase_data
, const void *test_data
),
202 const void *test_data
);
204 /* Add a testcase to a testsuite */
205 struct torture_tcase
*torture_suite_add_tcase(struct torture_suite
*suite
,
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
,
213 bool (*run
) (struct torture_context
*test
,
214 const void *test_data
),
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
,
222 bool (*run
) (struct torture_context
*test
,
223 const void *tcase_data
));
225 /* Convenience wrapper that adds a test that doesn't need any
227 struct torture_tcase
*torture_suite_add_simple_test(
228 struct torture_suite
*suite
,
230 bool (*run
) (struct torture_context
*test
));
232 /* Add a child testsuite to an existing testsuite */
233 bool torture_suite_add_suite(struct torture_suite
*suite
,
234 struct torture_suite
*child
);
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
,
242 /* Run the specified testsuite recursively */
243 bool torture_run_suite(struct torture_context
*context
,
244 struct torture_suite
*suite
);
246 /* Run the specified testsuite recursively, but only the specified
248 bool torture_run_suite_restricted(struct torture_context
*context
,
249 struct torture_suite
*suite
, const char **restricted
);
251 /* Run the specified testcase */
252 bool torture_run_tcase(struct torture_context
*context
,
253 struct torture_tcase
*tcase
);
255 bool torture_run_tcase_restricted(struct torture_context
*context
,
256 struct torture_tcase
*tcase
, const char **restricted
);
258 /* Run the specified test */
259 bool torture_run_test(struct torture_context
*context
,
260 struct torture_tcase
*tcase
,
261 struct torture_test
*test
);
263 bool torture_run_test_restricted(struct torture_context
*context
,
264 struct torture_tcase
*tcase
,
265 struct torture_test
*test
,
266 const char **restricted
);
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);
273 #define torture_assert(torture_ctx,expr,cmt) do { \
275 torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
280 #define torture_assertf(torture_ctx, expr, format, ...) do { \
282 char *_msg = talloc_asprintf(torture_ctx, \
285 torture_result(torture_ctx, \
287 __location__": Expression `%s' failed: %s", \
288 __STRING(expr), _msg); \
294 #define torture_assert_goto(torture_ctx,expr,ret,label,cmt) do { \
296 torture_result(torture_ctx, TORTURE_FAIL, __location__": Expression `%s' failed: %s", __STRING(expr), cmt); \
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); \
310 #define torture_assert_werr_equal_goto(torture_ctx, got, expected, ret, label, cmt) \
311 do { WERROR __got = got, __expected = expected; \
312 if (!W_ERROR_EQUAL(__got, __expected)) { \
313 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", win_errstr(__got), win_errstr(__expected), cmt); \
319 #define torture_assert_ntstatus_equal(torture_ctx,got,expected,cmt) \
320 do { NTSTATUS __got = got, __expected = expected; \
321 if (!NT_STATUS_EQUAL(__got, __expected)) { \
322 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_errstr(__got), nt_errstr(__expected), cmt); \
327 #define torture_assert_ntstatus_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
328 do { NTSTATUS __got = got, __expected = expected; \
329 if (!NT_STATUS_EQUAL(__got, __expected)) { \
330 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", nt_errstr(__got), nt_errstr(__expected), cmt); \
336 #define torture_assert_ndr_err_equal(torture_ctx,got,expected,cmt) \
337 do { enum ndr_err_code __got = got, __expected = expected; \
338 if (__got != __expected) { \
339 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
344 #define torture_assert_ndr_err_equal_goto(torture_ctx,got,expected,ret,label,cmt) \
345 do { enum ndr_err_code __got = got, __expected = expected; \
346 if (__got != __expected) { \
347 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, ndr_errstr(__got), __expected, __STRING(expected), cmt); \
353 #define torture_assert_hresult_equal(torture_ctx, got, expected, cmt) \
354 do { HRESULT __got = got, __expected = expected; \
355 if (!HRES_IS_EQUAL(__got, __expected)) { \
356 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %s, expected %s: %s", hresult_errstr(__got), hresult_errstr(__expected), cmt); \
361 #define torture_assert_krb5_error_equal(torture_ctx, got, expected, cmt) \
362 do { krb5_error_code __got = got, __expected = expected; \
363 if (__got != __expected) { \
364 torture_result(torture_ctx, TORTURE_FAIL, __location__": "#got" was %d (%s), expected %d (%s): %s", __got, error_message(__got), __expected, error_message(__expected), cmt); \
369 #define torture_assert_casestr_equal(torture_ctx,got,expected,cmt) \
370 do { const char *__got = (got), *__expected = (expected); \
371 if (!strequal(__got, __expected)) { \
372 torture_result(torture_ctx, TORTURE_FAIL, \
373 __location__": "#got" was %s, expected %s: %s", \
374 __got, __expected == NULL ? "null" : __expected, cmt); \
379 #define torture_assert_str_equal(torture_ctx,got,expected,cmt)\
380 do { const char *__got = (got), *__expected = (expected); \
381 if (strcmp_safe(__got, __expected) != 0) { \
382 torture_result(torture_ctx, TORTURE_FAIL, \
383 __location__": "#got" was %s, expected %s: %s", \
384 __got, __expected == NULL ? "NULL" : __expected, cmt); \
389 #define torture_assert_strn_equal(torture_ctx,got,expected,len,cmt)\
390 do { const char *__got = (got), *__expected = (expected); \
391 if (strncmp(__got, __expected, len) != 0) { \
392 torture_result(torture_ctx, TORTURE_FAIL, \
393 __location__": "#got" %s of len %d did not match "#expected" %s: %s", \
394 __got, (int)len, __expected, cmt); \
399 #define torture_assert_str_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
400 do { const char *__got = (got), *__expected = (expected); \
401 if (strcmp_safe(__got, __expected) != 0) { \
402 torture_result(torture_ctx, TORTURE_FAIL, \
403 __location__": "#got" was %s, expected %s: %s", \
404 __got, __expected, cmt); \
410 #define torture_assert_mem_equal(torture_ctx,got,expected,len,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); \
419 #define torture_assert_mem_equal_goto(torture_ctx,got,expected,len,ret,label,cmt) \
420 do { const void *__got = (got), *__expected = (expected); \
421 if (memcmp(__got, __expected, len) != 0) { \
422 torture_result(torture_ctx, TORTURE_FAIL, \
423 __location__": "#got" of len %d did not match "#expected": %s", (int)len, cmt); \
429 #define torture_assert_mem_not_equal_goto(torture_ctx,got,expected,len,ret,label,cmt) \
430 do { const void *__got = (got), *__expected = (expected); \
431 if (memcmp(__got, __expected, len) == 0) { \
432 torture_result(torture_ctx, TORTURE_FAIL, \
433 __location__": "#got" of len %d unexpectedly matches "#expected": %s", (int)len, cmt); \
439 static inline void torture_dump_data_str_cb(const char *buf
, void *private_data
)
441 char **dump
= (char **)private_data
;
442 *dump
= talloc_strdup_append_buffer(*dump
, buf
);
445 #define torture_assert_data_blob_equal(torture_ctx,got,expected,cmt)\
446 do { const DATA_BLOB __got = (got), __expected = (expected); \
447 if (__got.length != __expected.length) { \
448 torture_result(torture_ctx, TORTURE_FAIL, \
449 __location__": "#got".len %d did not match "#expected" len %d: %s", \
450 (int)__got.length, (int)__expected.length, cmt); \
453 if (memcmp(__got.data, __expected.data, __got.length) != 0) { \
454 char *__dump = NULL; \
455 uint8_t __byte_a = 0x00;\
456 uint8_t __byte_b = 0x00;\
458 for (__i=0; __i < __expected.length; __i++) {\
459 __byte_a = __expected.data[__i];\
460 if (__i == __got.length) {\
464 __byte_b = __got.data[__i];\
465 if (__byte_a != __byte_b) {\
469 torture_warning(torture_ctx, "blobs differ at byte 0x%02X (%zu)", (unsigned int)__i, __i);\
470 torture_warning(torture_ctx, "expected byte[0x%02X] = 0x%02X got byte[0x%02X] = 0x%02X",\
471 (unsigned int)__i, __byte_a, (unsigned int)__i, __byte_b);\
472 __dump = talloc_strdup(torture_ctx, ""); \
473 dump_data_cb(__got.data, __got.length, true, \
474 torture_dump_data_str_cb, &__dump); \
475 torture_warning(torture_ctx, "got[0x%02X]: \n%s", \
476 (unsigned int)__got.length, __dump); \
477 TALLOC_FREE(__dump); \
478 __dump = talloc_strdup(torture_ctx, ""); \
479 dump_data_cb(__expected.data, __expected.length, true, \
480 torture_dump_data_str_cb, &__dump); \
481 torture_warning(torture_ctx, "expected[0x%02X]: \n%s", \
482 (int)__expected.length, __dump); \
483 TALLOC_FREE(__dump); \
484 torture_result(torture_ctx, TORTURE_FAIL, \
485 __location__": "#got" of len %d did not match "#expected": %s", (int)__got.length, cmt); \
490 #define torture_assert_file_contains_text(torture_ctx,filename,expected,cmt)\
493 const char *__expected = (expected); \
495 __got = file_load(filename, &__size, 0, torture_ctx); \
496 if (__got == NULL) { \
497 torture_result(torture_ctx, TORTURE_FAIL, \
498 __location__": unable to open %s: %s\n", \
503 if (strcmp_safe(__got, __expected) != 0) { \
504 torture_result(torture_ctx, TORTURE_FAIL, \
505 __location__": %s contained:\n%sExpected: %s%s\n", \
506 filename, __got, __expected, cmt); \
507 talloc_free(__got); \
510 talloc_free(__got); \
513 #define torture_assert_file_contains(torture_ctx,filename,expected,cmt)\
514 do { const char *__got, *__expected = (expected); \
516 __got = file_load(filename, *size, 0, torture_ctx); \
517 if (strcmp_safe(__got, __expected) != 0) { \
518 torture_result(torture_ctx, TORTURE_FAIL, \
519 __location__": %s contained:\n%sExpected: %s%s\n", \
520 __got, __expected, cmt); \
521 talloc_free(__got); \
524 talloc_free(__got); \
527 #define torture_assert_int_equal(torture_ctx,got,expected,cmt)\
528 do { int __got = (got), __expected = (expected); \
529 if (__got != __expected) { \
530 torture_result(torture_ctx, TORTURE_FAIL, \
531 __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
532 __got, __got, __expected, __expected, cmt); \
537 #define torture_assert_int_less(torture_ctx,got,limit,cmt)\
538 do { int __got = (got), __limit = (limit); \
539 if (__got >= __limit) { \
540 torture_result(torture_ctx, TORTURE_FAIL, \
541 __location__": "#got" was %d (0x%X), expected < %d (0x%X): %s", \
542 __got, __got, __limit, __limit, cmt); \
547 #define torture_assert_int_greater(torture_ctx,got,limit,cmt)\
548 do { int __got = (got), __limit = (limit); \
549 if (__got <= __limit) { \
550 torture_result(torture_ctx, TORTURE_FAIL, \
551 __location__": "#got" was %d (0x%X), expected > %d (0x%X): %s", \
552 __got, __got, __limit, __limit, cmt); \
557 #define torture_assert_int_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
558 do { int __got = (got), __expected = (expected); \
559 if (__got != __expected) { \
560 torture_result(torture_ctx, TORTURE_FAIL, \
561 __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
562 __got, __got, __expected, __expected, cmt); \
568 #define torture_assert_int_not_equal(torture_ctx,got,not_expected,cmt)\
569 do { int __got = (got), __not_expected = (not_expected); \
570 if (__got == __not_expected) { \
571 torture_result(torture_ctx, TORTURE_FAIL, \
572 __location__": "#got" was %d (0x%X), expected a different number: %s", \
573 __got, __got, cmt); \
578 #define torture_assert_int_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
579 do { int __got = (got), __not_expected = (not_expected); \
580 if (__got == __not_expected) { \
581 torture_result(torture_ctx, TORTURE_FAIL, \
582 __location__": "#got" was %d (0x%X), expected a different number: %s", \
583 __got, __got, cmt); \
589 #define torture_assert_u32_equal(torture_ctx,got,expected,cmt)\
590 do { uint32_t __got = (got), __expected = (expected); \
591 if (__got != __expected) { \
592 torture_result(torture_ctx, TORTURE_FAIL, \
593 __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected %"PRIu32" (0x%"PRIX32"): %s", \
595 __expected, __expected, \
601 #define torture_assert_u32_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
602 do { uint32_t __got = (got), __expected = (expected); \
603 if (__got != __expected) { \
604 torture_result(torture_ctx, TORTURE_FAIL, \
605 __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected %"PRIu32" (0x%"PRIX32"): %s", \
607 __expected, __expected, \
614 #define torture_assert_u32_not_equal(torture_ctx,got,not_expected,cmt)\
615 do { uint32_t __got = (got), __not_expected = (not_expected); \
616 if (__got == __not_expected) { \
617 torture_result(torture_ctx, TORTURE_FAIL, \
618 __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected a different number: %s", \
625 #define torture_assert_u32_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
626 do { uint32_t __got = (got), __not_expected = (not_expected); \
627 if (__got == __not_expected) { \
628 torture_result(torture_ctx, TORTURE_FAIL, \
629 __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected a different number: %s", \
637 #define torture_assert_u64_equal(torture_ctx,got,expected,cmt)\
638 do { uint64_t __got = (got), __expected = (expected); \
639 if (__got != __expected) { \
640 torture_result(torture_ctx, TORTURE_FAIL, \
641 __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected %"PRIu64" (0x%"PRIX64"): %s", \
643 __expected, __expected, \
649 #define torture_assert_u64_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
650 do { uint64_t __got = (got), __expected = (expected); \
651 if (__got != __expected) { \
652 torture_result(torture_ctx, TORTURE_FAIL, \
653 __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected %"PRIu64" (0x%"PRIX64"): %s", \
655 __expected, __expected, \
662 #define torture_assert_u64_not_equal(torture_ctx,got,not_expected,cmt)\
663 do { uint64_t __got = (got), __not_expected = (not_expected); \
664 if (__got == __not_expected) { \
665 torture_result(torture_ctx, TORTURE_FAIL, \
666 __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected a different number: %s", \
673 #define torture_assert_u64_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
674 do { uint64_t __got = (got), __not_expected = (not_expected); \
675 if (__got == __not_expected) { \
676 torture_result(torture_ctx, TORTURE_FAIL, \
677 __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected a different number: %s", \
685 #define torture_assert_size_equal(torture_ctx,got,expected,cmt)\
686 do { size_t __got = (got), __expected = (expected); \
687 if (__got != __expected) { \
688 torture_result(torture_ctx, TORTURE_FAIL, \
689 __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \
691 __expected, __expected, \
697 #define torture_assert_size_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
698 do { size_t __got = (got), __expected = (expected); \
699 if (__got != __expected) { \
700 torture_result(torture_ctx, TORTURE_FAIL, \
701 __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \
703 __expected, __expected, \
710 #define torture_assert_size_not_equal(torture_ctx,got,not_expected,cmt)\
711 do { size_t __got = (got), __not_expected = (not_expected); \
712 if (__got == __not_expected) { \
713 torture_result(torture_ctx, TORTURE_FAIL, \
714 __location__": "#got" was %zu (0x%zX), expected a different number: %s", \
721 #define torture_assert_size_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
722 do { size_t __got = (got), __not_expected = (not_expected); \
723 if (__got == __not_expected) { \
724 torture_result(torture_ctx, TORTURE_FAIL, \
725 __location__": "#got" was %zu (0x%zX), expected a different number: %s", \
733 #define torture_assert_errno_equal(torture_ctx,expected,cmt)\
734 do { int __expected = (expected); \
735 if (errno != __expected) { \
736 torture_result(torture_ctx, TORTURE_FAIL, \
737 __location__": errno was %d (%s), expected %d: %s: %s", \
738 errno, strerror(errno), __expected, \
739 strerror(__expected), cmt); \
744 #define torture_assert_errno_equal_goto(torture_ctx,expected,ret,label,cmt)\
745 do { int __expected = (expected); \
746 if (errno != __expected) { \
747 torture_result(torture_ctx, TORTURE_FAIL, \
748 __location__": errno was %d (%s), expected %d: %s: %s", \
749 errno, strerror(errno), __expected, \
750 strerror(__expected), cmt); \
756 #define torture_assert_guid_equal(torture_ctx,got,expected,cmt)\
757 do {const struct GUID __got = (got), __expected = (expected); \
758 if (!GUID_equal(&__got, &__expected)) { \
759 torture_result(torture_ctx, TORTURE_FAIL, \
760 __location__": "#got" was %s, expected %s: %s", \
761 GUID_string(torture_ctx, &__got), GUID_string(torture_ctx, &__expected), cmt); \
766 #define torture_assert_nttime_equal(torture_ctx,got,expected,cmt) \
767 do { NTTIME __got = got, __expected = expected; \
768 if (!nt_time_equal(&__got, &__expected)) { \
769 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); \
774 #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
775 do {const struct dom_sid *__got = (got), *__expected = (expected); \
776 if (!dom_sid_equal(__got, __expected)) { \
777 torture_result(torture_ctx, TORTURE_FAIL, \
778 __location__": "#got" was %s, expected %s: %s", \
779 dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
784 #define torture_assert_not_null(torture_ctx,got,cmt)\
785 do {const void *__got = (got); \
786 if (__got == NULL) { \
787 torture_result(torture_ctx, TORTURE_FAIL, \
788 __location__": "#got" was NULL, expected != NULL: %s", \
794 #define torture_assert_not_null_goto(torture_ctx,got,ret,label,cmt)\
795 do {const void *__got = (got); \
796 if (__got == NULL) { \
797 torture_result(torture_ctx, TORTURE_FAIL, \
798 __location__": "#got" was NULL, expected != NULL: %s", \
805 #define torture_skip(torture_ctx,cmt) do {\
806 torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
809 #define torture_skip_goto(torture_ctx,label,cmt) do {\
810 torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
813 #define torture_fail(torture_ctx,cmt) do {\
814 torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
817 #define torture_fail_goto(torture_ctx,label,cmt) do {\
818 torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
822 #define torture_out stderr
824 /* Convenience macros */
825 #define torture_assert_ntstatus_ok(torture_ctx,expr,cmt) \
826 torture_assert_ntstatus_equal(torture_ctx,expr,NT_STATUS_OK,cmt)
828 #define torture_assert_ntstatus_ok_goto(torture_ctx,expr,ret,label,cmt) \
829 torture_assert_ntstatus_equal_goto(torture_ctx,expr,NT_STATUS_OK,ret,label,cmt)
831 #define torture_assert_werr_ok(torture_ctx,expr,cmt) \
832 torture_assert_werr_equal(torture_ctx,expr,WERR_OK,cmt)
834 #define torture_assert_werr_ok_goto(torture_ctx,expr,ret,label,cmt) \
835 torture_assert_werr_equal_goto(torture_ctx,expr,WERR_OK,ret,label,cmt)
837 #define torture_assert_ndr_success(torture_ctx,expr,cmt) \
838 torture_assert_ndr_err_equal(torture_ctx,expr,NDR_ERR_SUCCESS,cmt)
840 #define torture_assert_ndr_success_goto(torture_ctx,expr,ret,label,cmt) \
841 torture_assert_ndr_err_equal_goto(torture_ctx,expr,NDR_ERR_SUCCESS,ret,label,cmt)
843 #define torture_assert_hresult_ok(torture_ctx,expr,cmt) \
844 torture_assert_hresult_equal(torture_ctx,expr,HRES_ERROR(0), cmt)
846 /* Getting settings */
847 const char *torture_setting_string(struct torture_context
*test
, \
849 const char *default_value
);
851 int torture_setting_int(struct torture_context
*test
,
855 double torture_setting_double(struct torture_context
*test
,
857 double default_value
);
859 bool torture_setting_bool(struct torture_context
*test
,
863 struct torture_suite
*torture_find_suite(struct torture_suite
*parent
,
866 unsigned long torture_setting_ulong(struct torture_context
*test
,
868 unsigned long default_value
);
870 NTSTATUS
torture_temp_dir(struct torture_context
*tctx
,
873 NTSTATUS
torture_deltree_outputdir(struct torture_context
*tctx
);
875 struct torture_test
*torture_tcase_add_simple_test(struct torture_tcase
*tcase
,
877 bool (*run
) (struct torture_context
*test
, void *tcase_data
));
880 bool torture_suite_init_tcase(struct torture_suite
*suite
,
881 struct torture_tcase
*tcase
,
883 int torture_suite_children_count(const struct torture_suite
*suite
);
885 struct torture_context
*torture_context_init(struct tevent_context
*event_ctx
, struct torture_results
*results
);
887 struct torture_results
*torture_results_init(TALLOC_CTX
*mem_ctx
, const struct torture_ui_ops
*ui_ops
);
889 struct torture_context
*torture_context_child(struct torture_context
*tctx
);
891 extern const struct torture_ui_ops torture_subunit_ui_ops
;
892 extern const struct torture_ui_ops torture_simple_ui_ops
;
894 #endif /* __TORTURE_UI_H__ */