CppUTest in Atollic TrueSTUDIO for ARM

823 views
Skip to first unread message

Michal Dubovský

unread,
Oct 5, 2017, 6:55:34 AM10/5/17
to cpputest
Hi everyone!

I've been in need of unit testing tool that can be run on target in Atollic TrueSTUDIO.
Getting CppUTest to work was quite a battle but it looks like everything is working now so I'd like to share my approach. Mainly to help anyone that would like to implement on-target unit testing in atollic as well but also to see if anything could have been done better.
Bear in mind that you need Pro version of Atollic to be able to get any console output.

The first step was to build a library "libCppUTest.a":
  1. git clone the latest CppUTest release
  2. create a new static library in Atollic
  3. File -> New -> C++ Project -> Static Library  -> Embedded C++ Library
  4. Select your target hardware (STM32F401RE in my case)
  5. Uncheck "Disable C++ exception handling"
  6. From CppUTest root directory: Copy all sourcefiles from src/CppUTest and src/CppUTestExt to your library's src folder
  7. From CppUTest root directory: Copy src/Platforms/Gcc/UtestPlatform.cpp to your library's src folder
  8. Open the UtestPlatform.cpp you have just copied and substitute the lines 259-288 with lines 198-218 from src/Platforms/Keil/UtestPlatform.cpp (this makes all mutex functions just dummies)
  9. In your library's src folder edit IEEE754ExceptionsPlugin.cpp line 31 so it looks like this: #ifdef CPPUTEST_USE_FENV (this turns off support for floating-point enviroment)
  10. C/C++ Build -> Settings -> Tool Settings -> C++ Compiler -> Directories -> add [CppUTestRoot]/include
  11. C/C++ Build -> Settings -> Tool Settings -> C++ Compiler -> Symbols -> add CPPUTEST_STD_CPP_LIB_DISABLED
  12. C/C++ Build -> Settings -> Tool Settings -> C++ Compiler -> General -> C++ standard -> gnu++98
  13. C/C++ Build -> Settings -> Tool Settings -> General -> Runtime Library -> Reduced C and C++
This outputs a libCppUTest.a file in your library's Debug folder. Now to create a test project:
  1. File -> New -> C++ Project -> Embedded C++ Project  -> Embedded C++ Library (I have named my project CppUTestTest)
  2. Select your target hardware (STM32F401RE in my case)
  3. Uncheck "Disable C++ exception handling"
  4. Check Generate system calls file (enable I/O ...)
  5. Select your debugging tool (ST-LINK in my case)
  6. C/C++ Build -> Settings -> Tool Settings -> C++ Compiler -> Directories -> add [CppUTestRoot]/include
  7. C/C++ Build -> Settings -> Tool Settings -> C++ Linker -> Library search path -> [path_to_your_libCppUTest.a]
  8. C/C++ Build -> Settings -> Tool Settings -> C++ Linker -> Libraries -> add "CppUTest"
  9. C/C++ Build -> Settings -> Tool Settings -> C++ Compiler -> Symbols -> add CPPUTEST_STD_CPP_LIB_DISABLED
  10. C/C++ Build -> Settings -> Tool Settings -> C++ Compiler -> Symbols -> add CPPUTEST_STD_C_LIB_DISABLED
  11. Add #include for your peripheral acces layer into Syscalls.c (stm32f4xx.h in my case)
  12. In Syscalls.c change the body of _write function to this (to handle console output):
    int i;

    for(i=0;i<len;i++)

    ITM_SendChar
    (*ptr++);


    return len;


  13. In debugger configuration enable SWV and set the core frequency to core frequency of your MCU

  14. Include "CppUTest/CommandLineTestRunner.h" in your main

  15. Add to the body of the main function:

    const char * av_override[] = { }; // Add command line parameters here
    CommandLineTestRunner::RunAllTests(0, av_override);

  16. Create a tests.cpp file for your tests

  17. Insert into tests.cpp:

    #include "CppUTest/TestHarness.h"
    TEST_GROUP(FirstTestGroup)
    {
    };
    TEST(FirstTestGroup, FirstTest)
    {
    FAIL("Fail me!");
    }

  18. Start debug session

  19. Enable ITM port 0 in your SWV console, start tracing and run the debug

You should get following output in your SWV console indicating that the testing went OK and the test that was supposed to fail indeed failed
..\src\tests.cpp:9: error: Failure in TEST(FirstTestGroup, FirstTest)
Fail me!

.

Errors (1 failures, 1 tests, 1 ran, 1 checks, 0 ignored, 0 filtered out, 98367968 ms)


Now I am sure you have noticed the strange time at the end of test report. Any suggestions on what to do about that? :)

Reply all
Reply to author
Forward
0 new messages