add proc file tests

This commit is contained in:
stubbfel
2018-03-28 16:19:23 +02:00
parent 7d3f2a8beb
commit eb96de3b5f
5 changed files with 73 additions and 10 deletions

View File

@@ -4,7 +4,6 @@
#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>
@@ -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;
}

View File

@@ -3,6 +3,8 @@
#include "kunity_proc_test_file_handler_t.h"
//{ global include region
#include <linux/proc_fs.h>
//}
//{ 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

View File

@@ -2,7 +2,6 @@
#include <kunity_t.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/workqueue.h>
//}
@@ -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);
}
//}

View File

@@ -0,0 +1,51 @@
#include <kunity.h>
#include <kunity_proc_test_file_handler.h>
#include <linux/module.h>
#include <linux/string.h>
//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);
}