7860ad2be67776e1a876d4f28c89a7f306a7d356
[sfrench/samba-autobuild/.git] / lib / talloc / testsuite.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    local testing of talloc routines.
5
6    Copyright (C) Andrew Tridgell 2004
7    
8      ** NOTE! The following LGPL license applies to the talloc
9      ** library. This does NOT imply that all of Samba is released
10      ** under the LGPL
11    
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 3 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 */
25
26 #include "replace.h"
27 #include "system/time.h"
28 #include <talloc.h>
29
30 #include "talloc_testsuite.h"
31
32 static struct timeval timeval_current(void)
33 {
34         struct timeval tv;
35         gettimeofday(&tv, NULL);
36         return tv;
37 }
38
39 static double timeval_elapsed(struct timeval *tv)
40 {
41         struct timeval tv2 = timeval_current();
42         return (tv2.tv_sec - tv->tv_sec) + 
43                (tv2.tv_usec - tv->tv_usec)*1.0e-6;
44 }
45
46 #define torture_assert(test, expr, str) if (!(expr)) { \
47         printf("failure: %s [\n%s: Expression %s failed: %s\n]\n", \
48                 test, __location__, #expr, str); \
49         return false; \
50 }
51
52 #define torture_assert_str_equal(test, arg1, arg2, desc) \
53         if (arg1 == NULL && arg2 == NULL) {                             \
54         } else if (strcmp(arg1, arg2)) {                        \
55                 printf("failure: %s [\n%s: Expected %s, got %s: %s\n]\n", \
56                    test, __location__, arg1, arg2, desc); \
57                 return false; \
58         }
59
60 #define CHECK_SIZE(test, ptr, tsize) do { \
61         if (talloc_total_size(ptr) != (tsize)) { \
62                 printf("failed: %s [\n%s: wrong '%s' tree size: got %u  expected %u\n]\n", \
63                        test, __location__, #ptr, \
64                        (unsigned)talloc_total_size(ptr), \
65                        (unsigned)tsize); \
66                 talloc_report_full(ptr, stdout); \
67                 return false; \
68         } \
69 } while (0)
70
71 #define CHECK_BLOCKS(test, ptr, tblocks) do { \
72         if (talloc_total_blocks(ptr) != (tblocks)) { \
73                 printf("failed: %s [\n%s: wrong '%s' tree blocks: got %u  expected %u\n]\n", \
74                        test, __location__, #ptr, \
75                        (unsigned)talloc_total_blocks(ptr), \
76                        (unsigned)tblocks); \
77                 talloc_report_full(ptr, stdout); \
78                 return false; \
79         } \
80 } while (0)
81
82 #define CHECK_PARENT(test, ptr, parent) do { \
83         if (talloc_parent(ptr) != (parent)) { \
84                 printf("failed: %s [\n%s: '%s' has wrong parent: got %p  expected %p\n]\n", \
85                        test, __location__, #ptr, \
86                        talloc_parent(ptr), \
87                        (parent)); \
88                 talloc_report_full(ptr, stdout); \
89                 talloc_report_full(parent, stdout); \
90                 talloc_report_full(NULL, stdout); \
91                 return false; \
92         } \
93 } while (0)
94
95 static unsigned int test_abort_count;
96
97 #if 0
98 static void test_abort_fn(const char *reason)
99 {
100         printf("# test_abort_fn(%s)\n", reason);
101         test_abort_count++;
102 }
103
104 static void test_abort_start(void)
105 {
106         test_abort_count = 0;
107         talloc_set_abort_fn(test_abort_fn);
108 }
109 #endif
110
111 static void test_abort_stop(void)
112 {
113         test_abort_count = 0;
114         talloc_set_abort_fn(NULL);
115 }
116
117 static void test_log_stdout(const char *message)
118 {
119         fprintf(stdout, "%s", message);
120 }
121
122 /*
123   test references 
124 */
125 static bool test_ref1(void)
126 {
127         void *root, *p1, *p2, *ref, *r1;
128
129         printf("test: ref1\n# SINGLE REFERENCE FREE\n");
130
131         root = talloc_named_const(NULL, 0, "root");
132         p1 = talloc_named_const(root, 1, "p1");
133         p2 = talloc_named_const(p1, 1, "p2");
134         talloc_named_const(p1, 1, "x1");
135         talloc_named_const(p1, 2, "x2");
136         talloc_named_const(p1, 3, "x3");
137
138         r1 = talloc_named_const(root, 1, "r1"); 
139         ref = talloc_reference(r1, p2);
140         talloc_report_full(root, stderr);
141
142         CHECK_BLOCKS("ref1", p1, 5);
143         CHECK_BLOCKS("ref1", p2, 1);
144         CHECK_BLOCKS("ref1", r1, 2);
145
146         fprintf(stderr, "Freeing p2\n");
147         talloc_unlink(r1, p2);
148         talloc_report_full(root, stderr);
149
150         CHECK_BLOCKS("ref1", p1, 5);
151         CHECK_BLOCKS("ref1", p2, 1);
152         CHECK_BLOCKS("ref1", r1, 1);
153
154         fprintf(stderr, "Freeing p1\n");
155         talloc_free(p1);
156         talloc_report_full(root, stderr);
157
158         CHECK_BLOCKS("ref1", r1, 1);
159
160         fprintf(stderr, "Freeing r1\n");
161         talloc_free(r1);
162         talloc_report_full(NULL, stderr);
163
164         fprintf(stderr, "Testing NULL\n");
165         if (talloc_reference(root, NULL)) {
166                 return false;
167         }
168
169         CHECK_BLOCKS("ref1", root, 1);
170
171         CHECK_SIZE("ref1", root, 0);
172
173         talloc_free(root);
174         printf("success: ref1\n");
175         return true;
176 }
177
178 /*
179   test references 
180 */
181 static bool test_ref2(void)
182 {
183         void *root, *p1, *p2, *ref, *r1;
184
185         printf("test: ref2\n# DOUBLE REFERENCE FREE\n");
186         root = talloc_named_const(NULL, 0, "root");
187         p1 = talloc_named_const(root, 1, "p1");
188         talloc_named_const(p1, 1, "x1");
189         talloc_named_const(p1, 1, "x2");
190         talloc_named_const(p1, 1, "x3");
191         p2 = talloc_named_const(p1, 1, "p2");
192
193         r1 = talloc_named_const(root, 1, "r1"); 
194         ref = talloc_reference(r1, p2);
195         talloc_report_full(root, stderr);
196
197         CHECK_BLOCKS("ref2", p1, 5);
198         CHECK_BLOCKS("ref2", p2, 1);
199         CHECK_BLOCKS("ref2", r1, 2);
200
201         fprintf(stderr, "Freeing ref\n");
202         talloc_unlink(r1, ref);
203         talloc_report_full(root, stderr);
204
205         CHECK_BLOCKS("ref2", p1, 5);
206         CHECK_BLOCKS("ref2", p2, 1);
207         CHECK_BLOCKS("ref2", r1, 1);
208
209         fprintf(stderr, "Freeing p2\n");
210         talloc_free(p2);
211         talloc_report_full(root, stderr);
212
213         CHECK_BLOCKS("ref2", p1, 4);
214         CHECK_BLOCKS("ref2", r1, 1);
215
216         fprintf(stderr, "Freeing p1\n");
217         talloc_free(p1);
218         talloc_report_full(root, stderr);
219
220         CHECK_BLOCKS("ref2", r1, 1);
221
222         fprintf(stderr, "Freeing r1\n");
223         talloc_free(r1);
224         talloc_report_full(root, stderr);
225
226         CHECK_SIZE("ref2", root, 0);
227
228         talloc_free(root);
229         printf("success: ref2\n");
230         return true;
231 }
232
233 /*
234   test references 
235 */
236 static bool test_ref3(void)
237 {
238         void *root, *p1, *p2, *ref, *r1;
239
240         printf("test: ref3\n# PARENT REFERENCE FREE\n");
241
242         root = talloc_named_const(NULL, 0, "root");
243         p1 = talloc_named_const(root, 1, "p1");
244         p2 = talloc_named_const(root, 1, "p2");
245         r1 = talloc_named_const(p1, 1, "r1");
246         ref = talloc_reference(p2, r1);
247         talloc_report_full(root, stderr);
248
249         CHECK_BLOCKS("ref3", p1, 2);
250         CHECK_BLOCKS("ref3", p2, 2);
251         CHECK_BLOCKS("ref3", r1, 1);
252
253         fprintf(stderr, "Freeing p1\n");
254         talloc_free(p1);
255         talloc_report_full(root, stderr);
256
257         CHECK_BLOCKS("ref3", p2, 2);
258         CHECK_BLOCKS("ref3", r1, 1);
259
260         fprintf(stderr, "Freeing p2\n");
261         talloc_free(p2);
262         talloc_report_full(root, stderr);
263
264         CHECK_SIZE("ref3", root, 0);
265
266         talloc_free(root);
267
268         printf("success: ref3\n");
269         return true;
270 }
271
272 /*
273   test references 
274 */
275 static bool test_ref4(void)
276 {
277         void *root, *p1, *p2, *ref, *r1;
278
279         printf("test: ref4\n# REFERRER REFERENCE FREE\n");
280
281         root = talloc_named_const(NULL, 0, "root");
282         p1 = talloc_named_const(root, 1, "p1");
283         talloc_named_const(p1, 1, "x1");
284         talloc_named_const(p1, 1, "x2");
285         talloc_named_const(p1, 1, "x3");
286         p2 = talloc_named_const(p1, 1, "p2");
287
288         r1 = talloc_named_const(root, 1, "r1"); 
289         ref = talloc_reference(r1, p2);
290         talloc_report_full(root, stderr);
291
292         CHECK_BLOCKS("ref4", p1, 5);
293         CHECK_BLOCKS("ref4", p2, 1);
294         CHECK_BLOCKS("ref4", r1, 2);
295
296         fprintf(stderr, "Freeing r1\n");
297         talloc_free(r1);
298         talloc_report_full(root, stderr);
299
300         CHECK_BLOCKS("ref4", p1, 5);
301         CHECK_BLOCKS("ref4", p2, 1);
302
303         fprintf(stderr, "Freeing p2\n");
304         talloc_free(p2);
305         talloc_report_full(root, stderr);
306
307         CHECK_BLOCKS("ref4", p1, 4);
308
309         fprintf(stderr, "Freeing p1\n");
310         talloc_free(p1);
311         talloc_report_full(root, stderr);
312
313         CHECK_SIZE("ref4", root, 0);
314
315         talloc_free(root);
316
317         printf("success: ref4\n");
318         return true;
319 }
320
321
322 /*
323   test references 
324 */
325 static bool test_unlink1(void)
326 {
327         void *root, *p1, *p2, *ref, *r1;
328
329         printf("test: unlink\n# UNLINK\n");
330
331         root = talloc_named_const(NULL, 0, "root");
332         p1 = talloc_named_const(root, 1, "p1");
333         talloc_named_const(p1, 1, "x1");
334         talloc_named_const(p1, 1, "x2");
335         talloc_named_const(p1, 1, "x3");
336         p2 = talloc_named_const(p1, 1, "p2");
337
338         r1 = talloc_named_const(p1, 1, "r1");   
339         ref = talloc_reference(r1, p2);
340         talloc_report_full(root, stderr);
341
342         CHECK_BLOCKS("unlink", p1, 7);
343         CHECK_BLOCKS("unlink", p2, 1);
344         CHECK_BLOCKS("unlink", r1, 2);
345
346         fprintf(stderr, "Unreferencing r1\n");
347         talloc_unlink(r1, p2);
348         talloc_report_full(root, stderr);
349
350         CHECK_BLOCKS("unlink", p1, 6);
351         CHECK_BLOCKS("unlink", p2, 1);
352         CHECK_BLOCKS("unlink", r1, 1);
353
354         fprintf(stderr, "Freeing p1\n");
355         talloc_free(p1);
356         talloc_report_full(root, stderr);
357
358         CHECK_SIZE("unlink", root, 0);
359
360         talloc_free(root);
361
362         printf("success: unlink\n");
363         return true;
364 }
365
366 static int fail_destructor(void *ptr)
367 {
368         return -1;
369 }
370
371 /*
372   miscellaneous tests to try to get a higher test coverage percentage
373 */
374 static bool test_misc(void)
375 {
376         void *root, *p1;
377         char *p2;
378         double *d;
379         const char *name;
380
381         printf("test: misc\n# MISCELLANEOUS\n");
382
383         root = talloc_new(NULL);
384
385         p1 = talloc_size(root, 0x7fffffff);
386         torture_assert("misc", !p1, "failed: large talloc allowed\n");
387
388         p1 = talloc_strdup(root, "foo");
389         talloc_increase_ref_count(p1);
390         talloc_increase_ref_count(p1);
391         talloc_increase_ref_count(p1);
392         CHECK_BLOCKS("misc", p1, 1);
393         CHECK_BLOCKS("misc", root, 2);
394         talloc_unlink(NULL, p1);
395         CHECK_BLOCKS("misc", p1, 1);
396         CHECK_BLOCKS("misc", root, 2);
397         talloc_unlink(NULL, p1);
398         CHECK_BLOCKS("misc", p1, 1);
399         CHECK_BLOCKS("misc", root, 2);
400         p2 = talloc_strdup(p1, "foo");
401         torture_assert("misc", talloc_unlink(root, p2) == -1,
402                                    "failed: talloc_unlink() of non-reference context should return -1\n");
403         torture_assert("misc", talloc_unlink(p1, p2) == 0,
404                 "failed: talloc_unlink() of parent should succeed\n");
405         talloc_unlink(NULL, p1);
406         CHECK_BLOCKS("misc", p1, 1);
407         CHECK_BLOCKS("misc", root, 2);
408
409         name = talloc_set_name(p1, "my name is %s", "foo");
410         torture_assert_str_equal("misc", talloc_get_name(p1), "my name is foo",
411                 "failed: wrong name after talloc_set_name(my name is foo)");
412         CHECK_BLOCKS("misc", p1, 2);
413         CHECK_BLOCKS("misc", root, 3);
414
415         talloc_set_name_const(p1, NULL);
416         torture_assert_str_equal ("misc", talloc_get_name(p1), "UNNAMED",
417                 "failed: wrong name after talloc_set_name(NULL)");
418         CHECK_BLOCKS("misc", p1, 2);
419         CHECK_BLOCKS("misc", root, 3);
420
421         torture_assert("misc", talloc_free(NULL) == -1, 
422                                    "talloc_free(NULL) should give -1\n");
423
424         talloc_set_destructor(p1, fail_destructor);
425         torture_assert("misc", talloc_free(p1) == -1, 
426                 "Failed destructor should cause talloc_free to fail\n");
427         talloc_set_destructor(p1, NULL);
428
429         talloc_report(root, stderr);
430
431
432         p2 = (char *)talloc_zero_size(p1, 20);
433         torture_assert("misc", p2[19] == 0, "Failed to give zero memory\n");
434         talloc_free(p2);
435
436         torture_assert("misc", talloc_strdup(root, NULL) == NULL,
437                 "failed: strdup on NULL should give NULL\n");
438
439         p2 = talloc_strndup(p1, "foo", 2);
440         torture_assert("misc", strcmp("fo", p2) == 0, 
441                                    "strndup doesn't work\n");
442         p2 = talloc_asprintf_append_buffer(p2, "o%c", 'd');
443         torture_assert("misc", strcmp("food", p2) == 0, 
444                                    "talloc_asprintf_append_buffer doesn't work\n");
445         CHECK_BLOCKS("misc", p2, 1);
446         CHECK_BLOCKS("misc", p1, 3);
447
448         p2 = talloc_asprintf_append_buffer(NULL, "hello %s", "world");
449         torture_assert("misc", strcmp("hello world", p2) == 0,
450                 "talloc_asprintf_append_buffer doesn't work\n");
451         CHECK_BLOCKS("misc", p2, 1);
452         CHECK_BLOCKS("misc", p1, 3);
453         talloc_free(p2);
454
455         d = talloc_array(p1, double, 0x20000000);
456         torture_assert("misc", !d, "failed: integer overflow not detected\n");
457
458         d = talloc_realloc(p1, d, double, 0x20000000);
459         torture_assert("misc", !d, "failed: integer overflow not detected\n");
460
461         talloc_free(p1);
462         CHECK_BLOCKS("misc", root, 1);
463
464         p1 = talloc_named(root, 100, "%d bytes", 100);
465         CHECK_BLOCKS("misc", p1, 2);
466         CHECK_BLOCKS("misc", root, 3);
467         talloc_unlink(root, p1);
468
469         p1 = talloc_init("%d bytes", 200);
470         p2 = talloc_asprintf(p1, "my test '%s'", "string");
471         torture_assert_str_equal("misc", p2, "my test 'string'",
472                 "failed: talloc_asprintf(\"my test '%%s'\", \"string\") gave: \"%s\"");
473         CHECK_BLOCKS("misc", p1, 3);
474         CHECK_SIZE("misc", p2, 17);
475         CHECK_BLOCKS("misc", root, 1);
476         talloc_unlink(NULL, p1);
477
478         p1 = talloc_named_const(root, 10, "p1");
479         p2 = (char *)talloc_named_const(root, 20, "p2");
480         (void)talloc_reference(p1, p2);
481         talloc_report_full(root, stderr);
482         talloc_unlink(root, p2);
483         talloc_report_full(root, stderr);
484         CHECK_BLOCKS("misc", p2, 1);
485         CHECK_BLOCKS("misc", p1, 2);
486         CHECK_BLOCKS("misc", root, 3);
487         talloc_unlink(p1, p2);
488         talloc_unlink(root, p1);
489
490         p1 = talloc_named_const(root, 10, "p1");
491         p2 = (char *)talloc_named_const(root, 20, "p2");
492         (void)talloc_reference(NULL, p2);
493         talloc_report_full(root, stderr);
494         talloc_unlink(root, p2);
495         talloc_report_full(root, stderr);
496         CHECK_BLOCKS("misc", p2, 1);
497         CHECK_BLOCKS("misc", p1, 1);
498         CHECK_BLOCKS("misc", root, 2);
499         talloc_unlink(NULL, p2);
500         talloc_unlink(root, p1);
501
502         /* Test that talloc_unlink is a no-op */
503
504         torture_assert("misc", talloc_unlink(root, NULL) == -1,
505                 "failed: talloc_unlink(root, NULL) == -1\n");
506
507         talloc_report(root, stderr);
508         talloc_report(NULL, stderr);
509
510         CHECK_SIZE("misc", root, 0);
511
512         talloc_free(root);
513
514         CHECK_SIZE("misc", NULL, 0);
515
516         talloc_enable_null_tracking_no_autofree();
517         talloc_enable_leak_report();
518         talloc_enable_leak_report_full();
519
520         printf("success: misc\n");
521
522         return true;
523 }
524
525
526 /*
527   test realloc
528 */
529 static bool test_realloc(void)
530 {
531         void *root, *p1, *p2;
532
533         printf("test: realloc\n# REALLOC\n");
534
535         root = talloc_new(NULL);
536
537         p1 = talloc_size(root, 10);
538         CHECK_SIZE("realloc", p1, 10);
539
540         p1 = talloc_realloc_size(NULL, p1, 20);
541         CHECK_SIZE("realloc", p1, 20);
542
543         talloc_new(p1);
544
545         p2 = talloc_realloc_size(p1, NULL, 30);
546
547         talloc_new(p1);
548
549         p2 = talloc_realloc_size(p1, p2, 40);
550
551         CHECK_SIZE("realloc", p2, 40);
552         CHECK_SIZE("realloc", root, 60);
553         CHECK_BLOCKS("realloc", p1, 4);
554
555         p1 = talloc_realloc_size(NULL, p1, 20);
556         CHECK_SIZE("realloc", p1, 60);
557
558         talloc_increase_ref_count(p2);
559         torture_assert("realloc", talloc_realloc_size(NULL, p2, 5) == NULL,
560                 "failed: talloc_realloc() on a referenced pointer should fail\n");
561         CHECK_BLOCKS("realloc", p1, 4);
562
563         talloc_realloc_size(NULL, p2, 0);
564         talloc_realloc_size(NULL, p2, 0);
565         CHECK_BLOCKS("realloc", p1, 4);
566         talloc_realloc_size(p1, p2, 0);
567         CHECK_BLOCKS("realloc", p1, 3);
568
569         torture_assert("realloc", talloc_realloc_size(NULL, p1, 0x7fffffff) == NULL,
570                 "failed: oversize talloc should fail\n");
571
572         talloc_realloc_size(NULL, p1, 0);
573         CHECK_BLOCKS("realloc", root, 4);
574         talloc_realloc_size(root, p1, 0);
575         CHECK_BLOCKS("realloc", root, 1);
576
577         CHECK_SIZE("realloc", root, 0);
578
579         talloc_free(root);
580
581         printf("success: realloc\n");
582
583         return true;
584 }
585
586 /*
587   test realloc with a child
588 */
589 static bool test_realloc_child(void)
590 {
591         void *root;
592         struct el2 {
593                 const char *name;
594         } *el2; 
595         struct el1 {
596                 int count;
597                 struct el2 **list, **list2, **list3;
598         } *el1;
599
600         printf("test: REALLOC WITH CHILD\n");
601
602         root = talloc_new(NULL);
603
604         el1 = talloc(root, struct el1);
605         el1->list = talloc(el1, struct el2 *);
606         el1->list[0] = talloc(el1->list, struct el2);
607         el1->list[0]->name = talloc_strdup(el1->list[0], "testing");
608
609         el1->list2 = talloc(el1, struct el2 *);
610         el1->list2[0] = talloc(el1->list2, struct el2);
611         el1->list2[0]->name = talloc_strdup(el1->list2[0], "testing2");
612
613         el1->list3 = talloc(el1, struct el2 *);
614         el1->list3[0] = talloc(el1->list3, struct el2);
615         el1->list3[0]->name = talloc_strdup(el1->list3[0], "testing2");
616         
617         el2 = talloc(el1->list, struct el2);
618         el2 = talloc(el1->list2, struct el2);
619         el2 = talloc(el1->list3, struct el2);
620
621         el1->list = talloc_realloc(el1, el1->list, struct el2 *, 100);
622         el1->list2 = talloc_realloc(el1, el1->list2, struct el2 *, 200);
623         el1->list3 = talloc_realloc(el1, el1->list3, struct el2 *, 300);
624
625         talloc_free(root);
626
627         printf("success: REALLOC WITH CHILD\n");
628         return true;
629 }
630
631 /*
632   test type checking
633 */
634 static bool test_type(void)
635 {
636         void *root;
637         struct el1 {
638                 int count;
639         };
640         struct el2 {
641                 int count;
642         };
643         struct el1 *el1;
644
645         printf("test: type\n# talloc type checking\n");
646
647         root = talloc_new(NULL);
648
649         el1 = talloc(root, struct el1);
650
651         el1->count = 1;
652
653         torture_assert("type", talloc_get_type(el1, struct el1) == el1,
654                 "type check failed on el1\n");
655         torture_assert("type", talloc_get_type(el1, struct el2) == NULL,
656                 "type check failed on el1 with el2\n");
657         talloc_set_type(el1, struct el2);
658         torture_assert("type", talloc_get_type(el1, struct el2) == (struct el2 *)el1,
659                 "type set failed on el1 with el2\n");
660
661         talloc_free(root);
662
663         printf("success: type\n");
664         return true;
665 }
666
667 /*
668   test steal
669 */
670 static bool test_steal(void)
671 {
672         void *root, *p1, *p2;
673
674         printf("test: steal\n# STEAL\n");
675
676         root = talloc_new(NULL);
677
678         p1 = talloc_array(root, char, 10);
679         CHECK_SIZE("steal", p1, 10);
680
681         p2 = talloc_realloc(root, NULL, char, 20);
682         CHECK_SIZE("steal", p1, 10);
683         CHECK_SIZE("steal", root, 30);
684
685         torture_assert("steal", talloc_steal(p1, NULL) == NULL,
686                 "failed: stealing NULL should give NULL\n");
687
688         torture_assert("steal", talloc_steal(p1, p1) == p1,
689                 "failed: stealing to ourselves is a nop\n");
690         CHECK_BLOCKS("steal", root, 3);
691         CHECK_SIZE("steal", root, 30);
692
693         talloc_steal(NULL, p1);
694         talloc_steal(NULL, p2);
695         CHECK_BLOCKS("steal", root, 1);
696         CHECK_SIZE("steal", root, 0);
697
698         talloc_free(p1);
699         talloc_steal(root, p2);
700         CHECK_BLOCKS("steal", root, 2);
701         CHECK_SIZE("steal", root, 20);
702         
703         talloc_free(p2);
704
705         CHECK_BLOCKS("steal", root, 1);
706         CHECK_SIZE("steal", root, 0);
707
708         talloc_free(root);
709
710         p1 = talloc_size(NULL, 3);
711         talloc_report_full(NULL, stderr);
712         CHECK_SIZE("steal", NULL, 3);
713         talloc_free(p1);
714
715         printf("success: steal\n");
716         return true;
717 }
718
719 /*
720   test move
721 */
722 static bool test_move(void)
723 {
724         void *root;
725         struct t_move {
726                 char *p;
727                 int *x;
728         } *t1, *t2;
729
730         printf("test: move\n# MOVE\n");
731
732         root = talloc_new(NULL);
733
734         t1 = talloc(root, struct t_move);
735         t2 = talloc(root, struct t_move);
736         t1->p = talloc_strdup(t1, "foo");
737         t1->x = talloc(t1, int);
738         *t1->x = 42;
739
740         t2->p = talloc_move(t2, &t1->p);
741         t2->x = talloc_move(t2, &t1->x);
742         torture_assert("move", t1->p == NULL && t1->x == NULL &&
743             strcmp(t2->p, "foo") == 0 && *t2->x == 42,
744                 "talloc move failed");
745
746         talloc_free(root);
747
748         printf("success: move\n");
749
750         return true;
751 }
752
753 /*
754   test talloc_realloc_fn
755 */
756 static bool test_realloc_fn(void)
757 {
758         void *root, *p1;
759
760         printf("test: realloc_fn\n# talloc_realloc_fn\n");
761
762         root = talloc_new(NULL);
763
764         p1 = talloc_realloc_fn(root, NULL, 10);
765         CHECK_BLOCKS("realloc_fn", root, 2);
766         CHECK_SIZE("realloc_fn", root, 10);
767         p1 = talloc_realloc_fn(root, p1, 20);
768         CHECK_BLOCKS("realloc_fn", root, 2);
769         CHECK_SIZE("realloc_fn", root, 20);
770         p1 = talloc_realloc_fn(root, p1, 0);
771         CHECK_BLOCKS("realloc_fn", root, 1);
772         CHECK_SIZE("realloc_fn", root, 0);
773
774         talloc_free(root);
775
776         printf("success: realloc_fn\n");
777         return true;
778 }
779
780
781 static bool test_unref_reparent(void)
782 {
783         void *root, *p1, *p2, *c1;
784
785         printf("test: unref_reparent\n# UNREFERENCE AFTER PARENT FREED\n");
786
787         root = talloc_named_const(NULL, 0, "root");
788         p1 = talloc_named_const(root, 1, "orig parent");
789         p2 = talloc_named_const(root, 1, "parent by reference");
790
791         c1 = talloc_named_const(p1, 1, "child");
792         talloc_reference(p2, c1);
793
794         CHECK_PARENT("unref_reparent", c1, p1);
795
796         talloc_free(p1);
797
798         CHECK_PARENT("unref_reparent", c1, p2);
799
800         talloc_unlink(p2, c1);
801
802         CHECK_SIZE("unref_reparent", root, 1);
803
804         talloc_free(p2);
805         talloc_free(root);
806
807         printf("success: unref_reparent\n");
808         return true;
809 }
810
811 /*
812   measure the speed of talloc versus malloc
813 */
814 static bool test_speed(void)
815 {
816         void *ctx = talloc_new(NULL);
817         unsigned count;
818         const int loop = 1000;
819         int i;
820         struct timeval tv;
821
822         printf("test: speed\n# TALLOC VS MALLOC SPEED\n");
823
824         tv = timeval_current();
825         count = 0;
826         do {
827                 void *p1, *p2, *p3;
828                 for (i=0;i<loop;i++) {
829                         p1 = talloc_size(ctx, loop % 100);
830                         p2 = talloc_strdup(p1, "foo bar");
831                         p3 = talloc_size(p1, 300);
832                         talloc_free(p1);
833                 }
834                 count += 3 * loop;
835         } while (timeval_elapsed(&tv) < 5.0);
836
837         fprintf(stderr, "talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv));
838
839         talloc_free(ctx);
840
841         ctx = talloc_pool(NULL, 1024);
842
843         tv = timeval_current();
844         count = 0;
845         do {
846                 void *p1, *p2, *p3;
847                 for (i=0;i<loop;i++) {
848                         p1 = talloc_size(ctx, loop % 100);
849                         p2 = talloc_strdup(p1, "foo bar");
850                         p3 = talloc_size(p1, 300);
851                         talloc_free_children(ctx);
852                 }
853                 count += 3 * loop;
854         } while (timeval_elapsed(&tv) < 5.0);
855
856         talloc_free(ctx);
857
858         fprintf(stderr, "talloc_pool: %.0f ops/sec\n", count/timeval_elapsed(&tv));
859
860         tv = timeval_current();
861         count = 0;
862         do {
863                 void *p1, *p2, *p3;
864                 for (i=0;i<loop;i++) {
865                         p1 = malloc(loop % 100);
866                         p2 = strdup("foo bar");
867                         p3 = malloc(300);
868                         free(p1);
869                         free(p2);
870                         free(p3);
871                 }
872                 count += 3 * loop;
873         } while (timeval_elapsed(&tv) < 5.0);
874         fprintf(stderr, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv));
875
876         printf("success: speed\n");
877
878         return true;
879 }
880
881 static bool test_lifeless(void)
882 {
883         void *top = talloc_new(NULL);
884         char *parent, *child; 
885         void *child_owner = talloc_new(NULL);
886
887         printf("test: lifeless\n# TALLOC_UNLINK LOOP\n");
888
889         parent = talloc_strdup(top, "parent");
890         child = talloc_strdup(parent, "child");  
891         (void)talloc_reference(child, parent);
892         (void)talloc_reference(child_owner, child); 
893         talloc_report_full(top, stderr);
894         talloc_unlink(top, parent);
895         talloc_unlink(top, child);
896         talloc_report_full(top, stderr);
897         talloc_free(top);
898         talloc_free(child_owner);
899         talloc_free(child);
900
901         printf("success: lifeless\n");
902         return true;
903 }
904
905 static int loop_destructor_count;
906
907 static int test_loop_destructor(char *ptr)
908 {
909         loop_destructor_count++;
910         return 0;
911 }
912
913 static bool test_loop(void)
914 {
915         void *top = talloc_new(NULL);
916         char *parent;
917         struct req1 {
918                 char *req2, *req3;
919         } *req1;
920
921         printf("test: loop\n# TALLOC LOOP DESTRUCTION\n");
922
923         parent = talloc_strdup(top, "parent");
924         req1 = talloc(parent, struct req1);
925         req1->req2 = talloc_strdup(req1, "req2");  
926         talloc_set_destructor(req1->req2, test_loop_destructor);
927         req1->req3 = talloc_strdup(req1, "req3");
928         (void)talloc_reference(req1->req3, req1);
929         talloc_report_full(top, stderr);
930         talloc_free(parent);
931         talloc_report_full(top, stderr);
932         talloc_report_full(NULL, stderr);
933         talloc_free(top);
934
935         torture_assert("loop", loop_destructor_count == 1, 
936                                    "FAILED TO FIRE LOOP DESTRUCTOR\n");
937         loop_destructor_count = 0;
938
939         printf("success: loop\n");
940         return true;
941 }
942
943 static int fail_destructor_str(char *ptr)
944 {
945         return -1;
946 }
947
948 static bool test_free_parent_deny_child(void)
949 {
950         void *top = talloc_new(NULL);
951         char *level1;
952         char *level2;
953         char *level3;
954
955         printf("test: free_parent_deny_child\n# TALLOC FREE PARENT DENY CHILD\n");
956
957         level1 = talloc_strdup(top, "level1");
958         level2 = talloc_strdup(level1, "level2");
959         level3 = talloc_strdup(level2, "level3");
960
961         talloc_set_destructor(level3, fail_destructor_str);
962         talloc_free(level1);
963         talloc_set_destructor(level3, NULL);
964
965         CHECK_PARENT("free_parent_deny_child", level3, top);
966
967         talloc_free(top);
968
969         printf("success: free_parent_deny_child\n");
970         return true;
971 }
972
973 static bool test_talloc_ptrtype(void)
974 {
975         void *top = talloc_new(NULL);
976         struct struct1 {
977                 int foo;
978                 int bar;
979         } *s1, *s2, **s3, ***s4;
980         const char *location1;
981         const char *location2;
982         const char *location3;
983         const char *location4;
984
985         printf("test: ptrtype\n# TALLOC PTRTYPE\n");
986
987         s1 = talloc_ptrtype(top, s1);location1 = __location__;
988
989         if (talloc_get_size(s1) != sizeof(struct struct1)) {
990                 printf("failure: ptrtype [\n"
991                   "talloc_ptrtype() allocated the wrong size %lu (should be %lu)\n"
992                   "]\n", (unsigned long)talloc_get_size(s1),
993                            (unsigned long)sizeof(struct struct1));
994                 return false;
995         }
996
997         if (strcmp(location1, talloc_get_name(s1)) != 0) {
998                 printf("failure: ptrtype [\n"
999                   "talloc_ptrtype() sets the wrong name '%s' (should be '%s')\n]\n",
1000                         talloc_get_name(s1), location1);
1001                 return false;
1002         }
1003
1004         s2 = talloc_array_ptrtype(top, s2, 10);location2 = __location__;
1005
1006         if (talloc_get_size(s2) != (sizeof(struct struct1) * 10)) {
1007                 printf("failure: ptrtype [\n"
1008                            "talloc_array_ptrtype() allocated the wrong size "
1009                        "%lu (should be %lu)\n]\n",
1010                         (unsigned long)talloc_get_size(s2),
1011                     (unsigned long)(sizeof(struct struct1)*10));
1012                 return false;
1013         }
1014
1015         if (strcmp(location2, talloc_get_name(s2)) != 0) {
1016                 printf("failure: ptrtype [\n"
1017                 "talloc_array_ptrtype() sets the wrong name '%s' (should be '%s')\n]\n",
1018                         talloc_get_name(s2), location2);
1019                 return false;
1020         }
1021
1022         s3 = talloc_array_ptrtype(top, s3, 10);location3 = __location__;
1023
1024         if (talloc_get_size(s3) != (sizeof(struct struct1 *) * 10)) {
1025                 printf("failure: ptrtype [\n"
1026                            "talloc_array_ptrtype() allocated the wrong size "
1027                        "%lu (should be %lu)\n]\n",
1028                            (unsigned long)talloc_get_size(s3),
1029                        (unsigned long)(sizeof(struct struct1 *)*10));
1030                 return false;
1031         }
1032
1033         torture_assert_str_equal("ptrtype", location3, talloc_get_name(s3),
1034                 "talloc_array_ptrtype() sets the wrong name");
1035
1036         s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__;
1037
1038         if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) {
1039                 printf("failure: ptrtype [\n"
1040                       "talloc_array_ptrtype() allocated the wrong size "
1041                        "%lu (should be %lu)\n]\n",
1042                            (unsigned long)talloc_get_size(s4),
1043                        (unsigned long)(sizeof(struct struct1 **)*10));
1044                 return false;
1045         }
1046
1047         torture_assert_str_equal("ptrtype", location4, talloc_get_name(s4),
1048                 "talloc_array_ptrtype() sets the wrong name");
1049
1050         talloc_free(top);
1051
1052         printf("success: ptrtype\n");
1053         return true;
1054 }
1055
1056 static int _test_talloc_free_in_destructor(void **ptr)
1057 {
1058         talloc_free(*ptr);
1059         return 0;
1060 }
1061
1062 static bool test_talloc_free_in_destructor(void)
1063 {
1064         void *level0;
1065         void *level1;
1066         void *level2;
1067         void *level3;
1068         void *level4;
1069         void **level5;
1070
1071         printf("test: free_in_destructor\n# TALLOC FREE IN DESTRUCTOR\n");
1072
1073         level0 = talloc_new(NULL);
1074         level1 = talloc_new(level0);
1075         level2 = talloc_new(level1);
1076         level3 = talloc_new(level2);
1077         level4 = talloc_new(level3);
1078         level5 = talloc(level4, void *);
1079
1080         *level5 = level3;
1081         (void)talloc_reference(level0, level3);
1082         (void)talloc_reference(level3, level3);
1083         (void)talloc_reference(level5, level3);
1084
1085         talloc_set_destructor(level5, _test_talloc_free_in_destructor);
1086
1087         talloc_free(level1);
1088
1089         talloc_free(level0);
1090
1091         printf("success: free_in_destructor\n");
1092         return true;
1093 }
1094
1095 static bool test_autofree(void)
1096 {
1097 #if _SAMBA_BUILD_ < 4
1098         /* autofree test would kill smbtorture */
1099         void *p;
1100         printf("test: autofree\n# TALLOC AUTOFREE CONTEXT\n");
1101
1102         p = talloc_autofree_context();
1103         talloc_free(p);
1104
1105         p = talloc_autofree_context();
1106         talloc_free(p);
1107
1108         printf("success: autofree\n");
1109 #endif
1110         return true;
1111 }
1112
1113 static bool test_pool(void)
1114 {
1115         void *pool;
1116         void *p1, *p2, *p3, *p4;
1117         void *p2_2;
1118
1119         pool = talloc_pool(NULL, 1024);
1120
1121         p1 = talloc_size(pool, 80);
1122         memset(p1, 0x11, talloc_get_size(p1));
1123         p2 = talloc_size(pool, 20);
1124         memset(p2, 0x11, talloc_get_size(p2));
1125         p3 = talloc_size(p1, 50);
1126         memset(p3, 0x11, talloc_get_size(p3));
1127         p4 = talloc_size(p3, 1000);
1128         memset(p4, 0x11, talloc_get_size(p4));
1129
1130 #if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
1131         p2_2 = talloc_realloc_size(pool, p2, 20+1);
1132         torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed");
1133         memset(p2, 0x11, talloc_get_size(p2));
1134         p2_2 = talloc_realloc_size(pool, p2, 20-1);
1135         torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
1136         memset(p2, 0x11, talloc_get_size(p2));
1137         p2_2 = talloc_realloc_size(pool, p2, 20-1);
1138         torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
1139         memset(p2, 0x11, talloc_get_size(p2));
1140
1141         talloc_free(p3);
1142
1143         /* this should reclaim the memory of p4 and p3 */
1144         p2_2 = talloc_realloc_size(pool, p2, 400);
1145         torture_assert("pool realloc 400", p2_2 == p2, "failed: pointer changed");
1146         memset(p2, 0x11, talloc_get_size(p2));
1147
1148         talloc_free(p1);
1149
1150         /* this should reclaim the memory of p1 */
1151         p2_2 = talloc_realloc_size(pool, p2, 800);
1152         torture_assert("pool realloc 800", p2_2 == p1, "failed: pointer not changed");
1153         p2 = p2_2;
1154         memset(p2, 0x11, talloc_get_size(p2));
1155
1156         /* this should do a malloc */
1157         p2_2 = talloc_realloc_size(pool, p2, 1800);
1158         torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
1159         p2 = p2_2;
1160         memset(p2, 0x11, talloc_get_size(p2));
1161
1162         /* this should reclaim the memory from the pool */
1163         p3 = talloc_size(pool, 80);
1164         torture_assert("pool alloc 80", p3 == p1, "failed: pointer changed");
1165         memset(p3, 0x11, talloc_get_size(p3));
1166
1167         talloc_free(p2);
1168         talloc_free(p3);
1169
1170         p1 = talloc_size(pool, 80);
1171         memset(p1, 0x11, talloc_get_size(p1));
1172         p2 = talloc_size(pool, 20);
1173         memset(p2, 0x11, talloc_get_size(p2));
1174
1175         talloc_free(p1);
1176
1177         p2_2 = talloc_realloc_size(pool, p2, 20-1);
1178         torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
1179         memset(p2, 0x11, talloc_get_size(p2));
1180         p2_2 = talloc_realloc_size(pool, p2, 20-1);
1181         torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
1182         memset(p2, 0x11, talloc_get_size(p2));
1183
1184         /* this should do a malloc */
1185         p2_2 = talloc_realloc_size(pool, p2, 1800);
1186         torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
1187         p2 = p2_2;
1188         memset(p2, 0x11, talloc_get_size(p2));
1189
1190         /* this should reclaim the memory from the pool */
1191         p3 = talloc_size(pool, 800);
1192         torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed");
1193         memset(p3, 0x11, talloc_get_size(p3));
1194
1195 #endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
1196
1197         talloc_free(pool);
1198
1199         return true;
1200 }
1201
1202 static bool test_pool_steal(void)
1203 {
1204         void *root;
1205         void *pool;
1206         void *p1, *p2;
1207         void *p1_2, *p2_2;
1208         size_t hdr;
1209         size_t ofs1, ofs2;
1210
1211         root = talloc_new(NULL);
1212         pool = talloc_pool(root, 1024);
1213
1214         p1 = talloc_size(pool, 4 * 16);
1215         torture_assert("pool allocate 4 * 16", p1 != NULL, "failed ");
1216         memset(p1, 0x11, talloc_get_size(p1));
1217         p2 = talloc_size(pool, 4 * 16);
1218         torture_assert("pool allocate 4 * 16", p2 > p1, "failed: !(p2 > p1) ");
1219         memset(p2, 0x11, talloc_get_size(p2));
1220
1221         ofs1 = PTR_DIFF(p2, p1);
1222         hdr = ofs1 - talloc_get_size(p1);
1223
1224         talloc_steal(root, p1);
1225         talloc_steal(root, p2);
1226
1227         talloc_free(pool);
1228
1229         p1_2 = p1;
1230
1231 #if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
1232         p1_2 = talloc_realloc_size(root, p1, 5 * 16);
1233         torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed");
1234         memset(p1_2, 0x11, talloc_get_size(p1_2));
1235         ofs1 = PTR_DIFF(p1_2, p2);
1236         ofs2 = talloc_get_size(p2) + hdr;
1237
1238         torture_assert("pool realloc ", ofs1 == ofs2, "failed: pointer offset unexpected");
1239
1240         p2_2 = talloc_realloc_size(root, p2, 3 * 16);
1241         torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed");
1242         memset(p2_2, 0x11, talloc_get_size(p2_2));
1243 #endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
1244
1245         talloc_free(p1_2);
1246
1247         p2_2 = p2;
1248
1249 #if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
1250         /* now we should reclaim the full pool */
1251         p2_2 = talloc_realloc_size(root, p2, 8 * 16);
1252         torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected");
1253         p2 = p2_2;
1254         memset(p2_2, 0x11, talloc_get_size(p2_2));
1255
1256         /* now we malloc and free the full pool space */
1257         p2_2 = talloc_realloc_size(root, p2, 2 * 1024);
1258         torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected");
1259         memset(p2_2, 0x11, talloc_get_size(p2_2));
1260
1261 #endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
1262
1263         talloc_free(p2_2);
1264
1265         talloc_free(root);
1266
1267         return true;
1268 }
1269
1270 static bool test_free_ref_null_context(void)
1271 {
1272         void *p1, *p2, *p3;
1273         int ret;
1274
1275         talloc_disable_null_tracking();
1276         p1 = talloc_new(NULL);
1277         p2 = talloc_new(NULL);
1278
1279         p3 = talloc_reference(p2, p1);
1280         torture_assert("reference", p3 == p1, "failed: reference on null");
1281
1282         ret = talloc_free(p1);
1283         torture_assert("ref free with null parent", ret == 0, "failed: free with null parent");
1284         talloc_free(p2);
1285
1286         talloc_enable_null_tracking_no_autofree();
1287         p1 = talloc_new(NULL);
1288         p2 = talloc_new(NULL);
1289
1290         p3 = talloc_reference(p2, p1);
1291         torture_assert("reference", p3 == p1, "failed: reference on null");
1292
1293         ret = talloc_free(p1);
1294         torture_assert("ref free with null tracked parent", ret == 0, "failed: free with null parent");
1295         talloc_free(p2);
1296
1297         return true;
1298 }
1299
1300 static bool test_rusty(void)
1301 {
1302         void *root;
1303         const char *p1;
1304
1305         talloc_enable_null_tracking();
1306         root = talloc_new(NULL);
1307         p1 = talloc_strdup(root, "foo");
1308         talloc_increase_ref_count(p1);
1309         talloc_report_full(root, stdout);
1310         talloc_free(root);
1311         CHECK_BLOCKS("null_context", NULL, 2);
1312         return true;
1313 }
1314
1315 static bool test_free_children(void)
1316 {
1317         void *root;
1318         const char *p1, *p2, *name, *name2;
1319
1320         talloc_enable_null_tracking();
1321         root = talloc_new(NULL);
1322         p1 = talloc_strdup(root, "foo1");
1323         p2 = talloc_strdup(p1, "foo2");
1324
1325         talloc_set_name(p1, "%s", "testname");
1326         talloc_free_children(p1);
1327         /* check its still a valid talloc ptr */
1328         talloc_get_size(talloc_get_name(p1));
1329         if (strcmp(talloc_get_name(p1), "testname") != 0) {
1330                 return false;
1331         }
1332
1333         talloc_set_name(p1, "%s", "testname");
1334         name = talloc_get_name(p1);
1335         talloc_free_children(p1);
1336         /* check its still a valid talloc ptr */
1337         talloc_get_size(talloc_get_name(p1));
1338         torture_assert("name", name == talloc_get_name(p1), "name ptr changed");
1339         torture_assert("namecheck", strcmp(talloc_get_name(p1), "testname") == 0,
1340                        "wrong name");
1341         CHECK_BLOCKS("name1", p1, 2);
1342
1343         /* note that this does not free the old child name */
1344         talloc_set_name_const(p1, "testname2");
1345         name2 = talloc_get_name(p1);
1346         /* but this does */
1347         talloc_free_children(p1);
1348         torture_assert("namecheck", strcmp(talloc_get_name(p1), "testname2") == 0,
1349                        "wrong name");
1350         CHECK_BLOCKS("name1", p1, 1);
1351
1352         talloc_report_full(root, stdout);
1353         talloc_free(root);
1354         return true;
1355 }
1356
1357
1358 static void test_reset(void)
1359 {
1360         talloc_set_log_fn(test_log_stdout);
1361         test_abort_stop();
1362         talloc_disable_null_tracking();
1363         talloc_enable_null_tracking_no_autofree();
1364 }
1365
1366 bool torture_local_talloc(struct torture_context *tctx)
1367 {
1368         bool ret = true;
1369
1370         setlinebuf(stdout);
1371
1372         test_reset();
1373         ret &= test_ref1();
1374         test_reset();
1375         ret &= test_ref2();
1376         test_reset();
1377         ret &= test_ref3();
1378         test_reset();
1379         ret &= test_ref4();
1380         test_reset();
1381         ret &= test_unlink1(); 
1382         test_reset();
1383         ret &= test_misc();
1384         test_reset();
1385         ret &= test_realloc();
1386         test_reset();
1387         ret &= test_realloc_child(); 
1388         test_reset();
1389         ret &= test_steal(); 
1390         test_reset();
1391         ret &= test_move(); 
1392         test_reset();
1393         ret &= test_unref_reparent();
1394         test_reset();
1395         ret &= test_realloc_fn(); 
1396         test_reset();
1397         ret &= test_type();
1398         test_reset();
1399         ret &= test_lifeless(); 
1400         test_reset();
1401         ret &= test_loop();
1402         test_reset();
1403         ret &= test_free_parent_deny_child(); 
1404         test_reset();
1405         ret &= test_talloc_ptrtype();
1406         test_reset();
1407         ret &= test_talloc_free_in_destructor();
1408         test_reset();
1409         ret &= test_pool();
1410         test_reset();
1411         ret &= test_pool_steal();
1412         test_reset();
1413         ret &= test_free_ref_null_context();
1414         test_reset();
1415         ret &= test_rusty();
1416         test_reset();
1417         ret &= test_free_children();
1418
1419         if (ret) {
1420                 test_reset();
1421                 ret &= test_speed();
1422         }
1423         test_reset();
1424         ret &= test_autofree();
1425
1426         test_reset();
1427         talloc_disable_null_tracking();
1428         return ret;
1429 }