diff --git a/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c b/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c index 53bc9b8..f1361e9 100644 --- a/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c +++ b/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c @@ -40,66 +40,70 @@ static void cleaning_policy_alru_initialize_test01(void **state) { - int result; - struct ocf_cache cache; - ocf_part_id_t part_id = 0; + int result; + struct ocf_cache *cache; + ocf_part_id_t part_id = 0; - int collision_table_entries = 900729; + int collision_table_entries = 900729; - print_test_description("Check if all variables are set correctly"); + print_test_description("Check if all variables are set correctly"); - cache.user_parts[part_id].runtime = test_malloc(sizeof(struct ocf_user_part_runtime)); - cache.device = test_malloc(sizeof(struct ocf_cache_device)); - cache.device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_runtime)); + cache = test_malloc(sizeof(*cache)); + cache->user_parts[part_id].runtime = test_malloc(sizeof(struct ocf_user_part_runtime)); + cache->device = test_malloc(sizeof(struct ocf_cache_device)); + cache->device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_runtime)); - cache.device->collision_table_entries = collision_table_entries; + cache->device->collision_table_entries = collision_table_entries; - result = cleaning_policy_alru_initialize_part(&cache, &cache.user_parts[part_id], 1, 1); + result = cleaning_policy_alru_initialize_part(cache, &cache->user_parts[part_id], 1, 1); - assert_int_equal(result, 0); + assert_int_equal(result, 0); - assert_int_equal(env_atomic_read(&cache.user_parts[part_id].runtime->cleaning.policy.alru.size), 0); - assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head, collision_table_entries); - assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, collision_table_entries); + assert_int_equal(env_atomic_read(&cache->user_parts[part_id].runtime->cleaning.policy.alru.size), 0); + assert_int_equal(cache->user_parts[part_id].runtime->cleaning.policy.alru.lru_head, collision_table_entries); + assert_int_equal(cache->user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, collision_table_entries); - assert_int_equal(cache.device->runtime_meta->cleaning_thread_access, 0); + assert_int_equal(cache->device->runtime_meta->cleaning_thread_access, 0); - test_free(cache.device->runtime_meta); - test_free(cache.device); - test_free(cache.user_parts[part_id].runtime); + test_free(cache->device->runtime_meta); + test_free(cache->device); + test_free(cache->user_parts[part_id].runtime); + test_free(cache); } static void cleaning_policy_alru_initialize_test02(void **state) { - int result; - struct ocf_cache cache; - ocf_part_id_t part_id = 0; + int result; + struct ocf_cache *cache; + ocf_part_id_t part_id = 0; - uint32_t collision_table_entries = 900729; + uint32_t collision_table_entries = 900729; - print_test_description("Check if only appropirate variables are changed"); + print_test_description("Check if only appropirate variables are changed"); - cache.user_parts[part_id].runtime = test_malloc(sizeof(struct ocf_user_part_runtime)); - cache.device = test_malloc(sizeof(struct ocf_cache_device)); - cache.device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_runtime)); + cache = test_malloc(sizeof(*cache)); + cache->user_parts[part_id].runtime = test_malloc(sizeof(struct ocf_user_part_runtime)); + cache->device = test_malloc(sizeof(struct ocf_cache_device)); + cache->device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_runtime)); - env_atomic_set(&cache.user_parts[part_id].runtime->cleaning.policy.alru.size, 1); - cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head = -collision_table_entries; - cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail = -collision_table_entries; + env_atomic_set(&cache->user_parts[part_id].runtime->cleaning.policy.alru.size, 1); + cache->user_parts[part_id].runtime->cleaning.policy.alru.lru_head = -collision_table_entries; + cache->user_parts[part_id].runtime->cleaning.policy.alru.lru_tail = -collision_table_entries; - result = cleaning_policy_alru_initialize_part(&cache, &cache.user_parts[part_id], 0, 0); + result = cleaning_policy_alru_initialize_part(cache, cache->user_parts[part_id], 0, 0); - assert_int_equal(result, 0); + assert_int_equal(result, 0); - assert_int_equal(env_atomic_read(&cache.user_parts[part_id].runtime->cleaning.policy.alru.size), 1); - assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head, -collision_table_entries); - assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, -collision_table_entries); + assert_int_equal(env_atomic_read(&cache->user_parts[part_id].runtime->cleaning.policy.alru.size), 1); + assert_int_equal(cache->user_parts[part_id].runtime->cleaning.policy.alru.lru_head, -collision_table_entries); + assert_int_equal(cache->user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, -collision_table_entries); - assert_int_equal(cache.device->runtime_meta->cleaning_thread_access, 0); + assert_int_equal(cache->device->runtime_meta->cleaning_thread_access, 0); - test_free(cache.device->runtime_meta); - test_free(cache.device); - test_free(cache.user_parts[part_id].runtime); + test_free(cache->device->runtime_meta); + test_free(cache->device); + test_free(cache->user_parts[part_id].runtime); + test_free(cache); } /* @@ -107,14 +111,14 @@ static void cleaning_policy_alru_initialize_test02(void **state) */ int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test(cleaning_policy_alru_initialize_test01), - cmocka_unit_test(cleaning_policy_alru_initialize_test02) - }; + const struct CMUnitTest tests[] = { + cmocka_unit_test(cleaning_policy_alru_initialize_test01), + cmocka_unit_test(cleaning_policy_alru_initialize_test02) + }; - print_message("Unit test of alru.c\n"); + print_message("Unit test of alru.c\n"); - return cmocka_run_group_tests(tests, NULL, NULL); + return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/tests/unit/tests/cleaning/cleaning.c/ocf_cleaner_run_test.c b/tests/unit/tests/cleaning/cleaning.c/ocf_cleaner_run_test.c index 295ac69..9a7f618 100644 --- a/tests/unit/tests/cleaning/cleaning.c/ocf_cleaner_run_test.c +++ b/tests/unit/tests/cleaning/cleaning.c/ocf_cleaner_run_test.c @@ -103,20 +103,22 @@ static void cleaner_complete(ocf_cleaner_t cleaner, uint32_t interval) static void ocf_cleaner_run_test01(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; ocf_part_id_t part_id; uint32_t io_queue; int result; - //Initialize needed structures. - cache.conf_meta = test_malloc(sizeof(struct ocf_superblock_config)); - cache.conf_meta->cleaning_policy_type = ocf_cleaning_alru; - print_test_description("Parts are ready for cleaning - should perform cleaning" " for each part"); + //Initialize needed structures. + cache = test_malloc(sizeof(*cache)); + cache->conf_meta = test_malloc(sizeof(struct ocf_superblock_config)); + cache->conf_meta->cleaning_policy_type = ocf_cleaning_alru; + + expect_function_call(__wrap_ocf_cleaner_get_cache); - will_return(__wrap_ocf_cleaner_get_cache, &cache); + will_return(__wrap_ocf_cleaner_get_cache, cache); expect_function_call(__wrap_env_bit_test); will_return(__wrap_env_bit_test, 1); @@ -133,13 +135,14 @@ static void ocf_cleaner_run_test01(void **state) expect_function_call(__wrap_cleaning_alru_perform_cleaning); will_return(__wrap_cleaning_alru_perform_cleaning, 0); - ocf_cleaner_set_cmpl(&cache.cleaner, cleaner_complete); + ocf_cleaner_set_cmpl(&cache->cleaner, cleaner_complete); - ocf_cleaner_run(&cache.cleaner, 0xdeadbeef); + ocf_cleaner_run(&cache->cleaner, 0xdeadbeef); /* Release allocated memory if allocated with test_* functions */ - test_free(cache.conf_meta); + test_free(cache->conf_meta); + test_free(cache); } /* diff --git a/tests/unit/tests/concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency.c b/tests/unit/tests/concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency.c index 8c1da52..72fe4c6 100644 --- a/tests/unit/tests/concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency.c +++ b/tests/unit/tests/concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency.c @@ -35,15 +35,21 @@ void __wrap_ocf_metadata_hash_lock(struct ocf_metadata_lock *metadata_lock, static struct ocf_request *alloc_req() { struct ocf_request *req; - struct ocf_cache *cache = malloc(sizeof(*cache)); + struct ocf_cache *cache = test_malloc(sizeof(*cache)); - req = malloc(sizeof(*req) + MAP_SIZE * sizeof(req->map[0])); + req = test_malloc(sizeof(*req) + MAP_SIZE * sizeof(req->map[0])); req->map = req->__map; req->cache = cache; return req; } +static void free_req(struct ocf_request *req) +{ + test_free(req->cache); + test_free(req); +} + static void _test_lock_order(struct ocf_request* req, unsigned hash[], unsigned hash_count, unsigned expected_call[], unsigned expected_call_count) @@ -114,8 +120,7 @@ static void ocf_req_hash_lock_rd_test01(void **state) test_cases[i].expected_call.val, test_cases[i].expected_call.count); } - free(req->cache); - free(req); + free_req(req); } int main(void) diff --git a/tests/unit/tests/metadata/metadata_collision.c/metadata_collision.c b/tests/unit/tests/metadata/metadata_collision.c/metadata_collision.c index 2f7309a..7f83ca9 100644 --- a/tests/unit/tests/metadata/metadata_collision.c/metadata_collision.c +++ b/tests/unit/tests/metadata/metadata_collision.c/metadata_collision.c @@ -25,7 +25,7 @@ static void metadata_hash_func_test01(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; bool wrap = false; ocf_cache_line_t i; ocf_cache_line_t hash_cur, hash_next; @@ -36,21 +36,25 @@ static void metadata_hash_func_test01(void **state) print_test_description("Verify that hash function increments by 1 and generates" "collision after 'hash_table_entries' successive core lines"); - cache.device = malloc(sizeof(*cache.device)); - cache.device->hash_table_entries = 10; + cache = test_malloc(sizeof(*cache)); + cache->device = test_malloc(sizeof(*cache->device)); + cache->device->hash_table_entries = 10; for (c = 0; c < sizeof(core_ids) / sizeof(core_ids[0]); c++) { core_id = core_ids[c]; - for (i = 0; i < cache.device->hash_table_entries + 1; i++) { - hash_cur = ocf_metadata_hash_func(&cache, i, core_id); - hash_next = ocf_metadata_hash_func(&cache, i + 1, core_id); + for (i = 0; i < cache->device->hash_table_entries + 1; i++) { + hash_cur = ocf_metadata_hash_func(cache, i, core_id); + hash_next = ocf_metadata_hash_func(cache, i + 1, core_id); /* make sure hash value is within expected range */ - assert(hash_cur < cache.device->hash_table_entries); - assert(hash_next < cache.device->hash_table_entries); + assert(hash_cur < cache->device->hash_table_entries); + assert(hash_next < cache->device->hash_table_entries); /* hash should either increment by 1 or overflow to 0 */ - assert(hash_next == (hash_cur + 1) % cache.device->hash_table_entries); + assert(hash_next == (hash_cur + 1) % cache->device->hash_table_entries); } } + + test_free(cache->device); + test_free(cache); } int main(void) diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c index 7b61e14..fc74bb8 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c @@ -104,21 +104,24 @@ static void _cache_mngt_set_cache_mode_test01(void **state) struct ocf_superblock_config sb_config = { .cache_mode = mode_old, }; - struct ocf_cache cache = { - .owner = &ctx, - .conf_meta = &sb_config, - }; + struct ocf_cache *cache; int result; print_test_description("Invalid new mode produces appropirate error code"); + cache = test_malloc(sizeof(*cache)); + cache->owner = &ctx; + cache->conf_meta = &sb_config; + expect_function_call(__wrap_ocf_cache_mode_is_valid); will_return(__wrap_ocf_cache_mode_is_valid, 0); - result = _cache_mngt_set_cache_mode(&cache, mode_new); + result = _cache_mngt_set_cache_mode(cache, mode_new); assert_int_equal(result, -OCF_ERR_INVAL); - assert_int_equal(cache.conf_meta->cache_mode, mode_old); + assert_int_equal(cache->conf_meta->cache_mode, mode_old); + + test_free(cache); } static void _cache_mngt_set_cache_mode_test02(void **state) @@ -131,25 +134,28 @@ static void _cache_mngt_set_cache_mode_test02(void **state) struct ocf_superblock_config sb_config = { .cache_mode = mode_old, }; - struct ocf_cache cache = { - .owner = &ctx, - .conf_meta = &sb_config, - }; + struct ocf_cache *cache; uint8_t flush = 0; int result; print_test_description("Attempt to set mode the same as previous"); + cache = test_malloc(sizeof(*cache)); + cache->owner = &ctx; + cache->conf_meta = &sb_config; + expect_function_call(__wrap_ocf_cache_mode_is_valid); will_return(__wrap_ocf_cache_mode_is_valid, 1); expect_function_call(__wrap_ocf_log_raw); will_return(__wrap_ocf_log_raw, 0); - result = _cache_mngt_set_cache_mode(&cache, mode_new); + result = _cache_mngt_set_cache_mode(cache, mode_new); assert_int_equal(result, 0); - assert_int_equal(cache.conf_meta->cache_mode, mode_old); + assert_int_equal(cache->conf_meta->cache_mode, mode_old); + + test_free(cache); } static void _cache_mngt_set_cache_mode_test03(void **state) @@ -162,16 +168,17 @@ static void _cache_mngt_set_cache_mode_test03(void **state) struct ocf_superblock_config sb_config = { .cache_mode = mode_old, }; - struct ocf_cache cache = { - .owner = &ctx, - .conf_meta = &sb_config, - }; + struct ocf_cache *cache; int result; int i; print_test_description("Old cache mode is write back. " "Setting new cache mode is succesfull"); + cache = test_malloc(sizeof(*cache)); + cache->owner = &ctx; + cache->conf_meta = &sb_config; + expect_function_call(__wrap_ocf_cache_mode_is_valid); will_return(__wrap_ocf_cache_mode_is_valid, 1); @@ -180,10 +187,12 @@ static void _cache_mngt_set_cache_mode_test03(void **state) expect_function_call(__wrap_ocf_log_raw); will_return(__wrap_ocf_log_raw, 0); - result = _cache_mngt_set_cache_mode(&cache, mode_new); + result = _cache_mngt_set_cache_mode(cache, mode_new); assert_int_equal(result, 0); - assert_int_equal(cache.conf_meta->cache_mode, mode_new); + assert_int_equal(cache->conf_meta->cache_mode, mode_new); + + test_free(cache); } static void _cache_mngt_set_cache_mode_test04(void **state) @@ -196,25 +205,28 @@ static void _cache_mngt_set_cache_mode_test04(void **state) struct ocf_superblock_config sb_config = { .cache_mode = mode_old, }; - struct ocf_cache cache = { - .owner = &ctx, - .conf_meta = &sb_config, - }; + struct ocf_cache *cache; int result; int i; print_test_description("Mode changed successfully"); + cache = test_malloc(sizeof(*cache)); + cache->owner = &ctx; + cache->conf_meta = &sb_config; + expect_function_call(__wrap_ocf_cache_mode_is_valid); will_return(__wrap_ocf_cache_mode_is_valid, 1); expect_function_call(__wrap_ocf_log_raw); will_return(__wrap_ocf_log_raw, 0); - result = _cache_mngt_set_cache_mode(&cache, mode_new); + result = _cache_mngt_set_cache_mode(cache, mode_new); assert_int_equal(result, 0); - assert_int_equal(cache.conf_meta->cache_mode, mode_new); + assert_int_equal(cache->conf_meta->cache_mode, mode_new); + + test_free(cache); } /* diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c index dbf0e5b..e14b6aa 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c @@ -54,108 +54,124 @@ int __wrap_ocf_mngt_cache_set_fallback_pt(ocf_cache_t cache) static void ocf_mngt_cache_set_fallback_pt_error_threshold_test01(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; int new_threshold; int result; print_test_description("Appropriate error code on invalid threshold value"); + cache = test_malloc(sizeof(*cache)); + new_threshold = -1; - result = ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + result = ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); assert_int_equal(result, -OCF_ERR_INVAL); new_threshold = 10000001; - result = ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + result = ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); assert_int_equal(result, -OCF_ERR_INVAL); + + test_free(cache); } static void ocf_mngt_cache_set_fallback_pt_error_threshold_test02(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; int new_threshold; int old_threshold; print_test_description("Invalid new threshold value doesn't change current threshold"); + cache = test_malloc(sizeof(*cache)); + new_threshold = -1; - old_threshold = cache.fallback_pt_error_threshold = 1000; + old_threshold = cache->fallback_pt_error_threshold = 1000; - ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); - assert_int_equal(cache.fallback_pt_error_threshold, old_threshold); + assert_int_equal(cache->fallback_pt_error_threshold, old_threshold); new_threshold = 10000001; - old_threshold = cache.fallback_pt_error_threshold = 1000; + old_threshold = cache->fallback_pt_error_threshold = 1000; - ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); - assert_int_equal(cache.fallback_pt_error_threshold, old_threshold); + assert_int_equal(cache->fallback_pt_error_threshold, old_threshold); + + test_free(cache); } static void ocf_mngt_cache_set_fallback_pt_error_threshold_test03(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; int new_threshold, old_threshold; print_test_description("Setting new threshold value"); + cache = test_malloc(sizeof(*cache)); + new_threshold = 5000; - old_threshold = cache.fallback_pt_error_threshold = 1000; + old_threshold = cache->fallback_pt_error_threshold = 1000; - ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); - assert_int_equal(cache.fallback_pt_error_threshold, new_threshold); + assert_int_equal(cache->fallback_pt_error_threshold, new_threshold); new_threshold = 1000000; - old_threshold = cache.fallback_pt_error_threshold = 1000; + old_threshold = cache->fallback_pt_error_threshold = 1000; - ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); - assert_int_equal(cache.fallback_pt_error_threshold, new_threshold); + assert_int_equal(cache->fallback_pt_error_threshold, new_threshold); new_threshold = 0; - old_threshold = cache.fallback_pt_error_threshold = 1000; + old_threshold = cache->fallback_pt_error_threshold = 1000; - ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); - assert_int_equal(cache.fallback_pt_error_threshold, new_threshold); + assert_int_equal(cache->fallback_pt_error_threshold, new_threshold); + + test_free(cache); } static void ocf_mngt_cache_set_fallback_pt_error_threshold_test04(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; int new_threshold; int result; print_test_description("Return appropriate value on success"); + cache = test_malloc(sizeof(*cache)); + new_threshold = 5000; - result = ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + result = ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); assert_int_equal(result, 0); new_threshold = 1000000; - result = ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + result = ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); - assert_int_equal(cache.fallback_pt_error_threshold, new_threshold); + assert_int_equal(cache->fallback_pt_error_threshold, new_threshold); new_threshold = 0; - result = ocf_mngt_cache_set_fallback_pt_error_threshold(&cache, new_threshold); + result = ocf_mngt_cache_set_fallback_pt_error_threshold(cache, new_threshold); assert_int_equal(result, 0); + + test_free(cache); } int main(void) diff --git a/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c b/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c index f5e1d0f..1abec16 100644 --- a/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c +++ b/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c @@ -105,20 +105,22 @@ static inline void setup_valid_config(struct ocf_mngt_io_class_config *cfg, static void ocf_mngt_io_classes_configure_test03(void **state) { - struct ocf_cache cache = {0}; + struct ocf_cache *cache; struct ocf_mngt_io_classes_config cfg = {0}; int result, i; + print_test_description("Remove all io classes"); + + cache = test_malloc(sizeof(*cache)); + for (i = 0; i < OCF_IO_CLASS_MAX; i++) { - cache.user_parts[i].config = + cache->user_parts[i].config = test_malloc(sizeof(struct ocf_user_part_config)); } - cache.device = 1; + cache->device = 1; setup_valid_config(cfg.config, true); - print_test_description("Remove all io classes"); - for (i = 0; i < OCF_IO_CLASS_MAX; i++) { expect_function_call(__wrap__ocf_mngt_io_class_validate_cfg); will_return(__wrap__ocf_mngt_io_class_validate_cfg, 0); @@ -138,25 +140,29 @@ static void ocf_mngt_io_classes_configure_test03(void **state) expect_function_call(__wrap_ocf_part_sort); - result = ocf_mngt_cache_io_classes_configure(&cache, &cfg); + result = ocf_mngt_cache_io_classes_configure(cache, &cfg); assert_int_equal(result, 0); for (i = 0; i < OCF_IO_CLASS_MAX; i++) - test_free(cache.user_parts[i].config); + test_free(cache->user_parts[i].config); + + test_free(cache); } static void ocf_mngt_io_classes_configure_test02(void **state) { - struct ocf_cache cache = {0}; + struct ocf_cache *cache; struct ocf_mngt_io_classes_config cfg = {0}; int result, i; + cache = test_malloc(sizeof(*cache)); + for (i = 0; i < OCF_IO_CLASS_MAX; i++) { - cache.user_parts[i].config = + cache->user_parts[i].config = test_malloc(sizeof(struct ocf_user_part_config)); } - cache.device = 1; + cache->device = 1; setup_valid_config(cfg.config, false); @@ -197,17 +203,19 @@ static void ocf_mngt_io_classes_configure_test02(void **state) expect_function_call(__wrap_ocf_part_sort); - result = ocf_mngt_cache_io_classes_configure(&cache, &cfg); + result = ocf_mngt_cache_io_classes_configure(cache, &cfg); assert_int_equal(result, 0); for (i = 0; i < OCF_IO_CLASS_MAX; i++) - test_free(cache.user_parts[i].config); + test_free(cache->user_parts[i].config); + + test_free(cache); } static void ocf_mngt_io_classes_configure_test01(void **state) { - struct ocf_cache cache; + struct ocf_cache *cache; struct ocf_mngt_io_classes_config cfg[OCF_IO_CLASS_MAX]; int error_code = -OCF_ERR_INVAL; int result; @@ -215,12 +223,16 @@ static void ocf_mngt_io_classes_configure_test01(void **state) print_test_description("Invalid config - " "termination with error"); + cache = test_malloc(sizeof(*cache)); + expect_function_call(__wrap__ocf_mngt_io_class_validate_cfg); will_return(__wrap__ocf_mngt_io_class_validate_cfg, error_code); - result = ocf_mngt_cache_io_classes_configure(&cache, &cfg); + result = ocf_mngt_cache_io_classes_configure(cache, &cfg); assert_int_equal(result, error_code); + + test_free(cache); } int main(void)