diff --git a/examples/rakefile b/examples/rakefile.rb similarity index 79% rename from examples/rakefile rename to examples/rakefile.rb index e3e1ded..0dc53d5 100644 --- a/examples/rakefile +++ b/examples/rakefile.rb @@ -6,15 +6,23 @@ require 'fileutils' require 'set' require '../auto/unity_test_summary' require '../auto/generate_test_runner' -require 'rakefile_helper' + +#USE THIS ONE IF YOU WANT TO TRY THIS WITH GCC +#require 'rakefile_helper_GCC' + +#USE THIS ONE IF YOU WANT TO TRY THIS WITH IAR +require 'rakefile_helper_IAR' include RakefileHelpers +#This tells us where to clean our temporary files CLEAN.include('build/*') -desc "Build and run all tests, then output results (you can just type \"rake\" to get this." +#This is what is run when you type rake with no params +desc "Build and run all tests, then output results (you can just type \"rake\" to get this)." task :default => [:clobber, :all, :summary] +#This runs our test summary task :summary do flush_output summary = UnityTestSummary.new @@ -23,6 +31,7 @@ task :summary do summary.run end +#This builds and runs all the unit tests task :all do puts "Starting Test Suite" runner_generator = UnityTestRunnerGenerator.new diff --git a/examples/rakefile_helper_GCC.rb b/examples/rakefile_helper_GCC.rb new file mode 100644 index 0000000..161f007 --- /dev/null +++ b/examples/rakefile_helper_GCC.rb @@ -0,0 +1,66 @@ +#This rakefile sets you up to use GCC as your compiler for tests +module RakefileConstants + + C_EXTENSION = '.c' + OBJ_EXTENSION = '.obj' + BIN_EXTENSION = '.exe' + + UNIT_TEST_PATH = 'test' + UNITY_PATH = '../src' + SOURCE_PATH = 'src' + BUILD_PATH = 'build' + + UNITY_SRC = UNITY_PATH + '\unity.c' + UNITY_HDR = UNITY_PATH + '\unity.h' + + COMPILER = 'gcc.exe' + LINKER = 'gcc.exe' + +end + +module RakefileHelpers + include RakefileConstants + + def flush_output + $stderr.flush + $stdout.flush + end + + def report message + puts message + flush_output + end + + def compile src, obj + execute "#{COMPILER} -c -I#{SOURCE_PATH} -I#{UNITY_PATH} -DTEST #{src} -o#{obj}" + end + + def link prerequisites, executable + execute "#{LINKER} -DTEST #{prerequisites.join(' ')} -o#{executable}" + end + + def run_test executable + execute "\"#{executable}\"" + end + + def write_result_file filename, results + if (results.include?("OK\n")) + output_file = filename.gsub(BIN_EXTENSION, '.testpass') + else + output_file = filename.gsub(BIN_EXTENSION, '.testfail') + end + File.open(output_file, 'w') do |f| + f.print results + end + end + +private ##################### + + def execute command_string + report command_string + output = `#{command_string}` + report output + output + end + +end diff --git a/examples/rakefile_helper.rb b/examples/rakefile_helper_IAR.rb similarity index 84% rename from examples/rakefile_helper.rb rename to examples/rakefile_helper_IAR.rb index cca6582..44ce3b1 100644 --- a/examples/rakefile_helper.rb +++ b/examples/rakefile_helper_IAR.rb @@ -1,12 +1,11 @@ -HERE = File.expand_path( File.dirname( __FILE__ ) ).gsub(/\//, '\\') - +#This rakefile sets you up to use IAR System's C Compiler and Simulator for your tests. module RakefileConstants PROGRAM_FILES_PATH = ENV['ProgramFiles'] - begin + begin #If You installed the real thing Dir.new PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0\arm' IAR_ROOT = PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0' - rescue + rescue #Or If you installed the kick-start version Dir.new PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0 Kickstart\arm' IAR_ROOT = PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0 Kickstart' end @@ -21,7 +20,6 @@ module RakefileConstants BUILD_PATH = 'build' IAR_PATH = IAR_ROOT + '\common' IAR_BIN = IAR_PATH + '\bin' - IAR_INCLUDE = IAR_PATH + '\inc' IAR_CORE_PATH = IAR_ROOT + '\arm' IAR_CORE_BIN = IAR_CORE_PATH + '\bin' IAR_CORE_CONFIG = IAR_CORE_PATH + '\config' @@ -30,7 +28,6 @@ module RakefileConstants IAR_CORE_LIB = IAR_CORE_PATH + '\lib' IAR_CORE_DLIB = IAR_CORE_LIB + '\dl5tpannl8n.r79' IAR_CORE_DLIB_CONFIG = IAR_CORE_LIB + '\dl5tpannl8n.h' - IAR_PROCESSOR_SPECIFIC_PATH = HERE + '\proc' SIMULATOR_PROCESSOR = IAR_CORE_BIN + '\armproc.dll' SIMULATOR_DRIVER = IAR_CORE_BIN + '\armsim.dll' SIMULATOR_PLUGIN = IAR_CORE_BIN + '\armbat.dll' @@ -40,11 +37,6 @@ module RakefileConstants UNITY_SRC = UNITY_PATH + '\unity.c' UNITY_HDR = UNITY_PATH + '\unity.h' - UNITY_OBJ = BUILD_PATH + '\unity' + OBJ_EXTENSION - UNITY_TEST_OBJ = BUILD_PATH + '\testunity' + OBJ_EXTENSION - UNITY_TEST_RUNNER_OBJ = BUILD_PATH + '\testunity_Runner' + OBJ_EXTENSION - UNITY_TEST_EXEC = UNITY_TEST_OBJ.ext BIN_EXTENSION - TEST_RESULTS = UNITY_TEST_OBJ.ext '.testpass' COMPILER = IAR_CORE_BIN + '\iccarm.exe' LINKER = IAR_BIN + '\xlink.exe' diff --git a/rakefile b/rakefile.rb similarity index 87% rename from rakefile rename to rakefile.rb index 8450c97..5476918 100644 --- a/rakefile +++ b/rakefile.rb @@ -5,7 +5,12 @@ require 'rake/loaders/makefile' require 'fileutils' require 'set' require 'auto/unity_test_summary' -require 'rakefile_helper' + +#USE THIS ONE IF YOU WANT TO TRY THIS WITH GCC +require 'rakefile_helper_GCC' + +#USE THIS ONE IF YOU WANT TO TRY THIS WITH IAR +#require 'rakefile_helper_IAR' include RakefileHelpers diff --git a/rakefile_helper_GCC.rb b/rakefile_helper_GCC.rb new file mode 100644 index 0000000..6df7bbf --- /dev/null +++ b/rakefile_helper_GCC.rb @@ -0,0 +1,74 @@ +#This rakefile sets you up to use GCC as your compiler for tests +module RakefileConstants + + C_EXTENSION = '.c' + OBJ_EXTENSION = '.obj' + BIN_EXTENSION = '.exe' + + UNIT_TEST_PATH = 'test' + UNITY_PATH = 'src' + SOURCE_PATH = 'src' + BUILD_PATH = 'build' + + UNITY_SRC = UNITY_PATH + '\unity.c' + UNITY_HDR = UNITY_PATH + '\unity.h' + BIN_PATH = 'build' + UNITY_TEST_SRC = UNIT_TEST_PATH + '\testunity.c' + UNITY_TEST_RUNNER_SRC = UNIT_TEST_PATH + '\testunity_Runner.c' + UNITY_OBJ = BIN_PATH + '\unity' + OBJ_EXTENSION + UNITY_TEST_OBJ = BIN_PATH + '\testunity' + OBJ_EXTENSION + UNITY_TEST_RUNNER_OBJ = BIN_PATH + '\testunity_Runner' + OBJ_EXTENSION + UNITY_TEST_EXEC = UNITY_TEST_OBJ.ext BIN_EXTENSION + TEST_RESULTS = UNITY_TEST_OBJ.ext '.testpass' + + COMPILER = 'gcc.exe' + LINKER = 'gcc.exe' + +end + +module RakefileHelpers + include RakefileConstants + + def flush_output + $stderr.flush + $stdout.flush + end + + def report message + puts message + flush_output + end + + def compile src, obj + execute "#{COMPILER} -c -I#{SOURCE_PATH} -I#{UNITY_PATH} -DTEST #{src} -o#{obj}" + end + + def link prerequisites, executable + execute "#{LINKER} -DTEST #{prerequisites.join(' ')} -o#{executable}" + end + + def run_test executable + execute "\"#{executable}\"" + end + + def write_result_file filename, results + if (results.include?("OK\n")) + output_file = filename.gsub(BIN_EXTENSION, '.testpass') + else + output_file = filename.gsub(BIN_EXTENSION, '.testfail') + end + File.open(output_file, 'w') do |f| + f.print results + end + end + +private ##################### + + def execute command_string + report command_string + output = `#{command_string}` + report output + output + end + +end diff --git a/rakefile_helper.rb b/rakefile_helper_IAR.rb similarity index 79% rename from rakefile_helper.rb rename to rakefile_helper_IAR.rb index 7c628cc..11694f8 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper_IAR.rb @@ -1,12 +1,11 @@ -HERE = File.expand_path( File.dirname( __FILE__ ) ).gsub(/\//, '\\') - +#This rakefile sets you up to use IAR System's C Compiler and Simulator for your tests. module RakefileConstants PROGRAM_FILES_PATH = ENV['ProgramFiles'] - begin + begin #If You installed the real thing Dir.new PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0\arm' IAR_ROOT = PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0' - rescue + rescue #Or If you installed the kick-start version Dir.new PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0 Kickstart\arm' IAR_ROOT = PROGRAM_FILES_PATH + '\IAR Systems\Embedded Workbench 4.0 Kickstart' end @@ -16,11 +15,12 @@ module RakefileConstants BIN_EXTENSION = '.d79' UNIT_TEST_PATH = 'test' + UNITY_PATH = 'src' SOURCE_PATH = 'src' + BUILD_PATH = 'build' BIN_PATH = 'build' IAR_PATH = IAR_ROOT + '\common' IAR_BIN = IAR_PATH + '\bin' - IAR_INCLUDE = IAR_PATH + '\inc' IAR_CORE_PATH = IAR_ROOT + '\arm' IAR_CORE_BIN = IAR_CORE_PATH + '\bin' IAR_CORE_CONFIG = IAR_CORE_PATH + '\config' @@ -29,7 +29,6 @@ module RakefileConstants IAR_CORE_LIB = IAR_CORE_PATH + '\lib' IAR_CORE_DLIB = IAR_CORE_LIB + '\dl5tpannl8n.r79' IAR_CORE_DLIB_CONFIG = IAR_CORE_LIB + '\dl5tpannl8n.h' - IAR_PROCESSOR_SPECIFIC_PATH = HERE + '\proc' SIMULATOR_PROCESSOR = IAR_CORE_BIN + '\armproc.dll' SIMULATOR_DRIVER = IAR_CORE_BIN + '\armsim.dll' SIMULATOR_PLUGIN = IAR_CORE_BIN + '\armbat.dll' @@ -37,8 +36,8 @@ module RakefileConstants PROCESSOR_TYPE = "ARM926EJ-S" LINKER_CONFIG = IAR_CORE_CONFIG + '\lnkarm.xcl' - UNITY_SRC = SOURCE_PATH + '\unity.c' - UNITY_HDR = SOURCE_PATH + '\unity.h' + UNITY_SRC = UNITY_PATH + '\unity.c' + UNITY_HDR = UNITY_PATH + '\unity.h' UNITY_TEST_SRC = UNIT_TEST_PATH + '\testunity.c' UNITY_TEST_RUNNER_SRC = UNIT_TEST_PATH + '\testunity_Runner.c' UNITY_OBJ = BIN_PATH + '\unity' + OBJ_EXTENSION @@ -67,7 +66,7 @@ module RakefileHelpers end def compile src, obj - execute "#{COMPILER} --dlib_config \"#{IAR_CORE_DLIB_CONFIG}\" -z3 --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --no_clustering --no_scheduling --debug --cpu_mode arm --endian little --cpu #{PROCESSOR_TYPE} --stack_align 4 -e --fpu None --diag_suppress Pa050 --diag_suppress Pe111 -I\"#{IAR_CORE_INCLUDE}\" -Isrc -Itest #{src} -o#{obj}" + execute "#{COMPILER} --dlib_config \"#{IAR_CORE_DLIB_CONFIG}\" -z3 --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --no_clustering --no_scheduling --debug --cpu_mode arm --endian little --cpu #{PROCESSOR_TYPE} --stack_align 4 -e --fpu None --diag_suppress Pa050 --diag_suppress Pe111 -I\"#{IAR_CORE_INCLUDE}\" -I\"#{UNITY_PATH}\" -Isrc -Itest #{src} -o#{obj}" end def link prerequisites, executable @@ -78,7 +77,18 @@ module RakefileHelpers execute "\"#{SIMULATOR}\" --silent \"#{SIMULATOR_PROCESSOR}\" \"#{SIMULATOR_DRIVER}\" #{executable} --plugin \"#{SIMULATOR_PLUGIN}\" --backend -B --cpu #{PROCESSOR_TYPE} -p \"#{SIMULATOR_BACKEND_DDF}\" -d sim" end -private + def write_result_file filename, results + if (results.include?("OK\n")) + output_file = filename.gsub(BIN_EXTENSION, '.testpass') + else + output_file = filename.gsub(BIN_EXTENSION, '.testfail') + end + File.open(output_file, 'w') do |f| + f.print results + end + end + +private ##################### def execute command_string report command_string