2 * range-index-test.c: An extension for random-test.
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 #ifndef SVN_RANGE_INDEX_TEST_H
20 #define SVN_RANGE_INDEX_TEST_H
22 #include "../../libsvn_delta/compose_delta.c"
24 static range_index_node_t
*prev_node
, *prev_prev_node
;
26 walk_range_index(range_index_node_t
*node
, const char **msg
)
33 ret
= walk_range_index(node
->left
, msg
);
38 && node
->target_offset
> 0
39 && (prev_node
->offset
>= node
->offset
40 || (prev_node
->limit
>= node
->limit
)))
42 ret
= node
->target_offset
;
43 node
->target_offset
= -node
->target_offset
;
44 *msg
= "Oops, the previous node ate me.";
47 if (prev_prev_node
!= NULL
48 && prev_node
->target_offset
> 0
49 && prev_prev_node
->limit
> node
->offset
)
51 ret
= prev_node
->target_offset
;
52 prev_node
->target_offset
= -prev_node
->target_offset
;
53 *msg
= "Arrgh, my neighbours are conspiring against me.";
56 prev_prev_node
= prev_node
;
59 return walk_range_index(node
->right
, msg
);
64 print_node_data(range_index_node_t
*node
, const char *msg
, apr_off_t ndx
)
66 if (-node
->target_offset
== ndx
)
68 printf(" * Node: [%3"APR_OFF_T_FMT
70 ") = %-5"APR_OFF_T_FMT
"%s\n",
71 node
->offset
, node
->limit
, -node
->target_offset
, msg
);
75 printf(" Node: [%3"APR_OFF_T_FMT
77 ") = %"APR_OFF_T_FMT
"\n",
78 node
->offset
, node
->limit
,
79 (node
->target_offset
< 0
80 ? -node
->target_offset
: node
->target_offset
));
85 print_range_index_r(range_index_node_t
*node
, const char *msg
, apr_off_t ndx
)
90 print_range_index_r(node
->left
, msg
, ndx
);
91 print_node_data(node
, msg
, ndx
);
92 print_range_index_r(node
->right
, msg
, ndx
);
96 print_range_index_i(range_index_node_t
*node
, const char *msg
, apr_off_t ndx
)
106 print_node_data(node
, msg
, ndx
);
113 print_range_index(range_index_node_t
*node
, const char *msg
, apr_off_t ndx
)
115 printf(" (recursive)\n");
116 print_range_index_r(node
, msg
, ndx
);
117 printf(" (iterative)\n");
118 print_range_index_i(node
, msg
, ndx
);
123 check_copy_count(int src_cp
, int tgt_cp
)
125 printf("Source copies: %d Target copies: %d\n", src_cp
, tgt_cp
);
127 printf("WARN: More source than target copies; inefficient combiner?\n");
132 random_range_index_test(const char **msg
,
133 svn_boolean_t msg_only
,
136 static char msg_buff
[256];
138 unsigned long seed
, bytes_range
;
139 int i
, maxlen
, iterations
, dump_files
, print_windows
;
140 const char *random_bytes
;
142 int tgt_cp
= 0, src_cp
= 0;
144 /* Initialize parameters and print out the seed in case we dump core
146 init_params(&seed
, &maxlen
, &iterations
, &dump_files
, &print_windows
,
147 &random_bytes
, &bytes_range
, pool
);
148 sprintf(msg_buff
, "random range index test, seed = %lu", seed
);
151 /* ### This test is expected to fail randomly at the moment, so don't
152 enable it by default. --xbc */
156 printf("SEED: %s\n", msg_buff
);
158 ndx
= create_range_index(pool
);
159 for (i
= 1; i
<= iterations
; ++i
)
161 apr_off_t offset
= myrand(&seed
) % 47;
162 apr_off_t limit
= offset
+ myrand(&seed
) % 16 + 1;
163 range_list_node_t
*list
, *r
;
167 printf("%3d: Inserting [%3"APR_OFF_T_FMT
",%3"APR_OFF_T_FMT
") ...",
169 splay_range_index(offset
, ndx
);
170 list
= build_range_list(offset
, limit
, ndx
);
171 insert_range(offset
, limit
, i
, ndx
);
172 prev_prev_node
= prev_node
= NULL
;
173 ret
= walk_range_index(ndx
->tree
, &msg2
);
176 for (r
= list
; r
; r
= r
->next
)
177 printf(" %s[%3"APR_OFF_T_FMT
",%3"APR_OFF_T_FMT
")",
178 (r
->kind
== range_from_source
?
179 (++src_cp
, "S") : (++tgt_cp
, "T")),
180 r
->offset
, r
->limit
);
181 free_range_list(list
, ndx
);
187 print_range_index(ndx
->tree
, msg2
, ret
);
188 check_copy_count(src_cp
, tgt_cp
);
189 return svn_error_create(SVN_ERR_TEST_FAILED
, 0, NULL
, pool
,
194 printf("Final tree state:\n");
195 print_range_index(ndx
->tree
, "", iterations
+ 1);
196 check_copy_count(src_cp
, tgt_cp
);
201 #endif /* SVN_RANGE_INDEX_TEST_H */