update kunity

This commit is contained in:
stubbfel
2018-02-15 20:50:35 +01:00
parent 66f19afb8c
commit 52faaaff69
5 changed files with 142 additions and 42 deletions

View File

@@ -81,3 +81,12 @@ function(add_module module_name module_files module_include_dirs module_defs ker
SOURCES ${module_files}
COMMENT "Building Kernel Module ${module_name}")
endfunction()
#function(get_directory_definitions output_list)
#function(get_target_definitions output_list)
#function(get_directory_includes output_list)
#function(get_target_includes output_list)

View File

@@ -1,6 +1,7 @@
#include "kunity.h"
//{ global include region
#include <linux/slab.h>
#include <linux/string.h>
//}
@@ -8,58 +9,126 @@
//}
//{ local define region
//}
//{ local enum region
//}
//{ local typedef region
//}
//{local struct region
#pragma pack(push, 1)
#pragma pack(pop)
typedef struct string_builder_sTag {
size_t write_postion;
char buffer[KUNITY_LINE_SIZE];
} string_builder_s, ptr_string_builder_s;
//}
//{ local function prototype region
static void printk_put_char(char /* letter */);
static result_code_e set_test_output(/*in */ const ptr_output_functions_s output);
//}
//{ local global var region
static string_builder_s sb;
//}
//{ local var region
static output_functions_s prink_output = { printk_put_char };
static ptr_output_functions_s kunity_output = &prink_output;
static string_builder_s string_builder;
static size_t sizeof_output = sizeof(output_functions_s);
//}
//{ global function implements region
void putchark(/* in */ char a)
{
kunity_output->redirect_char(a);
}
result_code_e create_default_test_output(/* out*/ ptr_output_functions_s* output_location)
{
ptr_output_functions_s tmp_output = NULL;
if (output_location == NULL) {
return ERROR_NULL_ARGUMENT;
}
if (*output_location != NULL) {
return ERROR_INVALID_ARGUMENT;
}
tmp_output = kmalloc(sizeof_output, GFP_KERNEL);
if (tmp_output == NULL) {
return ERROR_INVALID_OPERATION;
}
*output_location = tmp_output;
return OK;
}
result_code_e run_unity_test(/* in */ const unity_test_function_ptr test_function, /* in */ const ptr_output_functions_s output)
{
result_code_e result;
if (output == NULL) {
return ERROR_NULL_ARGUMENT;
}
result = set_test_output(output);
if (result != OK) {
return result;
}
UNITY_BEGIN();
RUN_TEST(test_function);
UNITY_END();
return result;
}
result_code_e run_unity_printk_test(/* in */ const unity_test_function_ptr test_function)
{
return run_unity_test(test_function, &prink_output);
}
//}
//{ local function implements region
void putchark(char a)
static void printk_put_char(char letter)
{
if (a == '\n')
{
const char * c = (const char *)&sb.buffer[0];
if (letter == '\n') {
const char* c = (const char*)&string_builder.buffer[0];
printk(c);
sb.write_postion = 0;
memset(sb.buffer, 0, 1024);
string_builder.write_postion = 0;
memset(string_builder.buffer, 0, 1024);
return;
}
sb.buffer[sb.write_postion] = a;
sb.write_postion = (sb.write_postion + 1) % 1024;
string_builder.buffer[string_builder.write_postion] = letter;
string_builder.write_postion = (string_builder.write_postion + 1) % KUNITY_LINE_SIZE;
}
static result_code_e set_test_output(/* in */ const ptr_output_functions_s output)
{
if (output == NULL) {
return ERROR_NULL_ARGUMENT;
}
if (output->redirect_char == NULL) {
return ERROR_INVALID_ARGUMENT;
}
kunity_output = output;
return OK;
}
//}

View File

@@ -17,7 +17,13 @@ extern "C" {
//{ function region
extern void putchark(char a);
extern void putchark(/* in */ char a);
extern result_code_e create_default_test_output(/* out*/ ptr_output_functions_s* output_location);
extern result_code_e run_unity_test(/* in */ const unity_test_function_ptr test_function, /* in */ const ptr_output_functions_s output);
extern result_code_e run_unity_printk_test(/* in */ const unity_test_function_ptr test_function);
//}

View File

@@ -2,18 +2,15 @@
#define KUNITY_T_H
//{ global include region
#include <linux/types.h>
#ifndef KUNITY_TEST_RUNNER_APP
#include <linux/export.h>
#endif
#include <linux/types.h>
//}
//{ local include region
//}
//{ define region
#ifndef KUNITY_LINE_SIZE
@@ -31,41 +28,59 @@
#endif
#ifndef KUNITY_CREATE_TEST_NAME
#define JOIN(x,y) x ## y
#define CONCAT(x,y) JOIN(x,y)
#define JOIN(x, y) x##y
#define CONCAT(x, y) JOIN(x, y)
#define KUNITY_CREATE_TEST_NAME(function_name) CONCAT(KUNITY_DEFAULT_TEST_NAME_PREFIX, function_name)
#endif
#ifndef KUNITY_TEST
#define KUNITY_TEST(function_name) \
extern void KUNITY_CREATE_TEST_NAME(function_name) (void); \
extern result_code_e KUNITY_CREATE_TEST_NAME(function_name)(const ptr_output_functions_s output); \
static void function_name(void); \
\
result_code_e KUNITY_CREATE_TEST_NAME(function_name)(const ptr_output_functions_s output) \
{ \
return run_unity_test(function_name, output); \
} \
EXPORT_SYMBOL(KUNITY_CREATE_TEST_NAME(function_name)); \
void KUNITY_CREATE_TEST_NAME(function_name)()
\
static void function_name()
#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 (*redirect_char)(char a);
typedef void (*unity_test_function_ptr)(void);
//}
//{ struct region
#pragma pack(push, 1)
typedef struct string_builder_sTag
{
size_t write_postion;
char buffer[KUNITY_LINE_SIZE];
} string_builder_s, ptr_string_builder_s;
#pragma pack(pop)
typedef struct output_functions_sTag {
redirect_char redirect_char;
} output_functions_s, *ptr_output_functions_s;
typedef result_code_e (*kunity_test_function_ptr)(ptr_output_functions_s);
typedef struct test_sTag {
const char* name;
const char* modul_name;
kunity_test_function_ptr test_function;
} test_s, *ptr_test_s;
//}

View File

@@ -1,8 +1,9 @@
#ifndef UNITY_CONFIG_H
#define UNITY_CONFIG_H
#include "kunity_t.h"
#include <linux/kernel.h>
#ifndef UNITY_EXCLUDE_SETJMP_H
#define UNITY_EXCLUDE_SETJMP_H
#endif