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

@@ -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);
}
/*

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)
{
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)

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)
{
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)