aboutsummaryrefslogtreecommitdiff
path: root/khm/test_khm.c
blob: 5b822b5adbfbc8e703a585ac9b6b1daa759cb370 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <linux/module.h>
#include <linux/init.h>
#include "khashmap.h"

#define Z_ASD	1
#define Z_QWE	2
#define Z_BLR	3

static struct khashmap *hm;

static int __init test_init(void)
{
	char *values;

	hm = khm_create();

	if (khm_insert(hm, Z_ASD, "ASDF"))
		goto insert_err;
	if (khm_insert(hm, Z_QWE, "QWERTY"))
		goto insert_err;
	if (khm_insert(hm, Z_BLR, "BLRBLRBLR"))
		goto insert_err;

	khm_display(hm);
	khm_delete(hm, Z_QWE);
	khm_display(hm);
	khm_set(hm, Z_ASD, "ASDF NEW!!");
	khm_display(hm);

	if ((values = (char*)khm_get(hm, Z_ASD)))
		printk(KERN_ALERT "Z_ASD: %s\n", values);
	else
		printk(KERN_ALERT "Z_ASD does not exist\n");
	if ((values = (char*)khm_get(hm, Z_QWE)))
		printk(KERN_ALERT "Z_QWE: %s\n", values);
	else
		printk(KERN_ALERT "Z_QWE does not exist\n");
	if ((values = (char*)khm_get(hm, Z_BLR)))
		printk(KERN_ALERT "Z_BLR: %s\n", values);
	else
		printk(KERN_ALERT "Z_BLR does not exist\n");

	if (khm_insert(hm, Z_ASD, "REPEATED!!"))
		goto insert_err;

	return 0;

insert_err:
	printk(KERN_ALERT "Error inserting!\n");
	return 0;
}

static void __exit test_exit(void)
{
	khm_destroy(hm);
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");