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