update kunity runner

This commit is contained in:
stubbfel
2018-02-15 20:51:01 +01:00
parent 6b78d8ec3d
commit 2ae0093171
10 changed files with 322 additions and 142 deletions

View File

@@ -39,3 +39,13 @@ file(GLOB test_modules_includes
set(test_modules_definitions -DUNITY_INCLUDE_CONFIG_H)
add_module("test_${module_name}" "${module_test_files}" "${test_modules_includes}" "${test_modules_definitions}" "${KERNEL_DIR}")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
get_property(defs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
foreach(def ${defs})
message(STATUS "def='${def}'")
endforeach()

View File

@@ -0,0 +1,149 @@
#include "kunity_proc_test_file_handler.h"
//{ global include region
#include <kunity_t.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/string.h>
//}
//{ local include region
//}
//{ local define region
#ifndef MAX_FILE_NAME_LEN
#define MAX_FILE_NAME_LEN 1024
#endif
//}
//{ local enum region
//}
//{ local typedef region
//}
//{local struct region
#pragma pack(push, 1)
#pragma pack(pop)
//}
//{ local function prototype region
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 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);
//}
//{ global var implements region
struct proc_dir_entry* proc_dir;
//}
//{ local var implements region
static const struct file_operations proc_test_file_ops = {
.owner = THIS_MODULE,
.open = proc_test_file_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
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)
{
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) {
return ERROR_NULL_ARGUMENT;
}
test = list_item->test;
if (test == NULL) {
return ERROR_INVALID_ARGUMENT;
}
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;
}
//}
//{ local function implements region
static void put_seq_char(char letter)
{
seq_putc(test_proc_file, letter);
}
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_file_show(struct seq_file* m, void* v)
{
output_functions_s output = { put_seq_char };
ptr_test_s tmp_test = PDE_DATA(file_inode(m->file));
if (tmp_test == NULL) {
return ERROR_INVALID_ARGUMENT;
}
test_proc_file = m;
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)
{
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) {
return ERROR_INVALID_ARGUMENT;
}
memset(buffer, 0, file_name_size);
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;
}
//}

View File

@@ -0,0 +1,26 @@
#ifndef KUNITY_PROC_TEST_FILE_HANDLER_H
#define KUNITY_PROC_TEST_FILE_HANDLER_H
#include "kunity_proc_test_file_handler_t.h"
//{ global include region
//}
//{ local include region
#include "kunity_test_finder_t.h"
//}
#ifdef __cplusplus
extern "C" {
#endif
//{ function region
extern result_code_e create_proc_test_file(/* inout */ ptr_test_list_item_s list_item);
//}
#ifdef __cplusplus
}
#endif
#endif // KUNITY_PROC_TEST_FILE_HANDLER_H

View File

@@ -0,0 +1,34 @@
#ifndef KUNITY_PROC_TEST_FILE_HANDLER_T_H
#define KUNITY_PROC_TEST_FILE_HANDLER_T_H
//{ global include region
//}
//{ local include region
//}
//{ define region
//}
//{ enum region
//}
//{ typedef region
//}
//{ struct region
#pragma pack(push, 1)
#pragma pack(pop)
//}
#endif // KUNITY_PROC_TEST_FILE_HANDLER_T_H

View File

