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