2 # Copyright 2020 The Pigweed Authors
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 # use this file except in compliance with the License. You may obtain a copy of
8 # https://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations under
15 """The script that runs unit tests on lm3s6965evb-qemu targets."""
21 _TARGET_QEMU_COMMAND = 'qemu-system-arm'
22 _TESTS_STARTING_STRING = b'[==========] Running all tests.'
23 _TESTS_DONE_STRING = b'[==========] Done running all tests.'
24 _TEST_FAILURE_STRING = b'[ FAILED ]'
27 def handle_test_results(test_output):
28 """Parses test output to determine whether tests passed or failed."""
29 if test_output.find(_TESTS_STARTING_STRING) == -1:
31 if test_output.rfind(_TESTS_DONE_STRING) == -1:
33 if test_output.rfind(_TEST_FAILURE_STRING) != -1:
39 """Parses command-line arguments."""
40 parser = argparse.ArgumentParser(description=__doc__)
41 parser.add_argument('binary', help='The target test binary to run')
42 return parser.parse_args()
45 def launch_tests(binary: str) -> int:
46 """Start a process that runs test on binary."""
48 _TARGET_QEMU_COMMAND, '-cpu', 'cortex-m3', '-machine', 'lm3s6965evb',
49 '-nographic', '-no-reboot', '-kernel', binary
51 test_process = subprocess.run(cmd, stdout=subprocess.PIPE)
52 print(test_process.stdout.decode('utf-8'))
53 return handle_test_results(test_process.stdout)
59 return launch_tests(args.binary)
62 if __name__ == '__main__':