This is an example of BLE GATT Client, which receives broadcast data from BLE_Server_BME280 ( a GATT server) , then transfers values up to mbed Device Connector (cloud).
Please refer details about BLEClient_mbedDevConn below. https://github.com/soramame21/BLEClient_mbedDevConn
The location of required BLE GATT server, BLE_Server_BME280, is at here. https://developer.mbed.org/users/edamame22/code/BLE_Server_BME280/
pal/Test/Unity/test/rakefile_helper.rb@2:b894b3508057, 2017-09-05 (annotated)
- Committer:
- Ren Boting
- Date:
- Tue Sep 05 11:56:13 2017 +0900
- Revision:
- 2:b894b3508057
- Parent:
- 0:29983394c6b6
Update all libraries and reform main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edamame22 | 0:29983394c6b6 | 1 | # ========================================== |
edamame22 | 0:29983394c6b6 | 2 | # Unity Project - A Test Framework for C |
edamame22 | 0:29983394c6b6 | 3 | # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams |
edamame22 | 0:29983394c6b6 | 4 | # [Released under MIT License. Please refer to license.txt for details] |
edamame22 | 0:29983394c6b6 | 5 | # ========================================== |
edamame22 | 0:29983394c6b6 | 6 | |
edamame22 | 0:29983394c6b6 | 7 | require 'yaml' |
edamame22 | 0:29983394c6b6 | 8 | require 'fileutils' |
edamame22 | 0:29983394c6b6 | 9 | require UNITY_ROOT + '../auto/unity_test_summary' |
edamame22 | 0:29983394c6b6 | 10 | require UNITY_ROOT + '../auto/generate_test_runner' |
edamame22 | 0:29983394c6b6 | 11 | require UNITY_ROOT + '../auto/colour_reporter' |
edamame22 | 0:29983394c6b6 | 12 | |
edamame22 | 0:29983394c6b6 | 13 | module RakefileHelpers |
edamame22 | 0:29983394c6b6 | 14 | |
edamame22 | 0:29983394c6b6 | 15 | C_EXTENSION = '.c' |
edamame22 | 0:29983394c6b6 | 16 | |
edamame22 | 0:29983394c6b6 | 17 | def load_configuration(config_file) |
edamame22 | 0:29983394c6b6 | 18 | unless ($configured) |
edamame22 | 0:29983394c6b6 | 19 | $cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/) |
edamame22 | 0:29983394c6b6 | 20 | $cfg = YAML.load(File.read($cfg_file)) |
edamame22 | 0:29983394c6b6 | 21 | $colour_output = false unless $cfg['colour'] |
edamame22 | 0:29983394c6b6 | 22 | $configured = true if (config_file != DEFAULT_CONFIG_FILE) |
edamame22 | 0:29983394c6b6 | 23 | end |
edamame22 | 0:29983394c6b6 | 24 | end |
edamame22 | 0:29983394c6b6 | 25 | |
edamame22 | 0:29983394c6b6 | 26 | def configure_clean |
edamame22 | 0:29983394c6b6 | 27 | CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil? |
edamame22 | 0:29983394c6b6 | 28 | end |
edamame22 | 0:29983394c6b6 | 29 | |
edamame22 | 0:29983394c6b6 | 30 | def configure_toolchain(config_file=DEFAULT_CONFIG_FILE) |
edamame22 | 0:29983394c6b6 | 31 | config_file += '.yml' unless config_file =~ /\.yml$/ |
edamame22 | 0:29983394c6b6 | 32 | config_file = config_file unless config_file =~ /[\\|\/]/ |
edamame22 | 0:29983394c6b6 | 33 | load_configuration(config_file) |
edamame22 | 0:29983394c6b6 | 34 | configure_clean |
edamame22 | 0:29983394c6b6 | 35 | end |
edamame22 | 0:29983394c6b6 | 36 | |
edamame22 | 0:29983394c6b6 | 37 | def get_unit_test_files |
edamame22 | 0:29983394c6b6 | 38 | path = $cfg['compiler']['unit_tests_path'] + 'test*' + C_EXTENSION |
edamame22 | 0:29983394c6b6 | 39 | path.gsub!(/\\/, '/') |
edamame22 | 0:29983394c6b6 | 40 | FileList.new(path) |
edamame22 | 0:29983394c6b6 | 41 | end |
edamame22 | 0:29983394c6b6 | 42 | |
edamame22 | 0:29983394c6b6 | 43 | def get_local_include_dirs |
edamame22 | 0:29983394c6b6 | 44 | include_dirs = $cfg['compiler']['includes']['items'].dup |
edamame22 | 0:29983394c6b6 | 45 | include_dirs.delete_if {|dir| dir.is_a?(Array)} |
edamame22 | 0:29983394c6b6 | 46 | return include_dirs |
edamame22 | 0:29983394c6b6 | 47 | end |
edamame22 | 0:29983394c6b6 | 48 | |
edamame22 | 0:29983394c6b6 | 49 | def extract_headers(filename) |
edamame22 | 0:29983394c6b6 | 50 | includes = [] |
edamame22 | 0:29983394c6b6 | 51 | lines = File.readlines(filename) |
edamame22 | 0:29983394c6b6 | 52 | lines.each do |line| |
edamame22 | 0:29983394c6b6 | 53 | m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/) |
edamame22 | 0:29983394c6b6 | 54 | if not m.nil? |
edamame22 | 0:29983394c6b6 | 55 | includes << m[1] |
edamame22 | 0:29983394c6b6 | 56 | end |
edamame22 | 0:29983394c6b6 | 57 | end |
edamame22 | 0:29983394c6b6 | 58 | return includes |
edamame22 | 0:29983394c6b6 | 59 | end |
edamame22 | 0:29983394c6b6 | 60 | |
edamame22 | 0:29983394c6b6 | 61 | def find_source_file(header, paths) |
edamame22 | 0:29983394c6b6 | 62 | paths.each do |dir| |
edamame22 | 0:29983394c6b6 | 63 | src_file = dir + header.ext(C_EXTENSION) |
edamame22 | 0:29983394c6b6 | 64 | if (File.exists?(src_file)) |
edamame22 | 0:29983394c6b6 | 65 | return src_file |
edamame22 | 0:29983394c6b6 | 66 | end |
edamame22 | 0:29983394c6b6 | 67 | end |
edamame22 | 0:29983394c6b6 | 68 | return nil |
edamame22 | 0:29983394c6b6 | 69 | end |
edamame22 | 0:29983394c6b6 | 70 | |
edamame22 | 0:29983394c6b6 | 71 | def tackit(strings) |
edamame22 | 0:29983394c6b6 | 72 | if strings.is_a?(Array) |
edamame22 | 0:29983394c6b6 | 73 | result = "\"#{strings.join}\"" |
edamame22 | 0:29983394c6b6 | 74 | else |
edamame22 | 0:29983394c6b6 | 75 | result = strings |
edamame22 | 0:29983394c6b6 | 76 | end |
edamame22 | 0:29983394c6b6 | 77 | return result |
edamame22 | 0:29983394c6b6 | 78 | end |
edamame22 | 0:29983394c6b6 | 79 | |
edamame22 | 0:29983394c6b6 | 80 | def squash(prefix, items) |
edamame22 | 0:29983394c6b6 | 81 | result = '' |
edamame22 | 0:29983394c6b6 | 82 | items.each { |item| result += " #{prefix}#{tackit(item)}" } |
edamame22 | 0:29983394c6b6 | 83 | return result |
edamame22 | 0:29983394c6b6 | 84 | end |
edamame22 | 0:29983394c6b6 | 85 | |
edamame22 | 0:29983394c6b6 | 86 | def should(behave, &block) |
edamame22 | 0:29983394c6b6 | 87 | if block |
edamame22 | 0:29983394c6b6 | 88 | puts "Should " + behave |
edamame22 | 0:29983394c6b6 | 89 | yield block |
edamame22 | 0:29983394c6b6 | 90 | else |
edamame22 | 0:29983394c6b6 | 91 | puts "UNIMPLEMENTED CASE: Should #{behave}" |
edamame22 | 0:29983394c6b6 | 92 | end |
edamame22 | 0:29983394c6b6 | 93 | end |
edamame22 | 0:29983394c6b6 | 94 | |
edamame22 | 0:29983394c6b6 | 95 | def build_compiler_fields |
edamame22 | 0:29983394c6b6 | 96 | command = tackit($cfg['compiler']['path']) |
edamame22 | 0:29983394c6b6 | 97 | if $cfg['compiler']['defines']['items'].nil? |
edamame22 | 0:29983394c6b6 | 98 | defines = '' |
edamame22 | 0:29983394c6b6 | 99 | else |
edamame22 | 0:29983394c6b6 | 100 | defines = squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=putcharSpy']) |
edamame22 | 0:29983394c6b6 | 101 | end |
edamame22 | 0:29983394c6b6 | 102 | options = squash('', $cfg['compiler']['options']) |
edamame22 | 0:29983394c6b6 | 103 | includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) |
edamame22 | 0:29983394c6b6 | 104 | includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) |
edamame22 | 0:29983394c6b6 | 105 | return {:command => command, :defines => defines, :options => options, :includes => includes} |
edamame22 | 0:29983394c6b6 | 106 | end |
edamame22 | 0:29983394c6b6 | 107 | |
edamame22 | 0:29983394c6b6 | 108 | def compile(file, defines=[]) |
edamame22 | 0:29983394c6b6 | 109 | compiler = build_compiler_fields |
edamame22 | 0:29983394c6b6 | 110 | cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{file} " + |
edamame22 | 0:29983394c6b6 | 111 | "#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}" |
edamame22 | 0:29983394c6b6 | 112 | obj_file = "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}" |
edamame22 | 0:29983394c6b6 | 113 | execute(cmd_str + obj_file) |
edamame22 | 0:29983394c6b6 | 114 | return obj_file |
edamame22 | 0:29983394c6b6 | 115 | end |
edamame22 | 0:29983394c6b6 | 116 | |
edamame22 | 0:29983394c6b6 | 117 | def build_linker_fields |
edamame22 | 0:29983394c6b6 | 118 | command = tackit($cfg['linker']['path']) |
edamame22 | 0:29983394c6b6 | 119 | if $cfg['linker']['options'].nil? |
edamame22 | 0:29983394c6b6 | 120 | options = '' |
edamame22 | 0:29983394c6b6 | 121 | else |
edamame22 | 0:29983394c6b6 | 122 | options = squash('', $cfg['linker']['options']) |
edamame22 | 0:29983394c6b6 | 123 | end |
edamame22 | 0:29983394c6b6 | 124 | if ($cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil?) |
edamame22 | 0:29983394c6b6 | 125 | includes = '' |
edamame22 | 0:29983394c6b6 | 126 | else |
edamame22 | 0:29983394c6b6 | 127 | includes = squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items']) |
edamame22 | 0:29983394c6b6 | 128 | end |
edamame22 | 0:29983394c6b6 | 129 | includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) |
edamame22 | 0:29983394c6b6 | 130 | return {:command => command, :options => options, :includes => includes} |
edamame22 | 0:29983394c6b6 | 131 | end |
edamame22 | 0:29983394c6b6 | 132 | |
edamame22 | 0:29983394c6b6 | 133 | def link_it(exe_name, obj_list) |
edamame22 | 0:29983394c6b6 | 134 | linker = build_linker_fields |
edamame22 | 0:29983394c6b6 | 135 | cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + |
edamame22 | 0:29983394c6b6 | 136 | (obj_list.map{|obj|"#{$cfg['linker']['object_files']['path']}#{obj} "}).join + |
edamame22 | 0:29983394c6b6 | 137 | $cfg['linker']['bin_files']['prefix'] + ' ' + |
edamame22 | 0:29983394c6b6 | 138 | $cfg['linker']['bin_files']['destination'] + |
edamame22 | 0:29983394c6b6 | 139 | exe_name + $cfg['linker']['bin_files']['extension'] |
edamame22 | 0:29983394c6b6 | 140 | execute(cmd_str) |
edamame22 | 0:29983394c6b6 | 141 | end |
edamame22 | 0:29983394c6b6 | 142 | |
edamame22 | 0:29983394c6b6 | 143 | def build_simulator_fields |
edamame22 | 0:29983394c6b6 | 144 | return nil if $cfg['simulator'].nil? |
edamame22 | 0:29983394c6b6 | 145 | if $cfg['simulator']['path'].nil? |
edamame22 | 0:29983394c6b6 | 146 | command = '' |
edamame22 | 0:29983394c6b6 | 147 | else |
edamame22 | 0:29983394c6b6 | 148 | command = (tackit($cfg['simulator']['path']) + ' ') |
edamame22 | 0:29983394c6b6 | 149 | end |
edamame22 | 0:29983394c6b6 | 150 | if $cfg['simulator']['pre_support'].nil? |
edamame22 | 0:29983394c6b6 | 151 | pre_support = '' |
edamame22 | 0:29983394c6b6 | 152 | else |
edamame22 | 0:29983394c6b6 | 153 | pre_support = squash('', $cfg['simulator']['pre_support']) |
edamame22 | 0:29983394c6b6 | 154 | end |
edamame22 | 0:29983394c6b6 | 155 | if $cfg['simulator']['post_support'].nil? |
edamame22 | 0:29983394c6b6 | 156 | post_support = '' |
edamame22 | 0:29983394c6b6 | 157 | else |
edamame22 | 0:29983394c6b6 | 158 | post_support = squash('', $cfg['simulator']['post_support']) |
edamame22 | 0:29983394c6b6 | 159 | end |
edamame22 | 0:29983394c6b6 | 160 | return {:command => command, :pre_support => pre_support, :post_support => post_support} |
edamame22 | 0:29983394c6b6 | 161 | end |
edamame22 | 0:29983394c6b6 | 162 | |
edamame22 | 0:29983394c6b6 | 163 | def execute(command_string, verbose=true) |
edamame22 | 0:29983394c6b6 | 164 | report command_string |
edamame22 | 0:29983394c6b6 | 165 | output = `#{command_string}`.chomp |
edamame22 | 0:29983394c6b6 | 166 | report(output) if (verbose && !output.nil? && (output.length > 0)) |
edamame22 | 0:29983394c6b6 | 167 | if $?.exitstatus != 0 |
edamame22 | 0:29983394c6b6 | 168 | raise "Command failed. (Returned #{$?.exitstatus})" |
edamame22 | 0:29983394c6b6 | 169 | end |
edamame22 | 0:29983394c6b6 | 170 | return output |
edamame22 | 0:29983394c6b6 | 171 | end |
edamame22 | 0:29983394c6b6 | 172 | |
edamame22 | 0:29983394c6b6 | 173 | def report_summary |
edamame22 | 0:29983394c6b6 | 174 | summary = UnityTestSummary.new |
edamame22 | 0:29983394c6b6 | 175 | summary.set_root_path(UNITY_ROOT) |
edamame22 | 0:29983394c6b6 | 176 | results_glob = "#{$cfg['compiler']['build_path']}*.test*" |
edamame22 | 0:29983394c6b6 | 177 | results_glob.gsub!(/\\/, '/') |
edamame22 | 0:29983394c6b6 | 178 | results = Dir[results_glob] |
edamame22 | 0:29983394c6b6 | 179 | summary.set_targets(results) |
edamame22 | 0:29983394c6b6 | 180 | report summary.run |
edamame22 | 0:29983394c6b6 | 181 | end |
edamame22 | 0:29983394c6b6 | 182 | |
edamame22 | 0:29983394c6b6 | 183 | def run_tests(test_files) |
edamame22 | 0:29983394c6b6 | 184 | report 'Running Unity system tests...' |
edamame22 | 0:29983394c6b6 | 185 | |
edamame22 | 0:29983394c6b6 | 186 | # Tack on TEST define for compiling unit tests |
edamame22 | 0:29983394c6b6 | 187 | load_configuration($cfg_file) |
edamame22 | 0:29983394c6b6 | 188 | test_defines = ['TEST'] |
edamame22 | 0:29983394c6b6 | 189 | $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? |
edamame22 | 0:29983394c6b6 | 190 | $cfg['compiler']['defines']['items'] << 'TEST' |
edamame22 | 0:29983394c6b6 | 191 | |
edamame22 | 0:29983394c6b6 | 192 | include_dirs = get_local_include_dirs |
edamame22 | 0:29983394c6b6 | 193 | |
edamame22 | 0:29983394c6b6 | 194 | # Build and execute each unit test |
edamame22 | 0:29983394c6b6 | 195 | test_files.each do |test| |
edamame22 | 0:29983394c6b6 | 196 | obj_list = [] |
edamame22 | 0:29983394c6b6 | 197 | |
edamame22 | 0:29983394c6b6 | 198 | if !$cfg['compiler']['aux_sources'].nil? |
edamame22 | 0:29983394c6b6 | 199 | $cfg['compiler']['aux_sources'].each do |aux| |
edamame22 | 0:29983394c6b6 | 200 | obj_list << compile(aux, test_defines) |
edamame22 | 0:29983394c6b6 | 201 | end |
edamame22 | 0:29983394c6b6 | 202 | end |
edamame22 | 0:29983394c6b6 | 203 | |
edamame22 | 0:29983394c6b6 | 204 | # Detect dependencies and build required modules |
edamame22 | 0:29983394c6b6 | 205 | extract_headers(test).each do |header| |
edamame22 | 0:29983394c6b6 | 206 | # Compile corresponding source file if it exists |
edamame22 | 0:29983394c6b6 | 207 | src_file = find_source_file(header, include_dirs) |
edamame22 | 0:29983394c6b6 | 208 | if !src_file.nil? |
edamame22 | 0:29983394c6b6 | 209 | obj_list << compile(src_file, test_defines) |
edamame22 | 0:29983394c6b6 | 210 | end |
edamame22 | 0:29983394c6b6 | 211 | end |
edamame22 | 0:29983394c6b6 | 212 | |
edamame22 | 0:29983394c6b6 | 213 | # Build the test runner (generate if configured to do so) |
edamame22 | 0:29983394c6b6 | 214 | test_base = File.basename(test, C_EXTENSION) |
edamame22 | 0:29983394c6b6 | 215 | |
edamame22 | 0:29983394c6b6 | 216 | runner_name = test_base + '_Runner.c' |
edamame22 | 0:29983394c6b6 | 217 | runner_path = '' |
edamame22 | 0:29983394c6b6 | 218 | |
edamame22 | 0:29983394c6b6 | 219 | if $cfg['compiler']['runner_path'].nil? |
edamame22 | 0:29983394c6b6 | 220 | runner_path = $cfg['compiler']['build_path'] + runner_name |
edamame22 | 0:29983394c6b6 | 221 | else |
edamame22 | 0:29983394c6b6 | 222 | runner_path = $cfg['compiler']['runner_path'] + runner_name |
edamame22 | 0:29983394c6b6 | 223 | end |
edamame22 | 0:29983394c6b6 | 224 | |
edamame22 | 0:29983394c6b6 | 225 | options = $cfg[:unity] |
edamame22 | 0:29983394c6b6 | 226 | options[:use_param_tests] = (test =~ /parameterized/) ? true : false |
edamame22 | 0:29983394c6b6 | 227 | UnityTestRunnerGenerator.new(options).run(test, runner_path) |
edamame22 | 0:29983394c6b6 | 228 | obj_list << compile(runner_path, test_defines) |
edamame22 | 0:29983394c6b6 | 229 | |
edamame22 | 0:29983394c6b6 | 230 | # Build the test module |
edamame22 | 0:29983394c6b6 | 231 | obj_list << compile(test, test_defines) |
edamame22 | 0:29983394c6b6 | 232 | |
edamame22 | 0:29983394c6b6 | 233 | # Link the test executable |
edamame22 | 0:29983394c6b6 | 234 | link_it(test_base, obj_list) |
edamame22 | 0:29983394c6b6 | 235 | |
edamame22 | 0:29983394c6b6 | 236 | # Execute unit test and generate results file |
edamame22 | 0:29983394c6b6 | 237 | simulator = build_simulator_fields |
edamame22 | 0:29983394c6b6 | 238 | executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] |
edamame22 | 0:29983394c6b6 | 239 | if simulator.nil? |
edamame22 | 0:29983394c6b6 | 240 | cmd_str = executable |
edamame22 | 0:29983394c6b6 | 241 | else |
edamame22 | 0:29983394c6b6 | 242 | cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" |
edamame22 | 0:29983394c6b6 | 243 | end |
edamame22 | 0:29983394c6b6 | 244 | output = execute(cmd_str) |
edamame22 | 0:29983394c6b6 | 245 | test_results = $cfg['compiler']['build_path'] + test_base |
edamame22 | 0:29983394c6b6 | 246 | if output.match(/OK$/m).nil? |
edamame22 | 0:29983394c6b6 | 247 | test_results += '.testfail' |
edamame22 | 0:29983394c6b6 | 248 | else |
edamame22 | 0:29983394c6b6 | 249 | test_results += '.testpass' |
edamame22 | 0:29983394c6b6 | 250 | end |
edamame22 | 0:29983394c6b6 | 251 | File.open(test_results, 'w') { |f| f.print output } |
edamame22 | 0:29983394c6b6 | 252 | |
edamame22 | 0:29983394c6b6 | 253 | end |
edamame22 | 0:29983394c6b6 | 254 | end |
edamame22 | 0:29983394c6b6 | 255 | end |