From 4f7c91677ef2832588a1280c351ea3a9264a2154 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Thu, 1 Mar 2018 23:22:04 +0100 Subject: [PATCH] spilt find_tests and create_test_proc_files, add workquue for loading tests --- CMakeLists.txt | 1 + src/kunity_proc_test_file_handler.c | 2 +- src/kunity_proc_test_file_handler.h | 2 +- src/kunity_test_finder.c | 62 ++++++++++++++--------------- src/kunity_test_finder.h | 1 + src/kunity_test_finder_t.h | 2 + src/runner_module.c | 39 +++++++++++++++--- 7 files changed, 70 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f873ff5..cd6e581 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ project (${module_name}) if(NOT KERNEL_DIR) Set(KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build" ) endif() + set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Weverything") file(GLOB module_src_files diff --git a/src/kunity_proc_test_file_handler.c b/src/kunity_proc_test_file_handler.c index c8a7f4f..977359e 100644 --- a/src/kunity_proc_test_file_handler.c +++ b/src/kunity_proc_test_file_handler.c @@ -67,7 +67,7 @@ struct seq_file* test_proc_file; //{ global function implements region -result_code_e create_proc_test_file(/* inout */ ptr_test_list_item_s list_item) +result_code_e create_proc_test_file(/* in */ const ptr_test_list_item_s list_item) { char buffer[MAX_FILE_NAME_LEN]; const char * file_name = &buffer[0]; diff --git a/src/kunity_proc_test_file_handler.h b/src/kunity_proc_test_file_handler.h index f014912..6efff7f 100644 --- a/src/kunity_proc_test_file_handler.h +++ b/src/kunity_proc_test_file_handler.h @@ -16,7 +16,7 @@ extern "C" { //{ function region -extern result_code_e create_proc_test_file(/* inout */ ptr_test_list_item_s list_item); +extern result_code_e create_proc_test_file(/* in */ const ptr_test_list_item_s list_item); //} diff --git a/src/kunity_test_finder.c b/src/kunity_test_finder.c index c1d1c47..54323c7 100644 --- a/src/kunity_test_finder.c +++ b/src/kunity_test_finder.c @@ -11,8 +11,6 @@ //{ local include region -#include "kunity_proc_test_file_handler.h" - //} //{ local define region @@ -45,7 +43,7 @@ static result_code_e create_test_list(/* out */ ptr_test_list_s* test_list_locat static result_code_e destroy_test(/* in */ ptr_test_s* test_location); -static result_code_e destroy_test_list_item(/* in */ ptr_test_list_item_s* test_list_item_location, /* out */ ptr_test_list_item_s* next_test_item_location); +static result_code_e destroy_test_list_item(/* in */ const ptr_test_list_item_s test_list_item); static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item, /* in */ ptr_test_list_s test_list); @@ -86,6 +84,27 @@ result_code_e find_tests(/* in */ const ptr_test_query_s query) return OK; } + +result_code_e iterate_test_list(/* in */ const ptr_test_list_s test_list, test_list_iterator item_function) +{ + ptr_test_list_item_s tmp_test_item = NULL; + if (test_list == NULL || item_function == NULL) { + return ERROR_NULL_ARGUMENT; + } + + tmp_test_item = test_list->head; + while (tmp_test_item != NULL) { + const ptr_test_list_item_s tmp_next_test_item = tmp_test_item->next; + result_code_e result = item_function(tmp_test_item); + if (result != OK) { + return result; + } + + tmp_test_item = tmp_next_test_item; + } + + return OK; +} //} //{ local function implements region @@ -131,12 +150,6 @@ static result_code_e create_test_list_item(/* in */ const ptr_test_s test, /* ou tmp_test_item->test = test; tmp_test_item->next = NULL; - if (create_proc_test_file(tmp_test_item) != OK) { - pr_info ("fail"); - destroy_test_list_item(&tmp_test_item, NULL); - return ERROR_INVALID_OPERATION; - } -pr_info ("ok"); *test_list_item_location = tmp_test_item; return OK; } @@ -174,43 +187,28 @@ static result_code_e destroy_test(/* in */ ptr_test_s* test_location) return OK; } -static result_code_e destroy_test_list_item(/* in */ ptr_test_list_item_s* test_list_item_location, /* out */ ptr_test_list_item_s* next_test_item_location) +static result_code_e destroy_test_list_item(/* in */ const ptr_test_list_item_s test_list_item) { - ptr_test_list_item_s tmp_list_item = NULL; - if (test_list_item_location == NULL || *test_list_item_location == NULL) { + if (test_list_item == NULL) { return ERROR_NULL_ARGUMENT; } - tmp_list_item = *test_list_item_location; - if (next_test_item_location != NULL) { - *next_test_item_location = tmp_list_item->next; - } - - destroy_test(&tmp_list_item->test); - kfree(tmp_list_item); - *test_list_item_location = NULL; + test_list_item->next = NULL; + destroy_test(&test_list_item->test); + kfree(test_list_item); return OK; } result_code_e destroy_test_list(/* in */ ptr_test_list_s* test_list_location) { ptr_test_list_s tmp_list = NULL; - ptr_test_list_item_s tmp_test_item = NULL; if (test_list_location == NULL || *test_list_location == NULL) { return ERROR_NULL_ARGUMENT; } tmp_list = *test_list_location; - tmp_test_item = tmp_list->head; - while (tmp_test_item != NULL) { - ptr_test_list_item_s tmp_next_test_item = NULL; - if (destroy_test_list_item(&tmp_test_item, &tmp_next_test_item) != OK) { - break; - } - - tmp_test_item = tmp_next_test_item; - } - + iterate_test_list(tmp_list, destroy_test_list_item); + tmp_list->head = NULL; kfree(tmp_list); *test_list_location = NULL; return OK; @@ -257,7 +255,7 @@ static int find_test_for_each(void* data, const char* namebuf, struct module* mo } if (add_test_list_item(test_item, query->result_list) != OK) { - destroy_test_list_item(&test_item, NULL); + destroy_test_list_item(test_item); } return 0; diff --git a/src/kunity_test_finder.h b/src/kunity_test_finder.h index ff1f416..1f2decd 100644 --- a/src/kunity_test_finder.h +++ b/src/kunity_test_finder.h @@ -18,6 +18,7 @@ extern result_code_e find_tests(/* in */ const ptr_test_query_s query); extern result_code_e destroy_test_list(/* in */ ptr_test_list_s* test_list_location); +extern result_code_e iterate_test_list (/* in */ const ptr_test_list_s test_list, test_list_iterator item_function); //} #ifdef __cplusplus diff --git a/src/kunity_test_finder_t.h b/src/kunity_test_finder_t.h index 338bd01..0bf0300 100644 --- a/src/kunity_test_finder_t.h +++ b/src/kunity_test_finder_t.h @@ -54,6 +54,8 @@ typedef struct test_query_sTag { ptr_test_list_s result_list; } test_query_s, *ptr_test_query_s; +typedef result_code_e (*test_list_iterator) (/* in */ const ptr_test_list_item_s); + //} #endif // KUNITY_TEST_FINDER_T_H diff --git a/src/runner_module.c b/src/runner_module.c index 2849fe2..3604491 100644 --- a/src/runner_module.c +++ b/src/runner_module.c @@ -3,11 +3,13 @@ #include #include #include +#include //} //{ local include region +#include "kunity_proc_test_file_handler.h" #include "kunity_test_finder.h" //} @@ -34,18 +36,25 @@ //{ local function prototype region +static void init_tests(struct work_struct* work); static int kunity_init(void); static void kunity_exit(void); //} //{ global variabel implements region -extern struct proc_dir_entry * proc_dir; + +extern struct proc_dir_entry* proc_dir; + //} //{ local variabel implements region -static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*"}; +static struct workqueue_struct* queue; + +DECLARE_WORK(work, init_tests); + +static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*" }; //} //{ global function implements region @@ -54,16 +63,36 @@ static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*"}; //{ local function implements region +static void init_tests(struct work_struct* work) +{ + pr_info("init tests"); + proc_dir = proc_mkdir("kunity_test", NULL); + if (proc_dir == NULL || find_tests(&query) != OK) { + return; + } + + iterate_test_list(query.result_list, &create_proc_test_file); +} + static int kunity_init() { pr_info("init kunity_test_runner_module"); - proc_dir = proc_mkdir("kunity_test", NULL); - return -find_tests(&query); + queue = create_workqueue("test_runner_work_queue"); + if (queue == NULL) { + return -ERROR_INVALID_OPERATION; + } + + return !queue_work(queue, &work); } static void kunity_exit() { - pr_info("init kunity_test_runner_module"); + pr_info("exit kunity_test_runner_module"); + if (queue == NULL) { + return; + } + + destroy_workqueue(queue); destroy_test_list(&query.result_list); proc_remove(proc_dir); }