13 Commits

Author SHA1 Message Date
stubbfel
ed9d692d11 group test function by module 2018-03-31 01:08:29 +02:00
stubbfel
eb96de3b5f add proc file tests 2018-03-28 16:19:23 +02:00
stubbfel
7d3f2a8beb add new submodules and nix build env 2018-03-28 16:18:44 +02:00
stubbfel
e5b5e71af5 rm submodule 2018-03-08 21:57:53 +01:00
stubbfel
c80d2a7d41 fix pointer asserts 2018-03-02 00:35:08 +01:00
stubbfel
66af091b0f update KUnity 2018-03-02 00:34:49 +01:00
stubbfel
185bf91288 update KUnity 2018-03-01 23:33:14 +01:00
stubbfel
dceb0a685e switch submodule url form gitlab to gitea 2018-03-01 23:33:01 +01:00
stubbfel
e953a7cefb write test_found tests 2018-03-01 23:22:40 +01:00
stubbfel
4f7c91677e spilt find_tests and create_test_proc_files, add workquue for loading tests 2018-03-01 23:22:04 +01:00
stubbfel
d312f88cba update kunity and use new add_module function 2018-02-16 00:12:09 +01:00
stubbfel
da13097d85 update kunity and update cmake 2018-02-15 23:19:02 +01:00
stubbfel
2ae0093171 update kunity runner 2018-02-15 20:51:01 +01:00
12 changed files with 197 additions and 170 deletions

8
.gitmodules vendored
View File

@@ -1,8 +0,0 @@
[submodule "dev-utility/CMake-Module/BuildKernelModule"]
path = dev-utility/CMake-Module/BuildKernelModule
url = ../CMake-Module-KernelModuleBuilder.git
branch = master
[submodule "lib/KUnity"]
path = lib/KUnity
url = ../KUnity-Core.git
branch = master

7
Kbuild
View File

@@ -1,7 +0,0 @@
obj-m += kunity_test_runner_module.o
kunity_test_runner_module-objs += src/kunity_proc_test_file_handler.o
kunity_test_runner_module-objs += src/kunity_test_finder.o
kunity_test_runner_module-objs += src/runner_module.o
ccflags-y += -I${PWD}/src
ccflags-y += -I${PWD}/lib/KUnity/src

View File

