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