4
* test driver for rollover counter replay implementation
12
* Copyright (c) 2001-2006, Cisco Systems, Inc.
13
* All rights reserved.
15
* Redistribution and use in source and binary forms, with or without
16
* modification, are permitted provided that the following conditions
19
* Redistributions of source code must retain the above copyright
20
* notice, this list of conditions and the following disclaimer.
22
* Redistributions in binary form must reproduce the above
23
* copyright notice, this list of conditions and the following
24
* disclaimer in the documentation and/or other materials provided
25
* with the distribution.
27
* Neither the name of the Cisco Systems, Inc. nor the names of its
28
* contributors may be used to endorse or promote products derived
29
* from this software without specific prior written permission.
31
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
34
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
35
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
36
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
42
* OF THE POSSIBILITY OF SUCH DAMAGE.
50
* defining ROC_TEST causes small datatypes to be used in
51
* xtd_seq_num_t - this allows the functions to be exhaustively tested.
53
#if ROC_NEEDS_TO_BE_TESTED
61
roc_test(int num_trials);
67
printf("rollover counter test driver\n"
69
"Cisco Systems, Inc.\n");
71
printf("testing index functions...");
72
status = roc_test(1 << 18);
85
roc_test(int num_trials) {
86
xtd_seq_num_t local, est, ref;
88
int i, num_bad_est = 0;
97
printf("\n\ttesting sequential insertion...");
98
for (i=0; i < 2048; i++) {
99
delta = index_guess(&local, &est, (uint16_t) ref);
101
printf("%lld, %lld, %d\n", ref, est, i);
105
printf(" *bad estimate*\n");
109
index_advance(&ref, 1);
111
failure_rate = (double) num_bad_est / num_trials;
112
if (failure_rate > 0.01) {
113
printf("error: failure rate too high (%d bad estimates in %d trials)\n",
114
num_bad_est, num_trials);
115
return err_status_algo_fail;
120
printf("\ttesting non-sequential insertion...");
126
for (i=0; i < num_trials; i++) {
128
/* get next seq num from unreliable transport simulator */
129
ircvd = ut_next_index(&utc);
131
/* set ref to value of ircvd */
134
/* estimate index based on low bits of ircvd */
135
delta = index_guess(&local, &est, (uint16_t) ref);
137
printf("ref: %lld, local: %lld, est: %lld, ircvd: %d, delta: %d\n",
138
ref, local, est, ircvd, delta);
141
/* now update local xtd_seq_num_t as necessary */
143
index_advance(&local, delta);
147
printf(" *bad estimate*\n");
149
/* record failure event */
152
/* reset local value to correct value */
156
failure_rate = (double) num_bad_est / num_trials;
157
if (failure_rate > 0.01) {
158
printf("error: failure rate too high (%d bad estimates in %d trials)\n",
159
num_bad_est, num_trials);
160
return err_status_algo_fail;
164
return err_status_ok;