2 * <tested_file_path>src/ocf_freelist.c</tested_file_path>
3 * <tested_function>ocf_freelist_populate</tested_function>
7 * ocf_freelist_populate
9 * </functions_to_leave>
21 #include "print_desc.h"
24 #include "metadata/metadata.h"
26 #include "ocf_freelist.c/ocf_freelist_populate_generated_wraps.c"
28 ocf_cache_line_t
__wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache
)
33 ocf_cache_line_t
__wrap_env_get_execution_context_count(ocf_cache_t cache
)
38 /* simulate no striping */
39 ocf_cache_line_t
__wrap_ocf_metadata_map_phy2lg(ocf_cache_t cache
, ocf_cache_line_t phy
)
44 bool __wrap_metadata_test_valid_any(ocf_cache_t cache
, ocf_cache_line_t cline
)
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
)
53 print_message("%s %u %u %u\n", __func__
, prev_line
, line
, next_line
);
55 check_expected(part_id
);
56 check_expected(next_line
);
57 check_expected(prev_line
);
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);
66 static void ocf_freelist_populate_test01(void **state
)
69 unsigned num_ctxts
= 3;
70 ocf_freelist_t freelist
;
71 unsigned ctx_iter
, cl_iter
;
73 print_test_description("Verify proper set_partition_info order and arguments - empty cache");
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);
79 freelist
= ocf_freelist_init(NULL
);
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);
90 ocf_freelist_populate(freelist
, num_cls
);
92 ocf_freelist_deinit(freelist
);
95 static void ocf_freelist_populate_test02(void **state
)
98 unsigned num_ctxts
= 3;
99 ocf_freelist_t freelist
;
100 unsigned ctx_iter
, cl_iter
;
102 print_test_description("Verify proper set_partition_info order and arguments - some valid clines");
104 will_return_maybe(__wrap_ocf_metadata_collision_table_entries
, num_cls
);
105 will_return_maybe(__wrap_env_get_execution_context_count
, num_ctxts
);
107 freelist
= ocf_freelist_init(NULL
);
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);
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
);
124 ocf_freelist_populate(freelist
, 4);
126 ocf_freelist_deinit(freelist
);
130 const struct CMUnitTest tests
[] = {
131 cmocka_unit_test(ocf_freelist_populate_test01
),
132 cmocka_unit_test(ocf_freelist_populate_test02
)
135 print_message("Unit test of src/ocf_freelist.c\n");
137 return cmocka_run_group_tests(tests
, NULL
, NULL
);