]> git.proxmox.com Git - mirror_frr.git/blame - tests/lib/test_typelist.c
Merge pull request #4892 from pguibert6WIND/nhtresolvedefaultvrf
[mirror_frr.git] / tests / lib / test_typelist.c
CommitLineData
992f9967
DL
1/*
2 * Copyright (c) 2016-2018 David Lamparter, for NetDEF, Inc.
3 *
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.
7 *
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.
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <stdio.h>
22#include <stdint.h>
23#include <stdlib.h>
24#include <inttypes.h>
25#include <string.h>
26#include <unistd.h>
27#include <assert.h>
8c3d03b3 28#include <arpa/inet.h>
992f9967
DL
29
30#define WNO_ATOMLIST_UNSAFE_FIND
31
32#include "typesafe.h"
33#include "atomlist.h"
34#include "memory.h"
35#include "monotime.h"
2214f160 36#include "jhash.h"
8c3d03b3 37#include "sha256.h"
992f9967
DL
38
39#include "tests/helpers/c/prng.h"
40
41/* note: these macros are layered 2-deep because that makes the C
42 * preprocessor expand the "type" argument. Otherwise, you get
43 * "PREDECL_type" instead of "PREDECL_LIST"
44 */
45#define _concat(a, b) a ## b
46#define concat(a, b) _concat(a, b)
47#define _str(x) #x
48#define str(x) _str(x)
49
50#define _PREDECL(type, ...) PREDECL_##type(__VA_ARGS__)
51#define PREDECL(type, ...) _PREDECL(type, __VA_ARGS__)
52#define _DECLARE(type, ...) DECLARE_##type(__VA_ARGS__)
53#define DECLARE(type, ...) _DECLARE(type, __VA_ARGS__)
54
d0a0e597
DL
55#define T_SORTED (1 << 0)
56#define T_UNIQ (1 << 1)
57#define T_HASH (1 << 2)
58#define T_HEAP (1 << 3)
59#define T_ATOMIC (1 << 4)
60
61#define _T_LIST (0)
62#define _T_DLIST (0)
63#define _T_ATOMLIST (0 | T_ATOMIC)
64#define _T_HEAP (T_SORTED | T_HEAP)
65#define _T_SORTLIST_UNIQ (T_SORTED | T_UNIQ)
66#define _T_SORTLIST_NONUNIQ (T_SORTED)
67#define _T_HASH (T_SORTED | T_UNIQ | T_HASH)
68#define _T_SKIPLIST_UNIQ (T_SORTED | T_UNIQ)
69#define _T_SKIPLIST_NONUNIQ (T_SORTED)
70#define _T_RBTREE_UNIQ (T_SORTED | T_UNIQ)
71#define _T_RBTREE_NONUNIQ (T_SORTED)
72#define _T_ATOMSORT_UNIQ (T_SORTED | T_UNIQ | T_ATOMIC)
73#define _T_ATOMSORT_NONUNIQ (T_SORTED | T_ATOMIC)
74
75#define _T_TYPE(type) _T_##type
76#define IS_SORTED(type) (_T_TYPE(type) & T_SORTED)
77#define IS_UNIQ(type) (_T_TYPE(type) & T_UNIQ)
78#define IS_HASH(type) (_T_TYPE(type) & T_HASH)
79#define IS_HEAP(type) (_T_TYPE(type) & T_HEAP)
80#define IS_ATOMIC(type) (_T_TYPE(type) & T_ATOMIC)
992f9967
DL
81
82static struct timeval ref, ref0;
83
84static void ts_start(void)
85{
86 monotime(&ref0);
87 monotime(&ref);
88}
89static void ts_ref(const char *text)
90{
91 int64_t us;
92 us = monotime_since(&ref, NULL);
93 printf("%7"PRId64"us %s\n", us, text);
94 monotime(&ref);
95}
96static void ts_end(void)
97{
98 int64_t us;
99 us = monotime_since(&ref0, NULL);
100 printf("%7"PRId64"us total\n", us);
101}
102
8c3d03b3
DL
103#define TYPE LIST
104#include "test_typelist.h"
105
106#define TYPE DLIST
107#include "test_typelist.h"
108
d0a0e597
DL
109#define TYPE ATOMLIST
110#include "test_typelist.h"
111
112#define TYPE HEAP
113#include "test_typelist.h"
114
992f9967
DL
115#define TYPE SORTLIST_UNIQ
116#include "test_typelist.h"
117
118#define TYPE SORTLIST_NONUNIQ
119#include "test_typelist.h"
120
121#define TYPE HASH
122#include "test_typelist.h"
123
2214f160
DL
124#define TYPE HASH_collisions
125#define REALTYPE HASH
126#define SHITTY_HASH
127#include "test_typelist.h"
128#undef SHITTY_HASH
129
992f9967
DL
130#define TYPE SKIPLIST_UNIQ
131#include "test_typelist.h"
132
133#define TYPE SKIPLIST_NONUNIQ
134#include "test_typelist.h"
135
136#define TYPE RBTREE_UNIQ
137#include "test_typelist.h"
138
139#define TYPE RBTREE_NONUNIQ
140#include "test_typelist.h"
141
142#define TYPE ATOMSORT_UNIQ
143#include "test_typelist.h"
144
145#define TYPE ATOMSORT_NONUNIQ
146#include "test_typelist.h"
147
148int main(int argc, char **argv)
149{
150 srandom(1);
151
8c3d03b3
DL
152 test_LIST();
153 test_DLIST();
d0a0e597
DL
154 test_ATOMLIST();
155 test_HEAP();
992f9967
DL
156 test_SORTLIST_UNIQ();
157 test_SORTLIST_NONUNIQ();
158 test_HASH();
2214f160 159 test_HASH_collisions();
992f9967
DL
160 test_SKIPLIST_UNIQ();
161 test_SKIPLIST_NONUNIQ();
162 test_RBTREE_UNIQ();
163 test_RBTREE_NONUNIQ();
164 test_ATOMSORT_UNIQ();
165 test_ATOMSORT_NONUNIQ();
166
167 log_memstats_stderr("test: ");
168 return 0;
169}