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_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); \
543 : return false; \
544 : } \
545 : } while(0)
546 :
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); \
553 : return false; \
554 : } \
555 : } while(0)
556 :
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); \
563 : ret = false; \
564 : goto label; \
565 : } \
566 : } while(0)
567 :
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); \
574 : return false; \
575 : } \
576 : } while(0)
577 :
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); \
584 : ret = false; \
585 : goto label; \
586 : } \
587 : } while(0)
588 :
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", \
594 : __got, __got, \
595 : __expected, __expected, \
596 : cmt); \
597 : return false; \
598 : } \
599 : } while(0)
600 :
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", \
606 : __got, __got, \
607 : __expected, __expected, \
608 : cmt); \
609 : ret = false; \
610 : goto label; \
611 : } \
612 : } while(0)
613 :
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", \
619 : __got, __got, \
620 : cmt); \
621 : return false; \
622 : } \
623 : } while(0)
624 :
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", \
630 : __got, __got, \
631 : cmt); \
632 : ret = false; \
633 : goto label; \
634 : } \
635 : } while(0)
636 :
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", \
642 : __got, __got, \
643 : __expected, __expected, \
644 : cmt); \
645 : return false; \
646 : } \
647 : } while(0)
648 :
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", \
654 : __got, __got, \
655 : __expected, __expected, \
656 : cmt); \
657 : ret = false; \
658 : goto label; \
659 : } \
660 : } while(0)
661 :
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", \
667 : __got, __got, \
668 : cmt); \
669 : return false; \
670 : } \
671 : } while(0)
672 :
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", \
678 : __got, __got, \
679 : cmt); \
680 : ret = false; \
681 : goto label; \
682 : } \
683 : } while(0)
684 :
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", \
690 : __got, __got, \
691 : __expected, __expected, \
692 : cmt); \
693 : return false; \
694 : } \
695 : } while(0)
696 :
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", \
702 : __got, __got, \
703 : __expected, __expected, \
704 : cmt); \
705 : ret = false; \
706 : goto label; \
707 : } \
708 : } while(0)
709 :
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", \
715 : __got, __got, \
716 : cmt); \
717 : return false; \
718 : } \
719 : } while(0)
720 :
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", \
726 : __got, __got, \
727 : cmt); \
728 : ret = false; \
729 : goto label; \
730 : } \
731 : } while(0)
732 :
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); \
740 : return false; \
741 : } \
742 : } while(0)
743 :
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); \
751 : ret = false; \
752 : goto label; \
753 : } \
754 : } while(0)
755 :
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); \
762 : return false; \
763 : } \
764 : } while(0)
765 :
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); \
770 : return false; \
771 : }\
772 : } while(0)
773 :
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); \
780 : return false; \
781 : } \
782 : } while(0)
783 :
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", \
789 : cmt); \
790 : return false; \
791 : } \
792 : } while(0)
793 :
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", \
799 : cmt); \
800 : ret = false; \
801 : goto label; \
802 : } \
803 : } while(0)
804 :
805 : #define torture_skip(torture_ctx,cmt) do {\
806 : torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
807 : return true; \
808 : } while(0)
809 : #define torture_skip_goto(torture_ctx,label,cmt) do {\
810 : torture_result(torture_ctx, TORTURE_SKIP, __location__": %s", cmt);\
811 : goto label; \
812 : } while(0)
813 : #define torture_fail(torture_ctx,cmt) do {\
814 : torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
815 : return false; \
816 : } while (0)
817 : #define torture_fail_goto(torture_ctx,label,cmt) do {\
818 : torture_result(torture_ctx, TORTURE_FAIL, __location__": %s", cmt);\
819 : goto label; \
820 : } while (0)
821 :
822 : #define torture_out stderr
823 :
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)
827 :
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)
830 :
831 : #define torture_assert_werr_ok(torture_ctx,expr,cmt) \
832 : torture_assert_werr_equal(torture_ctx,expr,WERR_OK,cmt)
833 :
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)
836 :
837 : #define torture_assert_ndr_success(torture_ctx,expr,cmt) \
838 : torture_assert_ndr_err_equal(torture_ctx,expr,NDR_ERR_SUCCESS,cmt)
839 :
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)
842 :
843 : #define torture_assert_hresult_ok(torture_ctx,expr,cmt) \
844 : torture_assert_hresult_equal(torture_ctx,expr,HRES_ERROR(0), cmt)
845 :
846 : /* Getting settings */
847 : const char *torture_setting_string(struct torture_context *test, \
848 : const char *name,
849 : const char *default_value);
850 :
851 : int torture_setting_int(struct torture_context *test,
852 : const char *name,
853 : int default_value);
854 :
855 : double torture_setting_double(struct torture_context *test,
856 : const char *name,
857 : double default_value);
858 :
859 : bool torture_setting_bool(struct torture_context *test,
860 : const char *name,
861 : bool default_value);
862 :
863 : struct torture_suite *torture_find_suite(struct torture_suite *parent,
864 : const char *name);
865 :
866 : unsigned long torture_setting_ulong(struct torture_context *test,
867 : const char *name,
868 : unsigned long default_value);
869 :
870 : NTSTATUS torture_temp_dir(struct torture_context *tctx,
871 : const char *prefix,
872 : char **tempdir);
873 : NTSTATUS torture_deltree_outputdir(struct torture_context *tctx);
874 :
875 : struct torture_test *torture_tcase_add_simple_test(struct torture_tcase *tcase,
876 : const char *name,
877 : bool (*run) (struct torture_context *test, void *tcase_data));
878 :
879 :
880 : bool torture_suite_init_tcase(struct torture_suite *suite,
881 : struct torture_tcase *tcase,
882 : const char *name);
883 : int torture_suite_children_count(const struct torture_suite *suite);
884 :
885 : struct torture_context *torture_context_init(struct tevent_context *event_ctx, struct torture_results *results);
886 :
887 : struct torture_results *torture_results_init(TALLOC_CTX *mem_ctx, const struct torture_ui_ops *ui_ops);
888 :
889 : struct torture_context *torture_context_child(struct torture_context *tctx);
890 :
891 : extern const struct torture_ui_ops torture_subunit_ui_ops;
892 : extern const struct torture_ui_ops torture_simple_ui_ops;
893 :
894 : #endif /* __TORTURE_UI_H__ */
|