diff --git a/CMakeLists.txt b/CMakeLists.txt index bd14c99..9733db9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,6 @@ if(BUILD_TEST_MOUDLE) "${PROJECT_SOURCE_DIR}/lib/KUnity/lib/Unity/src/*.c") include_directories( - "${KERNEL_DIR}/include" "${PROJECT_SOURCE_DIR}/test/src" "${PROJECT_SOURCE_DIR}/lib/KUnity/lib/Unity/src") diff --git a/lib/KUnity b/lib/KUnity index 98ffa65..30c7c93 160000 --- a/lib/KUnity +++ b/lib/KUnity @@ -1 +1 @@ -Subproject commit 98ffa6508d4dd8b03b47afd02240173227a2a490 +Subproject commit 30c7c93ef4afddd09083f4202a5eb78078db09f8 diff --git a/src/kunity_proc_test_file_handler.c b/src/kunity_proc_test_file_handler.c index 8fb2708..5064442 100644 --- a/src/kunity_proc_test_file_handler.c +++ b/src/kunity_proc_test_file_handler.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -15,10 +16,6 @@ //{ local define region -#ifndef MAX_FILE_NAME_LEN -#define MAX_FILE_NAME_LEN 1024 -#endif - //} //{ local enum region @@ -41,8 +38,9 @@ static int proc_test_file_open(struct inode* inode, struct file* file); static int proc_test_file_show(struct seq_file* m, void* v); +static int proc_test_module_open(struct inode* inode, struct file* file); +static int proc_test_module_show(struct seq_file* m, void* v); static void put_seq_char(char letter); -static result_code_e create_test_file_name(/* in */ const char* module_name, /* in */ const char* test_name, /* in */ size_t max_len, /* out */ char* buffer); //} @@ -52,8 +50,6 @@ static result_code_e create_test_file_name(/* in */ const char* module_name, /* //{ local var implements region -static struct proc_dir_entry* proc_dir; - static const struct file_operations proc_test_file_ops = { .owner = THIS_MODULE, .open = proc_test_file_open, @@ -62,46 +58,54 @@ static const struct file_operations proc_test_file_ops = { .release = single_release, }; +static const struct file_operations proc_test_module_ops = { + .owner = THIS_MODULE, + .open = proc_test_module_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static struct seq_file* test_proc_file; //} //{ global function implements region - -result_code_e set_proc_test_root_folder(/* in */ struct proc_dir_entry * folder) +result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry * parent, /* in */const ptr_test_list_s test_list) { - proc_dir = folder; - return OK; -} - -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]; - struct proc_dir_entry* tmp_entry = NULL; - ptr_test_s test = NULL; - if (list_item == NULL) { + ptr_test_module_list_item_s module = NULL; + result_code_e result = OK; + if (test_list == NULL) { return ERROR_NULL_ARGUMENT; } - test = list_item->test; - if (test == NULL) { - return ERROR_INVALID_ARGUMENT; + list_for_each_entry(module, &test_list->test_module_list, test_module_head) + { + ptr_test_list_item_s test_item = NULL; + const char* module_name = module == NULL ? "__KERNEL__" : module->test_module->name; + struct proc_dir_entry* module_folder = proc_mkdir(module_name, parent); + struct proc_dir_entry* single_test_folder = proc_mkdir("single_tests", module_folder); + struct proc_dir_entry* tmp_entry = proc_create_data(module_name, 0, module_folder, &proc_test_module_ops, module); + if (tmp_entry == NULL) { + return ERROR_INVALID_OPERATION; + } + + list_for_each_entry(test_item, &module->test_list, test_head) + { + pr_info("bla %s; %p", test_item->test->name, single_test_folder); + tmp_entry = proc_create_data(test_item->test->name, 0, single_test_folder, &proc_test_file_ops, test_item->test); + if (tmp_entry == NULL) { + return ERROR_INVALID_OPERATION +1; + } + + } } - if (create_test_file_name(test->modul_name, test->name, MAX_FILE_NAME_LEN, buffer) != OK) { - return ERROR_INVALID_OPERATION; - } - - tmp_entry = proc_create_data(file_name, 0, proc_dir, &proc_test_file_ops, test); - if (tmp_entry == NULL) { - return ERROR_INVALID_OPERATION; - } - - return OK; + return result; } + //} //{ local function implements region @@ -116,9 +120,14 @@ static int proc_test_file_open(struct inode* inode, struct file* file) return single_open(file, proc_test_file_show, NULL); } +static int proc_test_module_open(struct inode* inode, struct file* file) +{ + return single_open(file, proc_test_module_show, NULL); +} + static int proc_test_file_show(struct seq_file* m, void* v) { - output_functions_s output = { put_seq_char }; + test_session_control_block_s output = { put_seq_char, 0, 0 }; ptr_test_s tmp_test = PDE_DATA(file_inode(m->file)); if (tmp_test == NULL) { return ERROR_INVALID_ARGUMENT; @@ -128,27 +137,31 @@ static int proc_test_file_show(struct seq_file* m, void* v) return tmp_test->test_function(&output); } -static result_code_e create_test_file_name(/* in */ const char* module_name, /* in */ const char* test_name, /* in */ size_t max_len, /* out */ char* buffer) +static int proc_test_module_show(struct seq_file* m, void* v) { - size_t module_name_size = 0; - size_t test_name_size = 0; - size_t file_name_size = 0; - - if (module_name == NULL || test_name == NULL || buffer == NULL) { - return ERROR_NULL_ARGUMENT; - } - - module_name_size = strlen(module_name); - test_name_size = strlen(module_name); - file_name_size = test_name_size + module_name_size + 2; - if (file_name_size > max_len) { + test_session_control_block_s output = { put_seq_char, 0, 1 }; + ptr_test_list_item_s tmp_test = NULL; + ptr_test_module_list_item_s tmp_module = PDE_DATA(file_inode(m->file)); + if (tmp_module == NULL) { return ERROR_INVALID_ARGUMENT; } - memset(buffer, 0, file_name_size); - strcpy(buffer, module_name); - strcat(buffer, "-"); - strcat(buffer, test_name); + test_proc_file = m; + list_for_each_entry(tmp_test, &tmp_module->test_list, test_head) + { + result_code_e result = OK; + if(list_is_last(&tmp_test->test_head, &tmp_module->test_list)){ + output._skip_end = 0; + } + + result = tmp_test->test->test_function(&output); + if (result != OK) { + return result; + } + + output._skip_start = 1; + } + return OK; } diff --git a/src/kunity_proc_test_file_handler.h b/src/kunity_proc_test_file_handler.h index 9221bd6..968aa12 100644 --- a/src/kunity_proc_test_file_handler.h +++ b/src/kunity_proc_test_file_handler.h @@ -18,9 +18,7 @@ extern "C" { //{ function region -extern result_code_e create_proc_test_file(/* in */ const ptr_test_list_item_s list_item); - -extern result_code_e set_proc_test_root_folder(/* in */ struct proc_dir_entry * folder); +extern result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry * parent, /* in */const ptr_test_list_s test_list); //} diff --git a/src/kunity_test_finder.c b/src/kunity_test_finder.c index 54323c7..c4e5b91 100644 --- a/src/kunity_test_finder.c +++ b/src/kunity_test_finder.c @@ -41,14 +41,20 @@ static result_code_e create_test_list_item(/* in */ const ptr_test_s test, /* ou static result_code_e create_test_list(/* out */ ptr_test_list_s* test_list_location); +static result_code_e create_test_module_list_item(/* in */ const struct module* module, /* out */ ptr_test_module_list_item_s* test_module_list_item_location); + static result_code_e destroy_test(/* in */ ptr_test_s* test_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 destroy_test_module(/* in */ const ptr_test_module_list_item_s test_module_item); + +static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item, /* in */ ptr_test_list_s test_list, /* in */ struct module* module); static int find_test_for_each(void* data, const char* namebuf, struct module* module, unsigned long address); +static result_code_e _add_test_list_item(/* in */ ptr_test_list_item_s test_item, /* in */ ptr_test_module_list_item_s test_module); + //} //{ global variabel implements region @@ -61,6 +67,8 @@ static const size_t sizeof_test = sizeof(test_s); static const size_t sizeof_test_list_item = sizeof(test_list_item_s); +static const size_t sizeof_test_module_list_item = sizeof(test_module_list_item_s); + static const size_t sizeof_test_list = sizeof(test_list_s); //} @@ -85,26 +93,6 @@ 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 @@ -126,7 +114,6 @@ static result_code_e create_test(/* in */ const char* name, /* in */ const char* } tmp_test->name = name; - tmp_test->modul_name = module_name; tmp_test->test_function = test_function; *test_location = tmp_test; return OK; @@ -149,11 +136,34 @@ 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; + INIT_LIST_HEAD(&tmp_test_item->test_head); *test_list_item_location = tmp_test_item; return OK; } +static result_code_e create_test_module_list_item(/* in */ const struct module* module, /* out */ ptr_test_module_list_item_s* test_module_list_item_location) +{ + ptr_test_module_list_item_s tmp_test_module_item = NULL; + if (test_module_list_item_location == NULL) { + return ERROR_NULL_ARGUMENT; + } + + if (*test_module_list_item_location != NULL) { + return ERROR_INVALID_ARGUMENT; + } + + tmp_test_module_item = kmalloc(sizeof_test_module_list_item, GFP_KERNEL); + if (tmp_test_module_item == NULL) { + return ERROR_INVALID_OPERATION; + } + + tmp_test_module_item->test_module = module; + INIT_LIST_HEAD(&tmp_test_module_item->test_module_head); + INIT_LIST_HEAD(&tmp_test_module_item->test_list); + *test_module_list_item_location = tmp_test_module_item; + return OK; +} + static result_code_e create_test_list(/* out */ ptr_test_list_s* test_list_location) { ptr_test_list_s tmp_list = NULL; @@ -170,8 +180,7 @@ static result_code_e create_test_list(/* out */ ptr_test_list_s* test_list_locat return ERROR_INVALID_OPERATION; } - tmp_list->count = 0; - tmp_list->head = NULL; + INIT_LIST_HEAD(&tmp_list->test_module_list); *test_list_location = tmp_list; return OK; } @@ -182,7 +191,7 @@ static result_code_e destroy_test(/* in */ ptr_test_s* test_location) return ERROR_NULL_ARGUMENT; } - kfree(*test_location); + kzfree(*test_location); *test_location = NULL; return OK; } @@ -193,37 +202,68 @@ static result_code_e destroy_test_list_item(/* in */ const ptr_test_list_item_s return ERROR_NULL_ARGUMENT; } - test_list_item->next = NULL; destroy_test(&test_list_item->test); - kfree(test_list_item); + kzfree(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; if (test_list_location == NULL || *test_list_location == NULL) { return ERROR_NULL_ARGUMENT; } tmp_list = *test_list_location; - iterate_test_list(tmp_list, destroy_test_list_item); - tmp_list->head = NULL; - kfree(tmp_list); + while (!list_empty(&tmp_list->test_module_list)) { + result_code_e result = OK; + ptr_test_module_list_item_s module = list_entry(tmp_list->test_module_list.next, test_module_list_item_s, test_module_head); + list_del(&module->test_module_head); + result = destroy_test_module(module); + if (result != OK) { + return result; + } + } + + kzfree(tmp_list); *test_list_location = NULL; return OK; } -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_module_list_item_s test_module) { + if (test_item == NULL || test_module == NULL) { + return ERROR_NULL_ARGUMENT; + } + + list_add(&test_item->test_head, &test_module->test_list); + return OK; +} + +static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item, /* in */ ptr_test_list_s test_list, /* in */ struct module* module) +{ + ptr_test_module_list_item_s it = NULL; if (test_item == NULL || test_list == NULL) { return ERROR_NULL_ARGUMENT; } - test_list->count++; - test_item->next = test_list->head; - test_list->head = test_item; - return OK; + list_for_each_entry(it, &test_list->test_module_list, test_module_head) + { + if (it->test_module != module) { + continue; + } + + return _add_test_list_item(test_item, it); + } + + it = NULL; + if (create_test_module_list_item(module, &it) != OK) { + return ERROR_INVALID_OPERATION; + } + + list_add(&it->test_module_head, &test_list->test_module_list); + return _add_test_list_item(test_item, it); } static int find_test_for_each(void* data, const char* namebuf, struct module* module, unsigned long address) @@ -254,11 +294,31 @@ static int find_test_for_each(void* data, const char* namebuf, struct module* mo return 0; } - if (add_test_list_item(test_item, query->result_list) != OK) { + if (add_test_list_item(test_item, query->result_list, module) != OK) { destroy_test_list_item(test_item); } return 0; } +static result_code_e destroy_test_module(/* in */ const ptr_test_module_list_item_s test_module_item) +{ + + if (test_module_item == NULL) { + return ERROR_NULL_ARGUMENT; + } + + while (!list_empty(&test_module_item->test_list)) { + result_code_e result = OK; + ptr_test_list_item_s test_item = list_entry(test_module_item->test_list.next, test_list_item_s, test_head); + list_del(&test_item->test_head); + result = destroy_test_list_item(test_item); + if (result != OK) { + return result; + } + } + + kzfree(test_module_item); + return OK; +} //} diff --git a/src/kunity_test_finder.h b/src/kunity_test_finder.h index 1f2decd..ff1f416 100644 --- a/src/kunity_test_finder.h +++ b/src/kunity_test_finder.h @@ -18,7 +18,6 @@ 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 0bf0300..70ac033 100644 --- a/src/kunity_test_finder_t.h +++ b/src/kunity_test_finder_t.h @@ -4,6 +4,8 @@ //{ global include region #include +#include +#include #include //} @@ -39,13 +41,19 @@ #pragma pack(pop) typedef struct test_list_item_sTag { + struct list_head test_head; ptr_test_s test; - struct test_list_item_sTag* next; } test_list_item_s, *ptr_test_list_item_s; + +typedef struct test_module_list_item_sTag { + struct list_head test_module_head; + const struct module * test_module; + struct list_head test_list; +} test_module_list_item_s, *ptr_test_module_list_item_s; + typedef struct test_list_sTag { - size_t count; - ptr_test_list_item_s head; + struct list_head test_module_list; } test_list_s, *ptr_test_list_s; typedef struct test_query_sTag { @@ -56,6 +64,8 @@ typedef struct test_query_sTag { typedef result_code_e (*test_list_iterator) (/* in */ const ptr_test_list_item_s); +typedef result_code_e (*test_module_list_iterator) (/* in */ const ptr_test_module_list_item_s); + //} #endif // KUNITY_TEST_FINDER_T_H diff --git a/src/runner_module.c b/src/runner_module.c index 2a69094..808ef51 100644 --- a/src/runner_module.c +++ b/src/runner_module.c @@ -72,8 +72,7 @@ static void init_tests(struct work_struct* work) return; } - set_proc_test_root_folder(proc_test_root); - iterate_test_list(query.result_list, &create_proc_test_file); + create_proc_test_structure(proc_test_root, query.result_list); } static int kunity_init() diff --git a/test/src/kunity_proc_test_file_handler_tests.c b/test/src/kunity_proc_test_file_handler_tests.c index 4870f83..ba32960 100644 --- a/test/src/kunity_proc_test_file_handler_tests.c +++ b/test/src/kunity_proc_test_file_handler_tests.c @@ -8,36 +8,25 @@ KUNITY_TEST(create_proc_test_file_null_argument) { - TEST_ASSERT_EQUAL(ERROR_NULL_ARGUMENT, create_proc_test_file(NULL)); + TEST_ASSERT_EQUAL(ERROR_NULL_ARGUMENT, create_proc_test_structure(NULL,NULL)); } -KUNITY_TEST(create_proc_test_file_invalid_argument) -{ - test_list_item_s test_item; - test_item.test = NULL; - TEST_ASSERT_EQUAL(ERROR_INVALID_ARGUMENT, create_proc_test_file(&test_item)); -} - - -KUNITY_TEST(create_proc_test_file_invalid_operation_null_names) -{ - test_s test; - test_list_item_s test_item; - test.modul_name = NULL; - test.name = NULL; - test.test_function = NULL; - - test_item.test = &test; - TEST_ASSERT_EQUAL(ERROR_INVALID_OPERATION, create_proc_test_file(&test_item)); -} - KUNITY_TEST(create_proc_test_file_ok) { test_s test; + + test_list_s list; + test_module_list_item_s module_item; test_list_item_s test_item; struct proc_dir_entry* test_root = proc_mkdir("test_kunity_test_root", NULL); - test.modul_name = "fake_test_module"; + module_item.test_module = THIS_MODULE; + INIT_LIST_HEAD(&test_item.test_head); + INIT_LIST_HEAD(&list.test_module_list); + INIT_LIST_HEAD(&module_item.test_module_head); + INIT_LIST_HEAD(&module_item.test_list); + list_add(&test_item.test_head, &module_item.test_list); + list_add(&module_item.test_module_head, &list.test_module_list); test.name = "fake_test_function"; test.test_function = NULL; test_item.test = &test; @@ -45,7 +34,6 @@ KUNITY_TEST(create_proc_test_file_ok) TEST_FAIL_MESSAGE("could not create \"test_kunity_test_root proc\" folder"); } - set_proc_test_root_folder(test_root); - TEST_ASSERT_EQUAL(OK, create_proc_test_file(&test_item)); + TEST_ASSERT_EQUAL(OK, create_proc_test_structure(test_root, &list)); proc_remove(test_root); } diff --git a/test/src/kunity_test_finder_tests.c b/test/src/kunity_test_finder_tests.c index 2cb95ce..0ada885 100644 --- a/test/src/kunity_test_finder_tests.c +++ b/test/src/kunity_test_finder_tests.c @@ -4,7 +4,7 @@ #include -result_code_e kunity_module_runner_fake_test_function_ok(const ptr_output_functions_s output) +result_code_e kunity_module_runner_fake_test_function_ok(const ptr_test_session_control_block_s output) { return OK; } @@ -15,10 +15,9 @@ static result_code_e assert_test_item(/* in */ const ptr_test_list_item_s test_l { TEST_ASSERT_NOT_EQUAL(NULL, test_list_item); TEST_ASSERT_NOT_EQUAL(NULL, test_list_item->test); - TEST_ASSERT_NOT_EQUAL(NULL, test_list_item->test->modul_name); TEST_ASSERT_NOT_EQUAL(NULL, test_list_item->test->name); TEST_ASSERT_NOT_EQUAL(NULL, test_list_item->test->test_function); - tmp_list_counter--; + tmp_list_counter++; return OK; } @@ -38,27 +37,38 @@ KUNITY_TEST(test_find_test_invalid_argument) KUNITY_TEST(test_find_test_found) { + ptr_test_module_list_item_s module = NULL; + ptr_test_list_item_s test = NULL; test_query_s query ={ "kunity_module_runner_fake_test_function_ok", THIS_MODULE->name, NULL}; TEST_ASSERT_EQUAL(OK, find_tests(&query)); TEST_ASSERT_NOT_NULL(query.result_list); - TEST_ASSERT_EQUAL(1, query.result_list->count); - TEST_ASSERT_NOT_NULL(query.result_list->head) - TEST_ASSERT_NOT_NULL(query.result_list->head->test) - TEST_ASSERT_EQUAL_STRING("test_kunity_test_runner_module", query.result_list->head->test->modul_name); - TEST_ASSERT_EQUAL_STRING("kunity_module_runner_fake_test_function_ok", query.result_list->head->test->name); - TEST_ASSERT_EQUAL_PTR(&kunity_module_runner_fake_test_function_ok, query.result_list->head->test->test_function); + + module = list_first_entry(&query.result_list->test_module_list, test_module_list_item_s, test_module_head); + TEST_ASSERT_NOT_NULL(module); + test = list_first_entry(&module->test_list, test_list_item_s, test_head); + TEST_ASSERT_NOT_NULL(test); + TEST_ASSERT_EQUAL_STRING("kunity_module_runner_fake_test_function_ok", test->test->name); + TEST_ASSERT_EQUAL_PTR(&kunity_module_runner_fake_test_function_ok, test->test->test_function); } KUNITY_TEST(test_find_tests_found) { + ptr_test_module_list_item_s module = NULL; + ptr_test_list_item_s test = NULL; test_query_s query ={ KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*", NULL}; TEST_ASSERT_EQUAL(OK, find_tests(&query)); TEST_ASSERT_NOT_NULL (query.result_list); - TEST_ASSERT_GREATER_OR_EQUAL(1, query.result_list->count); - tmp_list_counter = query.result_list->count; - TEST_ASSERT_EQUAL(OK, iterate_test_list(query.result_list, assert_test_item)); - TEST_ASSERT_EQUAL(0, tmp_list_counter); + TEST_ASSERT_FALSE( list_empty(&query.result_list->test_module_list)) + module = list_first_entry(&query.result_list->test_module_list, test_module_list_item_s, test_module_head); + TEST_ASSERT_FALSE( list_empty(&module->test_list)) + tmp_list_counter = 0; + list_for_each_entry(test, &module->test_list, test_head) + { + assert_test_item(test); + } + + TEST_ASSERT_GREATER_OR_EQUAL(1, tmp_list_counter); }