1 /*
2  * Copyright (c) 2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include "qdf_status.h"
20 #include "qdf_talloc.h"
21 #include "qdf_talloc_test.h"
22 #include "qdf_trace.h"
23 
qdf_talloc_test_alloc_free(void)24 static uint32_t qdf_talloc_test_alloc_free(void)
25 {
26 	uint32_t value;
27 	uint32_t *root;
28 	uint32_t *child;
29 
30 	root = &value;
31 
32 	child = qdf_talloc_type(root, child);
33 	QDF_BUG(child);
34 
35 	qdf_tfree(child);
36 
37 	return 0;
38 }
39 
qdf_talloc_test_parent_child(void)40 static uint32_t qdf_talloc_test_parent_child(void)
41 {
42 	uint32_t value;
43 	uint32_t *root;
44 	uint32_t *parent;
45 	uint32_t *child;
46 
47 	root = &value;
48 
49 	parent = qdf_talloc_type(root, parent);
50 	QDF_BUG(parent);
51 
52 	child = qdf_talloc_type(parent, child);
53 	QDF_BUG(child);
54 
55 	qdf_tfree(child);
56 	qdf_tfree(parent);
57 
58 	return 0;
59 }
60 
qdf_talloc_unit_test(void)61 uint32_t qdf_talloc_unit_test(void)
62 {
63 	uint32_t errors = 0;
64 
65 	errors += qdf_talloc_test_alloc_free();
66 	errors += qdf_talloc_test_parent_child();
67 
68 	return errors;
69 }
70 
71