1 // SPDX-License-Identifier: MIT
2 // SPDX-FileCopyrightText: 2024 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * rseq memory pool test.
19 #include <rseq/mempool.h>
26 struct test_data __rseq_percpu
*backref
;
27 struct list_head node
;
30 static void test_mempool_fill(size_t stride
)
32 struct test_data __rseq_percpu
*ptr
;
33 struct test_data
*iter
, *tmp
;
34 struct rseq_percpu_pool
*mempool
;
35 struct rseq_pool_attr
*attr
;
40 attr
= rseq_pool_attr_create();
41 ok(attr
, "Create pool attribute");
42 ret
= rseq_pool_attr_set_robust(attr
);
43 ok(ret
== 0, "Setting mempool robust attribute");
45 mempool
= rseq_percpu_pool_create("test_data",
46 sizeof(struct test_data
),
47 stride
, CPU_SETSIZE
, attr
);
48 ok(mempool
, "Create mempool of size %zu", stride
);
49 rseq_pool_attr_destroy(attr
);
52 struct test_data
*cpuptr
;
54 ptr
= (struct test_data __rseq_percpu
*) rseq_percpu_zmalloc(mempool
);
57 /* Link items in cpu 0. */
58 cpuptr
= __rseq_percpu_ptr(ptr
, 0, stride
);
59 cpuptr
->backref
= ptr
;
60 /* Randomize items in list. */
62 list_add(&cpuptr
->node
, &list
);
64 list_add_tail(&cpuptr
->node
, &list
);
68 ok(count
* sizeof(struct test_data
) == stride
, "Allocated %" PRIu64
" objects in pool", count
);
70 list_for_each_entry(iter
, &list
, node
) {
72 for (i
= 0; i
< CPU_SETSIZE
; i
++) {
73 struct test_data
*cpuptr
= __rseq_percpu_ptr(ptr
, i
, stride
);
75 if (cpuptr
->value
!= 0)
81 ok(1, "Check for pool content corruption");
83 list_for_each_entry_safe(iter
, tmp
, &list
, node
) {
85 __rseq_percpu_free(ptr
, stride
);
87 ret
= rseq_percpu_pool_destroy(mempool
);
88 ok(ret
== 0, "Destroy mempool");
98 for (len
= 4096; len
< 4096 * 1024; len
<<= 1) {
99 test_mempool_fill(len
);
This page took 0.045665 seconds and 4 git commands to generate.