Merge branch 'master' into master

This commit is contained in:
Mark VanderVoord
2020-03-16 13:44:41 -04:00
committed by GitHub
13 changed files with 401 additions and 26 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ namespace :test do
#individual system tests
FileList['system/test_interactions/*.yml'].each do |test|
basename = File.basename(test,'.*')
desc "Run system test #{basename}"
#desc "Run system test #{basename}"
task basename do
run_system_test_interactions([test])
end
+14 -2
View File
@@ -66,6 +66,7 @@ class SystemTestGenerator
generate_test_file(yaml_hash, namix, name)
generate_source_file(yaml_hash, namix, name)
generate_skeleton_file(yaml_hash, namix, name)
end
def generate_types_file(yaml_hash, namix)
@@ -136,11 +137,22 @@ class SystemTestGenerator
includes << (namix + MOCKABLE_H) if not yaml_hash[:systest][:mockable].nil?
includes << header_file
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
out.puts(source[:code])
unless (source[:code].nil?)
write_source_file(GENERATED_PATH + name + C_EXTENSION, includes.flatten) do |out|
out.puts(source[:code])
end
end
end
def generate_skeleton_file(yaml_hash, namix, name)
source = yaml_hash[:systest][:skeleton]
return if source.nil?
require 'cmock.rb'
cmock = CMock.new(GENERATED_PATH + namix + 'cmock' + YAML_EXTENSION)
cmock.setup_skeletons("#{$cfg['compiler']['source_path']}#{name}.h")
end
def write_header_file(filename, upcase_name, include_list=[])
File.open(filename, 'w') do |out|
out.puts("#ifndef _#{upcase_name}")
@@ -0,0 +1,55 @@
---
:cmock:
:plugins:
- # none
:skeleton_path: system/generated
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 something(int a);
:skeleton: skeleton.h
:source:
:header: |
void function_a(void);
int function_b(int a, int b);
const char* function_c(void);
# we are purposefully not including a :code section because it will be generated with skeleton
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'generate an empty shell for functions with no return values'
:code: |
test()
{
function_a();
}
- :pass: TRUE
:should: 'return numerical zero for numerical return values'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
}
- :pass: TRUE
:should: 'return null for pointer return values'
:code: |
test()
{
TEST_ASSERT_NULL(function_c());
}
...
@@ -0,0 +1,76 @@
---
:cmock:
:plugins:
- # none
:skeleton_path: system/generated
:systest:
:types: |
#define UINT32 unsigned int
:mockable: |
UINT32 something(int a);
:skeleton: skeleton_update.h
:source:
:header: |
void function_a(void);
int function_b(int a, int b);
const char* function_c(void);
# note that this code section exists and will be updated by the skeleton generator
:code: |
const char* donuts = "donuts";
const char* function_c(void)
{
return donuts;
}
int function_d(void)
{
return 77;
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
extern int function_d();
:units:
- :pass: TRUE
:should: 'generate an empty shell for functions with no return values'
:code: |
test()
{
function_a();
}
- :pass: TRUE
:should: 'return numerical zero for numerical return values'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(0, function_b(1, 2));
}
- :pass: TRUE
:should: 'not overwrite functions that already exist'
:code: |
test()
{
TEST_ASSERT_EQUAL_STRING("donuts", function_c());
}
- :pass: TRUE
:should: 'leave functions it has never heard of'
:code: |
test()
{
TEST_ASSERT_EQUAL_INT(77, function_d());
}
...
+112
View File
@@ -2083,4 +2083,116 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
assert_equal(expected, @parser.parse("module", source)[:functions])
end
it "Transform inline functions can handle inline function declarations" do
source =
"static inline int dummy_func_decl(int a, char b, float c);\n" + # First declaration
"static inline int dummy_func_decl2(int a, char b, float c)\n\n\n\n\n\n;\n" + # Second declaration with a lot of newlines before the semicolon to mess with the parser
"static inline int staticinlinefunc(struct my_struct *s)\n" + # 'normal' inline pattern
"{\n" +
" return dummy_func_decl(1, 1, 1);\n" +
"}\n" +
"struct my_struct_with_inline_in_it\n" # struct definition in between to mess with the parser
"{\n" +
" int a;\n" +
" char b;\n" +
" float inlineb;\n" +
"};\n" +
"static inline int dummy_func_decl(int a, char b, float c) {\n" + # Second user pattern
" return 42;\n" +
"}\n" +
"\n"
expected =
"int dummy_func_decl(int a, char b, float c);\n" +
"int dummy_func_decl2(int a, char b, float c)\n\n\n\n\n\n;\n" + # Second declaration with a lot of newlines until the semicolon to mess with the parser
"int staticinlinefunc(struct my_struct *s);\n" +
"struct my_struct_with_inline_in_it\n"
"{\n" +
" int a;\n" +
" char b;\n" +
" float inlineb;\n" +
"};\n" +
"int dummy_func_decl(int a, char b, float c);\n" +
"\n"
@parser.treat_inlines = :include
assert_equal(expected, @parser.transform_inline_functions(source))
end
it "Transform inline functions can handle header with only inline function declarations" do
source =
"static inline int dummy_func_decl(int a, char b, float c);\n" +
"\n"
expected =
"int dummy_func_decl(int a, char b, float c);\n" +
"\n"
@parser.treat_inlines = :include
assert_equal(expected, @parser.transform_inline_functions(source))
end
it "Transform inline functions takes user provided patterns into account" do
source =
"static __inline__ __attribute__ ((always_inline)) uint16_t _somefunc (uint32_t a)\n" +
"{\n" +
" return _someotherfunc (a);\n" +
"}\n" +
"static __inline__ uint16_t _somefunc_0 (uint32_t a)\n" +
"{\n" +
" return (uint16_t) a;\n" +
"}\n" +
"\n"
expected =
"uint16_t _somefunc (uint32_t a);\n" +
"uint16_t _somefunc_0 (uint32_t a);\n" +
"\n"
@parser.treat_inlines = :include
@parser.inline_function_patterns = ['static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__']
assert_equal(expected, @parser.transform_inline_functions(source))
end
it "Transform inline functions limits deleting user macro to actual line/word" do
source =
"#if defined (FORCE_INLINE)\n" +
"#define MY_LIBRARY_INLINE static __inline__ __attribute__ ((always_inline))\n" +
"#else\n" +
"#define MY_LIBRARY_INLINE\n" +
"#endif\n" +
"#define INLINE static __inline__ __attribute__ ((always_inline))\n" +
"#define INLINE_TWO \\\nstatic\\\ninline\n" +
"INLINE uint16_t _somefunc (uint32_t a)\n" +
"{\n" +
" return _someotherfunc (a);\n" +
"}\n" +
"static __inline__ uint16_t _somefunc_0 (uint32_t a)\n" +
"{\n" +
" return (uint16_t) a;\n" +
"}\n" +
"static __inline__ __attribute__ \(\(always_inline\)\) uint16_t _somefunc_1 (uint32_t a)\n" +
"{\n" +
" return (uint16_t) a;\n" +
"}\n" +
"INLINE_TWO uint16_t _somefunc_2(uint32_t a)\n" +
"{\n" +
" return (uint16_t) a;\n" +
"}\n" +
"#define INLINE_THREE \\\nstatic\\\ninline"
expected =
"#if defined (FORCE_INLINE)\n" +
"#else\n" +
"#endif\n" +
"uint16_t _somefunc (uint32_t a);\n" +
"uint16_t _somefunc_0 (uint32_t a);\n" +
"uint16_t _somefunc_1 (uint32_t a);\n" +
"uint16_t _somefunc_2(uint32_t a);\n"
@parser.treat_inlines = :include
@parser.inline_function_patterns = ['MY_LIBRARY_INLINE', 'INLINE_THREE', 'INLINE_TWO', 'INLINE', 'static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__']
assert_equal(expected, @parser.transform_inline_functions(source))
end
end