git subrepo clone git@github.com:compihu/platform-test-f4-ll.git platforms/platform-test-f4-ll

subrepo:
  subdir:   "platforms/platform-test-f4-ll"
  merged:   "bc41134"
upstream:
  origin:   "git@github.com:compihu/platform-test-f4-ll.git"
  branch:   "master"
  commit:   "bc41134"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "87ee373"
This commit is contained in:
Attila Body 2021-02-24 21:46:35 +01:00
parent 46ce55c6a0
commit 95af4ce0d8
460 changed files with 84105 additions and 0 deletions

View file

@ -0,0 +1,25 @@
Convert CppUTest files to Unity test files
------------------------------------------
To convert a CppUTest test file to Unity, enter a command like this
CONVERT=$CPPUTEST_HOME/scripts/convertToUnity/cpp_u_test_to_unity.rb
ruby $CONVERT tests/some/dir/or/dirs/MyThink.cpp
This will create two files like this
unity/some/dir/or/dirs/MyThing.c
unity/some/dir/or/dirs/MyThing_runner.c
Things that need to be done manually once to your
unity test environment:
Create directory 'unity/some/dir/or/dirs'
Adjust unity makefile to refer to the needed files
Unity main needs to call RUN_TEST_GROUP(MyThing)
Things not supported in converted test cases:
CppUMock
Hand built mocks that use CppUTest macros.
Formatting conventions can cause the script to fail

View file

@ -0,0 +1,24 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'cpp_u_test_to_unity_utils.rb')
include CppUTestToUnityUtils
in_file = ARGV[0]
unity_filename = convert_test_filename_to_unity_filename(in_file)
unity_runner_filename = convert_test_filename_to_unity_testrunner_filename(in_file)
puts "Converting :" + in_file + "\n"
puts " To :" + unity_filename + "\n"
test_lines = File.open(in_file).readlines
out_unity_file = File.open(unity_filename, 'w')
out_unity_runner_file = File.open(unity_runner_filename, 'w')
test_groups = get_test_groups(test_lines)
adjust_tabs(test_lines)
remove_extern_c(test_lines)
demote_group(/TEST_GROUP/, test_lines)
convert_macros(test_lines, test_groups)
group_runners = generate_group_runners(test_groups, test_lines)
write_lines_to_file(out_unity_file, test_lines)
write_lines_to_file(out_unity_runner_file, group_runners)
out_unity_file.close()
out_unity_runner_file.close()

View file

