From 1627d006353fa9b6825d9abcdc2962ead62f2062 Mon Sep 17 00:00:00 2001 From: Gilad Arnold Date: Thu, 16 Dec 2004 23:51:21 +0000 Subject: [PATCH] Added new test program + changes to make system. Tests recusive persisitifying updates. --- test/pobj/Makefile.am | 2 +- test/pobj/test-list2.c | 78 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 test/pobj/test-list2.c diff --git a/test/pobj/Makefile.am b/test/pobj/Makefile.am index 43ba600..cd124bf 100644 --- a/test/pobj/Makefile.am +++ b/test/pobj/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = test-list test-multilist +noinst_PROGRAMS = test-list test-multilist test-list2 LDADD = $(top_builddir)/src/pobj/libpobj.a $(top_builddir)/src/lladd/liblladd.a \ $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a CLEANFILES = storefile.txt logfile.txt blob0_file.txt blob1_file.txt diff --git a/test/pobj/test-list2.c b/test/pobj/test-list2.c new file mode 100644 index 0000000..2d8785d --- /dev/null +++ b/test/pobj/test-list2.c @@ -0,0 +1,78 @@ +#include +#include +#include + + +struct data { + int val; +}; + +struct item { + int val; + struct data *data; + struct item *next; + int dummy[45]; +}; +int item_ref_fields[] = { + member_offset(struct item, data), + member_offset(struct item, next), + -1 +}; + +int +main (int argc, char **argv) +{ + static struct item *list = NULL; + struct data *data; + struct item *tmp, *next; + int i; + + switch (pobj_init (NULL, NULL)) { + case 0: + printf ("first-time init\n"); + /* Build list. */ + next = NULL; + for (i = 0; i < 15; i++) { + tmp = (struct item *) pobj_malloc_transient (sizeof (struct item)); + data = (struct data *) pobj_malloc_transient (sizeof (struct data)); + if (! (tmp && data)) { + printf ("allocation error\n"); + abort (); + } + pobj_ref_typify (tmp, item_ref_fields); + + data->val = -i; + tmp->val = i; + tmp->data = data; + tmp->next = next; + + next = tmp; + } + pobj_update_recursive (tmp, 1); + pobj_static_set_ref (&list, tmp); + break; + + case 1: + printf ("subsequent init\n"); + break; + + case -1: + printf ("init error\n"); + break; + + default: + printf ("unknown return value\n"); + } + + /* Print list. */ + printf ("printing list...\n"); + for (tmp = list; tmp; tmp = tmp->next) + printf ("%p: val=%d next=%p data=%p data->val=%d\n", + (void *) tmp, tmp->val, (void *) tmp->next, + (void *) tmp->data, (tmp->data ? tmp->data->val : 0)); + printf ("...done\n"); + + pobj_shutdown (); + + return 0; +}