]>
git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/unit/ql.c
1 #include "test/jemalloc_test.h"
3 /* Number of ring entries, in [2..26]. */
6 typedef struct list_s list_t
;
7 typedef ql_head(list_t
) list_head_t
;
15 test_empty_list(list_head_t
*head
)
20 assert_ptr_null(ql_first(head
), "Unexpected element for empty list");
21 assert_ptr_null(ql_last(head
, link
),
22 "Unexpected element for empty list");
25 ql_foreach(t
, head
, link
) {
28 assert_u_eq(i
, 0, "Unexpected element for empty list");
31 ql_reverse_foreach(t
, head
, link
) {
34 assert_u_eq(i
, 0, "Unexpected element for empty list");
37 TEST_BEGIN(test_ql_empty
)
42 test_empty_list(&head
);
47 init_entries(list_t
*entries
, unsigned nentries
)
51 for (i
= 0; i
< nentries
; i
++) {
52 entries
[i
].id
= 'a' + i
;
53 ql_elm_new(&entries
[i
], link
);
58 test_entries_list(list_head_t
*head
, list_t
*entries
, unsigned nentries
)
63 assert_c_eq(ql_first(head
)->id
, entries
[0].id
, "Element id mismatch");
64 assert_c_eq(ql_last(head
, link
)->id
, entries
[nentries
-1].id
,
65 "Element id mismatch");
68 ql_foreach(t
, head
, link
) {
69 assert_c_eq(t
->id
, entries
[i
].id
, "Element id mismatch");
74 ql_reverse_foreach(t
, head
, link
) {
75 assert_c_eq(t
->id
, entries
[nentries
-i
-1].id
,
76 "Element id mismatch");
80 for (i
= 0; i
< nentries
-1; i
++) {
81 t
= ql_next(head
, &entries
[i
], link
);
82 assert_c_eq(t
->id
, entries
[i
+1].id
, "Element id mismatch");
84 assert_ptr_null(ql_next(head
, &entries
[nentries
-1], link
),
85 "Unexpected element");
87 assert_ptr_null(ql_prev(head
, &entries
[0], link
), "Unexpected element");
88 for (i
= 1; i
< nentries
; i
++) {
89 t
= ql_prev(head
, &entries
[i
], link
);
90 assert_c_eq(t
->id
, entries
[i
-1].id
, "Element id mismatch");
94 TEST_BEGIN(test_ql_tail_insert
)
97 list_t entries
[NENTRIES
];
101 init_entries(entries
, sizeof(entries
)/sizeof(list_t
));
102 for (i
= 0; i
< NENTRIES
; i
++)
103 ql_tail_insert(&head
, &entries
[i
], link
);
105 test_entries_list(&head
, entries
, NENTRIES
);
109 TEST_BEGIN(test_ql_tail_remove
)
112 list_t entries
[NENTRIES
];
116 init_entries(entries
, sizeof(entries
)/sizeof(list_t
));
117 for (i
= 0; i
< NENTRIES
; i
++)
118 ql_tail_insert(&head
, &entries
[i
], link
);
120 for (i
= 0; i
< NENTRIES
; i
++) {
121 test_entries_list(&head
, entries
, NENTRIES
-i
);
122 ql_tail_remove(&head
, list_t
, link
);
124 test_empty_list(&head
);
128 TEST_BEGIN(test_ql_head_insert
)
131 list_t entries
[NENTRIES
];
135 init_entries(entries
, sizeof(entries
)/sizeof(list_t
));
136 for (i
= 0; i
< NENTRIES
; i
++)
137 ql_head_insert(&head
, &entries
[NENTRIES
-i
-1], link
);
139 test_entries_list(&head
, entries
, NENTRIES
);
143 TEST_BEGIN(test_ql_head_remove
)
146 list_t entries
[NENTRIES
];
150 init_entries(entries
, sizeof(entries
)/sizeof(list_t
));
151 for (i
= 0; i
< NENTRIES
; i
++)
152 ql_head_insert(&head
, &entries
[NENTRIES
-i
-1], link
);
154 for (i
= 0; i
< NENTRIES
; i
++) {
155 test_entries_list(&head
, &entries
[i
], NENTRIES
-i
);
156 ql_head_remove(&head
, list_t
, link
);
158 test_empty_list(&head
);
162 TEST_BEGIN(test_ql_insert
)
166 list_t
*a
, *b
, *c
, *d
, *e
, *f
, *g
, *h
;
169 init_entries(entries
, sizeof(entries
)/sizeof(list_t
));
180 * ql_remove(), ql_before_insert(), and ql_after_insert() are used
181 * internally by other macros that are already tested, so there's no
182 * need to test them completely. However, insertion/deletion from the
183 * middle of lists is not otherwise tested; do so here.
185 ql_tail_insert(&head
, f
, link
);
186 ql_before_insert(&head
, f
, b
, link
);
187 ql_before_insert(&head
, f
, c
, link
);
188 ql_after_insert(f
, h
, link
);
189 ql_after_insert(f
, g
, link
);
190 ql_before_insert(&head
, b
, a
, link
);
191 ql_after_insert(c
, d
, link
);
192 ql_before_insert(&head
, f
, e
, link
);
194 test_entries_list(&head
, entries
, sizeof(entries
)/sizeof(list_t
));