]>
git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_typelist.c
2 * Copyright (c) 2016-2018 David Lamparter, for NetDEF, Inc.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 #include <arpa/inet.h>
30 #define WNO_ATOMLIST_UNSAFE_FIND
40 #include "tests/helpers/c/prng.h"
42 /* note: these macros are layered 2-deep because that makes the C
43 * preprocessor expand the "type" argument. Otherwise, you get
44 * "PREDECL_type" instead of "PREDECL_LIST"
46 #define _concat(a, b) a ## b
47 #define concat(a, b) _concat(a, b)
49 #define str(x) _str(x)
51 #define _PREDECL(type, ...) PREDECL_##type(__VA_ARGS__)
52 #define PREDECL(type, ...) _PREDECL(type, __VA_ARGS__)
53 #define _DECLARE(type, ...) DECLARE_##type(__VA_ARGS__)
54 #define DECLARE(type, ...) _DECLARE(type, __VA_ARGS__)
56 #define T_SORTED (1 << 0)
57 #define T_UNIQ (1 << 1)
58 #define T_HASH (1 << 2)
59 #define T_HEAP (1 << 3)
60 #define T_ATOMIC (1 << 4)
61 #define T_REVERSE (1 << 5)
64 #define _T_DLIST (0 | T_REVERSE)
65 #define _T_ATOMLIST (0 | T_ATOMIC)
66 #define _T_HEAP (T_SORTED | T_HEAP)
67 #define _T_SORTLIST_UNIQ (T_SORTED | T_UNIQ)
68 #define _T_SORTLIST_NONUNIQ (T_SORTED)
69 #define _T_HASH (T_SORTED | T_UNIQ | T_HASH)
70 #define _T_SKIPLIST_UNIQ (T_SORTED | T_UNIQ)
71 #define _T_SKIPLIST_NONUNIQ (T_SORTED)
72 #define _T_RBTREE_UNIQ (T_SORTED | T_UNIQ | T_REVERSE)
73 #define _T_RBTREE_NONUNIQ (T_SORTED | T_REVERSE)
74 #define _T_ATOMSORT_UNIQ (T_SORTED | T_UNIQ | T_ATOMIC)
75 #define _T_ATOMSORT_NONUNIQ (T_SORTED | T_ATOMIC)
77 #define _T_TYPE(type) _T_##type
78 #define IS_SORTED(type) (_T_TYPE(type) & T_SORTED)
79 #define IS_UNIQ(type) (_T_TYPE(type) & T_UNIQ)
80 #define IS_HASH(type) (_T_TYPE(type) & T_HASH)
81 #define IS_HEAP(type) (_T_TYPE(type) & T_HEAP)
82 #define IS_ATOMIC(type) (_T_TYPE(type) & T_ATOMIC)
83 #define IS_REVERSE(type) (_T_TYPE(type) & T_REVERSE)
85 static struct timeval ref
, ref0
;
87 static void ts_start(void)
92 static void ts_ref(const char *text
)
95 us
= monotime_since(&ref
, NULL
);
96 printfrr("%7"PRId64
"us %s\n", us
, text
);
99 static void ts_end(void)
102 us
= monotime_since(&ref0
, NULL
);
103 printfrr("%7"PRId64
"us total\n", us
);
107 #include "test_typelist.h"
110 #include "test_typelist.h"
112 #define TYPE ATOMLIST
113 #include "test_typelist.h"
116 #include "test_typelist.h"
118 #define TYPE SORTLIST_UNIQ
119 #include "test_typelist.h"
121 #define TYPE SORTLIST_NONUNIQ
122 #include "test_typelist.h"
125 #include "test_typelist.h"
127 #define TYPE HASH_collisions
128 #define REALTYPE HASH
130 #include "test_typelist.h"
133 #define TYPE SKIPLIST_UNIQ
134 #include "test_typelist.h"
136 #define TYPE SKIPLIST_NONUNIQ
137 #include "test_typelist.h"
139 #define TYPE RBTREE_UNIQ
140 #include "test_typelist.h"
142 #define TYPE RBTREE_NONUNIQ
143 #include "test_typelist.h"
145 #define TYPE ATOMSORT_UNIQ
146 #include "test_typelist.h"
148 #define TYPE ATOMSORT_NONUNIQ
149 #include "test_typelist.h"
151 int main(int argc
, char **argv
)
159 test_SORTLIST_UNIQ();
160 test_SORTLIST_NONUNIQ();
162 test_HASH_collisions();
163 test_SKIPLIST_UNIQ();
164 test_SKIPLIST_NONUNIQ();
166 test_RBTREE_NONUNIQ();
167 test_ATOMSORT_UNIQ();
168 test_ATOMSORT_NONUNIQ();
170 log_memstats_stderr("test: ");