|
23 | 23 | import json
|
24 | 24 | import pprint
|
25 | 25 | import random
|
26 |
| -import thread |
27 | 26 | import optparse
|
28 | 27 | import threading
|
29 | 28 | from types import ListType
|
|
41 | 40 | from workspace_tools.paths import HOST_TESTS
|
42 | 41 | from workspace_tools.tests import TEST_MAP
|
43 | 42 | from workspace_tools.tests import TESTS
|
44 |
| -from workspace_tools.utils import construct_enum |
45 | 43 | from workspace_tools.targets import TARGET_MAP
|
46 | 44 | from workspace_tools.build_api import build_project, build_mbed_libs, build_lib
|
47 | 45 | from workspace_tools.build_api import get_target_supported_toolchains
|
@@ -71,7 +69,7 @@ def stop(self):
|
71 | 69 |
|
72 | 70 |
|
73 | 71 | class SingleTestExecutor(threading.Thread):
|
74 |
| - """ Single test class separate thread usage """ |
| 72 | + """ Example: Single test class in separate thread usage """ |
75 | 73 | def __init__(self, single_test):
|
76 | 74 | self.single_test = single_test
|
77 | 75 | threading.Thread.__init__(self)
|
@@ -128,7 +126,7 @@ class SingleTestRunner(object):
|
128 | 126 |
|
129 | 127 | def __init__(self,
|
130 | 128 | _global_loops_count=1,
|
131 |
| - _test_loops_list="", |
| 129 | + _test_loops_list=None, |
132 | 130 | _muts={},
|
133 | 131 | _test_spec={},
|
134 | 132 | _opts_goanna_for_mbed_sdk=None,
|
@@ -185,50 +183,6 @@ def __init__(self,
|
185 | 183 | self.opts_test_x_toolchain_summary = _opts_test_x_toolchain_summary
|
186 | 184 | self.opts_copy_method = _opts_copy_method
|
187 | 185 |
|
188 |
| - # With this lock we should control access to certain resources inside this class |
189 |
| - self.resource_lock = thread.allocate_lock() |
190 |
| - |
191 |
| - self.RestRequest = construct_enum(REST_MUTS='muts', |
192 |
| - REST_TEST_SPEC='test_spec', |
193 |
| - REST_TEST_RESULTS='test_results') |
194 |
| - |
195 |
| - def get_rest_result_template(self, result, command, success_code): |
196 |
| - result = {"result": result, |
197 |
| - "command" : command, |
198 |
| - "success_code": success_code} |
199 |
| - return result |
200 |
| - |
201 |
| - # REST API handlers for Flask framework |
202 |
| - def rest_api_status(self): |
203 |
| - """ Returns current test execution status. E.g. running / finished etc. """ |
204 |
| - with self.resource_lock: |
205 |
| - pass |
206 |
| - |
207 |
| - def rest_api_config(self): |
208 |
| - """ Returns configuration passed to SingleTest executor """ |
209 |
| - with self.resource_lock: |
210 |
| - pass |
211 |
| - |
212 |
| - def rest_api_log(self): |
213 |
| - """ Returns current test log """ |
214 |
| - with self.resource_lock: |
215 |
| - pass |
216 |
| - |
217 |
| - def rest_api_request_handler(self, request_type): |
218 |
| - """ Returns various data structures. Both static and mutable during test """ |
219 |
| - result = {} |
220 |
| - success_code = 0 |
221 |
| - with self.resource_lock: |
222 |
| - if request_type == self.RestRequest.REST_MUTS: |
223 |
| - result = self.muts # Returns MUTs |
224 |
| - elif request_type == self.RestRequest.REST_TEST_SPEC: |
225 |
| - result = self.test_spec # Returns Test Specification |
226 |
| - elif request_type == self.RestRequest.REST_TEST_RESULTS: |
227 |
| - pass # Returns test results |
228 |
| - else: |
229 |
| - success_code = -1 |
230 |
| - return json.dumps(self.get_rest_result_template(result, 'request/' + request_type, success_code), indent=4) |
231 |
| - |
232 | 186 | def shuffle_random_func(self):
|
233 | 187 | return self.shuffle_random_seed
|
234 | 188 |
|
@@ -274,7 +228,7 @@ def execute(self):
|
274 | 228 |
|
275 | 229 | build_dir = join(BUILD_DIR, "test", target, toolchain)
|
276 | 230 |
|
277 |
| - # Enumerate through all tests |
| 231 | + # Enumerate through all tests and shuffle test order if requested |
278 | 232 | test_map_keys = TEST_MAP.keys()
|
279 | 233 | if self.opts_shuffle_test_order:
|
280 | 234 | random.shuffle(test_map_keys, self.shuffle_random_func)
|
@@ -974,6 +928,23 @@ def progress_bar(percent_progress, saturation=0):
|
974 | 928 | return str_progress
|
975 | 929 |
|
976 | 930 |
|
| 931 | +def singletest_in_cli_mode(single_test): |
| 932 | + """ Runs SingleTestRunner object in CLI (Command line interface) mode """ |
| 933 | + start = time() |
| 934 | + # Execute tests depending on options and filter applied |
| 935 | + test_summary, shuffle_seed = single_test.execute() |
| 936 | + elapsed_time = time() - start |
| 937 | + # Human readable summary |
| 938 | + if not single_test.opts_suppress_summary: |
| 939 | + # prints well-formed summary with results (SQL table like) |
| 940 | + print single_test.generate_test_summary(test_summary, shuffle_seed) |
| 941 | + if single_test.opts_test_x_toolchain_summary: |
| 942 | + # prints well-formed summary with results (SQL table like) |
| 943 | + # table shows text x toolchain test result matrix |
| 944 | + print single_test.generate_test_summary_by_target(test_summary, shuffle_seed) |
| 945 | + print "Completed in %d sec"% (elapsed_time) |
| 946 | + |
| 947 | + |
977 | 948 | def get_default_test_options_parser():
|
978 | 949 | """ Get common test script options used by CLI, webservices etc. """
|
979 | 950 | parser = optparse.OptionParser()
|
@@ -1089,18 +1060,6 @@ def get_default_test_options_parser():
|
1089 | 1060 | default=None,
|
1090 | 1061 | help='For some commands you can use filter to filter out results')
|
1091 | 1062 |
|
1092 |
| - |
1093 |
| - # Things related to webservices offered by test suite scripts |
1094 |
| - #parser.add_option('', '--rest-api', |
1095 |
| - # dest='rest_api_enabled', |
1096 |
| - # default=False, |
1097 |
| - # action="store_true", |
1098 |
| - # help='Enables REST API.') |
1099 |
| - |
1100 |
| - #parser.add_option('', '--rest-api-port', |
1101 |
| - # dest='rest_api_port_no', |
1102 |
| - # help='Sets port for REST API interface') |
1103 |
| - |
1104 | 1063 | parser.add_option('', '--verbose-skipped',
|
1105 | 1064 | dest='verbose_skipped_tests',
|
1106 | 1065 | default=False,
|
|
0 commit comments