diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index d20d83b..4c31ca8 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -132,7 +132,7 @@ class UnityTestRunnerGenerator output.puts("#{@tab}#{@tab}setUp();") output.puts("#{@tab}#{@tab}test();") output.puts("#{@tab}}") - output.puts("#{@tab}TEST_WRAP(CMock_Verify());") unless (used_mocks.empty?) + output.puts("#{@tab}CMock_Verify();") unless (used_mocks.empty?) output.puts("#{@tab}CMock_Destroy();") unless (used_mocks.empty?) output.puts("#{@tab}tearDown();") output.puts("}") diff --git a/config/environment.rb b/config/environment.rb index 46cac00..bad4c6d 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,6 +5,7 @@ ROOT_PATH = File.expand_path(File.dirname(__FILE__) + "/../") 'lib', 'vendor/behaviors/lib', 'vendor/hardmock/lib', + 'vendor/unity/auto/' ].each do |dir| $LOAD_PATH.unshift(File.join(ROOT_PATH, dir)) end diff --git a/gcc.yml b/gcc.yml index 23a47c3..e5ff53f 100644 --- a/gcc.yml +++ b/gcc.yml @@ -1,4 +1,34 @@ -compiler: 'gcc' -linker: 'gcc' -compile_flags: '-c' -link_flags: '' +compiler: + path: gcc + source_path: 'test/system/src/' + unit_tests_path: &unit_tests_path 'test/system/test/' + mocks_path: 'test/system/mocks/' + build_path: &build_path 'test/system/build/' + options: + - -c + includes: + prefix: '-I' + items: + - 'test/system/src/' + - *unit_tests_path + - 'test/system/mocks/' + - 'vendor/unity/src/' + defines: + prefix: '-D' + items: + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path \ No newline at end of file diff --git a/iar.yml b/iar.yml new file mode 100644 index 0000000..b07da5a --- /dev/null +++ b/iar.yml @@ -0,0 +1,86 @@ +tools_root: &tools_root 'C:\Program Files\IAR Systems\Embedded Workbench 4.0\' +compiler: + path: [*tools_root, 'arm\bin\iccarm.exe'] + source_path: 'test\system\src\' + unit_tests_path: &unit_tests_path 'test\system\test\' + mocks_path: 'test\system\mocks\' + build_path: &build_path 'test\system\build\' + options: + - --dlib_config + - [*tools_root, 'arm\lib\dl4tptinl8n.h'] + - -z3 + - --no_cse + - --no_unroll + - --no_inline + - --no_code_motion + - --no_tbaa + - --no_clustering + - --no_scheduling + - --debug + - --cpu_mode thumb + - --endian little + - --cpu ARM7TDMI + - --stack_align 4 + - --interwork + - -e + - --silent + - --warnings_are_errors + - --fpu None + - --diag_suppress Pa050 + includes: + prefix: '-I' + items: + - [*tools_root, 'arm\inc\'] + - 'test\system\src\' + - *unit_tests_path + - 'test\system\mocks\' + - 'vendor\unity\src\' + defines: + prefix: '-D' + items: + object_files: + prefix: '-o' + extension: '.r79' + destination: *build_path +linker: + path: [*tools_root, 'common\bin\xlink.exe'] + options: + - -rt + - [*tools_root, 'arm\lib\dl4tptinl8n.r79'] + - -D_L_EXTMEM_START=0 + - -D_L_EXTMEM_SIZE=0 + - -D_L_HEAP_SIZE=120 + - -D_L_STACK_SIZE=32 + - -e_small_write=_formatted_write + - -s + - __program_start + - '-f iar\at91SAM7X256_FLASH.xcl' + includes: + prefix: '-I' + items: + - [*tools_root, 'arm\config\'] + - [*tools_root, 'arm\lib\'] + object_files: + path: *build_path + extension: '.r79' + bin_files: + prefix: '-o' + extension: '.d79' + destination: *build_path +simulator: + path: [*tools_root, 'common\bin\CSpyBat.exe'] + pre_support: + - --silent + - [*tools_root, 'arm\bin\armproc.dll'] + - [*tools_root, 'arm\bin\armsim.dll'] + post_support: + - --plugin + - [*tools_root, 'arm\bin\armbat.dll'] + - --macro + - 'iar\SAM7_SIM.mac' + - --backend + - -B + - -p + - [*tools_root, 'arm\config\ioat91sam7X256.ddf'] + - -d + - sim \ No newline at end of file diff --git a/iar/SAM7_SIM.mac b/iar/SAM7_SIM.mac new file mode 100644 index 0000000..2be1a4c --- /dev/null +++ b/iar/SAM7_SIM.mac @@ -0,0 +1,67 @@ +//========================================================= +// Simulation setup file for esc07_demo project +//========================================================= + +__var _timer0_interrupt_ID; + +irqBreak() +{ + __var __AIC_SMR; + __var __AIC_IECR; + __var __AIC_IVR; + + // read AIC_IECR instead, since not fully supported by simulator + __AIC_IECR = __readMemory32(0xFFFFF120, "Memory"); + if(__AIC_IECR & 0x1000) + { + __AIC_SMR = __readMemory32(0xFFFFF060, "Memory"); + __AIC_IVR = __readMemory32(0xFFFFF0B0, "Memory"); //AIC_IVR = AIC_SVR[x] + __writeMemory32(__AIC_IVR, 0xFFFFF100, "Memory"); //AIC_IVR + __writeMemory32(0x1000, 0xFFFFF10C, "Memory"); //AIC_IPR + __writeMemory32(0x2, 0xFFFFF114, "Memory"); //AIC_CISR + } + + return 0; +} + +setupProcessorRegisters() +{ + // Write TC0_SR.CPCS with correct status for ISR (Clock enabled; RC Compare Flag = TRUE) + __writeMemory32(0x00010010, 0xfffa0020, "Memory"); + + // Set TX ready flag in USART0 status register + // USART0_BASE->US_CSR = AT91C_US_TXRDY + __writeMemory32(0x00000002, 0xfffc0014, "Memory"); +} + +configureTimer0Interrupt() +{ + __var _master_clock_frequency; + __var _timer0_period_cycles; + + // Calculate timer0 frequency in master clock cycles + _master_clock_frequency = 48054857; + _timer0_period_cycles = _master_clock_frequency / 100; + if((_master_clock_frequency % 100) >= 50) + { + _timer0_period_cycles++; + } + + __cancelAllInterrupts(); + __enableInterrupts(); + + _timer0_interrupt_ID = __orderInterrupt("IRQ", _timer0_period_cycles, _timer0_period_cycles, 0, 0, 0, 100); + + if(-1 == _timer0_interrupt_ID) + { + __message "ERROR: failed to order timer 0 interrupt"; + } + + __setCodeBreak("0x18", 0, "irqBreak()", "TRUE", ""); +} + +execUserReset() +{ + setupProcessorRegisters(); + configureTimer0Interrupt(); +} diff --git a/iar/at91SAM7X256_FLASH.xcl b/iar/at91SAM7X256_FLASH.xcl new file mode 100644 index 0000000..bbcabec --- /dev/null +++ b/iar/at91SAM7X256_FLASH.xcl @@ -0,0 +1,185 @@ +// ---------------------------------------------------------------------------- +// ATMEL Microcontroller Software Support - ROUSSET - +// ---------------------------------------------------------------------------- +// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE +// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// ---------------------------------------------------------------------------- +// File Name : at91SAM7X256_FLASH.xcl +// Object : Generic Linker Command File for IAR +// 1.0 30/Aug/05 FBr : Creation for 4.30A +// ---------------------------------------------------------------------------- + +//************************************************************************* +// XLINK command file template for EWARM/ICCARM +// +// Usage: xlink -f lnkarm +// -s +//************************************************************************* +// +// ------------- +// Code segments - may be placed anywhere in memory. +// ------------- +// +// INTVEC -- Exception vector table. +// SWITAB -- Software interrupt vector table. +// ICODE -- Startup (cstartup) and exception code. +// DIFUNCT -- Dynamic initialization vectors used by C++. +// CODE -- Compiler generated code. +// CODE_I -- Compiler generated code declared __ramfunc (executes in RAM) +// CODE_ID -- Initializer for CODE_I (ROM). +// +// ------------- +// Data segments - may be placed anywhere in memory. +// ------------- +// +// CSTACK -- The stack used by C/C++ programs (system and user mode). +// IRQ_STACK -- The stack used by IRQ service routines. +// SVC_STACK -- The stack used in supervisor mode +// (Define other exception stacks as needed for +// FIQ, ABT, UND). +// HEAP -- The heap used by malloc and free in C and new and +// delete in C++. +// INITTAB -- Table containing addresses and sizes of segments that +// need to be initialized at startup (by cstartup). +// CHECKSUM -- The linker places checksum byte(s) in this segment, +// when the -J linker command line option is used. +// DATA_y -- Data objects. +// +// Where _y can be one of: +// +// _AN -- Holds uninitialized located objects, i.e. objects with +// an absolute location given by the @ operator or the +// #pragma location directive. Since these segments +// contain objects which already have a fixed address, +// they should not be mentioned in this linker command +// file. +// _C -- Constants (ROM). +// _I -- Initialized data (RAM). +// _ID -- The original content of _I (copied to _I by cstartup) (ROM). +// _N -- Uninitialized data (RAM). +// _Z -- Zero initialized data (RAM). +// +// Note: Be sure to use end values for the defined address ranges. +// Otherwise, the linker may allocate space outside the +// intended memory range. +//************************************************************************* + +//************************************************************************* +// Inform the linker about the CPU family used. +// AT91SAM7X256 Memory mapping +// No remap +// ROMSTART +// Start address 0x0000 0000 +// Size 256 Kbo 0x0004 0000 +// RAMSTART +// Start address 0x0020 0000 +// Size 64 Kbo 0x0001 0000 +// Remap done +// RAMSTART +// Start address 0x0000 0000 +// Size 64 Kbo 0x0001 0000 +// ROMSTART +// Start address 0x0010 0000 +// Size 256 Kbo 0x0004 0000 + +//************************************************************************* +-carm + +//************************************************************************* +// Internal Ram segments mapped AFTER REMAP 64 K. +//************************************************************************* +-Z(CONST)INTRAMSTART_REMAP=00200000 +-Z(CONST)INTRAMEND_REMAP=0020FFFF + +//************************************************************************* +// Read-only segments mapped to Flash 256 K. +//************************************************************************* +-DROMSTART=00000000 +-DROMEND=0003FFFF +//************************************************************************* +// Read/write segments mapped to 64 K RAM. +//************************************************************************* +-DRAMSTART=00200000 +-DRAMEND=0020FFFF + +//************************************************************************* +// Address range for reset and exception +// vectors (INTVEC). +// The vector area is 32 bytes, +// an additional 32 bytes is allocated for the +// constant table used by ldr PC in cstartup.s79. +//************************************************************************* +-Z(CODE)INTVEC=00-3F + +//************************************************************************* +// Startup code and exception routines (ICODE). +//************************************************************************* +-Z(CODE)ICODE,DIFUNCT=ROMSTART-ROMEND +-Z(CODE)SWITAB=ROMSTART-ROMEND + +//************************************************************************* +// Code segments may be placed anywhere. +//************************************************************************* +-Z(CODE)CODE=ROMSTART-ROMEND + +//************************************************************************* +// Various constants and initializers. +//************************************************************************* +-Z(CONST)INITTAB,DATA_ID,DATA_C=ROMSTART-ROMEND +-Z(CONST)CHECKSUM=ROMSTART-ROMEND + +//************************************************************************* +// Data segments. +//************************************************************************* +-Z(DATA)DATA_I,DATA_Z,DATA_N=RAMSTART-RAMEND + +//************************************************************************* +// __ramfunc code copied to and executed from RAM. +//************************************************************************* +-Z(DATA)CODE_I=RAMSTART-RAMEND +-Z(CONST)CODE_ID=ROMSTART-ROMEND // Initializer for +-QCODE_I=CODE_ID + +//************************************************************************* +// ICCARM produces code for __ramfunc functions in +// CODE_I segments. The -Q XLINK command line +// option redirects XLINK to emit the code in the +// debug information associated with the CODE_I +// segment, where the code will execute. +//************************************************************************* + +//************************************************************************* +// Stack and heap segments. +//************************************************************************* +-D_CSTACK_SIZE=(100*4) +-D_IRQ_STACK_SIZE=(3*8*4) +-D_HEAP_SIZE=(1024*1) + +-Z(DATA)CSTACK+_CSTACK_SIZE=RAMSTART-RAMEND +-Z(DATA)IRQ_STACK+_IRQ_STACK_SIZE=RAMSTART-RAMEND +-Z(DATA)HEAP+_HEAP_SIZE=RAMSTART-RAMEND + +//************************************************************************* +// ELF/DWARF support. +// +// Uncomment the line "-Felf" below to generate ELF/DWARF output. +// Available format specifiers are: +// +// "-yn": Suppress DWARF debug output +// "-yp": Multiple ELF program sections +// "-yas": Format suitable for debuggers from ARM Ltd (also sets -p flag) +// +// "-Felf" and the format specifiers can also be supplied directly as +// command line options, or selected from the Xlink Output tab in the +// IAR Embedded Workbench. +//************************************************************************* + +// -Felf diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index f2970cd..38bec32 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -59,7 +59,7 @@ class CMockGeneratorPluginExpect lines << "#{@tab}Mock.#{function_name}_CallCount++;\n" lines << "#{@tab}if (Mock.#{function_name}_CallCount > Mock.#{function_name}_CallsExpected)\n" lines << "#{@tab}{\n" - lines << "#{@tab}#{@tab}TEST_THROW(\"#{function_name} Called More Times Than Expected\");\n" + lines << "#{@tab}#{@tab}TEST_FAIL(\"#{function_name} Called More Times Than Expected\");\n" lines << "#{@tab}}\n" function_args_as_array.each do |arg| arg_return_type = arg[:type].sub(/const/, '').strip diff --git a/rakefile.rb b/rakefile.rb index d846344..56e349d 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -1,23 +1,18 @@ $here = File.expand_path(File.dirname(__FILE__)) +require $here + '/config/environment' require 'rake' require 'rake/clean' require 'rake/testtask' require 'rakefile_helper' -include RakefileConstants include RakefileHelpers -SYSTEST_TEST_FILES = FileList.new(SYSTEST_TEST_DIR + 'Test*' + C_EXTENSION) - -COMPILER_CONFIGS = FileList.new('*.yml') - -CLEAN.include(SYSTEST_BUILD_DIR + '*.*') -CLEAN.include(SYSTEST_MOCKS_DIR + '*.*') +configure_clean task :default => [ :clobber, 'tests:all', :app ] -desc "Build and run application" +desc "Build application" task :app do COMPILER_CONFIGS.each do |cfg_file| build_application(yaml_read(cfg_file), 'Main') @@ -27,18 +22,20 @@ end namespace :tests do desc "Run unit and system tests" - task :all => [:clean, 'units', 'system', 'app'] + task :all => [:clean, :units, :system, :app] Rake::TestTask.new('units') do |t| - t.pattern = 'test//unit/*_test.rb' + t.pattern = 'test/unit/*_test.rb' t.verbose = true end desc "Run system tests" task :system => [:clean] do COMPILER_CONFIGS.each do |cfg_file| - run_systests(yaml_read(cfg_file), SYSTEST_TEST_FILES) - report_summary + config = yaml_read(cfg_file) + systest_test_files = get_unit_test_files(config) + run_systests(config, systest_test_files) + report_summary(config) end end diff --git a/rakefile_helper.rb b/rakefile_helper.rb index d888dd7..b66d5b0 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -1,39 +1,50 @@ require 'yaml' -require 'lib/cmock' -require 'vendor/unity/auto/generate_test_runner' -require 'vendor/unity/auto/unity_test_summary' +require 'fileutils' +require 'cmock' +require 'generate_test_runner' +require 'unity_test_summary' -def Kernel.is_windows? - processor, platform, *rest = RUBY_PLATFORM.split("-") - platform == 'mswin32' -end - -module RakefileConstants - - C_EXTENSION = '.c' - OBJ_EXTENSION = '.o' +module RakefileHelpers - if (Kernel.is_windows?) + # Configure constants appropriately + C_EXTENSION = '.c' + processor, platform, *rest = RUBY_PLATFORM.split("-") + if (platform == 'mswin32') EXE_EXTENSION = '.exe' else EXE_EXTENSION = '.out' end + COMPILER_CONFIGS = FileList.new('*.yml') - UNITY_DIR = 'vendor/unity/src/' + def yaml_read(filename) + return YAML.load(File.read(filename)) + end - SYSTEST_BASE = 'test/system/' - SYSTEST_SOURCE_DIR = SYSTEST_BASE + 'src/' - SYSTEST_TEST_DIR = SYSTEST_BASE + 'test/' - SYSTEST_MOCKS_DIR = SYSTEST_BASE + 'mocks/' - SYSTEST_BUILD_DIR = SYSTEST_BASE + 'build/' - - SYSTEST_INCLUDE_DIRS = [SYSTEST_SOURCE_DIR, SYSTEST_TEST_DIR, SYSTEST_MOCKS_DIR, UNITY_DIR] - -end - -module RakefileHelpers - - require 'fileutils' + def report(message) + puts message + $stdout.flush + $stderr.flush + end + + def configure_clean + COMPILER_CONFIGS.each do |f| + config = yaml_read(f) + CLEAN.include(config['compiler']['mocks_path'] + '*.*') unless config['compiler']['mocks_path'].nil? + CLEAN.include(config['compiler']['build_path'] + '*.*') unless config['compiler']['mocks_path'].nil? + end + end + + def get_unit_test_files(config) + path = config['compiler']['unit_tests_path'] + 'Test*' + C_EXTENSION + path.gsub!(/\\/, '/') + FileList.new(path) + end + + def get_local_include_dirs(config) + include_dirs = config['compiler']['includes']['items'].dup + include_dirs.delete_if {|dir| dir.is_a?(Array)} + return include_dirs + end def extract_headers(filename) includes = [] @@ -47,9 +58,8 @@ module RakefileHelpers return includes end - def find_source_file(header) - src_file = '' - SYSTEST_INCLUDE_DIRS.each do |dir| + def find_source_file(header, paths) + paths.each do |dir| src_file = dir + header.ext(C_EXTENSION) if (File.exists?(src_file)) return src_file @@ -58,38 +68,78 @@ module RakefileHelpers return nil end + def tackit(strings) + if strings.is_a?(Array) + result = "\"#{strings.join}\"" + else + result = strings + end + return result + end + + def squash(prefix, items) + result = '' + items.each { |item| result += " #{prefix}#{tackit(item)}" } + return result + end + + def build_compiler_fields(config) + command = tackit(config['compiler']['path']) + defines = '' + defines = squash(config['compiler']['defines']['prefix'], + config['compiler']['defines']['items']) unless config['compiler']['defines']['items'].nil? + options = squash('', config['compiler']['options']) + includes = squash(config['compiler']['includes']['prefix'], config['compiler']['includes']['items']) + includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) + return {:command => command, :defines => defines, :options => options, :includes => includes} + end + def compile(config, file, defines=[]) - cmd_str = "#{config["path"]}#{config["compiler"]} #{config["compile_flags"]} " - if !defines.nil? and defines.length > 0 - defines.each { |define| cmd_str += "-D#{define} " } - end - if !config["path"].nil? - cmd_str += "-B#{config["path"]} " - end - cmd_str += (SYSTEST_INCLUDE_DIRS.map{|dir|"-I#{dir} "}).join + - "#{file} " + - "-o #{SYSTEST_BUILD_DIR}#{File.basename(file, C_EXTENSION)}#{OBJ_EXTENSION}" + + compiler = build_compiler_fields(config) + + ################################################## + # NEED TO FIGURE OUT WHAT TO DO WITH THIS!!! + # if !config["path"].nil? + # cmd_str += "-B#{config["path"]} " + # end + ################################################## + + cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " + + "#{config['compiler']['object_files']['prefix']}#{config['compiler']['object_files']['destination']}" + + "#{File.basename(file, C_EXTENSION)}#{config['compiler']['object_files']['extension']}" + execute(cmd_str) end + def build_linker_fields(config) + command = tackit(config['linker']['path']) + options = '' + options += squash('', config['linker']['options']) unless config['linker']['options'].nil? + includes = '' + includes += squash(config['linker']['includes']['prefix'], + config['linker']['includes']['items']) unless config['linker']['includes']['items'].nil? + includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) + return {:command => command, :options => options, :includes => includes} + end + def link(config, exe_name, obj_list) - cmd_str = "#{config["path"]}#{config["linker"]} " - if !config["path"].nil? - cmd_str += "-B#{config["path"]} " - end - cmd_str += (obj_list.map{|obj|"#{SYSTEST_BUILD_DIR}#{obj} "}).join + - "-o #{SYSTEST_BUILD_DIR}#{exe_name}#{EXE_EXTENSION}" + linker = build_linker_fields(config) + cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + + (obj_list.map{|obj|"#{config['linker']['object_files']['path']}#{obj} "}).join + + "#{config['linker']['bin_files']['prefix']} #{config['linker']['bin_files']['destination']}#{exe_name}#{config['linker']['bin_files']['extension']}" execute(cmd_str) end - def yaml_read(filename) - return YAML.load(File.read(filename)) - end - - def report(message) - puts message - $stdout.flush - $stderr.flush + def build_simulator_fields(config) + return nil if config['simulator'].nil? + command = '' + command += (tackit(config['simulator']['path']) + ' ') unless config['simulator']['path'].nil? + pre_support = '' + pre_support = squash('', config['simulator']['pre_support']) unless config['simulator']['pre_support'].nil? + post_support = '' + post_support = squash('', config['simulator']['post_support']) unless config['simulator']['post_support'].nil? + return {:command => command, :pre_support => pre_support, :post_support => post_support} end def execute(command_string, verbose=true) @@ -102,16 +152,24 @@ module RakefileHelpers return output end - def report_summary + def report_summary(config) summary = UnityTestSummary.new summary.set_root_path($here) - summary.set_targets(Dir["#{SYSTEST_BUILD_DIR}*.test*"]) + summary.set_targets(Dir["#{config['compiler']['build_path']}*.test*"]) summary.run end def run_systests(config, test_files) + puts 'Running system tests...' + test_defines = ['TEST'] + my_config = config.dup + my_config['compiler']['defines']['items'] = [] if my_config['compiler']['defines']['items'].nil? + my_config['compiler']['defines']['items'] << 'TEST' + + include_dirs = get_local_include_dirs(my_config) + test_files.each do |test| obj_list = [] test_base = File.basename(test, C_EXTENSION) @@ -121,63 +179,73 @@ module RakefileHelpers if header =~ /^Mock(.*)\.h/i module_name = $1 report "Generating mock for module #{module_name}..." - cmock = CMock.new(SYSTEST_MOCKS_DIR, ['Types.h']) - cmock.setup_mocks("#{SYSTEST_SOURCE_DIR}#{module_name}.h") + cmock = CMock.new(config['compiler']['mocks_path'], ['Types.h']) + cmock.setup_mocks("#{config['compiler']['source_path']}#{module_name}.h") end - src_file = find_source_file(header) + src_file = find_source_file(header, include_dirs) if !src_file.nil? compile(config, src_file, test_defines) - obj_list << header.ext(OBJ_EXTENSION) + obj_list << header.ext(config['compiler']['object_files']['extension']) end end # Generate and build the test runner runner_name = test_base + '_Runner.c' - runner_path = SYSTEST_BUILD_DIR + runner_name + runner_path = config['compiler']['build_path'] + runner_name test_gen = UnityTestRunnerGenerator.new test_gen.run(test, runner_path, ['Types']) compile(config, runner_path, test_defines) - obj_list << runner_name.ext(OBJ_EXTENSION) + obj_list << runner_name.ext(config['compiler']['object_files']['extension']) # Build the test file compile(config, test, test_defines) - obj_list << test_base.ext(OBJ_EXTENSION) + obj_list << test_base.ext(config['compiler']['object_files']['extension']) + # Link the test executable link(config, test_base, obj_list) # Run test and generate results file - output = execute(SYSTEST_BUILD_DIR + test_base + EXE_EXTENSION) - test_results = SYSTEST_BUILD_DIR + test_base + simulator = build_simulator_fields(config) + executable = config['linker']['bin_files']['destination'] + test_base + config['linker']['bin_files']['extension'] + if simulator.nil? + cmd_str = executable + else + cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" + end + output = execute(cmd_str) + test_results = config['compiler']['build_path'] + test_base if output.match(/OK$/m).nil? test_results += '.testfail' else test_results += '.testpass' end - File.open(test_results, 'w') do |f| - f.print output - end + File.open(test_results, 'w') { |f| f.print output } end end def build_application(config, main) + + puts "Building application..." + obj_list = [] - main_path = SYSTEST_SOURCE_DIR + main + '.c' - executable_path = SYSTEST_BUILD_DIR + main + EXE_EXTENSION + main_path = config['compiler']['source_path'] + main + C_EXTENSION + executable_path = config['linker']['bin_files']['destination'] + main + config['linker']['bin_files']['extension'] main_base = File.basename(main_path, C_EXTENSION) headers = extract_headers(main_path) + include_dirs = get_local_include_dirs(config) headers.each do |header| - src_file = find_source_file(header) + src_file = find_source_file(header, include_dirs) if !src_file.nil? compile(config, src_file) - obj_list << header.ext(OBJ_EXTENSION) + obj_list << header.ext(config['compiler']['object_files']['extension']) end end compile(config, main_path) - obj_list << main_base.ext(OBJ_EXTENSION) + obj_list << main_base.ext(config['compiler']['object_files']['extension']) link(config, main_base, obj_list) end diff --git a/test/system/src/Main.c b/test/system/src/Main.c index 5a368ce..f5c783a 100644 --- a/test/system/src/Main.c +++ b/test/system/src/Main.c @@ -32,7 +32,9 @@ int AppMain(void) { Executor_Init(); - while(Executor_Run()); + while(Executor_Run()); + + return 0; } #ifndef TEST diff --git a/test/system/src/TemperatureCalculator.c b/test/system/src/TemperatureCalculator.c index 2746cfe..705b634 100644 --- a/test/system/src/TemperatureCalculator.c +++ b/test/system/src/TemperatureCalculator.c @@ -10,6 +10,11 @@ float TemperatureCalculator_Calculate(uint16 millivolts) const double coefficient_B = -0.1382009; double sensor_voltage = ((double)millivolts / 1000); double resistance; + + if (millivolts == 0) + { + return -INFINITY; + } // Series resistor is 5k Ohms; Reference voltage is 3.0V // R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C diff --git a/test/system/test/TestTemperatureFilter.c b/test/system/test/TestTemperatureFilter.c index b307549..ace33a9 100644 --- a/test/system/test/TestTemperatureFilter.c +++ b/test/system/test/TestTemperatureFilter.c @@ -55,15 +55,15 @@ void testShouldWeightEachSubsequentValueBy25PercentAfterInitialValue(void) void setInvalidTemperatureAndVerifyReinitialized(float invalidTemperature) { TemperatureFilter_Init(); - TEST_WRAP(setValueAndVerifyResponse(100.0f, 100.0f)); - TEST_WRAP(setValueAndVerifyResponse(invalidTemperature, -INFINITY)); - TEST_WRAP(setValueAndVerifyResponse(14.3f, 14.3f)); + setValueAndVerifyResponse(100.0f, 100.0f); + setValueAndVerifyResponse(invalidTemperature, -INFINITY); + setValueAndVerifyResponse(14.3f, 14.3f); } void testShouldResetAverageIfPassedInfinityOrInvalidValue(void) { - TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(-INFINITY)); - TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(+INFINITY)); - TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(+NAN)); - TEST_WRAP(setInvalidTemperatureAndVerifyReinitialized(-NAN)); + setInvalidTemperatureAndVerifyReinitialized(-INFINITY); + setInvalidTemperatureAndVerifyReinitialized(+INFINITY); + setInvalidTemperatureAndVerifyReinitialized(+NAN); + setInvalidTemperatureAndVerifyReinitialized(-NAN); } diff --git a/test/unit/cmock_generator_plugin_expect_test.rb b/test/unit/cmock_generator_plugin_expect_test.rb index 30522e3..bdfa305 100644 --- a/test/unit/cmock_generator_plugin_expect_test.rb +++ b/test/unit/cmock_generator_plugin_expect_test.rb @@ -140,7 +140,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase expected = [" Mock.Apple_CallCount++;\n", " if (Mock.Apple_CallCount > Mock.Apple_CallsExpected)\n", " {\n", - " TEST_THROW(\"Apple Called More Times Than Expected\");\n", + " TEST_FAIL(\"Apple Called More Times Than Expected\");\n", " }\n" ] returned = @cmock_generator_plugin_expect.mock_implementation(function_name, function_args) @@ -158,7 +158,7 @@ class CMockGeneratorPluginExpectTest < Test::Unit::TestCase expected = [" Mock.Cherry_CallCount++;\n", " if (Mock.Cherry_CallCount > Mock.Cherry_CallsExpected)\n", " {\n", - " TEST_THROW(\"Cherry Called More Times Than Expected\");\n", + " TEST_FAIL(\"Cherry Called More Times Than Expected\");\n", " }\n", "mocked_retval_1", "mocked_retval_2"