aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/radix-tree/linux.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@linux.intel.com>2016-03-17 17:21:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 18:09:34 -0400
commit1366c37ed84b166a0fffe201154b0d3b78a3976b (patch)
tree3a688edaf09069694db90421f200568b886a4295 /tools/testing/radix-tree/linux.c
parentf67c07f07fca95a7f330b8bb928eabaf9fcce75d (diff)
radix tree test harness
This code is mostly from Andrew Morton and Nick Piggin; tarball downloaded from http://ozlabs.org/~akpm/rtth.tar.gz with sha1sum 0ce679db9ec047296b5d1ff7a1dfaa03a7bef1bd Some small modifications were necessary to the test harness to fix the build with the current Linux source code. I also made minor modifications to automatically test the radix-tree.c and radix-tree.h files that are in the current source tree, as opposed to a copied and slightly modified version. I am sure more could be done to tidy up the harness, as well as adding more tests. [koct9i@gmail.com: fix compilation] Signed-off-by: Matthew Wilcox <willy@linux.intel.com> Cc: Shuah Khan <shuahkh@osg.samsung.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Matthew Wilcox <willy@linux.intel.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing/radix-tree/linux.c')
-rw-r--r--tools/testing/radix-tree/linux.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/testing/radix-tree/linux.c b/tools/testing/radix-tree/linux.c
new file mode 100644
index 000000000000..154823737b20
--- /dev/null
+++ b/tools/testing/radix-tree/linux.c
@@ -0,0 +1,60 @@
1#include <stdlib.h>
2#include <string.h>
3#include <malloc.h>
4#include <unistd.h>
5#include <assert.h>
6
7#include <linux/mempool.h>
8#include <linux/slab.h>
9#include <urcu/uatomic.h>
10
11int nr_allocated;
12
13void *mempool_alloc(mempool_t *pool, int gfp_mask)
14{
15 return pool->alloc(gfp_mask, pool->data);
16}
17
18void mempool_free(void *element, mempool_t *pool)
19{
20 pool->free(element, pool->data);
21}
22
23mempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn,
24 mempool_free_t *free_fn, void *pool_data)
25{
26 mempool_t *ret = malloc(sizeof(*ret));
27
28 ret->alloc = alloc_fn;
29 ret->free = free_fn;
30 ret->data = pool_data;
31 return ret;
32}
33
34void *kmem_cache_alloc(struct kmem_cache *cachep, int flags)
35{
36 void *ret = malloc(cachep->size);
37 if (cachep->ctor)
38 cachep->ctor(ret);
39 uatomic_inc(&nr_allocated);
40 return ret;
41}
42
43void kmem_cache_free(struct kmem_cache *cachep, void *objp)
44{
45 assert(objp);
46 uatomic_dec(&nr_allocated);
47 memset(objp, 0, cachep->size);
48 free(objp);
49}
50
51struct kmem_cache *
52kmem_cache_create(const char *name, size_t size, size_t offset,
53 unsigned long flags, void (*ctor)(void *))
54{
55 struct kmem_cache *ret = malloc(sizeof(*ret));
56
57 ret->size = size;
58 ret->ctor = ctor;
59 return ret;
60}