]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / spdk / ocf / tests / unit / tests / mngt / ocf_mngt_cache.c / _cache_mng_set_cache_mode_test.c
1 /*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6 //<tested_file_path>src/mngt/ocf_mngt_cache.c</tested_file_path>
7 //<tested_function>_cache_mng_set_cache_mode</tested_function>
8
9 /*
10 <functions_to_leave>
11 </functions_to_leave>
12 */
13
14 #undef static
15 #undef inline
16
17 #include <stdarg.h>
18 #include <stddef.h>
19 #include <setjmp.h>
20 #include <cmocka.h>
21 #include "print_desc.h"
22
23 /*
24 * Headers from tested target.
25 */
26 #include "ocf/ocf.h"
27 #include "ocf_mngt_common.h"
28 #include "../ocf_core_priv.h"
29 #include "../ocf_queue_priv.h"
30 #include "../metadata/metadata.h"
31 #include "../engine/cache_engine.h"
32 #include "../utils/utils_part.h"
33 #include "../utils/utils_cache_line.h"
34 #include "../utils/utils_device.h"
35 #include "../utils/utils_io.h"
36 #include "../utils/utils_cache_line.h"
37 #include "../utils/utils_pipeline.h"
38 #include "../ocf_utils.h"
39 #include "../concurrency/ocf_concurrency.h"
40 #include "../eviction/ops.h"
41 #include "../ocf_ctx_priv.h"
42 #include "../cleaning/cleaning.h"
43
44 /*
45 * Mocked functions
46 */
47 bool __wrap_ocf_cache_mode_is_valid(ocf_cache_mode_t mode)
48 {
49 function_called();
50 return mock();
51 }
52
53 const char *__wrap_ocf_get_io_iface_name(ocf_cache_mode_t cache_mode)
54 {
55 }
56
57 ocf_ctx_t __wrap_ocf_cache_get_ctx(ocf_cache_t cache)
58 {
59 return cache->owner;
60 }
61
62 int __wrap_ocf_log_raw(ocf_logger_t logger, ocf_logger_lvl_t lvl,
63 const char *fmt, ...)
64 {
65 function_called();
66 return mock();
67 }
68
69 int __wrap_ocf_mngt_cache_flush(ocf_cache_t cache, bool interruption)
70 {
71 function_called();
72 return mock();
73 }
74
75 int __wrap_ocf_metadata_flush_superblock(struct ocf_cache *cache)
76 {
77 }
78
79 bool __wrap_env_bit_test(int nr, const volatile unsigned long *addr)
80 {
81 function_called();
82 return mock();
83 }
84
85 void __wrap_env_atomic_set(env_atomic *a, int i)
86 {
87 function_called();
88 }
89
90 int __wrap_env_atomic_read(const env_atomic *a)
91 {
92 function_called();
93 return mock();
94 }
95
96 int __wrap_ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache)
97 {
98 function_called();
99 return mock();
100 }
101
102 char *__wrap_ocf_cache_get_name(ocf_cache_t cache)
103 {
104 }
105
106 void __wrap__ocf_mngt_test_volume_initial_write(
107 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
108 {
109 }
110
111 void __wrap_ocf_mngt_test_volume_first_read(
112 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
113 {
114 }
115
116 void __wrap__ocf_mngt_test_volume_discard(
117 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
118 {
119 }
120
121 void __wrap__ocf_mngt_test_volume_second_read(
122 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
123 {
124 }
125
126 void __wrap__ocf_mngt_attach_cache_device(
127 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
128 {
129 }
130
131 void __wrap__ocf_mngt_attach_check_ram(
132 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
133 {
134 }
135
136 void __wrap__ocf_mngt_attach_load_properties(
137 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
138 {
139 }
140
141 void __wrap__ocf_mngt_attach_prepare_metadata(
142 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
143 {
144 }
145
146 void __wrap__ocf_mngt_test_volume(
147 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
148 {
149 }
150
151 void __wrap__ocf_mngt_attach_load_superblock(
152 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
153 {
154 }
155
156 void __wrap__ocf_mngt_attach_init_instance(
157 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
158 {
159 }
160
161 void __wrap__ocf_mngt_attach_clean_pol(
162 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
163 {
164 }
165
166 void __wrap__ocf_mngt_attach_flush_metadata(
167 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
168 {
169 }
170
171 void __wrap__ocf_mngt_attach_discard(
172 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
173 {
174 }
175
176 void __wrap__ocf_mngt_attach_flush(
177 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
178 {
179 }
180
181 void __wrap__ocf_mngt_attach_shutdown_status(
182 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
183 {
184 }
185
186 void __wrap__ocf_mngt_attach_post_init(
187 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
188 {
189 }
190
191 void __wrap_ocf_mngt_cache_stop_wait_io(
192 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
193 {
194 }
195
196 void __wrap_ocf_mngt_cache_stop_remove_cores(
197 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
198 {
199 }
200
201 void __wrap_ocf_mngt_cache_stop_unplug(
202 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
203 {
204 }
205
206 void __wrap_ocf_mngt_cache_stop_put_io_queues(
207 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
208 {
209 }
210
211 void __wrap_ocf_mngt_cache_detach_flush(
212 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
213 {
214 }
215
216 void __wrap_ocf_mngt_cache_detach_wait_pending(
217 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
218 {
219 }
220
221 void __wrap_ocf_mngt_cache_detach_update_metadata(
222 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
223 {
224 }
225
226 void __wrap_ocf_mngt_cache_detach_unplug(
227 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
228 {
229 }
230
231 void __wrap__ocf_mngt_test_volume_first_read(
232 ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg)
233 {
234 }
235
236 void __wrap__ocf_mngt_test_volume_finish(
237 ocf_pipeline_t pipeline, void *priv, int error)
238 {
239 }
240
241 void __wrap__ocf_mngt_cache_attach_finish(
242 ocf_pipeline_t pipeline, void *priv, int error)
243 {
244 }
245
246 void __wrap_ocf_mngt_cache_stop_finish(
247 ocf_pipeline_t pipeline, void *priv, int error)
248 {
249 }
250
251 void __wrap_ocf_mngt_cache_detach_finish(
252 ocf_pipeline_t pipeline, void *priv, int error)
253 {
254 }
255
256 void __wrap_ocf_mngt_cache_save_finish(
257 ocf_pipeline_t pipeline, void *priv, int error)
258 {
259 }
260
261 static void _cache_mng_set_cache_mode_test01(void **state)
262 {
263 ocf_cache_mode_t mode_old = -20;
264 ocf_cache_mode_t mode_new = ocf_cache_mode_none;
265 struct ocf_ctx ctx = {
266 .logger = 0x1, /* Just not NULL, we don't care. */
267 };
268 struct ocf_superblock_config sb_config = {
269 .cache_mode = mode_old,
270 };
271 struct ocf_cache cache = {
272 .owner = &ctx,
273 .conf_meta = &sb_config,
274 };
275 int result;
276
277 print_test_description("Invalid new mode produces appropirate error code");
278
279 expect_function_call(__wrap_ocf_cache_mode_is_valid);
280 will_return(__wrap_ocf_cache_mode_is_valid, 0);
281
282 result = _cache_mng_set_cache_mode(&cache, mode_new);
283
284 assert_int_equal(result, -OCF_ERR_INVAL);
285 assert_int_equal(cache.conf_meta->cache_mode, mode_old);
286 }
287
288 static void _cache_mng_set_cache_mode_test02(void **state)
289 {
290 ocf_cache_mode_t mode_old = ocf_cache_mode_wt;
291 ocf_cache_mode_t mode_new = ocf_cache_mode_wt;
292 struct ocf_ctx ctx = {
293 .logger = 0x1, /* Just not NULL, we don't care. */
294 };
295 struct ocf_superblock_config sb_config = {
296 .cache_mode = mode_old,
297 };
298 struct ocf_cache cache = {
299 .owner = &ctx,
300 .conf_meta = &sb_config,
301 };
302 uint8_t flush = 0;
303 int result;
304
305 print_test_description("Attempt to set mode the same as previous");
306
307 expect_function_call(__wrap_ocf_cache_mode_is_valid);
308 will_return(__wrap_ocf_cache_mode_is_valid, 1);
309
310 expect_function_call(__wrap_ocf_log_raw);
311 will_return(__wrap_ocf_log_raw, 0);
312
313 result = _cache_mng_set_cache_mode(&cache, mode_new);
314
315 assert_int_equal(result, 0);
316 assert_int_equal(cache.conf_meta->cache_mode, mode_old);
317 }
318
319 static void _cache_mng_set_cache_mode_test03(void **state)
320 {
321 ocf_cache_mode_t mode_old = ocf_cache_mode_wb;
322 ocf_cache_mode_t mode_new = ocf_cache_mode_wa;
323 struct ocf_ctx ctx = {
324 .logger = 0x1, /* Just not NULL, we don't care. */
325 };
326 struct ocf_superblock_config sb_config = {
327 .cache_mode = mode_old,
328 };
329 struct ocf_cache cache = {
330 .owner = &ctx,
331 .conf_meta = &sb_config,
332 };
333 int result;
334 int i;
335
336 print_test_description("Old cache mode is write back. "
337 "Setting new cache mode is succesfull");
338
339 expect_function_call(__wrap_ocf_cache_mode_is_valid);
340 will_return(__wrap_ocf_cache_mode_is_valid, 1);
341
342 for(i = 0; i != OCF_CORE_MAX; ++i) {
343 expect_function_call(__wrap_env_bit_test);
344 will_return(__wrap_env_bit_test, 1);
345
346 expect_function_call(__wrap_env_atomic_read);
347 will_return(__wrap_env_atomic_read, 1);
348 expect_function_call(__wrap_env_atomic_set);
349 }
350
351 expect_function_call(__wrap_ocf_log_raw);
352 will_return(__wrap_ocf_log_raw, 0);
353
354 result = _cache_mng_set_cache_mode(&cache, mode_new);
355
356 assert_int_equal(result, 0);
357 assert_int_equal(cache.conf_meta->cache_mode, mode_new);
358 }
359
360 static void _cache_mng_set_cache_mode_test04(void **state)
361 {
362 ocf_cache_mode_t mode_old = ocf_cache_mode_wt;
363 ocf_cache_mode_t mode_new = ocf_cache_mode_wa;
364 struct ocf_ctx ctx = {
365 .logger = 0x1, /* Just not NULL, we don't care. */
366 };
367 struct ocf_superblock_config sb_config = {
368 .cache_mode = mode_old,
369 };
370 struct ocf_cache cache = {
371 .owner = &ctx,
372 .conf_meta = &sb_config,
373 };
374 int result;
375 int i;
376
377 print_test_description("Mode changed successfully");
378
379 expect_function_call(__wrap_ocf_cache_mode_is_valid);
380 will_return(__wrap_ocf_cache_mode_is_valid, 1);
381
382 expect_function_call(__wrap_ocf_log_raw);
383 will_return(__wrap_ocf_log_raw, 0);
384
385 result = _cache_mng_set_cache_mode(&cache, mode_new);
386
387 assert_int_equal(result, 0);
388 assert_int_equal(cache.conf_meta->cache_mode, mode_new);
389 }
390
391 /*
392 * Main function. It runs tests.
393 */
394 int main(void)
395 {
396 const struct CMUnitTest tests[] = {
397 cmocka_unit_test(_cache_mng_set_cache_mode_test01),
398 cmocka_unit_test(_cache_mng_set_cache_mode_test02),
399 cmocka_unit_test(_cache_mng_set_cache_mode_test03),
400 cmocka_unit_test(_cache_mng_set_cache_mode_test04),
401 };
402
403 print_message("Unit test of _cache_mng_set_cache_mode\n");
404
405 return cmocka_run_group_tests(tests, NULL, NULL);
406 }