diff --git a/src/kunity_proc_test_file_handler.c b/src/kunity_proc_test_file_handler.c index 977359e..8fb2708 100644 --- a/src/kunity_proc_test_file_handler.c +++ b/src/kunity_proc_test_file_handler.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -48,11 +47,13 @@ static result_code_e create_test_file_name(/* in */ const char* module_name, /* //} //{ global var implements region -struct proc_dir_entry* proc_dir; + //} //{ 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, @@ -61,12 +62,19 @@ static const struct file_operations proc_test_file_ops = { .release = single_release, }; -struct seq_file* test_proc_file; +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) +{ + 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]; @@ -141,8 +149,6 @@ static result_code_e create_test_file_name(/* in */ const char* module_name, /* strcpy(buffer, module_name); strcat(buffer, "-"); strcat(buffer, test_name); - - pr_info("%s\n%s\n%s\n", module_name, test_name, buffer); return OK; } diff --git a/src/kunity_proc_test_file_handler.h b/src/kunity_proc_test_file_handler.h index 6efff7f..9221bd6 100644 --- a/src/kunity_proc_test_file_handler.h +++ b/src/kunity_proc_test_file_handler.h @@ -3,6 +3,8 @@ #include "kunity_proc_test_file_handler_t.h" //{ global include region +#include + //} //{ local include region @@ -18,6 +20,8 @@ extern "C" { 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); + //} #ifdef __cplusplus diff --git a/src/runner_module.c b/src/runner_module.c index 3604491..2a69094 100644 --- a/src/runner_module.c +++ b/src/runner_module.c @@ -2,7 +2,6 @@ #include #include -#include #include //} @@ -44,7 +43,7 @@ static void kunity_exit(void); //{ global variabel implements region -extern struct proc_dir_entry* proc_dir; + //} @@ -55,6 +54,8 @@ static struct workqueue_struct* queue; DECLARE_WORK(work, init_tests); static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*" }; + +static struct proc_dir_entry* proc_test_root = NULL; //} //{ global function implements region @@ -66,11 +67,12 @@ static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*" }; 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) { + proc_test_root = proc_mkdir("kunity_test", NULL); + if (proc_test_root == NULL || find_tests(&query) != OK) { return; } + set_proc_test_root_folder(proc_test_root); iterate_test_list(query.result_list, &create_proc_test_file); } @@ -94,7 +96,7 @@ static void kunity_exit() destroy_workqueue(queue); destroy_test_list(&query.result_list); - proc_remove(proc_dir); + proc_remove(proc_test_root); } //} diff --git a/test/src/kunity_proc_test_file_handler_tests.c b/test/src/kunity_proc_test_file_handler_tests.c new file mode 100644 index 0000000..4870f83 --- /dev/null +++ b/test/src/kunity_proc_test_file_handler_tests.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + + +//extern result_code_e kunity_module_runner_fake_test_function_ok(const ptr_output_functions_s output); + +KUNITY_TEST(create_proc_test_file_null_argument) +{ + TEST_ASSERT_EQUAL(ERROR_NULL_ARGUMENT, create_proc_test_file(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_item_s test_item; + struct proc_dir_entry* test_root = proc_mkdir("test_kunity_test_root", NULL); + test.modul_name = "fake_test_module"; + test.name = "fake_test_function"; + test.test_function = NULL; + test_item.test = &test; + if (test_root == NULL) { + 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)); + proc_remove(test_root); +} diff --git a/test/src/test.c b/test/src/kunity_test_finder_tests.c similarity index 100% rename from test/src/test.c rename to test/src/kunity_test_finder_tests.c