From 2409815a823c749355af26ee1c247830883ce89f Mon Sep 17 00:00:00 2001 From: stubbfel Date: Fri, 26 Jan 2018 02:04:31 +0100 Subject: [PATCH] Initial commit --- .gitignore | 167 ++++++++++++++++++++++++++++ LICENSE | 21 ++++ dev-utility/BuildKernelModule.cmake | 75 +++++++++++++ src/kunity.c | 65 +++++++++++ src/kunity.h | 30 +++++ src/kunity_t.h | 55 +++++++++ src/unity_config.h | 38 +++++++ 7 files changed, 451 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 dev-utility/BuildKernelModule.cmake create mode 100644 src/kunity.c create mode 100644 src/kunity.h create mode 100644 src/kunity_t.h create mode 100644 src/unity_config.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..baeb131 --- /dev/null +++ b/.gitignore @@ -0,0 +1,167 @@ + +# Created by https://www.gitignore.io/api/c,git,c++,linux,cmake,qtcreator,qt + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### CMake ### +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +build + +### Git ### +*.orig + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Qt ### +# C++ objects and libs + + +# Qt-es + +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +Makefile* +*build-* + +# QtCreator + +*.autosave + +# QtCtreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCtreator CMake +CMakeLists.txt.user* + + +### QtCreator ### +# gitignore for Qt Creator like IDE for pure C/C++ project without Qt +# +# Reference: http://doc.qt.io/qtcreator/creator-project-generic.html + + + +# Qt Creator autogenerated files + + +# A listing of all the files included in the project +*.files + +# Include directories +*.includes + +# Project configuration settings like predefined Macros +*.config + +# Qt Creator settings +*.creator + +# User project settings +*.creator.user* + +# Qt Creator backups + + +# End of https://www.gitignore.io/api/c,git,c++,linux,cmake,qtcreator,qt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..74599ac --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 kttd + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/dev-utility/BuildKernelModule.cmake b/dev-utility/BuildKernelModule.cmake new file mode 100644 index 0000000..d0d906a --- /dev/null +++ b/dev-utility/BuildKernelModule.cmake @@ -0,0 +1,75 @@ +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() diff --git a/src/kunity.c b/src/kunity.c new file mode 100644 index 0000000..26d72e3 --- /dev/null +++ b/src/kunity.c @@ -0,0 +1,65 @@ +#include "kunity.h" +//{ global include region + +#include + +//} +//{ 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 + +//} + +//{ local global var region +static string_builder_s sb; +//} + + +//{ global function implements region + +//} + + +//{ local function implements region +void putchark(char a) +{ + if (a == '\n') + { + const char * c = (const char *)&sb.buffer[0]; + printk(c); + sb.write_postion = 0; + memset(sb.buffer, 0, 1024); + return; + } + + sb.buffer[sb.write_postion] = a; + sb.write_postion = (sb.write_postion + 1) % 1024; +} +//} diff --git a/src/kunity.h b/src/kunity.h new file mode 100644 index 0000000..ed5978c --- /dev/null +++ b/src/kunity.h @@ -0,0 +1,30 @@ +#ifndef KUNITY_H +#define KUNITY_H +#include "kunity_t.h" + +#ifndef TEST_MACRO + +//{ global include region +#include +//} +//{ local include region + +//} + +#ifdef __cplusplus +extern "C" { +#endif + +//{ function region + +extern void putchark(char a); + +//} + +#ifdef __cplusplus +} +#endif + +#endif // TEST_MACRO + +#endif // KUNITY_H diff --git a/src/kunity_t.h b/src/kunity_t.h new file mode 100644 index 0000000..7786be8 --- /dev/null +++ b/src/kunity_t.h @@ -0,0 +1,55 @@ +#ifndef KUNITY_T_H +#define KUNITY_T_H + +//{ global include region +#include + +#ifndef KUNITY_TEST_RUNNER_APP +#include +#endif + +//} +//{ local include region + +//} + + +//{ define region + +#ifndef KUNITY_LINE_SIZE +#define KUNITY_LINE_SIZE 1024 +#endif + +#ifndef KUNITY_TEST +#define KUNITY_TEST(function_name) \ + extern void function_name (void); \ + EXPORT_SYMBOL(function_name); \ + void function_name() +#endif + +//} + + +//{ enum region + +//} + + +//{ typedef region + +//} + +//{ 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) + + +//} + +#endif // KUNITY_T_H diff --git a/src/unity_config.h b/src/unity_config.h new file mode 100644 index 0000000..eb65b65 --- /dev/null +++ b/src/unity_config.h @@ -0,0 +1,38 @@ +#ifndef UNITY_CONFIG_H +#define UNITY_CONFIG_H + + +#include +#ifndef UNITY_EXCLUDE_SETJMP_H +#define UNITY_EXCLUDE_SETJMP_H +#endif + +#ifndef UNITY_EXCLUDE_MATH_H +#define UNITY_EXCLUDE_MATH_H +#endif + +#ifndef UNITY_EXCLUDE_LIMITS_H +#define UNITY_EXCLUDE_LIMITS_H +#endif + +#ifndef UNITY_EXCLUDE_STDINT_H +#define UNITY_EXCLUDE_STDINT_H +#endif + +#ifndef UNITY_EXCLUDE_FLOAT +#define UNITY_EXCLUDE_FLOAT +#endif + +#ifndef UNITY_OUTPUT_CHAR +#define UNITY_OUTPUT_CHAR(a) putchark(a) +#endif + +#ifndef UNITY_OUTPUT_CHAR_HEADER_DECLARATION +#define UNITY_OUTPUT_CHAR_HEADER_DECLARATION putchark(char a) +#endif + +#ifndef UNITY_INT_WIDTH +#define UNITY_INT_WIDTH (32) +#endif + +#endif // UNITY_CONFIG_H