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_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); \
314 : ret = false; \
315 : goto label; \
316 : } \
317 : } while (0)
318 :
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); \
323 : return false; \
324 : }\
325 : } while(0)
326 :
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); \
331 : ret = false; \
332 : goto label; \
333 : }\
334 : } while(0)
335 :
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); \
340 : return false; \
341 : }\
342 : } while(0)
343 :
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); \
348 : ret = false; \
349 : goto label; \
350 : }\
351 : } while(0)
352 :
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); \
357 : return false; \
358 : } \
359 : } while (0)
360 :
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); \
365 : return false; \
366 : } \
367 : } while (0)
368 :
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); \
375 : return false; \
376 : } \
377 : } while(0)
378 :
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); \
385 : return false; \
386 : } \
387 : } while(0)
388 :
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); \
395 : return false; \
396 : } \
397 : } while(0)
398 :
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); \
405 : ret = false; \
406 : goto label; \
407 : } \
408 : } while(0)
409 :
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); \
415 : return false; \
416 : } \
417 : } while(0)
418 :
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); \
424 : ret = false; \
425 : goto label; \
426 : } \
427 : } while(0)
428 :
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); \
434 : ret = false; \
435 : goto label; \
436 : } \
437 : } while(0)
438 :
439 0 : static inline void torture_dump_data_str_cb(const char *buf, void *private_data)
440 : {
441 0 : char **dump = (char **)private_data;
442 0 : *dump = talloc_strdup_append_buffer(*dump, buf);
443 0 : }
444 :
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); \
451 : return false; \
452 : } \
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;\
457 : size_t __i;\
458 : for (__i=0; __i < __expected.length; __i++) {\
459 : __byte_a = __expected.data[__i];\
460 : if (__i == __got.length) {\
461 : __byte_b = 0x00;\
462 : break;\
463 : }\
464 : __byte_b = __got.data[__i];\
465 : if (__byte_a != __byte_b) {\
466 : break;\
467 : }\
468 : }\
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); \
486 : return false; \
487 : } \
488 : } while(0)
489 :
490 : #define torture_assert_file_contains_text(torture_ctx,filename,expected,cmt)\
491 : do { \
492 : char *__got; \
493 : const char *__expected = (expected); \
494 : size_t __size; \
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", \
499 : filename, cmt); \
500 : return false; \
501 : } \
502 : \
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); \
508 : return false; \
509 : } \
510 : talloc_free(__got); \
511 : } while(0)
512 :
513 : #define torture_assert_file_contains(torture_ctx,filename,expected,cmt)\
514 : do { const char *__got, *__expected = (expected); \
515 : size_t __size; \
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); \
522 : return false; \
523 : } \
524 : talloc_free(__got); \
525 : } while(0)
526 :
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); \
533 : return false; \
534 : } \
535 : } while(0)
536 :
537 : #define torture_assert_int_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
538 : do { int __got = (got), __expected = (expected); \
539 : if (__got != __expected) { \
540 : torture_result(torture_ctx, TORTURE_FAIL, \
541 : __location__": "#got" was %d (0x%X), expected %d (0x%X): %s", \
542 : __got, __got, __expected, __expected, cmt); \
543 : ret = false; \
544 : goto label; \
545 : } \
546 : } while(0)
547 :
548 : #define torture_assert_int_not_equal(torture_ctx,got,not_expected,cmt)\
549 : do { int __got = (got), __not_expected = (not_expected); \
550 : if (__got == __not_expected) { \
551 : torture_result(torture_ctx, TORTURE_FAIL, \
552 : __location__": "#got" was %d (0x%X), expected a different number: %s", \
553 : __got, __got, cmt); \
554 : return false; \
555 : } \
556 : } while(0)
557 :
558 : #define torture_assert_int_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
559 : do { int __got = (got), __not_expected = (not_expected); \
560 : if (__got == __not_expected) { \
561 : torture_result(torture_ctx, TORTURE_FAIL, \
562 : __location__": "#got" was %d (0x%X), expected a different number: %s", \
563 : __got, __got, cmt); \
564 : ret = false; \
565 : goto label; \
566 : } \
567 : } while(0)
568 :
569 : #define torture_assert_u32_equal(torture_ctx,got,expected,cmt)\
570 : do { uint32_t __got = (got), __expected = (expected); \
571 : if (__got != __expected) { \
572 : torture_result(torture_ctx, TORTURE_FAIL, \
573 : __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected %"PRIu32" (0x%"PRIX32"): %s", \
574 : __got, __got, \
575 : __expected, __expected, \
576 : cmt); \
577 : return false; \
578 : } \
579 : } while(0)
580 :
581 : #define torture_assert_u32_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
582 : do { uint32_t __got = (got), __expected = (expected); \
583 : if (__got != __expected) { \
584 : torture_result(torture_ctx, TORTURE_FAIL, \
585 : __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected %"PRIu32" (0x%"PRIX32"): %s", \
586 : __got, __got, \
587 : __expected, __expected, \
588 : cmt); \
589 : ret = false; \
590 : goto label; \
591 : } \
592 : } while(0)
593 :
594 : #define torture_assert_u32_not_equal(torture_ctx,got,not_expected,cmt)\
595 : do { uint32_t __got = (got), __not_expected = (not_expected); \
596 : if (__got == __not_expected) { \
597 : torture_result(torture_ctx, TORTURE_FAIL, \
598 : __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected a different number: %s", \
599 : __got, __got, \
600 : cmt); \
601 : return false; \
602 : } \
603 : } while(0)
604 :
605 : #define torture_assert_u32_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
606 : do { uint32_t __got = (got), __not_expected = (not_expected); \
607 : if (__got == __not_expected) { \
608 : torture_result(torture_ctx, TORTURE_FAIL, \
609 : __location__": "#got" was %"PRIu32" (0x%"PRIX32"), expected a different number: %s", \
610 : __got, __got, \
611 : cmt); \
612 : ret = false; \
613 : goto label; \
614 : } \
615 : } while(0)
616 :
617 : #define torture_assert_u64_equal(torture_ctx,got,expected,cmt)\
618 : do { uint64_t __got = (got), __expected = (expected); \
619 : if (__got != __expected) { \
620 : torture_result(torture_ctx, TORTURE_FAIL, \
621 : __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected %"PRIu64" (0x%"PRIX64"): %s", \
622 : __got, __got, \
623 : __expected, __expected, \
624 : cmt); \
625 : return false; \
626 : } \
627 : } while(0)
628 :
629 : #define torture_assert_u64_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
630 : do { uint64_t __got = (got), __expected = (expected); \
631 : if (__got != __expected) { \
632 : torture_result(torture_ctx, TORTURE_FAIL, \
633 : __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected %"PRIu64" (0x%"PRIX64"): %s", \
634 : __got, __got, \
635 : __expected, __expected, \
636 : cmt); \
637 : ret = false; \
638 : goto label; \
639 : } \
640 : } while(0)
641 :
642 : #define torture_assert_u64_not_equal(torture_ctx,got,not_expected,cmt)\
643 : do { uint64_t __got = (got), __not_expected = (not_expected); \
644 : if (__got == __not_expected) { \
645 : torture_result(torture_ctx, TORTURE_FAIL, \
646 : __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected a different number: %s", \
647 : __got, __got, \
648 : cmt); \
649 : return false; \
650 : } \
651 : } while(0)
652 :
653 : #define torture_assert_u64_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
654 : do { uint64_t __got = (got), __not_expected = (not_expected); \
655 : if (__got == __not_expected) { \
656 : torture_result(torture_ctx, TORTURE_FAIL, \
657 : __location__": "#got" was %"PRIu64" (0x%"PRIX64"), expected a different number: %s", \
658 : __got, __got, \
659 : cmt); \
660 : ret = false; \
661 : goto label; \
662 : } \
663 : } while(0)
664 :
665 : #define torture_assert_size_equal(torture_ctx,got,expected,cmt)\
666 : do { size_t __got = (got), __expected = (expected); \
667 : if (__got != __expected) { \
668 : torture_result(torture_ctx, TORTURE_FAIL, \
669 : __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \
670 : __got, __got, \
671 : __expected, __expected, \
672 : cmt); \
673 : return false; \
674 : } \
675 : } while(0)
676 :
677 : #define torture_assert_size_equal_goto(torture_ctx,got,expected,ret,label,cmt)\
678 : do { size_t __got = (got), __expected = (expected); \
679 : if (__got != __expected) { \
680 : torture_result(torture_ctx, TORTURE_FAIL, \
681 : __location__": "#got" was %zu (0x%zX), expected %zu (0x%zX): %s", \
682 : __got, __got, \
683 : __expected, __expected, \
684 : cmt); \
685 : ret = false; \
686 : goto label; \
687 : } \
688 : } while(0)
689 :
690 : #define torture_assert_size_not_equal(torture_ctx,got,not_expected,cmt)\
691 : do { size_t __got = (got), __not_expected = (not_expected); \
692 : if (__got == __not_expected) { \
693 : torture_result(torture_ctx, TORTURE_FAIL, \
694 : __location__": "#got" was %zu (0x%zX), expected a different number: %s", \
695 : __got, __got, \
696 : cmt); \
697 : return false; \
698 : } \
699 : } while(0)
700 :
701 : #define torture_assert_size_not_equal_goto(torture_ctx,got,not_expected,ret,label,cmt)\
702 : do { size_t __got = (got), __not_expected = (not_expected); \
703 : if (__got == __not_expected) { \
704 : torture_result(torture_ctx, TORTURE_FAIL, \
705 : __location__": "#got" was %zu (0x%zX), expected a different number: %s", \
706 : __got, __got, \
707 : cmt); \
708 : ret = false; \
709 : goto label; \
710 : } \
711 : } while(0)
712 :
713 : #define torture_assert_errno_equal(torture_ctx,expected,cmt)\
714 : do { int __expected = (expected); \
715 : if (errno != __expected) { \
716 : torture_result(torture_ctx, TORTURE_FAIL, \
717 : __location__": errno was %d (%s), expected %d: %s: %s", \
718 : errno, strerror(errno), __expected, \
719 : strerror(__expected), cmt); \
720 : return false; \
721 : } \
722 : } while(0)
723 :
724 : #define torture_assert_errno_equal_goto(torture_ctx,expected,ret,label,cmt)\
725 : do { int __expected = (expected); \
726 : if (errno != __expected) { \
727 : torture_result(torture_ctx, TORTURE_FAIL, \
728 : __location__": errno was %d (%s), expected %d: %s: %s", \
729 : errno, strerror(errno), __expected, \
730 : strerror(__expected), cmt); \
731 : ret = false; \
732 : goto label; \
733 : } \
734 : } while(0)
735 :
736 : #define torture_assert_guid_equal(torture_ctx,got,expected,cmt)\
737 : do {const struct GUID __got = (got), __expected = (expected); \
738 : if (!GUID_equal(&__got, &__expected)) { \
739 : torture_result(torture_ctx, TORTURE_FAIL, \
740 : __location__": "#got" was %s, expected %s: %s", \
741 : GUID_string(torture_ctx, &__got), GUID_string(torture_ctx, &__expected), cmt); \
742 : return false; \
743 : } \
744 : } while(0)
745 :
746 : #define torture_assert_nttime_equal(torture_ctx,got,expected,cmt) \
747 : do { NTTIME __got = got, __expected = expected; \
748 : if (!nt_time_equal(&__got, &__expected)) { \
749 : 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); \
750 : return false; \
751 : }\
752 : } while(0)
753 :
754 : #define torture_assert_sid_equal(torture_ctx,got,expected,cmt)\
755 : do {const struct dom_sid *__got = (got), *__expected = (expected); \
756 : if (!dom_sid_equal(__got, __expected)) { \
757 : torture_result(torture_ctx, TORTURE_FAIL, \
758 : __location__": "#got" was %s, expected %s: %s", \
759 : dom_sid_string(torture_ctx, __got), dom_sid_string(torture_ctx, __expected), cmt); \
760 : return false; \
761 : } \
762 : } while(0)
763 :
764 : #define torture_assert_not_null(torture_ctx,got,cmt)\
765 : do {const void *__got = (got); \
766 : if (__got == NULL) { \
767 : torture_result(torture_ctx, TORTURE_FAIL, \
768 : __location__": "#got" was NULL, expected != NULL: %s", \
769 : cmt); \
770 : return false; \
771 : } \
772 : } while(0)
773 :
774 : #define torture_assert_not_null_goto(torture_ctx,got,ret,label,cmt)\
775 : do {const void *__got = (got); \
776 : if (__got == NULL) { \
777 : torture_result(torture_ctx, TORTURE_FAIL, \
778 : __location__": "#got" was NULL, expected != NULL: %s", \
779 : cmt); \
780 : ret = false; \
781 : goto label; \
782 : } \
783 : } while(0)
784 :
785 : #define torture_skip(torture_ctx,cmt) do {\
786 : torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
787 : return true; \
788 : } while(0)
789 : #define torture_skip_goto(torture_ctx,label,cmt) do {\
790 : torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
791 : goto label; \
792 : } while(0)
793 : #define torture_fail(torture_ctx,cmt) do {\
794 : torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
795 : return false; \
796 : } while (0)
797 : #define torture_fail_goto(torture_ctx,label,cmt) do {\
798 : torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
799 : goto label; \
800 : } while (0)
801 :
802 : #define torture_out stderr
803 :
804 : /* Convenience macros */
805 : #define torture_assert_ntstatus_ok(torture_ctx,expr,cmt) \
806 : torture_assert_ntstatus_equal(torture_ctx,expr,NT_STATUS_OK,cmt)
807 :
808 : #define torture_assert_ntstatus_ok_goto(torture_ctx,expr,ret,label,cmt) \
809 : torture_assert_ntstatus_equal_goto(torture_ctx,expr,NT_STATUS_OK,ret,label,cmt)
810 :
811 : #define torture_assert_werr_ok(torture_ctx,expr,cmt) \
812 : torture_assert_werr_equal(torture_ctx,expr,WERR_OK,cmt)
813 :
814 : #define torture_assert_werr_ok_goto(torture_ctx,expr,ret,label,cmt) \
815 : torture_assert_werr_equal_goto(torture_ctx,expr,WERR_OK,ret,label,cmt)
816 :
817 : #define torture_assert_ndr_success(torture_ctx,expr,cmt) \
818 : torture_assert_ndr_err_equal(torture_ctx,expr,NDR_ERR_SUCCESS,cmt)
819 :
820 : #define torture_assert_ndr_success_goto(torture_ctx,expr,ret,label,cmt) \
821 : torture_assert_ndr_err_equal_goto(torture_ctx,expr,NDR_ERR_SUCCESS,ret,label,cmt)
822 :
823 : #define torture_assert_hresult_ok(torture_ctx,expr,cmt) \
824 : torture_assert_hresult_equal(torture_ctx,expr,HRES_ERROR(0), cmt)
825 :
826 : /* Getting settings */
827 : const char *torture_setting_string(struct torture_context *test, \
828 : const char *name,
829 : const char *default_value);
830 :
831 : int torture_setting_int(struct torture_context *test,
832 : const char *name,
833 : int default_value);
834 :
835 : double torture_setting_double(struct torture_context *test,
836 : const char *name,
837 : double default_value);
838 :
839 : bool torture_setting_bool(struct torture_context *test,
840 : const char *name,
841 : bool default_value);
842 :
843 : struct torture_suite *torture_find_suite(struct torture_suite *parent,
844 : const char *name);
845 :
846 : unsigned long torture_setting_ulong(struct torture_context *test,
847 : const char *name,
848 : unsigned long default_value);
849 :
850 : NTSTATUS torture_temp_dir(struct torture_context *tctx,
851 : const char *prefix,
852 : char **tempdir);
853 : NTSTATUS torture_deltree_outputdir(struct torture_context *tctx);
854 :
855 : struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
856 : const char *name,
857 : bool (*run) (struct torture_context *test, void *tcase_data));
858 :
859 :
860 : bool torture_suite_init_tcase(struct torture_suite *suite,
861 : struct torture_tcase *tcase,
862 : const char *name);
863 : int torture_suite_children_count(const struct torture_suite *suite);
864 :
865 : struct torture_context *torture_context_init(struct tevent_context *event_ctx, struct torture_results *results);
866 :
867 : struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops);
868 :
869 : struct torture_context *torture_context_child(struct torture_context *tctx);
870 :
871 : extern const struct torture_ui_ops torture_subunit_ui_ops;
872 : extern const struct torture_ui_ops torture_simple_ui_ops;
873 :
874 : #endif /* __TORTURE_UI_H__ */
|