]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/tests/unit/tests/ocf_freelist.c/ocf_freelist_populate.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / ocf / tests / unit / tests / ocf_freelist.c / ocf_freelist_populate.c
1 /*
2 * <tested_file_path>src/ocf_freelist.c</tested_file_path>
3 * <tested_function>ocf_freelist_populate</tested_function>
4 * <functions_to_leave>
5 * ocf_freelist_init
6 * ocf_freelist_deinit
7 * ocf_freelist_populate
8 * next_phys_invalid
9 * </functions_to_leave>
10 */
11
12 #undef static
13
14 #undef inline
15
16
17 #include <stdarg.h>
18 #include <stddef.h>
19 #include <setjmp.h>
20 #include <cmocka.h>
21 #include "print_desc.h"
22
23 #include "ocf/ocf.h"
24 #include "metadata/metadata.h"
25
26 #include "ocf_freelist.c/ocf_freelist_populate_generated_wraps.c"
27
28 ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
29 {
30 return mock();
31 }
32
33 ocf_cache_line_t __wrap_env_get_execution_context_count(ocf_cache_t cache)
34 {
35 return mock();
36 }
37
38 /* simulate no striping */
39 ocf_cache_line_t __wrap_ocf_metadata_map_phy2lg(ocf_cache_t cache, ocf_cache_line_t phy)
40 {
41 return phy;
42 }
43
44 bool __wrap_metadata_test_valid_any(ocf_cache_t cache, ocf_cache_line_t cline)
45 {
46 return mock();
47 }
48
49 void __wrap_ocf_metadata_set_partition_info(struct ocf_cache *cache,
50 ocf_cache_line_t line, ocf_part_id_t part_id,
51 ocf_cache_line_t next_line, ocf_cache_line_t prev_line)
52 {
53 print_message("%s %u %u %u\n", __func__, prev_line, line, next_line);
54 check_expected(line);
55 check_expected(part_id);
56 check_expected(next_line);
57 check_expected(prev_line);
58 }
59
60 #define expect_set_info(curr, part, next, prev) \
61 expect_value(__wrap_ocf_metadata_set_partition_info, line, curr); \
62 expect_value(__wrap_ocf_metadata_set_partition_info, part_id, part); \
63 expect_value(__wrap_ocf_metadata_set_partition_info, next_line, next); \
64 expect_value(__wrap_ocf_metadata_set_partition_info, prev_line, prev);
65
66 static void ocf_freelist_populate_test01(void **state)
67 {
68 unsigned num_cls = 8;
69 unsigned num_ctxts = 3;
70 ocf_freelist_t freelist;
71 unsigned ctx_iter, cl_iter;
72
73 print_test_description("Verify proper set_partition_info order and arguments - empty cache");
74
75 will_return_maybe(__wrap_ocf_metadata_collision_table_entries, num_cls);
76 will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
77 will_return_maybe(__wrap_metadata_test_valid_any, false);
78
79 freelist = ocf_freelist_init(NULL);
80
81 expect_set_info(0, PARTITION_INVALID, 1 , num_cls);
82 expect_set_info(1, PARTITION_INVALID, 2 , 0);
83 expect_set_info(2, PARTITION_INVALID, num_cls, 1);
84 expect_set_info(3, PARTITION_INVALID, 4 , num_cls);
85 expect_set_info(4, PARTITION_INVALID, 5 , 3);
86 expect_set_info(5, PARTITION_INVALID, num_cls, 4);
87 expect_set_info(6, PARTITION_INVALID, 7 , num_cls);
88 expect_set_info(7, PARTITION_INVALID, num_cls, 6);
89
90 ocf_freelist_populate(freelist, num_cls);
91
92 ocf_freelist_deinit(freelist);
93 }
94
95 static void ocf_freelist_populate_test02(void **state)
96 {
97 unsigned num_cls = 8;
98 unsigned num_ctxts = 3;
99 ocf_freelist_t freelist;
100 unsigned ctx_iter, cl_iter;
101
102 print_test_description("Verify proper set_partition_info order and arguments - some valid clines");
103
104 will_return_maybe(__wrap_ocf_metadata_collision_table_entries, num_cls);
105 will_return_maybe(__wrap_env_get_execution_context_count, num_ctxts);
106
107 freelist = ocf_freelist_init(NULL);
108
109 /* simulate only cachelines 2, 3, 4, 7 invalid */
110 will_return(__wrap_metadata_test_valid_any, true);
111 will_return(__wrap_metadata_test_valid_any, true);
112 will_return(__wrap_metadata_test_valid_any, false);
113 will_return(__wrap_metadata_test_valid_any, false);
114 will_return(__wrap_metadata_test_valid_any, false);
115 will_return(__wrap_metadata_test_valid_any, true);
116 will_return(__wrap_metadata_test_valid_any, true);
117 will_return(__wrap_metadata_test_valid_any, false);
118
119 expect_set_info(2, PARTITION_INVALID, 3 , num_cls);
120 expect_set_info(3, PARTITION_INVALID, num_cls, 2);
121 expect_set_info(4, PARTITION_INVALID, num_cls, num_cls);
122 expect_set_info(7, PARTITION_INVALID, num_cls, num_cls);
123
124 ocf_freelist_populate(freelist, 4);
125
126 ocf_freelist_deinit(freelist);
127 }
128 int main(void)
129 {
130 const struct CMUnitTest tests[] = {
131 cmocka_unit_test(ocf_freelist_populate_test01),
132 cmocka_unit_test(ocf_freelist_populate_test02)
133 };
134
135 print_message("Unit test of src/ocf_freelist.c\n");
136
137 return cmocka_run_group_tests(tests, NULL, NULL);
138 }