@@ -1,45 +0,0 @@
# Kunity test runner module
The Kunity test runner runs any kunity tests (see [KUnity-Core](https://github.com/stubbfel/KUnity-Core)) by a kernel module.
This module search for test function in the symbol table of the kernel space (https://www.linux.com/learn/kernel-newbie-corner-kernel-symbols-whats-available-your-module-what-isnt) and made them runable for the userspace (by proc files).
## proc file struce
```plain
+ /proc/kunity_test
+ <modulename>
- <modulename> -> read of this file, will be run all test case of this module
+ single_tests
- <test_name> -> read of this file, will be run the specific test case
```
## building module
### cmake
``` bash
mkdir build
cd build
cmake ../
# cmake -DKERNEL_DIR=<path/to/kernel/module/build> ../
make
#load module by "insmod kunity_test_runner_module/kunity_test_runner_module.ko"
```
By default the `/lib/modules/${CMAKE_SYSTEM_VERSION}/build` path is use for the kernel build path. This path can be change by using the `KERNEL_DIR` option.
### KBuild
```bash
make -C /lib/modules/<KernelVersion>/build M=${PWD} modules KBUILD_EXTRA_SYMBOLS=${PWD}/Module.symvers
#load module by "insmod kunity_test_runner_module.ko"
```
## execution
simple use `cat` on the proc file :) like : `cat /proc/kunity_test/my_module/single_tests/my_first_module_test`
## module parameter
* proc_test_root_folder_name - The name of the proc folder, which will contains the test proc files. (Default is "kunity_test")
* test_function_filter - a filter option for test function names, which the runner is looking for. (Default is "kunity_test_*")
* module_filter - a filter option for modules, which the runner is looking for test functions. (Default is * -> search in all modules)

Submodule dev-utility/CMake-Module/BuildKernelModule updated: 70e9c0eb3b...fc86d1e5f7

Submodule lib/KUnity updated: 45ba80e18a...30c7c93ef4

View File

@@ -10,22 +10,45 @@
#include <linux/string.h>
//}
//{ local function prototypes region
static int proc_test_file_open(/* in */ struct inode* inode, /* in */ struct file* file);
static int proc_test_file_show(/* in */ struct seq_file* m, /* in */ void* v);
static int proc_test_module_open(/* in */ struct inode* inode, /* in */ struct file* file);
static int proc_test_module_show(/* in */ struct seq_file* m, /* in */ void* v);
static void put_seq_char(/* in */ char letter);
//{ local include region
//}
//{ local variables region
//{ local define region
//}
//{ 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 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);
//}
//{ global var implements region
//}
//{ local var implements region
static const struct file_operations proc_test_file_ops = {
.owner = THIS_MODULE,
@@ -49,7 +72,7 @@ static struct seq_file* test_proc_file;
//{ global function implements region
result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry* parent, /* in */ const ptr_test_list_s test_list)
result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry * parent, /* in */const ptr_test_list_s test_list)
{
ptr_test_module_list_item_s module = NULL;
result_code_e result = OK;
@@ -70,61 +93,64 @@ result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry* parent,
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;
return ERROR_INVALID_OPERATION +1;
}
}
}
return result;
}
//}
//{ local function implements region
static void put_seq_char(/* in */ char letter)
static void put_seq_char(char letter)
{
seq_putc(test_proc_file, letter);
}
static int proc_test_file_open(/* in */ struct inode* inode, /* in */ struct file* file)
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(/* in */ struct inode* inode, /* in */ struct file* file)
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(/* in */ struct seq_file* seqfile, /* in */ void* data)
static int proc_test_file_show(struct seq_file* m, void* v)
{
test_session_control_block_s output = { put_seq_char, 0, 0 };
ptr_test_s tmp_test = PDE_DATA(file_inode(seqfile->file));
ptr_test_s tmp_test = PDE_DATA(file_inode(m->file));
if (tmp_test == NULL) {
return ERROR_INVALID_ARGUMENT;
}
test_proc_file = seqfile;
test_proc_file = m;
return tmp_test->test_function(&output);
}
static int proc_test_module_show(/* in */ struct seq_file* seqfile, /* in */ void* data)
static int proc_test_module_show(struct seq_file* m, void* v)
{
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(seqfile->file));
ptr_test_module_list_item_s tmp_module = PDE_DATA(file_inode(m->file));
if (tmp_module == NULL) {
return ERROR_INVALID_ARGUMENT;
}
test_proc_file = seqfile;
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)) {
if(list_is_last(&tmp_test->test_head, &tmp_module->test_list)){
output._skip_end = 0;
}

View File

@@ -1,6 +1,6 @@
#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
#include <linux/proc_fs.h>
@@ -12,10 +12,17 @@
//}
#ifdef __cplusplus
extern "C" {
#endif
//{ function region
extern result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry* parent, /* in */ const ptr_test_list_s test_list);
extern result_code_e create_proc_test_structure(/* in */ struct proc_dir_entry * parent, /* in */const ptr_test_list_s test_list);
//}
#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

@@ -9,7 +9,31 @@
//}
//{ local function prototypes region
//{ local include region
//}
//{ local define region
//}
//{ local enum region
//}
//{ local typedef region
//}
//{local struct region
#pragma pack(push, 1)
#pragma pack(pop)
//}
//{ local function prototype region
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);
@@ -27,13 +51,17 @@ static result_code_e destroy_test_module(/* in */ const ptr_test_module_list_ite
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(/* in */ void* data, /* in */ const char* namebuf, /* in */ struct module* module, /* in */ unsigned long address);
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);
//}
//{ local variables region
//{ global variabel implements region
//}
//{ local variabel implements region
static const size_t sizeof_test = sizeof(test_s);
@@ -238,7 +266,7 @@ static result_code_e add_test_list_item(/* in */ ptr_test_list_item_s test_item,
return _add_test_list_item(test_item, it);
}
static int find_test_for_each(/* in */ void* data, /* in */ const char* namebuf, /* in */ struct module* module, /* in */ 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;

View File

@@ -1,6 +1,16 @@
#ifndef KUNITY_TEST_FINDER_H
#define KUNITY_TEST_FINDER_H
#include "kunity_test_finder_t.h"
//{ global include region
//}
//{ local include region
//}
#ifdef __cplusplus
extern "C" {
#endif
//{ function region
@@ -10,4 +20,7 @@ extern result_code_e destroy_test_list(/* in */ ptr_test_list_s* test_list_locat
//}
#ifdef __cplusplus
}
#endif
#endif // KUNITY_TEST_FINDER_H

View File

@@ -10,6 +10,10 @@
//}
//{ local include region
//}
//{ define region
#ifndef KUNITY_DEFAULT_TEST_NAME_FITER
#define KUNITY_DEFAULT_TEST_NAME_FITER KUNITY_DEFAULT_TEST_NAME_PREFIX*
@@ -22,6 +26,14 @@
#endif
//}
//{ enum region
//}
//{ typedef region
//}
//{ struct region
#pragma pack(push, 1)
@@ -33,10 +45,11 @@ typedef struct test_list_item_sTag {
ptr_test_s test;
} 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;
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 {
@@ -49,9 +62,9 @@ typedef struct test_query_sTag {
ptr_test_list_s result_list;
} test_query_s, *ptr_test_query_s;
typedef result_code_e (*test_list_iterator)(/* in */ const ptr_test_list_item_s);
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);
typedef result_code_e (*test_module_list_iterator) (/* in */ const ptr_test_module_list_item_s);
//}

View File

@@ -2,7 +2,6 @@
#include <kunity_t.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
//}
@@ -14,101 +13,71 @@
//}
//{ local typedef region
typedef struct runner_control_block_sTag {
const char* proc_folder_name;
struct proc_dir_entry* proc_test_root;
test_query_s query;
} runner_control_block_s, *ptr_runner_control_blocks;
//{ local define region
//}
//{ local function prototypes region
//{ local enum region
static void init_tests(/* in */ struct work_struct* work);
//}
static void clean_tests(void);
//{ local typedef region
//}
//{local struct region
#pragma pack(push, 1)
#pragma pack(pop)
//}
//{ local function prototype region
static void init_tests(struct work_struct* work);
static int kunity_init(void);
static void kunity_exit(void);
//}
//{ local variables region
//{ global variabel implements region
//}
//{ local variabel implements region
static struct workqueue_struct* queue;
DECLARE_WORK(work, init_tests);
static char* module_filter = "*";
module_param(module_filter, charp, 0);
MODULE_PARM_DESC(module_filter, "a filter option for modules, which the runner is looking for test functions. (Default is \"*\"");
static test_query_s query = { KUNITY_DEFAULT_TEST_NAME_FITER_STR, "*" };
static char* test_function_filter = KUNITY_DEFAULT_TEST_NAME_FITER_STR;
module_param(test_function_filter, charp, 0);
MODULE_PARM_DESC(test_function_filter, "a filter option for test function names, which the runner is looking for. (Default is \"kunity_test_*\"");
static struct proc_dir_entry* proc_test_root = NULL;
//}
static char* proc_test_root_folder_name = "kunity_test";
module_param(proc_test_root_folder_name, charp, 0);
MODULE_PARM_DESC(proc_test_root_folder_name, "the name of the proc folder, which will contains the test proc files. (Default is \"kunity_test\"");
static const size_t sizeof_runner_control_block = sizeof(runner_control_block_s);
static runner_control_block_s* rcb = NULL;
//{ global function implements region
//}
//{ local function implements region
static void clean_tests()
static void init_tests(struct work_struct* work)
{
destroy_test_list(&rcb->query.result_list);
if (rcb->proc_test_root != NULL) {
proc_remove(rcb->proc_test_root);
}
kzfree(rcb);
}
static void init_tests(/* in */ struct work_struct* work)
{
result_code_e result = OK;
if (rcb != NULL) {
clean_tests();
}
rcb = kzalloc(sizeof(runner_control_block_s), GFP_KERNEL);
rcb->query.test_function_filter = test_function_filter;
rcb->query.module_filter = module_filter;
rcb->proc_folder_name = proc_test_root_folder_name;
rcb->proc_test_root = proc_mkdir(rcb->proc_folder_name, NULL);
if (rcb->proc_test_root == NULL) {
pr_warning("cant create proc folder %s", rcb->proc_folder_name);
pr_info("init tests");
proc_test_root = proc_mkdir("kunity_test", NULL);
if (proc_test_root == NULL || find_tests(&query) != OK) {
return;
}
result = find_tests(&rcb->query);
if (result == OK) {
result = create_proc_test_structure(rcb->proc_test_root, rcb->query.result_list);
if (result == OK) {
pr_info("successful created tests with following options:");
} else {
pr_info("test creation failed with error code %u, following options was used:", result);
}
} else {
pr_info("could not find any test with follwing options:");
}
pr_info("\tmodule_filter = \"%s\"", rcb->query.module_filter);
pr_info("\ttest_function_filter = \"%s\"", rcb->query.test_function_filter);
pr_info("\tproc_folder_name = \"%s\"", rcb->proc_folder_name);
create_proc_test_structure(proc_test_root, query.result_list);
}
static int kunity_init()
{
pr_info("init %s", THIS_MODULE->name);
pr_info("init kunity_test_runner_module");
queue = create_workqueue("test_runner_work_queue");
if (queue == NULL) {
return -ERROR_INVALID_OPERATION;
@@ -119,17 +88,14 @@ static int kunity_init()
static void kunity_exit()
{
pr_info("exit %s", THIS_MODULE->name);
pr_info("exit kunity_test_runner_module");
if (queue == NULL) {
return;
}
destroy_workqueue(queue);
if (rcb == NULL) {
return;
}
clean_tests();
destroy_test_list(&query.result_list);
proc_remove(proc_test_root);
}
//}
@@ -138,4 +104,4 @@ module_init(kunity_init);
module_exit(kunity_exit);
MODULE_AUTHOR("Felix Stubbe");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("run kunity tests");
MODULE_DESCRIPTION("run tests");