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) 2001, 2002, 2003 Eliot Dresselhaus
17 Written by Fred Delley <fdelley@cisco.com> .
19 Permission is hereby granted, free of charge, to any person obtaining
20 a copy of this software and associated documentation files (the
21 "Software"), to deal in the Software without restriction, including
22 without limitation the rights to use, copy, modify, merge, publish,
23 distribute, sublicense, and/or sell copies of the Software, and to
24 permit persons to whom the Software is furnished to do so, subject to
25 the following conditions:
27 The above copyright notice and this permission notice shall be
28 included in all copies or substantial portions of the Software.
30 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 #ifdef CLIB_LINUX_KERNEL
40 # include <linux/unistd.h>
49 #include <vppinfra/clib.h>
50 #include <vppinfra/mheap.h>
51 #include <vppinfra/format.h>
52 #include <vppinfra/error.h>
53 #include <vppinfra/random.h>
54 #include <vppinfra/time.h>
59 #define if_verbose(format,args...) \
60 if (verbose) { clib_warning(format, ## args); }
62 #define MAX_CHANGE 100
66 /* Values have to be sequential and start with 0. */
72 OP_IS_VEC_INSERT_ELTS,
84 /* Operations on vectors with custom headers. */
91 #define FIRST_VEC_OP OP_IS_VEC_RESIZE
92 #define LAST_VEC_OP OP_IS_VEC_PREPEND
93 #define FIRST_VEC_HDR_OP OP_IS_VEC_INIT_H
94 #define LAST_VEC_HDR_OP OP_IS_VEC_FREE_H
96 uword g_prob_ratio[] = {
97 [OP_IS_VEC_RESIZE] = 5,
101 [OP_IS_VEC_INSERT] = 5,
102 [OP_IS_VEC_INSERT_ELTS] = 5,
103 [OP_IS_VEC_DELETE] = 30,
105 [OP_IS_VEC_IS_EQUAL] = 5,
106 [OP_IS_VEC_ZERO] = 2,
108 [OP_IS_VEC_VALIDATE] = 5,
109 [OP_IS_VEC_FREE] = 5,
110 [OP_IS_VEC_INIT] = 5,
111 [OP_IS_VEC_CLONE] = 5,
112 [OP_IS_VEC_APPEND] = 5,
113 [OP_IS_VEC_PREPEND] = 5,
114 /* Operations on vectors with custom headers. */
115 [OP_IS_VEC_INIT_H] = 5,
116 [OP_IS_VEC_RESIZE_H] = 5,
117 [OP_IS_VEC_FREE_H] = 5,
123 uword g_call_stats[OP_MAX];
126 /* A structure for both vector headers and vector elements might be useful to
127 uncover potential alignement issues. */
131 CLIB_PACKED (u32 field2);
136 CLIB_PACKED (u32 field2);
141 u32 g_seed = 0xdeadbabe;
146 uword g_set_verbose_at = ~0;
147 uword g_dump_period = ~0;
150 static u8 * format_vec_op_type (u8 * s, va_list * args)
152 op_t op = va_arg (*args, int);
158 s = format (s, "OP_IS_" #n); \
161 _(VEC_RESIZE); _(VEC_ADD1); _(VEC_ADD2); _(VEC_ADD); _(VEC_INSERT);
162 _(VEC_INSERT_ELTS); _(VEC_DELETE); _(VEC_DUP); _(VEC_IS_EQUAL);
163 _(VEC_ZERO); _(VEC_SET); _(VEC_VALIDATE); _(VEC_FREE); _(VEC_INIT);
164 _(VEC_CLONE); _(VEC_APPEND); _(VEC_PREPEND); _(VEC_INIT_H); _(VEC_RESIZE_H);
168 s = format (s, "Unknown vec op (%d)", op);
177 static void dump_call_stats (uword * stats)
181 fformat (stdout, "Call Stats\n----------\n");
183 for (i = 0; i < OP_MAX; i++)
184 fformat (stdout, "%-8d %U\n", stats[i], format_vec_op_type, i);
188 /* XXX - Purposely low value for debugging the validator. Will be set it to a
189 more sensible value later. */
190 #define MAX_VEC_LEN 10
192 #define create_random_vec_wh(elt_type, len, hdr_bytes, seed) \
194 elt_type * _v(v) = NULL; \
195 uword _v(l) = (len); \
196 uword _v(h) = (hdr_bytes); \
202 /* ~0 means select random length between 0 and MAX_VEC_LEN. */ \
204 _v(l) = bounded_random_u32 (&(seed), 0, MAX_VEC_LEN); \
206 _v(v) = _vec_resize (NULL, _v(l), _v(l) * sizeof (elt_type), _v(h), 0); \
207 fill_with_random_data (_v(v), vec_bytes (_v(v)), (seed)); \
209 /* Fill header with random data as well. */ \
212 _v(hdr) = vec_header (_v(v), _v(h)); \
213 fill_with_random_data (_v(hdr), _v(h), (seed)); \
220 #define create_random_vec(elt_type, len, seed) \
221 create_random_vec_wh (elt_type, len, 0, seed)
223 #define compute_vec_hash(hash, vec) \
225 u8 * _v(v) = (u8 *) (vec); \
226 uword _v(n) = vec_len (vec) * sizeof ((vec)[0]); \
227 u8 _v(hh) = (u8) (hash); \
229 compute_mem_hash (_v(hh), _v(v), _v(n)); \
232 static elt_t * validate_vec_free (elt_t * vec)
235 ASSERT (vec == NULL);
239 static elt_t * validate_vec_free_h (elt_t * vec, uword hdr_bytes)
241 vec_free_h (vec, hdr_bytes);
242 ASSERT (vec == NULL);
246 static void validate_vec_hdr (elt_t * vec, uword hdr_bytes)
255 vh = _vec_find (vec);
256 hdr = vec_header (vec, hdr_bytes);
257 hdr_end = vec_header_end (hdr, hdr_bytes);
259 ASSERT (hdr_end == (u8 *) vec);
260 ASSERT ((u8 *) vh - (u8 *) hdr >= hdr_bytes);
263 static void validate_vec_len (elt_t * vec)
276 end = (u8 *) vec_end (vec);
278 bytes = sizeof (vec[0]) * len;
280 ASSERT (bytes == vec_bytes (vec));
281 ASSERT ((ptr + bytes) == end);
285 /* XXX - TODO: confirm that auto-incrementing in vec_is_member() would not
286 have the expected result. */
287 while (vec_is_member (vec, (__typeof__(vec[0]) *) ptr))
298 vec_foreach (elt, vec)
304 static void validate_vec (elt_t * vec, uword hdr_bytes)
306 validate_vec_hdr (vec, hdr_bytes);
307 validate_vec_len (vec);
309 if (! vec || vec_len (vec) == 0)
311 VERBOSE3 ("Vector at %p has zero elements.\n\n", vec);
316 VERBOSE3 ("Header: %U\n",
317 format_hex_bytes, vec_header (vec, sizeof (vec[0])),
321 format_hex_bytes, vec, vec_len (vec) * sizeof (vec[0]));
325 static elt_t * validate_vec_resize (elt_t * vec, uword num_elts)
327 uword len1 = vec_len (vec);
329 u8 hash = compute_vec_hash (0, vec);
331 vec_resize (vec, num_elts);
332 len2 = vec_len (vec);
334 ASSERT (len2 == len1 + num_elts);
335 ASSERT (compute_vec_hash (hash, vec) == 0);
336 validate_vec (vec, 0);
340 static elt_t * validate_vec_resize_h (elt_t * vec,
341 uword num_elts, uword hdr_bytes)
348 len1 = vec_len (vec);
351 hdr = vec_header (vec, hdr_bytes);
353 hash = compute_vec_hash (0, vec);
354 hdr_hash = compute_mem_hash (0, hdr, hdr_bytes);
356 vec_resize_ha (vec, num_elts, hdr_bytes, 0);
357 len2 = vec_len (vec);
359 ASSERT (len2 == len1 + num_elts);
361 end1 = (u8 *) (vec + len1);
362 end2 = (u8 *) vec_end (vec);
371 hdr = vec_header (vec, hdr_bytes);
373 ASSERT (compute_vec_hash (hash, vec) == 0);
374 ASSERT (compute_mem_hash (hdr_hash, hdr, hdr_bytes) == 0);
375 validate_vec (vec, 1);
379 static elt_t * generic_validate_vec_add (elt_t * vec,
380 uword num_elts, uword is_add2)
382 uword len1 = vec_len (vec);
384 u8 hash = compute_vec_hash (0, vec);
389 vec_add2 (vec, new, num_elts);
393 new = create_random_vec (elt_t, num_elts, g_seed);
395 VERBOSE3 ("%U\n", format_hex_bytes, new, vec_len (new) * sizeof (new[0]));
397 /* Add the hash value of the new elements to that of the old vector. */
398 hash = compute_vec_hash (hash, new);
401 vec_add1 (vec, new[0]);
402 else if (num_elts > 1)
403 vec_add (vec, new, num_elts);
408 len2 = vec_len (vec);
409 ASSERT (len2 == len1 + num_elts);
411 ASSERT (compute_vec_hash (hash, vec) == 0);
412 validate_vec (vec, 0);
416 static elt_t * validate_vec_add1 (elt_t * vec)
418 return generic_validate_vec_add (vec, 1, 0);
421 static elt_t * validate_vec_add2 (elt_t * vec, uword num_elts)
423 return generic_validate_vec_add (vec, num_elts, 1);
426 static elt_t * validate_vec_add (elt_t * vec, uword num_elts)
428 return generic_validate_vec_add (vec, num_elts, 0);
431 static elt_t * validate_vec_insert (elt_t * vec,
432 uword num_elts, uword start_elt)
434 uword len1 = vec_len (vec);
438 /* vec_insert() would not handle it properly. */
439 if (start_elt > len1 || num_elts == 0)
442 hash = compute_vec_hash (0, vec);
443 vec_insert (vec, num_elts, start_elt);
444 len2 = vec_len (vec);
446 ASSERT (len2 == len1 + num_elts);
447 ASSERT (compute_vec_hash (hash, vec) == 0);
448 validate_vec (vec, 0);
452 static elt_t * validate_vec_insert_elts (elt_t * vec,
453 uword num_elts, uword start_elt)
455 uword len1 = vec_len (vec);
460 /* vec_insert_elts() would not handle it properly. */
461 if (start_elt > len1 || num_elts == 0)
464 new = create_random_vec (elt_t, num_elts, g_seed);
466 VERBOSE3 ("%U\n", format_hex_bytes, new, vec_len (new) * sizeof (new[0]));
468 /* Add the hash value of the new elements to that of the old vector. */
469 hash = compute_vec_hash (0, vec);
470 hash = compute_vec_hash (hash, new);
472 vec_insert_elts (vec, new, num_elts, start_elt);
473 len2 = vec_len (vec);
477 ASSERT (len2 == len1 + num_elts);
478 ASSERT (compute_vec_hash (hash, vec) == 0);
479 validate_vec (vec, 0);
483 static elt_t * validate_vec_delete (elt_t * vec,
484 uword num_elts, uword start_elt)
486 uword len1 = vec_len (vec);
492 /* vec_delete() would not handle it properly. */
493 if (start_elt + num_elts > len1)
496 start = (u8 *) vec + (start_elt * sizeof (vec[0]));
498 hash = compute_vec_hash (0, vec);
499 hash_del = compute_mem_hash (0, start, num_elts * sizeof (vec[0]));
502 vec_delete (vec, num_elts, start_elt);
503 len2 = vec_len (vec);
505 ASSERT (len2 == len1 - num_elts);
506 ASSERT (compute_vec_hash (hash, vec) == 0);
507 validate_vec (vec, 0);
511 static elt_t * validate_vec_dup (elt_t * vec)
516 hash = compute_vec_hash (0, vec);
519 ASSERT (compute_vec_hash (hash, new) == 0);
521 validate_vec (new, 0);
525 static elt_t * validate_vec_zero (elt_t * vec)
533 end = (u8 *) (vec + vec_len (vec));
537 ASSERT (ptr < (u8 *) vec_end (vec));
538 ASSERT (ptr[0] == 0);
542 validate_vec (vec, 0);
546 static void validate_vec_is_equal (elt_t * vec)
550 if (vec_len (vec) <= 0)
554 ASSERT (vec_is_equal (new, vec));
558 static elt_t * validate_vec_set (elt_t * vec)
561 uword len = vec_len (vec);
567 new = create_random_vec (elt_t, 1, g_seed);
569 VERBOSE3 ("%U\n", format_hex_bytes, new, vec_len (new) * sizeof (new[0]));
571 vec_set (vec, new[0]);
573 for (i = 0; i < len; i++)
574 ASSERT (memcmp (&vec[i], &new[0], sizeof (vec[0])) == 0);
577 validate_vec (vec, 0);
581 static elt_t * validate_vec_validate (elt_t * vec, uword index)
583 uword len = vec_len (vec);
584 word num_new = index - len + 1;
587 u8 hash = compute_vec_hash (0, vec);
592 vec_validate (vec, index);
594 /* Old len but new vec pointer! */
595 ptr = (u8 *) (vec + len);
596 end = (u8 *) (vec + len + num_new);
598 ASSERT (len + num_new == vec_len (vec));
599 ASSERT (compute_vec_hash (hash, vec) == 0);
603 ASSERT (ptr < (u8 *) vec_end (vec));
604 ASSERT (ptr[0] == 0);
608 validate_vec (vec, 0);
612 static elt_t * validate_vec_init (uword num_elts)
619 new = vec_new (elt_t, num_elts);
622 ASSERT (len == num_elts);
625 end = (u8 *) (new + len);
629 ASSERT (ptr < (u8 *) vec_end (new));
630 ASSERT (ptr[0] == 0);
634 validate_vec (new, 0);
638 static elt_t * validate_vec_init_h (uword num_elts, uword hdr_bytes)
646 new = vec_new_ha (elt_t, num_elts, hdr_bytes, 0);
649 ASSERT (len == num_elts);
651 /* We have 2 zero-regions to check: header & vec data (skip _VEC struct). */
652 for (i = 0; i < 2; i++)
656 ptr = (u8 *) vec_header (new, hdr_bytes);
657 end = ptr + hdr_bytes;
662 end = (u8 *) (new + len);
667 ASSERT (ptr < (u8 *) vec_end (new));
668 ASSERT (ptr[0] == 0);
673 validate_vec (new, 1);
677 /* XXX - I don't understand the purpose of the vec_clone() call. */
678 static elt_t * validate_vec_clone (elt_t * vec)
682 vec_clone (new, vec);
684 ASSERT (vec_len (new) == vec_len (vec));
685 ASSERT (compute_vec_hash (0, new) == 0);
686 validate_vec (new, 0);
690 static elt_t * validate_vec_append (elt_t * vec)
693 uword num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
697 new = create_random_vec (elt_t, num_elts, g_seed);
699 len = vec_len (vec) + vec_len (new);
700 hash = compute_vec_hash (0, vec);
701 hash = compute_vec_hash (hash, new);
703 vec_append (vec, new);
706 ASSERT (vec_len (vec) == len);
707 ASSERT (compute_vec_hash (hash, vec) == 0);
708 validate_vec (vec, 0);
712 static elt_t * validate_vec_prepend (elt_t * vec)
715 uword num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
719 new = create_random_vec (elt_t, num_elts, g_seed);
721 len = vec_len (vec) + vec_len (new);
722 hash = compute_vec_hash (0, vec);
723 hash = compute_vec_hash (hash, new);
725 vec_prepend (vec, new);
728 ASSERT (vec_len (vec) == len);
729 ASSERT (compute_vec_hash (hash, vec) == 0);
730 validate_vec (vec, 0);
734 static void run_validator_wh (uword iter)
742 f64 time[3]; /* [0]: start, [1]: last, [2]: current */
744 vec = create_random_vec_wh (elt_t, ~0, sizeof (hdr_t), g_seed);
745 validate_vec (vec, 0);
746 VERBOSE2 ("Start with len %d\n", vec_len (vec));
748 time[0] = unix_time_now ();
750 dump_time = g_dump_period;
752 for (i = 1; i <= iter; i++)
754 if (i >= g_set_verbose_at)
757 op = bounded_random_u32 (&g_seed, 0, vec_len (g_prob_wh) - 1);
762 case OP_IS_VEC_INIT_H:
763 num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
764 vec_free_h (vec, sizeof (hdr_t));
765 VERBOSE2 ("vec_init_h(), new elts %d\n", num_elts);
766 vec = validate_vec_init_h (num_elts, sizeof (hdr_t));
769 case OP_IS_VEC_RESIZE_H:
771 num_elts = bounded_random_u32 (&g_seed, len, len + MAX_CHANGE);
772 VERBOSE2 ("vec_resize_h(), %d new elts.\n", num_elts);
773 vec = validate_vec_resize_h (vec, num_elts, sizeof (hdr_t));
776 case OP_IS_VEC_FREE_H:
777 VERBOSE2 ("vec_free_h()\n");
778 vec = validate_vec_free_h (vec, sizeof (hdr_t));
790 time[2] = unix_time_now ();
791 VERBOSE1 ("%d vec ops in %f secs. (last %d in %f secs.).\n",
792 i, time[2] - time[0], g_dump_period, time[2] - time[1]);
794 dump_time += g_dump_period;
796 VERBOSE1 ("vec len %d\n", vec_len (vec));
798 format_hex_bytes, vec, vec_len (vec) * sizeof (vec[0]));
801 VERBOSE2 ("len %d\n", vec_len (vec));
804 validate_vec (vec, sizeof (hdr_t));
805 vec_free_h (vec, sizeof (hdr_t));
808 static void run_validator (uword iter)
818 f64 time[3]; /* [0]: start, [1]: last, [2]: current */
820 vec = create_random_vec (elt_t, ~0, g_seed);
821 validate_vec (vec, 0);
822 VERBOSE2 ("Start with len %d\n", vec_len (vec));
824 time[0] = unix_time_now ();
826 dump_time = g_dump_period;
828 for (i = 1; i <= iter; i++)
830 if (i >= g_set_verbose_at)
833 op = bounded_random_u32 (&g_seed, 0, vec_len (g_prob) - 1);
838 case OP_IS_VEC_RESIZE:
840 num_elts = bounded_random_u32 (&g_seed, len, len + MAX_CHANGE);
841 VERBOSE2 ("vec_resize(), %d new elts.\n", num_elts);
842 vec = validate_vec_resize (vec, num_elts);
846 VERBOSE2 ("vec_add1()\n");
847 vec = validate_vec_add1 (vec);
851 num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
852 VERBOSE2 ("vec_add2(), %d new elts.\n", num_elts);
853 vec = validate_vec_add2 (vec, num_elts);
857 num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
858 VERBOSE2 ("vec_add(), %d new elts.\n", num_elts);
859 vec = validate_vec_add (vec, num_elts);
862 case OP_IS_VEC_INSERT:
864 num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
865 index = bounded_random_u32 (&g_seed, 0,
866 (len > 0) ? (len - 1) : (0));
867 VERBOSE2 ("vec_insert(), %d new elts, index %d.\n", num_elts, index);
868 vec = validate_vec_insert (vec, num_elts, index);
871 case OP_IS_VEC_INSERT_ELTS:
873 num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
874 index = bounded_random_u32 (&g_seed, 0,
875 (len > 0) ? (len - 1) : (0));
876 VERBOSE2 ("vec_insert_elts(), %d new elts, index %d.\n",
878 vec = validate_vec_insert_elts (vec, num_elts, index);
881 case OP_IS_VEC_DELETE:
883 index = bounded_random_u32 (&g_seed, 0, len - 1);
884 num_elts = bounded_random_u32 (&g_seed, 0,
885 (len > index) ? (len - index) : (0));
886 VERBOSE2 ("vec_delete(), %d elts, index %d.\n", num_elts, index);
887 vec = validate_vec_delete (vec, num_elts, index);
891 VERBOSE2 ("vec_dup()\n");
892 new = validate_vec_dup (vec);
896 case OP_IS_VEC_IS_EQUAL:
897 VERBOSE2 ("vec_is_equal()\n");
898 validate_vec_is_equal (vec);
902 VERBOSE2 ("vec_zero()\n");
903 vec = validate_vec_zero (vec);
907 VERBOSE2 ("vec_set()\n");
908 vec = validate_vec_set (vec);
911 case OP_IS_VEC_VALIDATE:
913 index = bounded_random_u32 (&g_seed, 0, len - 1 + MAX_CHANGE);
914 VERBOSE2 ("vec_validate(), index %d\n", index);
915 vec = validate_vec_validate (vec, index);
919 VERBOSE2 ("vec_free()\n");
920 vec = validate_vec_free (vec);
924 num_elts = bounded_random_u32 (&g_seed, 0, MAX_CHANGE);
926 VERBOSE2 ("vec_init(), new elts %d\n", num_elts);
927 vec = validate_vec_init (num_elts);
930 case OP_IS_VEC_CLONE:
931 VERBOSE2 ("vec_clone()\n");
932 new = validate_vec_clone (vec);
936 case OP_IS_VEC_APPEND:
937 VERBOSE2 ("vec_append()\n");
938 vec = validate_vec_append (vec);
941 case OP_IS_VEC_PREPEND:
942 VERBOSE2 ("vec_prepend()\n");
943 vec = validate_vec_prepend (vec);
955 time[2] = unix_time_now ();
956 VERBOSE1 ("%d vec ops in %f secs. (last %d in %f secs.).\n",
957 i, time[2] - time[0], g_dump_period, time[2] - time[1]);
959 dump_time += g_dump_period;
961 VERBOSE1 ("vec len %d\n", vec_len (vec));
963 format_hex_bytes, vec, vec_len (vec) * sizeof (vec[0]));
966 VERBOSE2 ("len %d\n", vec_len (vec));
969 validate_vec (vec, 0);
973 static void prob_init (void)
975 uword i, j, ratio, len, index;
977 /* Create the vector to implement the statistical profile:
978 vec [ op1 op1 op1 op2 op3 op3 op3 op4 op4 .... ] */
979 for (i = FIRST_VEC_OP; i <= LAST_VEC_OP; i++)
981 ratio = g_prob_ratio[i];
985 len = vec_len (g_prob);
986 index = len - 1 + ratio;
989 /* Pre-allocate new elements. */
990 vec_validate (g_prob, index);
992 for (j = len; j <= index; j++)
996 /* Operations on vectors with headers. */
997 for (i = FIRST_VEC_HDR_OP; i <= LAST_VEC_HDR_OP; i++)
999 ratio = g_prob_ratio[i];
1003 len = vec_len (g_prob_wh);
1004 index = len - 1 + ratio;
1005 ASSERT (index >= 0);
1007 /* Pre-allocate new elements. */
1008 vec_validate (g_prob_wh, index);
1010 for (j = len; j <= index; j++)
1014 VERBOSE3 ("prob_vec, len %d\n%U\n", vec_len (g_prob),
1015 format_hex_bytes, g_prob, vec_len (g_prob) * sizeof (g_prob[0]));
1016 VERBOSE3 ("prob_vec_wh, len %d\n%U\n", vec_len (g_prob_wh),
1017 format_hex_bytes, g_prob_wh,
1018 vec_len (g_prob_wh) * sizeof (g_prob_wh[0]));
1021 static void prob_free (void)
1024 vec_free (g_prob_wh);
1027 int test_vec_main (unformat_input_t * input)
1033 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1035 if (0 == unformat (input, "iter %d", &iter)
1036 && 0 == unformat (input, "seed %d", &g_seed)
1037 && 0 == unformat (input, "verbose %d", &g_verbose)
1038 && 0 == unformat (input, "set %d", &g_set_verbose_at)
1039 && 0 == unformat (input, "dump %d", &g_dump_period)
1040 && 0 == unformat (input, "help %=", &help, 1)
1041 && 0 == unformat (input, "big %=", &big, 1))
1043 clib_error ("unknown input `%U'", format_unformat_error, input);
1051 u64 one_gig = (1<<30);
1054 fformat (stdout, "giant vector test...");
1055 size = 5ULL * one_gig;
1057 vec_validate (bigboy, size);
1059 for (index = size; index >= 0; index--)
1060 bigboy[index] = index & 0xff;
1069 run_validator (iter);
1070 run_validator_wh (iter);
1071 if (verbose) dump_call_stats (g_call_stats);
1074 if (verbose) { memory_snap (); }
1078 fformat (stdout, "Usage: test_vec iter <N> seed <N> verbose <N> "
1079 "set <N> dump <N>\n");
1087 int main (int argc, char * argv[])
1092 mheap_alloc (0, 10ULL<<30);
1094 verbose = (argc > 1);
1095 unformat_init_command_line (&i, argv);
1096 ret = test_vec_main (&i);
1101 #endif /* CLIB_UNIX */