@@ -11,24 +11,22 @@
//{ local include region
//}
#include "kunity_proc_test_file_handler.h"
//}
//{ local define region
//}
//{ local enum region
//}
//{ local typedef region
//}
//{local struct region
#pragma pack(push, 1)
@@ -37,22 +35,21 @@
//}
//{ local function prototype region
static result_code_e create_test(/* in */ const char * name, /* in */ const char * module_name, /* in */ const test_function_ptr test_function, /* out */ ptr_test_s * test_location);
static result_code_e create_test(/* in */ const char* name, /* in */ const char* module_name, /* in */ const kunity_test_function_ptr test_function, /* out */ ptr_test_s* test_location);
static result_code_e create_test_list_item(/* in */ const ptr_test_s test, /* out */ ptr_test_list_item_s * test_list_item_location);
static result_code_e create_test_list_item(/* in */ const ptr_test_s test, /* out */ ptr_test_list_item_s* test_list_item_location);
static result_code_e create_test_list(/* out */ ptr_test_list_s * test_list_location);
static result_code_e create_test_list(/* out */ ptr_test_list_s* test_list_location);
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 */ ptr_test_list_item_s* test_list_item_location, /* out */ ptr_test_list_item_s* next_test_item_location);
static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item, /* in */ ptr_test_list_s test_list);
static int find_test_for_each(void *data, const char *namebuf, struct module *module, unsigned long address);
static int find_test_for_each(void* data, const char* namebuf, struct module* module, unsigned long address);
//}
@@ -60,14 +57,13 @@ static int find_test_for_each(void *data, const char *namebuf, struct module *mo
//}
//{ local variabel implements region
static const size_t sizeof_test = sizeof (test_s);
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_list_item = sizeof(test_list_item_s);
static const size_t sizeof_test_list = sizeof (test_list_s);
static const size_t sizeof_test_list = sizeof(test_list_s);
//}
@@ -75,18 +71,15 @@ static const size_t sizeof_test_list = sizeof (test_list_s);
result_code_e find_tests(/* in */ const ptr_test_query_s query)
{
if (query == NULL)
{
return ERROR_NULL_ARGUMENT;
if (query == NULL) {
return ERROR_NULL_ARGUMENT;
}
if (create_test_list(&query->result_list) != OK)
{
if (create_test_list(&query->result_list) != OK) {
return ERROR_INVALID_ARGUMENT;
}
if(kallsyms_on_each_symbol(find_test_for_each, query) != 0)
{
if (kallsyms_on_each_symbol(find_test_for_each, query) != 0) {
destroy_test_list(&query->result_list);
return ERROR_INVALID_OPERATION;
}
@@ -95,86 +88,84 @@ result_code_e find_tests(/* in */ const ptr_test_query_s query)
}
//}
//{ local function implements region
static result_code_e create_test(/* in */ const char * name, /* in */ const char * module_name, /* in */ const test_function_ptr test_function, /* out */ ptr_test_s * test_location)
static result_code_e create_test(/* in */ const char* name, /* in */ const char* module_name, /* in */ const kunity_test_function_ptr test_function, /* out */ ptr_test_s* test_location)
{
ptr_test_s tmp_test = NULL;
if (name == NULL || module_name == NULL || test_function == NULL || test_location == NULL)
{
return ERROR_NULL_ARGUMENT;
if (name == NULL || module_name == NULL || test_function == NULL || test_location == NULL) {
return ERROR_NULL_ARGUMENT;
}
if (*test_location != NULL)
{
if (*test_location != NULL) {
return ERROR_INVALID_ARGUMENT;
}
tmp_test = kmalloc(sizeof_test, GFP_KERNEL);
if (tmp_test == NULL)
{
tmp_test = kmalloc(sizeof_test, GFP_KERNEL);
if (tmp_test == NULL) {
return ERROR_INVALID_OPERATION;
}
tmp_test->name = name;
tmp_test->modul_name = name;
tmp_test->modul_name = module_name;
tmp_test->test_function = test_function;
*test_location = tmp_test;
return OK;
}
static result_code_e create_test_list_item(/* in */ const ptr_test_s test, /* out */ ptr_test_list_item_s * test_list_item_location)
static result_code_e create_test_list_item(/* in */ const ptr_test_s test, /* out */ ptr_test_list_item_s* test_list_item_location)
{
ptr_test_list_item_s tmp_test_item = NULL;
if (test == NULL || test_list_item_location == NULL)
{
return ERROR_NULL_ARGUMENT;
if (test == NULL || test_list_item_location == NULL) {
return ERROR_NULL_ARGUMENT;
}
if (*test_list_item_location != NULL)
{
if (*test_list_item_location != NULL) {
return ERROR_INVALID_ARGUMENT;
}
tmp_test_item = kmalloc(sizeof_test_list_item, GFP_KERNEL);
if (tmp_test_item == NULL)
{
if (tmp_test_item == NULL) {
return ERROR_INVALID_OPERATION;
}
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;
}
static result_code_e create_test_list(/* out */ ptr_test_list_s * test_list_location)
static result_code_e create_test_list(/* out */ ptr_test_list_s* test_list_location)
{
ptr_test_list_s tmp_list = NULL;
if (test_list_location == NULL)
{
return ERROR_NULL_ARGUMENT;
if (test_list_location == NULL) {
return ERROR_NULL_ARGUMENT;
}
if (*test_list_location != NULL)
{
if (*test_list_location != NULL) {
return ERROR_INVALID_ARGUMENT;
}
tmp_list = kmalloc(sizeof_test_list, GFP_KERNEL);
if (tmp_list == NULL)
{
if (tmp_list == NULL) {
return ERROR_INVALID_OPERATION;
}
tmp_list->count = 0;
tmp_list->head = NULL;
*test_list_location = tmp_list;
return OK;
}
static result_code_e destroy_test(/* in */ ptr_test_s * test_location)
static result_code_e destroy_test(/* in */ ptr_test_s* test_location)
{
if (test_location == NULL || *test_location == NULL)
{
if (test_location == NULL || *test_location == NULL) {
return ERROR_NULL_ARGUMENT;
}
@@ -183,17 +174,15 @@ 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 */ ptr_test_list_item_s* test_list_item_location, /* out */ ptr_test_list_item_s* next_test_item_location)
{
ptr_test_list_item_s tmp_list_item = NULL;
if (test_list_item_location == NULL || *test_list_item_location == NULL)
{
if (test_list_item_location == NULL || *test_list_item_location == NULL) {
return ERROR_NULL_ARGUMENT;
}
tmp_list_item = *test_list_item_location;
if (next_test_item_location != NULL)
{
if (next_test_item_location != NULL) {
*next_test_item_location = tmp_list_item->next;
}
@@ -203,22 +192,19 @@ static result_code_e destroy_test_list_item(/* in */ ptr_test_list_item_s * test
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_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;
}
tmp_list = *test_list_location;
tmp_test_item = tmp_list->head;
while (tmp_test_item != NULL)
{
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)
{
if (destroy_test_list_item(&tmp_test_item, &tmp_next_test_item) != OK) {
break;
}
@@ -232,9 +218,8 @@ result_code_e destroy_test_list(/* in */ ptr_test_list_s * test_list_location)
static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item, /* in */ ptr_test_list_s test_list)
{
if(test_item == NULL || test_list == NULL)
{
return ERROR_NULL_ARGUMENT;
if (test_item == NULL || test_list == NULL) {
return ERROR_NULL_ARGUMENT;
}
test_list->count++;
@@ -243,41 +228,35 @@ static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item,
return OK;
}
static int find_test_for_each(void *data, const char *namebuf, struct module *module, unsigned long address)
static int find_test_for_each(void* data, const char* namebuf, struct module* module, unsigned long address)
{
ptr_test_query_s query = NULL;
ptr_test_s test = NULL;
ptr_test_list_item_s test_item = NULL;
const char * module_name= module == NULL ? "__KERNEL__" : module->name;
if (address ==0)
{
const char* module_name = module == NULL ? "__KERNEL__" : module->name;
if (address == 0) {
return 0;
}
query = (ptr_test_query_s)data;
if (glob_match(query->module_filter, module_name) == 0)
{
if (glob_match(query->module_filter, module_name) == 0) {
return 0;
}
if (glob_match(query->test_function_filter, namebuf) == 0)
{
if (glob_match(query->test_function_filter, namebuf) == 0) {
return 0;
}
if (create_test(namebuf, module_name, (test_function_ptr)address, &test) != OK)
{
if (create_test(namebuf, module_name, (kunity_test_function_ptr)address, &test) != OK) {
return 0;
}
if (create_test_list_item(test, &test_item) != OK)
{
if (create_test_list_item(test, &test_item) != OK) {
destroy_test(&test);
return 0;
}
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);
}

View File

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

View File

@@ -3,6 +3,7 @@
//{ global include region
#include <kunity_t.h>
#include <linux/types.h>
//}
@@ -11,29 +12,24 @@
//}
//{ define region
#ifndef KUNITY_DEFAULT_TEST_NAME_FITER
#define KUNITY_DEFAULT_TEST_NAME_FITER KUNITY_DEFAULT_TEST_NAME_PREFIX*
#endif
#ifndef KUNITY_DEFAULT_TEST_NAME_FITER_STR
#define STR(s) #s
#define XSTR(s) STR(s)
#define KUNITY_DEFAULT_TEST_NAME_FITER_STR XSTR(KUNITY_DEFAULT_TEST_NAME_FITER)
#endif
//}
//{ enum region
typedef enum result_code_eTag
{
OK,
ERROR_NULL_ARGUMENT,
ERROR_INVALID_ARGUMENT,
ERROR_INVALID_OPERATION
} result_code_e, *ptr_result_code_e;
//}
//{ typedef region
typedef void (*test_function_ptr) (void);
//}
//{ struct region
@@ -42,29 +38,19 @@ typedef void (*test_function_ptr) (void);
#pragma pack(pop)
typedef struct test_sTag
{
const char * name;
const char * modul_name;
test_function_ptr test_function;
} test_s, *ptr_test_s;
typedef struct test_list_item_sTag
{
typedef struct test_list_item_sTag {
ptr_test_s test;
struct test_list_item_sTag * next;
struct test_list_item_sTag* next;
} test_list_item_s, *ptr_test_list_item_s;
typedef struct test_list_sTag
{
typedef struct test_list_sTag {
size_t count;
ptr_test_list_item_s head;
} test_list_s, *ptr_test_list_s;
typedef struct test_query_sTag
{
const char * test_function_filter;
const char * module_filter;
typedef struct test_query_sTag {
const char* test_function_filter;
const char* module_filter;
ptr_test_list_s result_list;
} test_query_s, *ptr_test_query_s;

View File

@@ -1,7 +1,8 @@
//{ global include region
#include <linux/module.h>
#include <kunity_t.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
//}
@@ -11,22 +12,18 @@
//}
//{ local define region
//}
//{ local enum region
//}
//{ local typedef region
//}
//{local struct region
#pragma pack(push, 1)
@@ -43,42 +40,38 @@ static void kunity_exit(void);
//}
//{ global variabel implements region
extern struct proc_dir_entry * proc_dir;
//}
//{ local variabel implements region
static test_query_s query;
static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*"};
//}
//{ global function implements region
//}
//{ local function implements region
static int kunity_init()
{
pr_info("init kunity_test_runner_module");
find_tests(&query);
return 0;
proc_dir = proc_mkdir("kunity_test", NULL);
return -find_tests(&query);
}
static void kunity_exit()
{
pr_info("init kunity_test_runner_module");
destroy_test_list(&query.result_list);
proc_remove(proc_dir);
}
//}
module_init(kunity_init)
module_exit(kunity_exit)
module_init(kunity_init);
module_exit(kunity_exit);
MODULE_AUTHOR("Felix Stubbe");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("run tests");

View File

@@ -1,20 +1,23 @@
#include <linux/string.h>
#include <kunity.h>
#include <fff.h>
DEFINE_FFF_GLOBALS
#include <kunity_test_finder.h>
FAKE_VOID_FUNC(IO_MEM_WR8, int, int);
KUNITY_TEST(bar_test)
KUNITY_TEST(test_find_test_null_argument)
{
IO_MEM_WR8(1,0);
TEST_ASSERT_EQUAL_INT(1, IO_MEM_WR8_fake.call_count);
TEST_ASSERT_TRUE(1)
TEST_ASSERT_EQUAL(ERROR_NULL_ARGUMENT, find_tests(NULL));
}
KUNITY_TEST(test_find_test_invalid_argument)
{
test_list_s list;
test_query_s query ={ KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*", &list};
TEST_ASSERT_EQUAL(ERROR_INVALID_ARGUMENT, find_tests(&query));
}
KUNITY_TEST(test_find_test_found)
{
TEST_IGNORE();
}
void bar_test_2(void)
{
kunity_test_bar_test();
pr_info ("huhu");
}