Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

singletest.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #!/usr/bin/env python2
  2. """
  3. mbed SDK
  4. Copyright (c) 2011-2014 ARM Limited
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. Author: Przemyslaw Wirkus <[email protected]>
  15. """
  16. """
  17. File format example: test_spec.json:
  18. {
  19. "targets": {
  20. "KL46Z": ["ARM", "GCC_ARM"],
  21. "LPC1768": ["ARM", "GCC_ARM", "GCC_CR", "GCC_CS", "IAR"],
  22. "LPC11U24": ["uARM"],
  23. "NRF51822": ["ARM"]
  24. }
  25. }
  26. File format example: muts_all.json:
  27. {
  28. "1" : {"mcu": "LPC1768",
  29. "port":"COM4",
  30. "disk":"J:\\",
  31. "peripherals": ["TMP102", "digital_loop", "port_loop", "analog_loop", "SD"]
  32. },
  33. "2" : {"mcu": "KL25Z",
  34. "port":"COM7",
  35. "disk":"G:\\",
  36. "peripherals": ["digital_loop", "port_loop", "analog_loop"]
  37. }
  38. }
  39. """
  40. # Be sure that the tools directory is in the search path
  41. import sys
  42. from os.path import join, abspath, dirname
  43. ROOT = abspath(join(dirname(__file__), ".."))
  44. sys.path.insert(0, ROOT)
  45. # Check: Extra modules which are required by core test suite
  46. from workspace_tools.utils import check_required_modules
  47. check_required_modules(['prettytable', 'serial'])
  48. # Imports related to mbed build api
  49. from workspace_tools.build_api import mcu_toolchain_matrix
  50. # Imports from TEST API
  51. from workspace_tools.test_api import SingleTestRunner
  52. from workspace_tools.test_api import singletest_in_cli_mode
  53. from workspace_tools.test_api import detect_database_verbose
  54. from workspace_tools.test_api import get_json_data_from_file
  55. from workspace_tools.test_api import get_avail_tests_summary_table
  56. from workspace_tools.test_api import get_default_test_options_parser
  57. from workspace_tools.test_api import print_muts_configuration_from_json
  58. from workspace_tools.test_api import print_test_configuration_from_json
  59. from workspace_tools.test_api import get_autodetected_MUTS
  60. from workspace_tools.test_api import get_autodetected_TEST_SPEC
  61. from workspace_tools.test_api import get_module_avail
  62. # Importing extra modules which can be not installed but if available they can extend test suite functionality
  63. try:
  64. import mbed_lstools
  65. except:
  66. pass
  67. def get_version():
  68. """ Returns test script version
  69. """
  70. single_test_version_major = 1
  71. single_test_version_minor = 4
  72. return (single_test_version_major, single_test_version_minor)
  73. if __name__ == '__main__':
  74. # Command line options
  75. parser = get_default_test_options_parser()
  76. parser.description = """This script allows you to run mbed defined test cases for particular MCU(s) and corresponding toolchain(s)."""
  77. parser.epilog = """Example: singletest.py -i test_spec.json -M muts_all.json"""
  78. (opts, args) = parser.parse_args()
  79. # Print scrip version
  80. if opts.version:
  81. print parser.description
  82. print parser.epilog
  83. print "Version %d.%d"% get_version()
  84. exit(0)
  85. if opts.db_url and opts.verbose_test_configuration_only:
  86. detect_database_verbose(opts.db_url)
  87. exit(0)
  88. # Print summary / information about automation test status
  89. if opts.test_automation_report:
  90. print get_avail_tests_summary_table(platform_filter=opts.general_filter_regex)
  91. exit(0)
  92. # Print summary / information about automation test status
  93. if opts.test_case_report:
  94. test_case_report_cols = ['id',
  95. 'automated',
  96. 'description',
  97. 'peripherals',
  98. 'host_test',
  99. 'duration',
  100. 'source_dir']
  101. print get_avail_tests_summary_table(cols=test_case_report_cols,
  102. result_summary=False,
  103. join_delim='\n',
  104. platform_filter=opts.general_filter_regex)
  105. exit(0)
  106. # Only prints matrix of supported toolchains
  107. if opts.supported_toolchains:
  108. print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
  109. exit(0)
  110. test_spec = None
  111. MUTs = None
  112. if hasattr(opts, 'auto_detect') and opts.auto_detect:
  113. # If auto_detect attribute is present, we assume other auto-detection
  114. # parameters like 'toolchains_filter' are also set.
  115. print "MBEDLS: Detecting connected mbed-enabled devices... "
  116. if get_module_avail('mbed_lstools'):
  117. mbeds = mbed_lstools.create()
  118. muts_list = mbeds.list_mbeds()
  119. for mut in muts_list:
  120. print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['platform_name'],
  121. mut['serial_port'],
  122. mut['mount_point'])
  123. # Set up parameters for test specification filter function (we need to set toolchains per target here)
  124. use_default_toolchain = 'default' in opts.toolchains_filter.split(',') if opts.toolchains_filter is not None else True
  125. use_supported_toolchains = 'all' in opts.toolchains_filter.split(',') if opts.toolchains_filter is not None else False
  126. toolchain_filter = opts.toolchains_filter
  127. platform_name_filter = opts.general_filter_regex.split(',') if opts.general_filter_regex is not None else opts.general_filter_regex
  128. # Test specification with information about each target and associated toolchain
  129. test_spec = get_autodetected_TEST_SPEC(muts_list,
  130. use_default_toolchain=use_default_toolchain,
  131. use_supported_toolchains=use_supported_toolchains,
  132. toolchain_filter=toolchain_filter,
  133. platform_name_filter=platform_name_filter)
  134. # MUTs configuration auto-detection
  135. MUTs = get_autodetected_MUTS(muts_list)
  136. else:
  137. # Open file with test specification
  138. # test_spec_filename tells script which targets and their toolchain(s)
  139. # should be covered by the test scenario
  140. test_spec = get_json_data_from_file(opts.test_spec_filename) if opts.test_spec_filename else None
  141. if test_spec is None:
  142. if not opts.test_spec_filename:
  143. parser.print_help()
  144. exit(-1)
  145. # Get extra MUTs if applicable
  146. MUTs = get_json_data_from_file(opts.muts_spec_filename) if opts.muts_spec_filename else None
  147. if MUTs is None:
  148. if not opts.muts_spec_filename:
  149. parser.print_help()
  150. exit(-1)
  151. if opts.verbose_test_configuration_only:
  152. print "MUTs configuration in %s:"% ('auto-detected' if opts.auto_detect else opts.muts_spec_filename)
  153. if MUTs:
  154. print print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex)
  155. print
  156. print "Test specification in %s:"% ('auto-detected' if opts.auto_detect else opts.test_spec_filename)
  157. if test_spec:
  158. print print_test_configuration_from_json(test_spec)
  159. exit(0)
  160. # Verbose test specification and MUTs configuration
  161. if MUTs and opts.verbose:
  162. print print_muts_configuration_from_json(MUTs)
  163. if test_spec and opts.verbose:
  164. print print_test_configuration_from_json(test_spec)
  165. if opts.only_build_tests:
  166. # We are skipping testing phase, and suppress summary
  167. opts.suppress_summary = True
  168. single_test = SingleTestRunner(_global_loops_count=opts.test_global_loops_value,
  169. _test_loops_list=opts.test_loops_list,
  170. _muts=MUTs,
  171. _clean=opts.clean,
  172. _opts_db_url=opts.db_url,
  173. _opts_log_file_name=opts.log_file_name,
  174. _opts_report_html_file_name=opts.report_html_file_name,
  175. _opts_report_junit_file_name=opts.report_junit_file_name,
  176. _opts_report_build_file_name=opts.report_build_file_name,
  177. _test_spec=test_spec,
  178. _opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk,
  179. _opts_goanna_for_tests=opts.goanna_for_tests,
  180. _opts_shuffle_test_order=opts.shuffle_test_order,
  181. _opts_shuffle_test_seed=opts.shuffle_test_seed,
  182. _opts_test_by_names=opts.test_by_names,
  183. _opts_peripheral_by_names=opts.peripheral_by_names,
  184. _opts_test_only_peripheral=opts.test_only_peripheral,
  185. _opts_test_only_common=opts.test_only_common,
  186. _opts_verbose_skipped_tests=opts.verbose_skipped_tests,
  187. _opts_verbose_test_result_only=opts.verbose_test_result_only,
  188. _opts_verbose=opts.verbose,
  189. _opts_firmware_global_name=opts.firmware_global_name,
  190. _opts_only_build_tests=opts.only_build_tests,
  191. _opts_parallel_test_exec=opts.parallel_test_exec,
  192. _opts_suppress_summary=opts.suppress_summary,
  193. _opts_test_x_toolchain_summary=opts.test_x_toolchain_summary,
  194. _opts_copy_method=opts.copy_method,
  195. _opts_mut_reset_type=opts.mut_reset_type,
  196. _opts_jobs=opts.jobs,
  197. _opts_waterfall_test=opts.waterfall_test,
  198. _opts_extend_test_timeout=opts.extend_test_timeout)
  199. # Runs test suite in CLI mode
  200. singletest_in_cli_mode(single_test)