@ -0,0 +1,247 @@
module CppUTestToUnityUtils
def convert_test_filename_to_unity_filename(testpath)
testpath.sub(/tests\/(.*)\.cpp/, "unity/\\1.c")
end
def convert_test_filename_to_unity_testrunner_filename(testpath)
testpath.sub(/tests\/(.*)\.cpp/, "unity/\\1_runner.c")
end
def convert_one_liners(line, group)
line.sub!(/#include "CppUTest\/TestHarness.h\"/, "#include \"unity_fixture.h\"" )
line.sub!(/FAIL\(/, 'TEST_FAIL(')
line.sub!(/CHECK\(/, "TEST_ASSERT_TRUE(")
line.sub!(/CHECK_TRUE\(/, "TEST_ASSERT_TRUE(")
line.sub!(/CHECK_FALSE\(/, "TEST_ASSERT_FALSE(")
line.sub!(/LONGS_EQUAL\(/, "TEST_ASSERT_EQUAL(")
line.sub!(/BYTES_EQUAL\(/, "TEST_ASSERT_EQUAL_HEX8(")
line.sub!(/STRCMP_EQUAL\(/, "TEST_ASSERT_EQUAL_STRING(")
line.sub!(/DOUBLES_EQUAL\(/, "TEST_ASSERT_FLOAT_WITHIN(")
line.sub!(/ POINTERS_EQUAL\(/, " TEST_ASSERT_POINTERS_EQUAL(")
line.sub!(/CHECK_EQUAL\(true,/, "TEST_ASSERT_TRUE(")
line.sub!(/CHECK_EQUAL\(false,/, "TEST_ASSERT_FALSE(")
line.sub!(/CHECK_EQUAL\(/, "TEST_ASSERT_EQUAL(")
#line.sub!(/static void setup\(/, "TEST_SETUP(" + group)
#line.sub!(/static void teardown\(/, "TEST_TEAR_DOWN(" + group)
end
def convert_setup(lines, group)
lines.each do | line |
if line.sub!(/static void setup\(/, "TEST_SETUP(" + group)
return
end
end
end
def convert_teardown(lines, group)
lines.each do | line |
if line.sub!(/static void teardown\(/, "TEST_TEAR_DOWN(" + group)
return
end
end
end
def convert_macros(lines, groups)
groups.each do | group |
lines.each do | line |
convert_one_liners(line, group)
end
convert_setup(lines, group)
convert_teardown(lines, group)
end
end
def get_test_group(lines)
@test_group = "None"
lines.each do | line |
if /TEST_GROUP/ =~ line
@test_group = line.split(/[()]/)[1]
end
end
@test_group
end
def get_test_groups(lines)
@test_groups = []
i = 0
lines.each do | line |
if /TEST_GROUP/ =~ line
@test_groups[i] = line.split(/[()]/)[1]
i = i + 1
end
end
@test_groups
end
def adjust_tabs(lines)
lines.each do | line |
line.gsub!(/^ {2,3}(\w+)/, " \\1")
line.gsub!(/\t/, " ")
end
end
def include_line?(line)
/\#include/ =~ line
end
def convert_member_to_static(line)
line.gsub!(/^\s*(\w)/, "static \\1")
end
def add_semicolon_to_end_of_test_group_line(line)
line.gsub!(/\)/, ");")
end
def consume_closing_curley_brace(line)
line.gsub!(/\}\;*[ \t]*(.*)/, "\\1")
end
def outdent(line)
line.gsub!(/^ /, "")
end
def consume_opening_curley_brace(line)
line.gsub!(/\{/, "")
end
def demote_group(group, lines)
test_group = "None"
scope_level = 0
in_test_group = false
lines.each do | line |
next if include_line?(line)
if !in_test_group
if line.match(group)
add_semicolon_to_end_of_test_group_line(line)
in_test_group = true
end
next
end
if line.include?("}")
scope_level -= 1
elsif line.include?("{")
scope_level += 1
end
outdent(line)
if scope_level == 1
convert_member_to_static(line)
consume_opening_curley_brace(line)
end
if scope_level == 0
consume_closing_curley_brace(line)
in_test_group = false
end
end
end
def search_and_destroy(pattern, lines)
lines.each do | line |
line.gsub!(pattern, "")
end
end
def extern_c_line?(line)
line.match(/extern \"C\"/)
end
def remove_extern_c(lines)
in_extern_c = false;
scope_level = 0
lines.each do | line |
if !in_extern_c
if extern_c_line?(line)
in_extern_c = true
line.gsub!(/extern \"C\"/, "")
end
next
end
# next if ! in_extern_c and ! extern_c_line?(line)
#
# in_extern_c = true
if line.include?("{")
scope_level += 1
elsif line.include?("}")
scope_level -= 1
end
if scope_level == 1
consume_opening_curley_brace(line)
end
if scope_level == 0 and line.include?("}")
in_extern_c = false
consume_closing_curley_brace(line)
end
end
end
def test_declaration?(line, group)
/TEST\(#{group}/ =~ line
end
def generate_group_runner(group, lines)
group_runner = []
group_runner << "/* Make sure you invoke RUN_TEST_GROUP(" + group + ") from unity main */\n\n"
group_runner << "TEST_GROUP_RUNNER(" + group + ")\n"
group_runner << "{\n"
lines.each do | line |
if test_declaration?(line, group)
temp = line.clone
temp.sub!(/\n/, "")
temp.sub!(/^IGNORE_/, "")
temp.sub!(/^TEST/, " RUN_TEST_CASE")
group_runner << temp + ";\n"
end
end
group_runner << "}\n\n"
end
def generate_group_runners(groups, lines)
group_runners = []
group_runners << "/* Generated code, edit at your own risk */\n\n"
group_runners << "#include \"unity_fixture.h\"\n\n"
groups.each do | group |
group_runners.concat generate_group_runner(group, lines)
end
group_runners
end
def generate_group_runner_plainUnity(group, lines)
prototypes = []
callers = []
group_runner = []
lines.each do | line |
if /void test.*\(.*\)/ =~ line
temp = line.clone
temp.sub!(/\n/, "")
prototypes << temp + ";"
temp.sub!(/void /, " ")
temp.sub!(/\(void\)/, "()")
callers << temp
end
end
group_runner << "\n"
group_runner << "//Generated code, edit at your own risk\n\n"
group_runner << "\#include \"unity_fixture.h\"\n\n"
group_runner << prototypes
group_runner << "\n\nTEST_GROUP_RUNNER(" + group + ")\n"
group_runner << "{\n"
group_runner << callers
group_runner << "}\n"
end
def write_lines_to_file(file, lines)
lines.each do | line |
file.write(line)
end
end
end

View file

@ -0,0 +1,506 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'cpp_u_test_to_unity_utils.rb')
include CppUTestToUnityUtils
test_lines = Array.new
expected_lines = Array.new
def check(theTest, expected, actual)
unless (expected == actual)
puts theTest + " failed"
puts "Actual:\n"
show(actual)
puts "unmatched lines"
show(expected - actual)
puts("Expected: " + expected.inspect)
puts(" Actual: " + actual.inspect)
end
end
#---------------------------------------------------
test_lines =
[
"\n",
"TEST_GROUP(mygroup)\n",
"{\n",
"}\n",
"\n",
"\n",
"TEST_GROUP(yourgroup)\n",
"{\n",
"}\n",
"\n"
]
groups = get_test_groups(test_lines)
unless /mygroup/ =~ groups[0]
puts "Expected mygroup, but got #{groups[0]}"
end
unless /yourgroup/ =~ groups[1]
puts "Expected yourgroup, but got #{groups[1]}"
end
#---------------------------------------------------
test_lines =
["\n",
"TEST_GROUP(mygroup)\n",
"{\n",
" int xxxx;\n",
" void yyyy()\n",
" {\n",
" int i = 0;\n",
" }\n",
"};\n",
"\n",
" void f()\n"
]
expected_lines =
["\n",
"TEST_GROUP(mygroup);\n",
"\n",
"static int xxxx;\n",
"static void yyyy()\n",
"{\n",
" int i = 0;\n",
"}\n",
"\n",
"\n",
" void f()\n"
]
def show(lines)
lines.each do | line |
puts line
end
end
demote_group(/TEST_GROUP/, test_lines)
check("demote_group", expected_lines, test_lines)
#---------------------------------
test_lines =
[
"\n",
"TEST_GROUP(mygroup)\n",
"{\n",
"}\n",
";\n",
"\n",
"TEST_GROUP(yourgroup)\n",
"{\n",
"}\n",
";\n"
]
expected_lines =
[
"\n",
"TEST_GROUP(mygroup);\n",
"\n",
"\n",
";\n",
"\n",
"TEST_GROUP(yourgroup);\n",
"\n",
"\n",
";\n"
]
demote_group(/TEST_GROUP/, test_lines)
check("demote_group", expected_lines, test_lines)
#---------------------------------
test_lines =
["\n",
"TEST_GROUP(mygroup)\n",
"{\n",
" int xxxx;\n",
" void yyyy()\n",
" {\n",
" int i = 0;\n",
" }\n",
"}; //End TEST_GROUP\n",
"\n"
]
expected_lines =
["\n",
"TEST_GROUP(mygroup);\n",
"\n",
"static int xxxx;\n",
"static void yyyy()\n",
"{\n",
" int i = 0;\n",
"}\n",
"//End TEST_GROUP\n",
"\n"
]
demote_group(/TEST_GROUP/, test_lines)
check("demote_group", expected_lines, test_lines)
#---------------------------------------------------
test_lines =
["\n",
"extern \"C\"\n",
"{\n",
"\#include \"heythere.h\"\n",
"int xxxx;\n",
"void yyyy()\n",
"{\n",
" int i = 0;\n",
"}\n",
"}\n",
"int foo()\n",
"{\n",
" int aaaa;\n",
"}\n"
]
expected_lines =
["\n",
"\n",
"\n",
"\#include \"heythere.h\"\n",
"int xxxx;\n",
"void yyyy()\n",
"{\n",
" int i = 0;\n",
"}\n",
"\n",
"int foo()\n",
"{\n",
" int aaaa;\n",
"}\n"
]
remove_extern_c(test_lines)
check("remove_extern_c", expected_lines, test_lines)
#---------------------------------------------------
test_lines =
["\n",
"extern \"C\"\n",
"{\n",
"#include \"LightScheduler.h\"\n",
"#include \"FakeLightController.h\"\n",
"#include \"FakeTimeService.h\"\n",
"#include \"FakeRandomMinute.h\"\n",
"}\n",
"#include \"CppUTest/TestHarness.h\"\n"
]
expected_lines =
["\n",
"\n",
"\n",
"#include \"LightScheduler.h\"\n",
"#include \"FakeLightController.h\"\n",
"#include \"FakeTimeService.h\"\n",
"#include \"FakeRandomMinute.h\"\n",
"\n",
"#include \"CppUTest/TestHarness.h\"\n"
]
remove_extern_c(test_lines)
check("remove_extern_c", expected_lines, test_lines)
#---------------------------------------------------
test_lines =
[
"\n",
"#include \"unity_fixture.h\" expected\n",
"#include \"CppUTest\/TestHarness.h\"\n",
"\n",
"TEST_SETUP(theGroup) expected\n",
"static void setup()\n",
"{\n",
" x = 1;\n",
"}\n",
"TEST_TEAR_DOWN(theGroup) expected\n",
"static void teardown()\n",
"{\n",
" y = 0;\n",
"}\n",
"TEST(LedDriver, Create)\n",
"{\n",
" FAIL(\"Start here\");\n",
"}\n",
"\n",
"IGNORE_TEST(LedDriver, ignore)\n",
"{\n",
" TEST_ASSERT_TRUE(0 == 0); expected\n",
" CHECK(0 == 0);\n",
"\n",
" TEST_ASSERT_TRUE(0 == 0); expected\n",
" CHECK_TRUE(0 == 0);\n",
"\n",
" TEST_ASSERT_FALSE(0 != 0); expected\n",
" CHECK_FALSE(0 != 0);\n",
"\n",
" TEST_ASSERT_EQUAL(1,1); expected\n",
" LONGS_EQUAL(1,1);\n",
"\n",
" TEST_ASSERT_EQUAL_HEX8(0xab,0xab); expected\n",
" BYTES_EQUAL(0xab,0xab);\n",
"\n",
" TEST_ASSERT_EQUAL(100,100); expected\n",
" CHECK_EQUAL(100,100);\n",
"\n",
" TEST_ASSERT_TRUE(true); expected\n",
" CHECK_EQUAL(true,true);\n",
"\n",
" TEST_ASSERT_FALSE(false); expected\n",
" CHECK_EQUAL(false,false);\n",
"\n",
" TEST_ASSERT_EQUAL_STRING(\"THIS\", \"THIS\"); expected\n",
" STRCMP_EQUAL(\"THIS\", \"THIS\");\n",
"\n",
" TEST_ASSERT_FLOAT_WITHIN(1.0, 1.0, .01); expected\n",
" DOUBLES_EQUAL(1.0, 1.0, .01);\n",
"\n",
" TEST_ASSERT_POINTERS_EQUAL(this, this); expected\n",
" POINTERS_EQUAL(this, this);\n",
"}\n"
]
expected_lines =
[
"\n",
"#include \"unity_fixture.h\" expected\n",
"#include \"unity_fixture.h\"\n",
"\n",
"TEST_SETUP(theGroup) expected\n",
"TEST_SETUP(theGroup)\n",
"{\n",
" x = 1;\n",
"}\n",
"TEST_TEAR_DOWN(theGroup) expected\n",
"TEST_TEAR_DOWN(theGroup)\n",
"{\n",
" y = 0;\n",
"}\n",
"TEST(LedDriver, Create)\n",
"{\n",
" TEST_FAIL(\"Start here\");\n",
"}\n",
"\n",
"IGNORE_TEST(LedDriver, ignore)\n",
"{\n",
" TEST_ASSERT_TRUE(0 == 0); expected\n",
" TEST_ASSERT_TRUE(0 == 0);\n",
"\n",
" TEST_ASSERT_TRUE(0 == 0); expected\n",
" TEST_ASSERT_TRUE(0 == 0);\n",
"\n",
" TEST_ASSERT_FALSE(0 != 0); expected\n",
" TEST_ASSERT_FALSE(0 != 0);\n",
"\n",
" TEST_ASSERT_EQUAL(1,1); expected\n",
" TEST_ASSERT_EQUAL(1,1);\n",
"\n",
" TEST_ASSERT_EQUAL_HEX8(0xab,0xab); expected\n",
" TEST_ASSERT_EQUAL_HEX8(0xab,0xab);\n",
"\n",
" TEST_ASSERT_EQUAL(100,100); expected\n",
" TEST_ASSERT_EQUAL(100,100);\n",
"\n",
" TEST_ASSERT_TRUE(true); expected\n",
" TEST_ASSERT_TRUE(true);\n",
"\n",
" TEST_ASSERT_FALSE(false); expected\n",
" TEST_ASSERT_FALSE(false);\n",
"\n",
" TEST_ASSERT_EQUAL_STRING(\"THIS\", \"THIS\"); expected\n",
" TEST_ASSERT_EQUAL_STRING(\"THIS\", \"THIS\");\n",
"\n",
" TEST_ASSERT_FLOAT_WITHIN(1.0, 1.0, .01); expected\n",
" TEST_ASSERT_FLOAT_WITHIN(1.0, 1.0, .01);\n",
"\n",
" TEST_ASSERT_POINTERS_EQUAL(this, this); expected\n",
" TEST_ASSERT_POINTERS_EQUAL(this, this);\n",
"}\n"
]
convert_macros(test_lines, ["theGroup"])
check("convert_macros", expected_lines, test_lines)
#---------------------------------------------------
test_lines =
[
"TEST_SETUP(group1) expected\n",
"static void setup()\n",
"TEST_TEAR_DOWN(group1) expected\n",
"static void teardown()\n",
"TEST(group1, Create)\n",
"IGNORE_TEST(group1, ignore)\n",
"TEST_SETUP(group2) expected\n",
"static void setup()\n",
"TEST_TEAR_DOWN(group2) expected\n",
"static void teardown()\n",
"TEST(group2, Create)\n",
"IGNORE_TEST(group2, ignore)\n"
]
expected_lines =
[
"TEST_SETUP(group1) expected\n",
"TEST_SETUP(group1)\n",
"TEST_TEAR_DOWN(group1) expected\n",
"TEST_TEAR_DOWN(group1)\n",
"TEST(group1, Create)\n",
"IGNORE_TEST(group1, ignore)\n",
"TEST_SETUP(group2) expected\n",
"TEST_SETUP(group2)\n",
"TEST_TEAR_DOWN(group2) expected\n",
"TEST_TEAR_DOWN(group2)\n",
"TEST(group2, Create)\n",
"IGNORE_TEST(group2, ignore)\n",
]
convert_macros(test_lines, ["group1", "group2"])
check("convert_macros", expected_lines, test_lines)
#---------------------------------------------------
test_lines =
[
" aaaa expected\n",
"\taaa\n",
" bbbb expected\n",
"\t\t\t\tbbbb\n",
" int a3; expected\n",
" int a3;\n",
" int a4; expected\n",
" int a4;\n"
]
expected_lines =
[
" aaaa expected\n",
" aaa\n",
" bbbb expected\n",
" bbbb\n",
" int a3; expected\n",
" int a3;\n",
" int a4; expected\n",
" int a4;\n"
]
adjust_tabs(test_lines)
check("adjust_tabs", expected_lines, test_lines)
#---------------------------------------------------
test_lines =
[
"TEST(LedDriver, Create)\n",
"{\n",
" FAIL(\"Start here\");\n",
"}\n",
"\n",
"TEST(LedDriver, XXXXX)\n",
"{\n",
" FAIL(\"Start here\");\n",
"}\n",
"\n",
"IGNORE_TEST(LedDriver, ignore)\n",
"{\n",
" TEST_ASSERT_TRUE(0 == 0); expected\n",
"}\n"
]
expected_group_runner =
[
"/* Make sure you invoke RUN_TEST_GROUP(LedDriver) from unity main */\n\n",
"TEST_GROUP_RUNNER(LedDriver)\n",
"{\n",
" RUN_TEST_CASE(LedDriver, Create);\n",
" RUN_TEST_CASE(LedDriver, XXXXX);\n",
" RUN_TEST_CASE(LedDriver, ignore);\n",
"}\n\n"
]
group_runner = generate_group_runner("LedDriver", test_lines)
check("generate_group_runner", expected_group_runner, group_runner)
#---------------------------------------------------
test_lines =
[
"TEST(LedDriverGroup1, Create)\n",
"{\n",
" FAIL(\"Start here\");\n",
"}\n",
"\n",
"TEST(LedDriverGroup2, XXXXX)\n",
"{\n",
" FAIL(\"Start here\");\n",
"}\n",
"\n"
]
expected_group_runners =
[
"/* Generated code, edit at your own risk */\n\n",
"#include \"unity_fixture.h\"\n\n",
"/* Make sure you invoke RUN_TEST_GROUP(LedDriverGroup1) from unity main */\n\n",
"TEST_GROUP_RUNNER(LedDriverGroup1)\n",
"{\n",
" RUN_TEST_CASE(LedDriverGroup1, Create);\n",
"}\n\n",
"/* Make sure you invoke RUN_TEST_GROUP(LedDriverGroup2) from unity main */\n\n",
"TEST_GROUP_RUNNER(LedDriverGroup2)\n",
"{\n",
" RUN_TEST_CASE(LedDriverGroup2, XXXXX);\n",
"}\n\n"
]
runners = generate_group_runners(["LedDriverGroup1", "LedDriverGroup2"], test_lines)
check("generate_group_runners", expected_group_runners, runners)
#---------------------------------------------------
test_filename = "prefix/tests/pooltable/EightballTest.cpp"
expected_unity_filename = "prefix/unity/pooltable/EightballTest.c"
unity_filename = convert_test_filename_to_unity_filename(test_filename)
if expected_unity_filename != unity_filename
puts("Failure in: convert_test_path_to_unity_path")
puts("Expected: " + expected_unity_filename.inspect)
puts(" Actual: " + unity_filename.inspect)
end
#---------------------------------------------------
test_filename = "tests/pool/table/EightballTest.cpp"
expected_unity_runner_filename = "unity/pool/table/EightballTest_runner.c"
unity_runner_filename = convert_test_filename_to_unity_testrunner_filename(test_filename)
if expected_unity_runner_filename != unity_runner_filename
puts("Failure in: convert_test_path_to_unity_path")
puts("Expected: " + expected_unity_runner_filename.inspect)
puts(" Actual: " + unity_runner_filename.inspect)
end

View file

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'cpp_u_test_to_unity_utils.rb')
include CppUTestToUnityUtils
in_file = ARGV[0]
create_group_runner_file(in_file)
unity_runner_filename = convert_test_filename_to_unity_testrunner_filename(in_file)
puts "Creating test runner for :" + in_file + "\n"
puts " Generating :" + unity_filename + "\n"
test_lines = File.open(in_file).readlines
out_unity_runner_file = File.open(unity_runner_filename, 'w')
test_group = get_test_group(test_lines)
group_runner = generate_group_runner(test_group, test_lines)
write_lines_to_file(out_unity_runner_file, group_runner)
out_unity_runner_file.close()

View file

@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'cpp_u_test_to_unity_utils.rb')
include CppUTestToUnityUtils
in_file = ARGV[0]
test_lines = File.open(in_file).collect
out_file = File.open(File.basename(in_file, ".c") + "_runner.c", 'w')
group_runner = generate_group_runner_plainUnity("unity", test_lines)
write_lines_to_file(out_file, group_runner)
out_file.close()