|
9 | 9 | <!--te-->
|
10 | 10 |
|
11 | 11 | # Installlation
|
12 |
| -Our test scripts assume that the non static `user` mode installation of QEMU is |
13 |
| -available in the PATH. For example, if using QEMU for ARM testing, please make |
14 |
| -sure `qemu-arm` is installed and available to the test scripts. |
| 12 | + |
| 13 | +There are two primary ways to set up the testing environment. |
| 14 | + |
| 15 | +## Native Installation |
| 16 | + |
| 17 | +To run the test scripts, you must have a non-static, user-mode installation |
| 18 | +of QEMU available in your system's PATH. For example, to test on ARM, the |
| 19 | +`qemu-arm` binary must be installed and accessible from your shell. |
| 20 | + |
| 21 | +## Docker Environment |
| 22 | + |
| 23 | +As an alternative to installing dependencies on your host machine, |
| 24 | +you can use the provided Docker environment. |
| 25 | +For instructions, see the "Run locally for debugging" section in the |
| 26 | +[Dockerfile](https://github.com/tensorflow/tflite-micro/blob/main/ci/Dockerfile.micro). |
15 | 27 |
|
16 | 28 | # Software Emulation with QEMU
|
17 |
| -TensorFlow Lite Micro makes use of [QEMU](https://qemu.org) to |
18 |
| -for testing cross compiled tests. |
19 | 29 |
|
20 |
| -QEMU can quickly test unit tests that are cross compiled for non x64\_86 |
21 |
| -hardware. |
| 30 | +TensorFlow Lite Micro uses [QEMU](https://qemu.org) to run tests that have |
| 31 | +been cross-compiled for architectures other than x86_64. This setup enables |
| 32 | +the rapid execution of unit tests for various hardware targets directly |
| 33 | +on a standard development machine. |
22 | 34 |
|
23 | 35 | # Running Unit Tests
|
24 |
| -All unit tests can be ran using |
25 |
| -`tensorflow/lite/micro/tools/ci_build/test_cortex_m_qemu.sh` for the cortex-m |
26 |
| -processor. |
| 36 | + |
| 37 | +You can run all Cortex-M unit tests using a single build script: |
| 38 | + |
| 39 | +```bash |
| 40 | +tensorflow/lite/micro/tools/ci_build/test_cortex_m_qemu.sh |
| 41 | +``` |
| 42 | + |
| 43 | +After this script completes the initial build, you can run an individual |
| 44 | +test target as follows: |
| 45 | + |
| 46 | +```bash |
| 47 | +make -f tensorflow/lite/micro/tools/make/Makefile \ |
| 48 | + TARGET=cortex_m_qemu \ |
| 49 | + TARGET_ARCH=cortex-m3 \ |
| 50 | + OPTIMIZED_KERNEL_DIR=cmsis_nn |
| 51 | + <TEST_TARGET> |
| 52 | +``` |
| 53 | + |
| 54 | +# Debugging |
| 55 | + |
| 56 | +You can debug failures either interactively with GDB |
| 57 | +or by analyzing the core file after a crash. |
| 58 | + |
| 59 | +## Live GDB Debugging |
| 60 | + |
| 61 | +### Terminal 1: Start QEMU, telling it to wait for a GDB connection on port 1234. |
| 62 | + |
| 63 | +```bash |
| 64 | +qemu-arm -cpu cortex-m3 -g 1234 <TEST_BINARY_PATH> |
| 65 | +``` |
| 66 | + |
| 67 | +### Terminal 2: Launch GDB and connect to the waiting QEMU session. |
| 68 | + |
| 69 | +```bash |
| 70 | +$ arm-none-eabi-gdb <TEST_BINARY_PATH> |
| 71 | +(gdb) target remote :1234 |
| 72 | +``` |
| 73 | + |
| 74 | +## Core Dump Analysis |
| 75 | + |
| 76 | +Load the test executable and the generated core file into GDB |
| 77 | +to inspect the state at the time of the crash. |
| 78 | + |
| 79 | +```bash |
| 80 | +$ arm-none-eabi-gdb <TEST_BINARY_PATH> <CORE_FILE_PATH> |
| 81 | +(gdb) bt |
| 82 | +``` |
27 | 83 |
|
28 | 84 | # Useful External Links for QEMU
|
29 |
| -The current QEMU implementation uses `user` mode. The documentation for [user |
30 |
| -mode is here](https://www.qemu.org/docs/master/user/index.html). |
31 | 85 |
|
32 |
| -QEMU uses ARM |
33 |
| -[semihosting](https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst) |
34 |
| -to replace newlib system calls for specific boards with the host OS. Further |
35 |
| -documentation on how this works is contained in `cortex_m_qemu_makefile.inc`. |
| 86 | +* The current testing framework uses QEMU's user mode. |
| 87 | + Read [doc](https://www.qemu.org/docs/master/user/index.html) |
| 88 | + |
| 89 | +* QEMU uses ARM [semihosting](https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst) |
| 90 | + to replace newlib system calls for specific boards with the host OS. |
| 91 | + Further documentation on how this works is contained in `cortex_m_qemu_makefile.inc`. |
0 commit comments