2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 Copyright (c) 2005 Eliot Dresselhaus
18 Permission is hereby granted, free of charge, to any person obtaining
19 a copy of this software and associated documentation files (the
20 "Software"), to deal in the Software without restriction, including
21 without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense, and/or sell copies of the Software, and to
23 permit persons to whom the Software is furnished to do so, subject to
24 the following conditions:
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include <vppinfra/format.h>
39 #include <vppinfra/hash.h>
40 #include <vppinfra/random.h>
41 #include <vppinfra/random_isaac.h>
44 #define if_verbose(format,args...) \
45 if (verbose) { clib_warning(format, ## args); }
47 int test_isaac_main (unformat_input_t * input)
49 uword n_iterations, seed;
50 uword i, repeat_count;
54 uword results[ISAAC_SIZE] = {0};
61 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
63 if (0 == unformat (input, "iter %d", &n_iterations)
64 && 0 == unformat (input, "print %d", &print)
65 && 0 == unformat (input, "seed %d", &seed))
66 clib_error ("unknown input `%U'", format_unformat_error, input);
70 seed = random_default_seed ();
74 if (n_iterations == 0)
77 if_verbose ("%d iterations, seed %d\n", n_iterations, seed);
80 isaac_init (&ctx, results);
81 isaac (&ctx, results);
83 for (i = 0; i < n_iterations; i++)
85 uword r = results[n_results++];
88 hash = hash_create (0, /* value bytes */ 0);
90 if (hash_get (hash, r))
95 if (n_results >= ARRAY_LEN (results))
97 isaac (&ctx, results);
101 if (verbose && 0 == (i & (print - 1)))
102 fformat (stderr, "0x%08x iterations %d repeats\n", i, repeat_count);
104 if (hash_elts (hash) > 0x100000)
110 fformat (stderr, "repeat found at iteration %d/%d\n", i, n_iterations);
115 return repeat_count > 0 ? 1 : 0;
119 int main (int argc, char * argv[])
124 verbose = (argc > 1);
125 unformat_init_command_line (&i, argv);
126 ret = test_isaac_main (&i);
131 #endif /* CLIB_UNIX */