From 0d3f3cde145284b2371b2d455b5efc290c5a4780 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 19 Mar 2021 12:22:35 +0100 Subject: [PATCH 1/2] Return error when modifying default ioclass rule Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_io_class.c | 13 +++++++++++-- .../mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index e348551..090a7a4 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -135,9 +135,18 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache, if (part_id == PARTITION_DEFAULT) { /* Special behavior for default partition */ + if (env_strncmp(name, OCF_IO_CLASS_NAME_MAX, + dest_part->config->name, OCF_IO_CLASS_NAME_MAX)) { + + ocf_cache_log(cache, log_err, + "Can't change classification rule of the default IO class" + " [ ERROR ]\n"); + return -OCF_ERR_INVAL; + } + /* Try set partition size */ if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) { - ocf_cache_log(cache, log_info, + ocf_cache_log(cache, log_err, "Setting IO class size, id: %u, name: '%s', max size: %u%%" " [ ERROR ]\n", part_id, dest_part->config->name, max); return -OCF_ERR_INVAL; @@ -161,7 +170,7 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache, /* Try set partition size */ if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) { - ocf_cache_log(cache, log_info, + ocf_cache_log(cache, log_err, "Setting IO class size, id: %u, name: '%s', max size %u%%" "[ ERROR ]\n", part_id, dest_part->config->name, max); return -OCF_ERR_INVAL; 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 04c0741..3445109 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 @@ -95,7 +95,7 @@ static inline void setup_valid_config(struct ocf_mngt_io_class_config *cfg, int i; for (i = 0; i < OCF_IO_CLASS_MAX; i++) { cfg[i].class_id = i; - cfg[i].name = remove ? NULL : "test_io_class_name" ; + cfg[i].name = remove ? NULL : i == 0 ? "unclassified" :"test_io_class_name" ; cfg[i].prio = i; cfg[i].cache_mode = ocf_cache_mode_pt; cfg[i].max_size = 20*i; @@ -161,6 +161,8 @@ static void ocf_mngt_io_classes_configure_test02(void **state) cache->user_parts[i].config = test_malloc(sizeof(struct ocf_user_part_config)); } + + strcpy(cache->user_parts[0].config->name, "unclassified"); cache->device = 1; setup_valid_config(cfg.config, false); From 92a5ddd524a0db0cdedabb460ca41eb804d20634 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 19 Mar 2021 16:06:47 +0100 Subject: [PATCH 2/2] ut framework: don't mock env functions Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_io_class.c | 1 - tests/unit/framework/prepare_sources_for_testing.py | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index 090a7a4..9685c97 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -137,7 +137,6 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache, if (env_strncmp(name, OCF_IO_CLASS_NAME_MAX, dest_part->config->name, OCF_IO_CLASS_NAME_MAX)) { - ocf_cache_log(cache, log_err, "Can't change classification rule of the default IO class" " [ ERROR ]\n"); diff --git a/tests/unit/framework/prepare_sources_for_testing.py b/tests/unit/framework/prepare_sources_for_testing.py index d7ba6ef..83ac35d 100755 --- a/tests/unit/framework/prepare_sources_for_testing.py +++ b/tests/unit/framework/prepare_sources_for_testing.py @@ -146,6 +146,11 @@ class UnitTestsSourcesGenerator(object): wrap_file_path = wrap_file_path + "_generated_wraps.c" return wrap_file_path + def is_env_function(self, name): + prefixes = ["env", "bug", "memcpy", "memset", "memcmp", "strnlen", "strncmp", "strncpy"] + + return list(filter(name.startswith, prefixes)) != [] + def prepare_autowraps(self, test_file_path, preprocessed_file_path): functions_to_wrap = self.get_functions_calls( self.get_sources_to_test_repo() + test_file_path) @@ -160,10 +165,7 @@ class UnitTestsSourcesGenerator(object): with open(preprocessed_file_path) as f: code = f.readlines() for function in functions_to_wrap: - if function.startswith("env_") or function.startswith("bug") \ - or function.startswith("memcpy"): - # added memcpy function to list of ignored functions - # because this is macro + if self.is_env_function(function): continue for tag in tags_list: if function in tag: