# ctest for embedded

**URL:** https://discourse.cmake.org/t/ctest-for-embedded/7415
**Category:** Usage
**Created:** [February 7, 2023, 3:27am UTC](https://discourse.cmake.org/t/ctest-for-embedded/7415 "2023-02-07T03:27:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pavel\_krupets](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@pavel\_krupets](https://discourse.cmake.org/u/pavel_krupets)
#### Post date: [February 7, 2023, 3:27am UTC](https://discourse.cmake.org/t/ctest-for-embedded/7415/1 "2023-02-07T03:27:25Z")

</div>

is it possible to program microchip, then connect and run tests (collect results over uart, usb, bluetooth, etc.)?

are there points I can hook into to make it work?

i have a bunch of projects and most have libraries, was hoping i can run all tests (or subset) by using ctest as i moved to cmake build. don’t want to write stuff from scratch.

---

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [February 7, 2023, 12:49pm UTC](https://discourse.cmake.org/t/ctest-for-embedded/7415/2 "2023-02-07T12:49:13Z")

</div>

Hello, Pavel!

Yes, you may try `add_test(NAME <name> COMMAND <executable>)` with launching the proper executables.  
Usually that command is wrapped by helper macro for auto-registering some test sets;

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [February 7, 2023, 6:23pm UTC](https://discourse.cmake.org/t/ctest-for-embedded/7415/3 "2023-02-07T18:23:43Z")

</div>

There is also the variable `CMAKE_CROSSCOMPILING_EMULATOR`, which if it is set and `CMAKE_CROSSCOMPILING` is on, that string will be prepended to every test command. So basically, you can use this to make it so that you can properly handle tests for crosscompiling, but run them normally without any emulators or whatever if you’re not crosscompiling. (This may be less of a concern if your project is embedded-only.)

Typically I would set `CMAKE_CROSSCOMPILING_EMULATOR` to something like `wine`, but you can also set it to the path of a script to do any custom startup/teardown logic you need, such as copying the cross-compiled executable over to the target system, executing it there, doing any cleanup, and reporting the results back to the host system.

---

<div class="post-metadata">

### Author: ![pavel\_krupets](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@pavel\_krupets](https://discourse.cmake.org/u/pavel_krupets)
#### Post date: [February 9, 2023, 9:58pm UTC](https://discourse.cmake.org/t/ctest-for-embedded/7415/4 "2023-02-09T21:58:02Z")

</div>

this has no effect on how tests are run. still wants to run file directly. ☹

```auto
set(CMAKE_CROSSCOMPILING "TRUE")
set(CMAKE_CROSSCOMPILING_EMULATOR "${CMAKE_CURRENT_LIST_DIR}/stm32_test_runner_bin/stm32_test_runner.exe")

```

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [February 17, 2023, 7:11am UTC](https://discourse.cmake.org/t/ctest-for-embedded/7415/5 "2023-02-17T07:11:04Z")

</div>

you should not direct call your cross target!  
see [using cross emulator with custom target and ctest](https://discourse.cmake.org/t/using-cross-emulator-with-custom-target-and-ctest/4076)
