spilt find_tests and create_test_proc_files, add workquue for loading tests

This commit is contained in:
stubbfel
2018-03-01 23:22:04 +01:00
parent d312f88cba
commit 4f7c91677e
7 changed files with 70 additions and 39 deletions

View File

@@ -7,6 +7,7 @@ project (${module_name})
if(NOT KERNEL_DIR) if(NOT KERNEL_DIR)
Set(KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build" ) Set(KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build" )
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Weverything") set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Weverything")
file(GLOB module_src_files file(GLOB module_src_files

View File

@@ -67,7 +67,7 @@ struct seq_file* test_proc_file;
//{ global function implements region //{ 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]; char buffer[MAX_FILE_NAME_LEN];
const char * file_name = &buffer[0]; const char * file_name = &buffer[0];

View File

@@ -16,7 +16,7 @@ extern "C" {
//{ function region //{ 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);
//} //}

View File

@@ -11,8 +11,6 @@
//{ local include region //{ local include region
#include "kunity_proc_test_file_handler.h"
//} //}
//{ local define region //{ 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(/* 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); 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; 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 //{ 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->test = test;
tmp_test_item->next = NULL; 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; *test_list_item_location = tmp_test_item;
return OK; return OK;
} }
@@ -174,43 +187,28 @@ static result_code_e destroy_test(/* in */ ptr_test_s* test_location)
return OK; 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 == NULL) {
if (test_list_item_location == NULL || *test_list_item_location == NULL) {
return ERROR_NULL_ARGUMENT; return ERROR_NULL_ARGUMENT;
} }
tmp_list_item = *test_list_item_location; test_list_item->next = NULL;
if (next_test_item_location != NULL) { destroy_test(&test_list_item->test);
*next_test_item_location = tmp_list_item->next; kfree(test_list_item);
}
destroy_test(&tmp_list_item->test);
kfree(tmp_list_item);
*test_list_item_location = NULL;
return OK; return OK;
} }
result_code_e destroy_test_list(/* in */ ptr_test_list_s* test_list_location) result_code_e destroy_test_list(/* in */ ptr_test_list_s* test_list_location)
{ {
ptr_test_list_s tmp_list = NULL; 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) { if (test_list_location == NULL || *test_list_location == NULL) {
return ERROR_NULL_ARGUMENT; return ERROR_NULL_ARGUMENT;
} }
tmp_list = *test_list_location; tmp_list = *test_list_location;
tmp_test_item = tmp_list->head; iterate_test_list(tmp_list, destroy_test_list_item);
while (tmp_test_item != NULL) { tmp_list->head = 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;
}
kfree(tmp_list); kfree(tmp_list);
*test_list_location = NULL; *test_list_location = NULL;
return OK; 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) { 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; return 0;

View File

@@ -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 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 #ifdef __cplusplus

View File

@@ -54,6 +54,8 @@ typedef struct test_query_sTag {
ptr_test_list_s result_list; ptr_test_list_s result_list;
} test_query_s, *ptr_test_query_s; } 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 #endif // KUNITY_TEST_FINDER_T_H

View File

@@ -3,11 +3,13 @@
#include <kunity_t.h> #include <kunity_t.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/workqueue.h>
//} //}
//{ local include region //{ local include region
#include "kunity_proc_test_file_handler.h"
#include "kunity_test_finder.h" #include "kunity_test_finder.h"
//} //}
@@ -34,18 +36,25 @@
//{ local function prototype region //{ local function prototype region
static void init_tests(struct work_struct* work);
static int kunity_init(void); static int kunity_init(void);
static void kunity_exit(void); static void kunity_exit(void);
//} //}
//{ global variabel implements region //{ global variabel implements region
extern struct proc_dir_entry * proc_dir;
extern struct proc_dir_entry* proc_dir;
//} //}
//{ local variabel implements region //{ 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 //{ global function implements region
@@ -54,16 +63,36 @@ static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*"};
//{ local function implements region //{ 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() static int kunity_init()
{ {
pr_info("init kunity_test_runner_module"); pr_info("init kunity_test_runner_module");
proc_dir = proc_mkdir("kunity_test", NULL); queue = create_workqueue("test_runner_work_queue");
return -find_tests(&query); if (queue == NULL) {
return -ERROR_INVALID_OPERATION;
}
return !queue_work(queue, &work);
} }
static void kunity_exit() 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); destroy_test_list(&query.result_list);
proc_remove(proc_dir); proc_remove(proc_dir);
} }