/*
Unix SMB/CIFS implementation.
local testing of talloc routines.
Copyright (C) Andrew Tridgell 2004
** NOTE! The following LGPL license applies to the talloc
** library. This does NOT imply that all of Samba is released
** under the LGPL
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "replace.h"
#include "system/time.h"
#include <talloc.h>
#include "talloc_testsuite.h"
static struct timeval timeval_current(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv;
}
static double timeval_elapsed(struct timeval *tv)
{
struct timeval tv2 = timeval_current();
return (tv2.tv_sec - tv->tv_sec) +
(tv2.tv_usec - tv->tv_usec)*1.0e-6;
}
#define torture_assert(test, expr, str) if (!(expr)) { \
printf("failure: %s [\n%s: Expression %s failed: %s\n]\n", \
test, __location__, #expr, str); \
return false; \
}
#define torture_assert_str_equal(test, arg1, arg2, desc) \
if (arg1 == NULL && arg2 == NULL) { \
} else if (strcmp(arg1, arg2)) { \
printf("failure: %s [\n%s: Expected %s, got %s: %s\n]\n", \
test, __location__, arg1, arg2, desc); \
return false; \
}
#define CHECK_SIZE(test, ptr, tsize) do { \
if (talloc_total_size(ptr) != (tsize)) { \
printf("failed: %s [\n%s: wrong '%s' tree size: got %u expected %u\n]\n", \
test, __location__, #ptr, \
(unsigned)talloc_total_size(ptr), \
(unsigned)tsize); \
talloc_report_full(ptr, stdout); \
return false; \
} \
} while (0)
#define CHECK_BLOCKS(test, ptr, tblocks) do { \
if (talloc_total_blocks(ptr) != (tblocks)) { \
printf("failed: %s [\n%s: wrong '%s' tree blocks: got %u expected %u\n]\n", \
test, __location__, #ptr, \
(unsigned)talloc_total_blocks(ptr), \
(unsigned)tblocks); \
talloc_report_full(ptr, stdout); \
return false; \
} \
} while (0)
#define CHECK_PARENT(test, ptr, parent) do { \
if (talloc_parent(ptr) != (parent)) { \
printf("failed: %s [\n%s: '%s' has wrong parent: got %p expected %p\n]\n", \
test, __location__, #ptr, \
talloc_parent(ptr), \
(parent)); \
talloc_report_full(ptr, stdout); \
talloc_report_full(parent, stdout); \
talloc_report_full(NULL, stdout); \
return false; \
} \
} while (0)
static unsigned int test_abort_count;
#if 0
static void test_abort_fn(const char *reason)
{
printf("# test_abort_fn(%s)\n", reason);
test_abort_count++;
}
static void test_abort_start(void)
{
test_abort_count = 0;
talloc_set_abort_fn(test_abort_fn);
}
#endif
static void test_abort_stop(void)
{
test_abort_count = 0;
talloc_set_abort_fn(NULL);
}
static void test_log_stdout(const char *message)
{
fprintf(stdout, "%s", message);
}
/*
test references
*/
static bool test_ref1(void)
{
void *root, *p1, *p2, *ref, *r1;
printf("test: ref1\n# SINGLE REFERENCE FREE\n");
root = talloc_named_const(NULL, 0, "root");
p1 = talloc_named_const(root, 1, "p1");
p2 = talloc_named_const(p1, 1, "p2");
talloc_named_con
|