Fix existing unit tests

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Mielewczyk 2018-12-05 11:04:43 -05:00
parent e2ed529b89
commit 35ae74e3fa
6 changed files with 29 additions and 15 deletions

View File

@ -46,12 +46,14 @@ static void cleaning_policy_alru_initialize_test01(void **state)
ocf_part_id_t part_id = 0;
int collision_table_entries = 900729;
cache.collision_table_entries = collision_table_entries;
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.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;
result = cleaning_policy_alru_initialize_part(&cache, &cache.user_parts[part_id], 1, 1);
@ -61,9 +63,10 @@ static void cleaning_policy_alru_initialize_test01(void **state)
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.runtime_meta->cleaning_thread_access, 0);
assert_int_equal(cache.device->runtime_meta->cleaning_thread_access, 0);
test_free(cache.runtime_meta);
test_free(cache.device->runtime_meta);
test_free(cache.device);
test_free(cache.user_parts[part_id].runtime);
}
@ -74,12 +77,12 @@ static void cleaning_policy_alru_initialize_test02(void **state)
ocf_part_id_t part_id = 0;
uint32_t collision_table_entries = 900729;
cache.collision_table_entries = collision_table_entries;
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.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.user_parts[part_id].runtime->cleaning.policy.alru.size = 1;
cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head = -collision_table_entries;
@ -93,9 +96,10 @@ static void cleaning_policy_alru_initialize_test02(void **state)
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.runtime_meta->cleaning_thread_access, 0);
assert_int_equal(cache.device->runtime_meta->cleaning_thread_access, 0);
test_free(cache.runtime_meta);
test_free(cache.device->runtime_meta);
test_free(cache.device);
test_free(cache.user_parts[part_id].runtime);
}

View File

@ -184,13 +184,13 @@ int __wrap_env_bit_test(int nr, const void *addr)
return mock();
}
int __wrap_env_rmutex_trylock(env_rmutex *rmutex)
int __wrap_env_rwsem_down_write_trylock(env_rwsem *s)
{
function_called();
return mock();
}
void __wrap_env_rmutex_unlock(env_rmutex *rmutex)
void __wrap_env_rwsem_up_write(env_rwsem *s)
{
function_called();
}
@ -224,8 +224,8 @@ static void ocf_cleaner_run_test01(void **state)
expect_function_call(__wrap_ocf_mngt_is_cache_locked);
will_return(__wrap_ocf_mngt_is_cache_locked, 0);
expect_function_call(__wrap_env_rmutex_trylock);
will_return(__wrap_env_rmutex_trylock, 1);
expect_function_call(__wrap_env_rwsem_down_write_trylock);
will_return(__wrap_env_rwsem_down_write_trylock, 1);
expect_function_call(__wrap__ocf_cleaner_run_check_dirty_inactive);
will_return(__wrap__ocf_cleaner_run_check_dirty_inactive, 0);
@ -233,7 +233,7 @@ static void ocf_cleaner_run_test01(void **state)
expect_function_call(__wrap_cleaning_alru_perform_cleaning);
will_return(__wrap_cleaning_alru_perform_cleaning, 0);
expect_function_call(__wrap_env_rmutex_unlock);
expect_function_call(__wrap_env_rwsem_up_write);
result = ocf_cleaner_run(&cache.cleaner, io_queue);
assert_int_equal(result, 0);

View File

@ -99,6 +99,10 @@ int __wrap_ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache)
return mock();
}
char *__wrap_ocf_cache_get_name(ocf_cache_t cache)
{
}
static void _cache_mng_set_cache_mode_test01(void **state)
{
int result;

View File

@ -55,6 +55,10 @@ bool __wrap_ocf_fallback_pt_is_on(ocf_cache_t cache)
{
}
char *__wrap_ocf_cache_get_name(ocf_cache_t cache)
{
}
static void ocf_mngt_cache_set_fallback_pt_error_threshold_test01(void **state)
{
struct ocf_cache cache;

View File

@ -13,6 +13,8 @@
#define __USE_GNU
#endif
#define OCF_PREFIX_SHORT "OCF"
#include <linux/limits.h>
#include <linux/stddef.h>
#include <stdint.h>