Skip to content

Commit

Permalink
Examples and main tests can be run on GCC or IAR now
Browse files Browse the repository at this point in the history
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@5 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
  • Loading branch information
mvandervoord committed Oct 29, 2008
1 parent d1550d8 commit 8fb0204
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 24 deletions.
13 changes: 11 additions & 2 deletions examples/rakefile → examples/rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
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
Expand All @@ -23,6 +31,7 @@
summary.run
end

#This builds and runs all the unit tests
task :all do
puts "Starting Test Suite"
runner_generator = UnityTestRunnerGenerator.new
Expand Down
66 changes: 66 additions & 0 deletions examples/rakefile_helper_GCC.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions examples/rakefile_helper.rb → examples/rakefile_helper_IAR.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
7 changes: 6 additions & 1 deletion rakefile → rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
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

Expand Down
74 changes: 74 additions & 0 deletions rakefile_helper_GCC.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 20 additions & 10 deletions rakefile_helper.rb → rakefile_helper_IAR.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand All @@ -29,16 +29,15 @@ 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'
SIMULATOR_BACKEND_DDF = IAR_CORE_CONFIG + '\ioat91sam9261.ddf'
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
Expand Down Expand Up @@ -67,7 +66,7 @@ def report message
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
Expand All @@ -78,7 +77,18 @@ def run_test executable
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
Expand Down

0 comments on commit 8fb0204

Please sign in to comment.