Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98ffa6508d | ||
|
|
a0bddbbda3 | ||
|
|
a25162238b | ||
|
|
1a37404f5e | ||
|
|
c04badcf5a | ||
|
|
695403d014 | ||
|
|
52faaaff69 | ||
|
|
66f19afb8c | ||
|
|
7c4a1d6fe8 | ||
|
|
80f56f28f3 | ||
|
|
cc125783a9 | ||
|
|
d549077c78 | ||
|
|
3632dd5c39 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "lib/Unity"]
|
||||||
|
path = lib/Unity
|
||||||
|
url = gitea@gitea.stubbe.rocks:3rd-party/Unity.git
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
function(module_objects module_name input_files output_string)
|
|
||||||
foreach(module_file ${input_files})
|
|
||||||
string(REGEX MATCH "^.*[oc]$" match_file ${module_file})
|
|
||||||
if(NOT ${match_file})
|
|
||||||
file(RELATIVE_PATH rel_file "${PROJECT_SOURCE_DIR}" ${module_file} )
|
|
||||||
string(REPLACE ".c" ".o" module_object ${rel_file})
|
|
||||||
list(APPEND module_objects "${module_name}-objs += ${module_object}")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
string(REPLACE ";" "\n" module_objects_string "${module_objects}")
|
|
||||||
set(${output_string} ${module_objects_string} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(module_include_directories input_dirs output_string)
|
|
||||||
foreach(include_dir ${input_dirs})
|
|
||||||
get_filename_component(abs_path ${include_dir} REALPATH)
|
|
||||||
list(APPEND module_includes "ccflags-y += -I${abs_path}")
|
|
||||||
include_directories(${abs_path})
|
|
||||||
endforeach()
|
|
||||||
string(REPLACE ";" "\n" module_includes_string "${module_includes}")
|
|
||||||
set(${output_string} ${module_includes_string} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(module_add_definitions input_definitions output_string)
|
|
||||||
foreach(input_definition ${input_definitions})
|
|
||||||
add_definitions(${input_definition})
|
|
||||||
list(APPEND module_definitions "ccflags-y += ${input_definition}")
|
|
||||||
endforeach()
|
|
||||||
string(REPLACE ";" "\n" module_definitions_string "${module_definitions}")
|
|
||||||
set(${output_string} ${module_definitions_string} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(module_kbuild module_name module_files module_include_dirs module_defs output_string)
|
|
||||||
module_objects("${module_name}" "${module_files}" kobjects_string)
|
|
||||||
module_include_directories("${module_include_dirs}" kincludes_string)
|
|
||||||
module_add_definitions("${module_defs}" kdefintions_string)
|
|
||||||
set(${output_string}
|
|
||||||
"${module_name}-m += ${module_name}.o
|
|
||||||
${kobjects_string}
|
|
||||||
|
|
||||||
${kincludes_string}
|
|
||||||
|
|
||||||
${kdefintions_string}" PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(add_module module_name module_files module_include_dirs module_defs kernel_dir)
|
|
||||||
set(module_build_path "${PROJECT_BINARY_DIR}/${module_name}")
|
|
||||||
module_kbuild("${module_name}" "${module_files}" "${module_include_dirs}" "${module_include_dirs}" Kbuild_string)
|
|
||||||
file(WRITE "${module_build_path}/Kbuild" ${Kbuild_string})
|
|
||||||
|
|
||||||
foreach(copy_file ${module_files})
|
|
||||||
file(RELATIVE_PATH rel_copy_file "${PROJECT_SOURCE_DIR}" ${copy_file} )
|
|
||||||
list(APPEND cmd_list "cp --parents ${copy_file} ${module_build_path}")
|
|
||||||
endforeach()
|
|
||||||
string(REPLACE ";" "\n" cmd_list_string "${cmd_list}")
|
|
||||||
file(WRITE "${module_build_path}/cp.sh" "#!/bin/bash\n${cmd_list_string}")
|
|
||||||
file(COPY "${module_build_path}/cp.sh"
|
|
||||||
DESTINATION "${module_build_path}/.tmp"
|
|
||||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|
||||||
file(REMOVE "${module_build_path}/cp.sh")
|
|
||||||
|
|
||||||
ADD_CUSTOM_COMMAND(
|
|
||||||
OUTPUT ${module_name}.built
|
|
||||||
COMMAND "${module_build_path}/.tmp/cp.sh"
|
|
||||||
COMMAND ${CMAKE_MAKE_PROGRAM} -C ${kernel_dir} M=${module_build_path} modules KBUILD_EXTRA_SYMBOLS=${module_build_path}/Module.symvers
|
|
||||||
COMMAND cmake -E touch ${module_name}.built
|
|
||||||
COMMENT "Kernel make modules ${module_name}:\n${Kbuild_string}\n"
|
|
||||||
DEPENDS ${PROJECT_SOURCE_DIR}/CMakeLists.txt ${module_files} ${module_include_dirs}
|
|
||||||
VERBATIM)
|
|
||||||
|
|
||||||
ADD_CUSTOM_TARGET("${module_name}" ALL
|
|
||||||
DEPENDS ${PROJECT_BINARY_DIR}/${module_name}.built
|
|
||||||
SOURCES ${module_files}
|
|
||||||
COMMENT "Building Kernel Module ${module_name}")
|
|
||||||
endfunction()
|
|
||||||
1
lib/Unity
Submodule
1
lib/Unity
Submodule
Submodule lib/Unity added at d9cd6988f3
112
src/kunity.c
112
src/kunity.c
@@ -1,6 +1,7 @@
|
|||||||
#include "kunity.h"
|
#include "kunity.h"
|
||||||
//{ global include region
|
//{ global include region
|
||||||
|
|
||||||
|
#include <linux/slab.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
|
|
||||||
//}
|
//}
|
||||||
@@ -8,58 +9,129 @@
|
|||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ local define region
|
//{ local define region
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ local enum region
|
//{ local enum region
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ local typedef region
|
//{ local typedef region
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{local struct region
|
//{local struct region
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
typedef struct string_builder_sTag {
|
||||||
|
size_t write_postion;
|
||||||
#pragma pack(pop)
|
char buffer[KUNITY_LINE_SIZE];
|
||||||
|
} string_builder_s, ptr_string_builder_s;
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ local function prototype region
|
//{ 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
|
//{ local var region
|
||||||
static string_builder_s sb;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
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
|
//{ 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 char* file_name, /* in */ const char* test_name, /* in */ int line_number, /* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnityBegin(file_name);
|
||||||
|
UnityDefaultTestRun(test_function, test_name, line_number);
|
||||||
|
UNITY_END();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_code_e run_unity_printk_test(/* in */ const kunity_test_function_ptr test_function)
|
||||||
|
{
|
||||||
|
if (test_function == NULL) {
|
||||||
|
return ERROR_NULL_ARGUMENT;
|
||||||
|
}
|
||||||
|
return test_function(&prink_output);
|
||||||
|
}
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ local function implements region
|
//{ local function implements region
|
||||||
void putchark(char a)
|
|
||||||
|
static void printk_put_char(char letter)
|
||||||
{
|
{
|
||||||
if (a == '\n')
|
if (letter == '\n') {
|
||||||
{
|
const char* c = (const char*)&string_builder.buffer[0];
|
||||||
const char * c = (const char *)&sb.buffer[0];
|
|
||||||
printk(c);
|
printk(c);
|
||||||
sb.write_postion = 0;
|
string_builder.write_postion = 0;
|
||||||
memset(sb.buffer, 0, 1024);
|
memset(string_builder.buffer, 0, KUNITY_LINE_SIZE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.buffer[sb.write_postion] = a;
|
string_builder.buffer[string_builder.write_postion] = letter;
|
||||||
sb.write_postion = (sb.write_postion + 1) % 1024;
|
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;
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
|
|||||||
12
src/kunity.h
12
src/kunity.h
@@ -2,8 +2,6 @@
|
|||||||
#define KUNITY_H
|
#define KUNITY_H
|
||||||
#include "kunity_t.h"
|
#include "kunity_t.h"
|
||||||
|
|
||||||
#ifndef TEST_MACRO
|
|
||||||
|
|
||||||
//{ global include region
|
//{ global include region
|
||||||
#include <unity.h>
|
#include <unity.h>
|
||||||
//}
|
//}
|
||||||
@@ -17,7 +15,13 @@ extern "C" {
|
|||||||
|
|
||||||
//{ function region
|
//{ 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 char* file_name, /* in */ const char* test_name, /* in */ int line_number, /* in */ const ptr_output_functions_s output);
|
||||||
|
|
||||||
|
extern result_code_e run_unity_printk_test(/* in */ const kunity_test_function_ptr test_function);
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
@@ -25,6 +29,4 @@ extern void putchark(char a);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TEST_MACRO
|
|
||||||
|
|
||||||
#endif // KUNITY_H
|
#endif // KUNITY_H
|
||||||
|
|||||||
@@ -2,54 +2,88 @@
|
|||||||
#define KUNITY_T_H
|
#define KUNITY_T_H
|
||||||
|
|
||||||
//{ global include region
|
//{ global include region
|
||||||
#include <linux/types.h>
|
|
||||||
|
|
||||||
#ifndef KUNITY_TEST_RUNNER_APP
|
|
||||||
#include <linux/export.h>
|
#include <linux/export.h>
|
||||||
#endif
|
#include <linux/types.h>
|
||||||
|
|
||||||
//}
|
//}
|
||||||
//{ local include region
|
//{ local include region
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ define region
|
//{ define region
|
||||||
|
|
||||||
#ifndef KUNITY_LINE_SIZE
|
#ifndef KUNITY_LINE_SIZE
|
||||||
#define KUNITY_LINE_SIZE 1024
|
#define KUNITY_LINE_SIZE 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef KUNITY_DEFAULT_TEST_NAME_PREFIX
|
||||||
|
#define KUNITY_DEFAULT_TEST_NAME_PREFIX kunity_test_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef KUNITY_DEFAULT_TEST_NAME_PREFIX_STR
|
||||||
|
#define STR(s) #s
|
||||||
|
#define XSTR(s) STR(s)
|
||||||
|
#define KUNITY_DEFAULT_TEST_NAME_PREFIX_STR XSTR(KUNITY_DEFAULT_TEST_NAME_PREFIX)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef KUNITY_CREATE_TEST_NAME
|
||||||
|
#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
|
#ifndef KUNITY_TEST
|
||||||
#define KUNITY_TEST(function_name) \
|
#define KUNITY_TEST(function_name) \
|
||||||
extern void function_name (void); \
|
extern result_code_e KUNITY_CREATE_TEST_NAME(function_name)(const ptr_output_functions_s output); \
|
||||||
EXPORT_SYMBOL(function_name); \
|
static void function_name(void); \
|
||||||
void function_name()
|
\
|
||||||
|
result_code_e KUNITY_CREATE_TEST_NAME(function_name)(const ptr_output_functions_s output) \
|
||||||
|
{ \
|
||||||
|
return run_unity_test(function_name, __FILE__, #function_name, __LINE__, output); \
|
||||||
|
} \
|
||||||
|
EXPORT_SYMBOL(KUNITY_CREATE_TEST_NAME(function_name)); \
|
||||||
|
\
|
||||||
|
static void function_name()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
//{ enum region
|
//{ 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 region
|
||||||
|
|
||||||
|
typedef void (*redirect_char)(char a);
|
||||||
|
|
||||||
|
typedef void (*unity_test_function_ptr)(void);
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//{ struct region
|
//{ struct region
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
typedef struct output_functions_sTag {
|
||||||
typedef struct string_builder_sTag
|
redirect_char redirect_char;
|
||||||
{
|
} output_functions_s, *ptr_output_functions_s;
|
||||||
size_t write_postion;
|
|
||||||
char buffer[KUNITY_LINE_SIZE];
|
|
||||||
} string_builder_s, ptr_string_builder_s;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#endif // KUNITY_T_H
|
#endif // KUNITY_T_H
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#ifndef UNITY_CONFIG_H
|
#ifndef UNITY_CONFIG_H
|
||||||
#define UNITY_CONFIG_H
|
#define UNITY_CONFIG_H
|
||||||
|
|
||||||
|
#include "kunity_t.h"
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
|
|
||||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
#define UNITY_EXCLUDE_SETJMP_H
|
#define UNITY_EXCLUDE_SETJMP_H
|
||||||
#endif
|
#endif
|
||||||
@@ -35,4 +36,8 @@
|
|||||||
#define UNITY_INT_WIDTH (32)
|
#define UNITY_INT_WIDTH (32)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNITY_OUTPUT_COLOR
|
||||||
|
#define UNITY_OUTPUT_COLOR
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // UNITY_CONFIG_H
|
#endif // UNITY_CONFIG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user