Compare commits
14 Commits
gh-master
...
30c7c93ef4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30c7c93ef4 | ||
|
|
98ffa6508d | ||
|
|
a0bddbbda3 | ||
|
|
a25162238b | ||
|
|
1a37404f5e | ||
|
|
c04badcf5a | ||
|
|
695403d014 | ||
|
|
52faaaff69 | ||
|
|
66f19afb8c | ||
|
|
7c4a1d6fe8 | ||
|
|
80f56f28f3 | ||
|
|
cc125783a9 | ||
|
|
d549077c78 | ||
|
|
3632dd5c39 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
||||
[submodule "lib/Unity"]
|
||||
path = lib/Unity
|
||||
url = https://github.com/ThrowTheSwitch/Unity.git
|
||||
url = gitea@gitea.stubbe.rocks:3rd-party/Unity.git
|
||||
51
README.md
51
README.md
@@ -1,51 +0,0 @@
|
||||
# KUnity
|
||||
|
||||
KUnity configure the c unit test framework Unity (http://www.throwtheswitch.org/unity) so that it can use in kernel space. The test results will be "shown" by `printk`.
|
||||
|
||||
## Add KUnity to a kernel module
|
||||
|
||||
```Makefile
|
||||
|
||||
# add KUnity and Unity source files
|
||||
module-objs += lib/KUnity/src/kunity.o
|
||||
module-objs += lib/KUnity/lib/Unity/src/unity.o
|
||||
|
||||
# include KUnity and Unity header
|
||||
ccflags-y += -I<lib_path>/KUnity/src
|
||||
ccflags-y += -I<lib_path>/KUnity/lib/Unity/src
|
||||
|
||||
# set the unity config by header file flag, which is provided by KUnity
|
||||
ccflags-y += -DUNITY_INCLUDE_CONFIG_H
|
||||
```
|
||||
|
||||
## Write and Running test cases
|
||||
|
||||
Test can be written like Unity tests, but for the definition of the test function you have to use the ```KUNITY_TEST``` makro.
|
||||
When a kunity test should run, its necessary to add the prefix ```kunity_test_``` to the test function name.
|
||||
|
||||
```c
|
||||
#include <kunity.h>
|
||||
// ... application includes
|
||||
KUNITY_TEST(first_simple_test)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(1, 0);
|
||||
}
|
||||
|
||||
// add more tests
|
||||
|
||||
// run tests
|
||||
int module_init(void) {
|
||||
int result = 0;
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(kunity_test_first_simple_test);
|
||||
// ... call the other tests
|
||||
result = UNITY_END();
|
||||
if ( < 1) {
|
||||
// all tests was successful, startup module
|
||||
// ...
|
||||
}
|
||||
|
||||
return -result;
|
||||
}
|
||||
```
|
||||
For running tests it can also use the [KUnity-Test-Runner-Module](https://github.com/stubbfel/KUnity-Test-Runner-Module)
|
||||
21
src/kunity.c
21
src/kunity.c
@@ -4,6 +4,21 @@
|
||||
#include <linux/slab.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
//}
|
||||
//{ local include region
|
||||
|
||||
//}
|
||||
|
||||
//{ local define region
|
||||
|
||||
//}
|
||||
|
||||
//{ local enum region
|
||||
|
||||
//}
|
||||
|
||||
//{ local typedef region
|
||||
|
||||
//}
|
||||
|
||||
//{local struct region
|
||||
@@ -25,7 +40,7 @@ static result_code_e set_test_output(/*in */ const ptr_test_session_control_bloc
|
||||
|
||||
//{ local var region
|
||||
|
||||
static test_session_control_block_s prink_output = { printk_put_char, 0, 0 };
|
||||
static test_session_control_block_s prink_output = { printk_put_char,0 ,0 };
|
||||
|
||||
static ptr_test_session_control_block_s kunity_output = &prink_output;
|
||||
|
||||
@@ -74,14 +89,14 @@ result_code_e run_unity_test(/* in */ const unity_test_function_ptr test_functio
|
||||
return result;
|
||||
}
|
||||
|
||||
if (output->_skip_start) {
|
||||
if (output->_skip_start){
|
||||
Unity.TestFile = file_name;
|
||||
} else {
|
||||
UnityBegin(file_name);
|
||||
}
|
||||
|
||||
UnityDefaultTestRun(test_function, test_name, line_number);
|
||||
if (!output->_skip_end) {
|
||||
if (!output->_skip_end){
|
||||
UNITY_END();
|
||||
}
|
||||
|
||||
|
||||
11
src/kunity.h
11
src/kunity.h
@@ -3,11 +3,16 @@
|
||||
#include "kunity_t.h"
|
||||
|
||||
//{ global include region
|
||||
|
||||
#include <unity.h>
|
||||
//}
|
||||
//{ local include region
|
||||
|
||||
//}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//{ function region
|
||||
|
||||
extern void putchark(/* in */ char a);
|
||||
@@ -20,4 +25,8 @@ extern result_code_e run_unity_printk_test(/* in */ const kunity_test_function_p
|
||||
|
||||
//}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // KUNITY_H
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <linux/export.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
//}
|
||||
//{ local include region
|
||||
|
||||
//}
|
||||
|
||||
//{ define region
|
||||
|
||||
Reference in New Issue
Block a user