group test function by module
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <kunity_t.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/slab.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
//}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
//}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
//{ global include region
|
||||
|
||||
#include <kunity_t.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
//}
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user