ut: Add cache allocation & do little cleanup

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2020-03-23 12:37:45 +01:00
parent c295a4f670
commit f7d191b765
7 changed files with 185 additions and 129 deletions

View File

@ -40,66 +40,70 @@
static void cleaning_policy_alru_initialize_test01(void **state) static void cleaning_policy_alru_initialize_test01(void **state)
{ {
int result; int result;
struct ocf_cache cache; struct ocf_cache *cache;
ocf_part_id_t part_id = 0; 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 = test_malloc(sizeof(*cache));
cache.device = test_malloc(sizeof(struct ocf_cache_device)); cache->user_parts[part_id].runtime = test_malloc(sizeof(struct ocf_user_part_runtime));
cache.device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_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(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_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->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->runtime_meta);
test_free(cache.device); test_free(cache->device);
test_free(cache.user_parts[part_id].runtime); test_free(cache->user_parts[part_id].runtime);
test_free(cache);
} }
static void cleaning_policy_alru_initialize_test02(void **state) static void cleaning_policy_alru_initialize_test02(void **state)
{ {
int result; int result;
struct ocf_cache cache; struct ocf_cache *cache;
ocf_part_id_t part_id = 0; 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 = test_malloc(sizeof(*cache));
cache.device = test_malloc(sizeof(struct ocf_cache_device)); cache->user_parts[part_id].runtime = test_malloc(sizeof(struct ocf_user_part_runtime));
cache.device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_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); 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_head = -collision_table_entries;
cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail = -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(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_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->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->runtime_meta);
test_free(cache.device); test_free(cache->device);
test_free(cache.user_parts[part_id].runtime); 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) int main(void)
{ {
const struct CMUnitTest tests[] = { const struct CMUnitTest tests[] = {
cmocka_unit_test(cleaning_policy_alru_initialize_test01), cmocka_unit_test(cleaning_policy_alru_initialize_test01),
cmocka_unit_test(cleaning_policy_alru_initialize_test02) 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);
} }

View File

@ -103,20 +103,22 @@ static void cleaner_complete(ocf_cleaner_t cleaner, uint32_t interval)
static void ocf_cleaner_run_test01(void **state) static void ocf_cleaner_run_test01(void **state)
{ {
struct ocf_cache cache; struct ocf_cache *cache;
ocf_part_id_t part_id; ocf_part_id_t part_id;
uint32_t io_queue; uint32_t io_queue;
int result; 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" print_test_description("Parts are ready for cleaning - should perform cleaning"
" for each part"); " 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); 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); expect_function_call(__wrap_env_bit_test);
will_return(__wrap_env_bit_test, 1); 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); expect_function_call(__wrap_cleaning_alru_perform_cleaning);
will_return(__wrap_cleaning_alru_perform_cleaning, 0); 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 */ /* Release allocated memory if allocated with test_* functions */
test_free(cache.conf_meta); test_free(cache->conf_meta);
test_free(cache);
} }
/* /*

View File

@ -35,15 +35,21 @@ void __wrap_ocf_metadata_hash_lock(struct ocf_metadata_lock *metadata_lock,
static struct ocf_request *alloc_req() static struct ocf_request *alloc_req()
{ {
struct ocf_request *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->map = req->__map;
req->cache = cache; req->cache = cache;
return req; 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, static void _test_lock_order(struct ocf_request* req,
unsigned hash[], unsigned hash_count, unsigned hash[], unsigned hash_count,
unsigned expected_call[], unsigned expected_call_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); test_cases[i].expected_call.val, test_cases[i].expected_call.count);
} }
free(req->cache); free_req(req);
free(req);
} }
int main(void) int main(void)

View File

@ -25,7 +25,7 @@
static void metadata_hash_func_test01(void **state) static void metadata_hash_func_test01(void **state)
{ {
struct ocf_cache cache; struct ocf_cache *cache;
bool wrap = false; bool wrap = false;
ocf_cache_line_t i; ocf_cache_line_t i;
ocf_cache_line_t hash_cur, hash_next; 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" print_test_description("Verify that hash function increments by 1 and generates"
"collision after 'hash_table_entries' successive core lines"); "collision after 'hash_table_entries' successive core lines");
cache.device = malloc(sizeof(*cache.device)); cache = test_malloc(sizeof(*cache));
cache.device->hash_table_entries = 10; 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++) { for (c = 0; c < sizeof(core_ids) / sizeof(core_ids[0]); c++) {
core_id = core_ids[c]; core_id = core_ids[c];
for (i = 0; i < cache.device->hash_table_entries + 1; i++) { for (i = 0; i < cache->device->hash_table_entries + 1; i++) {
hash_cur = ocf_metadata_hash_func(&cache, i, core_id); hash_cur = ocf_metadata_hash_func(cache, i, core_id);
hash_next = ocf_metadata_hash_func(&cache, i + 1, core_id); hash_next = ocf_metadata_hash_func(cache, i + 1, core_id);
/* make sure hash value is within expected range */ /* make sure hash value is within expected range */
assert(hash_cur < cache.device->hash_table_entries); assert(hash_cur < cache->device->hash_table_entries);
assert(hash_next < cache.device->hash_table_entries); assert(hash_next < cache->device->hash_table_entries);
/* hash should either increment by 1 or overflow to 0 */ /* 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) int main(void)

View File

@ -104,21 +104,24 @@ static void _cache_mngt_set_cache_mode_test01(void **state)
struct ocf_superblock_config sb_config = { struct ocf_superblock_config sb_config = {
.cache_mode = mode_old, .cache_mode = mode_old,
}; };
struct ocf_cache cache = { struct ocf_cache *cache;
.owner = &ctx,
.conf_meta = &sb_config,
};
int result; int result;
print_test_description("Invalid new mode produces appropirate error code"); 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); expect_function_call(__wrap_ocf_cache_mode_is_valid);
will_return(__wrap_ocf_cache_mode_is_valid, 0); 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(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) 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 = { struct ocf_superblock_config sb_config = {
.cache_mode = mode_old, .cache_mode = mode_old,
}; };
struct ocf_cache cache = { struct ocf_cache *cache;
.owner = &ctx,
.conf_meta = &sb_config,
};
uint8_t flush = 0; uint8_t flush = 0;
int result; int result;
print_test_description("Attempt to set mode the same as previous"); 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); expect_function_call(__wrap_ocf_cache_mode_is_valid);
will_return(__wrap_ocf_cache_mode_is_valid, 1); will_return(__wrap_ocf_cache_mode_is_valid, 1);
expect_function_call(__wrap_ocf_log_raw); expect_function_call(__wrap_ocf_log_raw);
will_return(__wrap_ocf_log_raw, 0); 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(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) 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 = { struct ocf_superblock_config sb_config = {
.cache_mode = mode_old, .cache_mode = mode_old,
}; };
struct ocf_cache cache = { struct ocf_cache *cache;
.owner = &ctx,
.conf_meta = &sb_config,
};
int result; int result;
int i; int i;
print_test_description("Old cache mode is write back. " print_test_description("Old cache mode is write back. "
"Setting new cache mode is succesfull"); "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); expect_function_call(__wrap_ocf_cache_mode_is_valid);
will_return(__wrap_ocf_cache_mode_is_valid, 1); 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); expect_function_call(__wrap_ocf_log_raw);
will_return(__wrap_ocf_log_raw, 0); 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(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) 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 = { struct ocf_superblock_config sb_config = {
.cache_mode = mode_old, .cache_mode = mode_old,
}; };
struct ocf_cache cache = { struct ocf_cache *cache;
.owner = &ctx,
.conf_meta = &sb_config,
};
int result; int result;
int i; int i;
print_test_description("Mode changed successfully"); 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); expect_function_call(__wrap_ocf_cache_mode_is_valid);
will_return(__wrap_ocf_cache_mode_is_valid, 1); will_return(__wrap_ocf_cache_mode_is_valid, 1);
expect_function_call(__wrap_ocf_log_raw); expect_function_call(__wrap_ocf_log_raw);
will_return(__wrap_ocf_log_raw, 0); 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(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);
} }
/* /*

View File

@ -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) 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 new_threshold;
int result; int result;
print_test_description("Appropriate error code on invalid threshold value"); print_test_description("Appropriate error code on invalid threshold value");
cache = test_malloc(sizeof(*cache));
new_threshold = -1; 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); assert_int_equal(result, -OCF_ERR_INVAL);
new_threshold = 10000001; 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); assert_int_equal(result, -OCF_ERR_INVAL);
test_free(cache);
} }
static void ocf_mngt_cache_set_fallback_pt_error_threshold_test02(void **state) 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 new_threshold;
int old_threshold; int old_threshold;
print_test_description("Invalid new threshold value doesn't change current threshold"); print_test_description("Invalid new threshold value doesn't change current threshold");
cache = test_malloc(sizeof(*cache));
new_threshold = -1; 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; 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) 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; int new_threshold, old_threshold;
print_test_description("Setting new threshold value"); print_test_description("Setting new threshold value");
cache = test_malloc(sizeof(*cache));
new_threshold = 5000; 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; 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; 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) 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 new_threshold;
int result; int result;
print_test_description("Return appropriate value on success"); print_test_description("Return appropriate value on success");
cache = test_malloc(sizeof(*cache));
new_threshold = 5000; 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); assert_int_equal(result, 0);
new_threshold = 1000000; 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; 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); assert_int_equal(result, 0);
test_free(cache);
} }
int main(void) int main(void)

View File

@ -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) 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}; struct ocf_mngt_io_classes_config cfg = {0};
int result, i; int result, i;
print_test_description("Remove all io classes");
cache = test_malloc(sizeof(*cache));
for (i = 0; i < OCF_IO_CLASS_MAX; i++) { 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)); test_malloc(sizeof(struct ocf_user_part_config));
} }
cache.device = 1; cache->device = 1;
setup_valid_config(cfg.config, true); setup_valid_config(cfg.config, true);
print_test_description("Remove all io classes");
for (i = 0; i < OCF_IO_CLASS_MAX; i++) { for (i = 0; i < OCF_IO_CLASS_MAX; i++) {
expect_function_call(__wrap__ocf_mngt_io_class_validate_cfg); expect_function_call(__wrap__ocf_mngt_io_class_validate_cfg);
will_return(__wrap__ocf_mngt_io_class_validate_cfg, 0); 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); 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); assert_int_equal(result, 0);
for (i = 0; i < OCF_IO_CLASS_MAX; i++) 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) 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}; struct ocf_mngt_io_classes_config cfg = {0};
int result, i; int result, i;
cache = test_malloc(sizeof(*cache));
for (i = 0; i < OCF_IO_CLASS_MAX; i++) { 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)); test_malloc(sizeof(struct ocf_user_part_config));
} }
cache.device = 1; cache->device = 1;
setup_valid_config(cfg.config, false); 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); 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); assert_int_equal(result, 0);
for (i = 0; i < OCF_IO_CLASS_MAX; i++) 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) 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]; struct ocf_mngt_io_classes_config cfg[OCF_IO_CLASS_MAX];
int error_code = -OCF_ERR_INVAL; int error_code = -OCF_ERR_INVAL;
int result; int result;
@ -215,12 +223,16 @@ static void ocf_mngt_io_classes_configure_test01(void **state)
print_test_description("Invalid config - " print_test_description("Invalid config - "
"termination with error"); "termination with error");
cache = test_malloc(sizeof(*cache));
expect_function_call(__wrap__ocf_mngt_io_class_validate_cfg); expect_function_call(__wrap__ocf_mngt_io_class_validate_cfg);
will_return(__wrap__ocf_mngt_io_class_validate_cfg, error_code); 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); assert_int_equal(result, error_code);
test_free(cache);
} }
int main(void) int main(void)