CppUTest in IAR on Windows - perspectives from a first timer

5,256 views
Skip to first unread message

Heath Raftery

unread,
Sep 17, 2013, 6:34:09 PM9/17/13
to cppu...@googlegroups.com
I've just completed an assessment of CppUTest for adoption as our company's standard Unit Testing framework. It was a bit of a battle at times but I've come out victorious so would like to share my experience for three reasons: see if there's anything I could be doing better; provide a crumb trail for other pioneers; and also contribute to CppUTest itself.

One of our strict criteria is compatibility with IAR Embedded Workbench 6.4 projects. We don't want to have to maintain a separate build environment just to run tests. Here's what I found:
  • Pulling from git source was best way to download, since that simultaneously allows us to make local changes to enable a build and store it all in our own repositories, while still allowing synchronisation with changes to the CppUTest source. As a bonus, for our users that don't want to know about git, as far as they're concerned they're pulling the software from our (SVN) repository.
  • To build the CppUTest library in IAR, I created a new empty IAR project in the root folder of cpputest and made the following changes:
    • Project -> Options -> General Options -> Target -> Core = Cortex-M3.
    • Project -> Options -> General Options -> Output -> Output file = Library
    • Project -> Options -> General Options -> Output -> Executables/libraries = Debug (removed exe subdirectory)
    • Project -> Options -> C/C++ Compiler -> Language 1 -> Language = C++
    • Project -> Options -> C/C++ Compiler -> Language 1 -> Language conformance =  Standard
    • Project -> Options -> C/C++ Compiler -> Language 1 -> C++ Dialect = C++ (leave exceptions checked)
    • Project -> Options -> C/C++ Compiler -> Preprocessor -> Additional include directories = $PROJ_DIR$\include
    • Project -> Options -> C/C++ Compiler -> Diagnostics -> Suppress these diagnostics = Pa050 (turn off warning about non-standard line endings)
    • Added all .cpp files in src\CppUTest\
    • Added src\Platforms\Iar\UtestPlatform.cpp
    • Changed line 89 of UtestPlatform.cpp from return 1; to return t; which enables timing.
  • CppUTest then builds successfully in both Debug and Release configurations, producing a CppUTest.a file.
  • To build the CppUTest tests, I created a new empty IAR project in the root folder of cpputest, called it CppUTestTest, and made the following changes:
    • Project -> Options -> General Options -> Target -> Core = Cortex-M3.
    • Project -> Options -> General Options -> Library Configuration -> Library low-level interface implementation = Semihosted
    • Project -> Options -> C/C++ Compiler -> Language 1 -> Language = Auto
    • Project -> Options -> C/C++ Compiler -> Language 1 -> Language conformance =  Standard
    • Project -> Options -> C/C++ Compiler -> Language 1 -> C++ Dialect = C++ (leave exceptions checked)
    • Project -> Options -> C/C++ Compiler -> Preprocessor -> Additional include directories = $PROJ_DIR$\include
    • Project -> Options -> C/C++ Compiler -> Diagnostics -> Suppress these diagnostics = Pa050 (turn off warning about non-standard line endings)
    • Project -> Options -> Linker -> Config -> Override default -> Edit -> Stack/Heap Sizes -> CSTACK = 0x600
    • Project -> Options -> Linker -> Config -> Override default -> Edit -> Stack/Heap Sizes -> HEAP =  0x8000
    • Added all .cpp and .c files in tests\
    • Added Debug\CppUTest.a
    • Changed line 16 of tests\AllocLetTestFree.c to explicit cast to (AllocLetTestFree) to satisfy compiler
    • Changed line 22 of tests\AllocLetTestFree.c to type AllocLetTestFree instead of void* to satisfy compiler
    • Changed tests\AllTests.cpp to declare a const char*[] with "-v" as the second element, so it can be passed to RunAllTests to turn on verbose mode in IAR
    • Built and ran in simulator.
      • Turned on Debug->C++ Exceptions->Break on uncaught exception to intercept mysterious jumps to abort.
With that out of the way I did the same for CppUTestExt and CppUTestExtTester, with no further dramas.

The stack/heap allocations were probably the largest source of drama, firstly because it wasn't clear that an out of memory situation had occurred. If the heap was exhausted a malloc/new would return zero, throw an exception and the debugger would jump to abort with no sign of the offensive statement. Turning on "Break on uncaught exception" helped. If the stack was exhausted, program behaviour was very hard to predict, and often it was in the course of trying to print out a useful error message that the stack would get corrupted! I found values of 0x600 and 0x8000 were narrowly enough to allow completion execution of the tests. It was a very tight fit though, since the Cortex-M3 architecture in IAR has 64kB of RAM on chip. With those allocations the map file showed these totals for the RAM region:
  • Static: 21056 bytes
  • Heap: 32768 bytes
  • iar.dynexit (atexit statics): 8760
  • Stack:  1536 bytes
  • Total:  64120 bytes out of 65535 bytes.
Turning off "Destroy static objects" might have given us another 8760 bytes to play with, but it's still pretty tight.

As already noted, I also needed to make two changes to the source to build and run correctly. As far as I can see, these could be applied to the master:
  • src\Platforms\Iar\UtestPlatform.cpp:89 (return t;)
  • tests\AllocLetTestFree.c:16 and  tests\AllocLetTestFree.c:22 (explicit types)
The third change to AllTests.cpp will probably only be important for IAR users, because there's no option to set command line arguments of the target executable in IAR.

With the libraries and their tests built and run successfully, the next step was to create a test for a real project. I found the following to be a suitable procedure:
  • Add a folder called tests to the target project's source hierarchy.
    • Create AllTests.cpp with this content:
#include "CppUTest/CommandLineTestRunner.h"
int main(int ac, char** av)
{
  const char * av_override[] = { "exe", "-v" }; //turn on verbose mode

  //return CommandLineTestRunner::RunAllTests(ac, av);
  return CommandLineTestRunner::RunAllTests(2, av_override);
}

    • And create MyCodeTest.cpp with this content:
extern "C"
{
#include "..\MyCode.h"
}

#include "CppUTest/TestHarness.h"

TEST_GROUP(FirstTestGroup)
{
  void setup() {}
  void teardown() {}
};

TEST(FirstTestGroup, FirstTest)
{
  FAIL("Fail me!");
}

TEST(FirstTestGroup, SecondTest)
{
  STRCMP_EQUAL("hello", "world");
}
  • Then in the same directory as your target project's project file, create a new C++ main project called MyProjectTest. Make the following changes to Project -> Options:
    • General Options -> change Device to your target device
    • General Options -> Library Configuration -> check "Use CMSIS" if it used in your target project
    • C/C++ Compiler -> Language 1 -> Language = Auto
    • C/C++ Compiler -> Language 1 -> C++ Dialect = C++
    • C/C++ Compiler -> Preprocessor -> Additional include directories = path\to\cpputest\include
    • C/C++ Compiler -> Preprocessor -> add any necessary #defines from the target project to Defined symbols
    • C/C++ Compiler -> Diagnostics -> Suppress these diagnostics = Pa050
    • Linker -> Config -> Override default with icf file used by target project
  • Ensure CSTACK is at least 0x600 and HEAP is at least 0x5000. If your target project already uses those regions, expand accordingly, otherwise ensure they're placed somewhere where they'll fit.
  • Remove main.cpp and add AllTests.cpp, MyCodeTest.cpp and Debug\CppUTest.a (use Debug version so breakpoints can be used in code and there's an inconsequential performance/size hit).
  • Create a new Group called src and add source files from the target project as necessary.
  • Use the simulator to debug the executable and run the tests.
    • Show the Terminal I/O window to see the output. In non-verbose mode a dot is written for a successful test and an exclamation mark for an ignored test.
There's lots of other details to be considered such as Workspaces, build configurations, and what to do when things go wrong, but hopefully that's enough to get started.

So that's about it. At the end of the day, CppUTest looks like it will meet our needs nicely. Once the initial setup is done, it integrates well into IAR and the output is readable within the IDE. The simulator provides a suitable alternative to execution on the PC (which means having to maintain a build with a different compiler) and execution on the hardware (which requires working hardware, Flash writes, functioning peripherals and is difficult to inject test vectors into).

My questions then:

  1. Am I using CppUTest in the optimal way so far?
  2. Is the documentation fundamentally lacking, since I couldn't easily find critical aspects like a suitable source tree hierarchy, the meaning of the dots and exclamations marks, and the minimum starter file templates?
  3. Could a couple of my changes (UTestPlatform, AllocLetTestFree and IAR project files) be considered for inclusion in the master? I understand that's doubtful, since they're not widely tested and I make no commitment to maintaining them.

Bas Vodde

unread,
Sep 18, 2013, 5:26:14 AM9/18/13
to cppu...@googlegroups.com

Hi Heath,

Wow, thanks for your loong report ;) Impressive.

I'll just to the questions immediately:

Question 0: Related to passing arguments to the AllTest.cpp.

Robert (on this list) had a similar thing with the TI compiler and he created a separate AllTest.cpp for the TI compiler where he would set the arguments. You are doing something similarly.

> • Am I using CppUTest in the optimal way so far?

I've myself not use AIR except for pair-debugging with James years ago on memory alignment issues :) I'll pass this question to James :)

> • Is the documentation fundamentally lacking, since I couldn't easily find critical aspects like a suitable source tree hierarchy, the meaning of the dots and exclamations marks, and the minimum starter file templates?

There is some documentation (www.cpputest.org) but it is indeed quite minimum. The documentation is also on github so contributions are welcome :P

> • Could a couple of my changes (UTestPlatform, AllocLetTestFree and IAR project files) be considered for inclusion in the master? I understand that's doubtful, since they're not widely tested and I make no commitment to maintaining them.

As long as the changes are improvements, sure we'll accept them. I suggest to work with them one at the time via pull requests on github. Have you used github before?

In principle, we'll try to make sure that all platforms work out of the box.

Question back: Do you know if there is an ability to generate the AIR files via CMake? That might save some startup work.

Thanks,

Bas
> •
>
> --
> You received this message because you are subscribed to the Google Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

James Grenning

unread,
Sep 18, 2013, 5:47:02 PM9/18/13
to cppu...@googlegroups.com
Hi Heath

It has been a while since I have used IAR, though adjusting AllTests to set command line arguments is a good approach. Nice job providing the details. You might add that as a read me along with the IAR project file.

James

Terry Yin

unread,
Sep 20, 2013, 3:15:43 AM9/20/13
to cppu...@googlegroups.com
Shall we put Heath's great report on the CppUTest webpages?

Bas Vodde

unread,
Sep 20, 2013, 11:52:11 PM9/20/13
to cppu...@googlegroups.com

Sure :) The website is in github, so anyone can do a pull request (and you are a commuter, Terry :P)

Bas

Terry Yin

unread,
Sep 21, 2013, 12:00:07 AM9/21/13
to cppu...@googlegroups.com
Heath, do you mind if I put your report on the cpputest webpages?

A. Robert S.

unread,
Sep 23, 2013, 4:29:55 AM9/23/13
to cppu...@googlegroups.com
Hi Heath,
 
Impressive documentation... You will find my take at AllTests.cpp, which I called AllTestsForTarget.cpp, at
 
    C:\data\00_Dev\05_CppUTest\cpputest\project\CCStudio\tests\CppUTest and
    C:\data\00_Dev\05_CppUTest\cpputest\project\CCStudio\tests\CppUTestExt
 
I do think that they are a bit hard to find there, and since they would basically work the same for all embedded targets, maybe we can find a better place to keep them, so they can serve IAR, CCStudio or what have you.
 
For my own projects, I have since changed that to a slightly different approach, more like:
 
    char* argv[] = {
        0,
        (char*) "-v",
        (char*) "-g Groupname",
    };
    int argc = sizeof(argv) / sizeof(char*);
which I find easier to change around, since you can just add or remove elements in the initialization of argv[].
Robert

Heath Raftery

unread,
Sep 24, 2013, 7:59:50 PM9/24/13
to cppu...@googlegroups.com
Sorry for the delay in responding, priorities are fickle beasts around here. Thank you for all the replies. I'll try to respond to each in turn:


On Wednesday, September 18, 2013 7:26:14 PM UTC+10, Bas Vodde wrote:
As long as the changes are improvements, sure we'll accept them. I suggest to work with them one at the time via pull requests on github. Have you used github before? 

Unfortunately no. In fact, cpputest is the first time I actually used the git client for something more than a learning exercise. I'll look into it.

> Question back: Do you know if there is an ability to generate the AIR files via CMake? That might save some startup work.  

As far as I know, no. This was a major drama with other UT packages - unless an IAR project could be created manually it was unlikely to work. The project files are proprietary (although conveniently, in XML) so unless IAR support some programmatic method, it's unlikely to be reliable.


On Saturday, September 21, 2013 2:00:07 PM UTC+10, Terry Yin wrote:
Heath, do you mind if I put your report on the cpputest webpages?

Not at all! Would be happy to contribute. I'm nervous about contributing to the splintered nature of crowd-sourced documentation, but it's better than nothing.


On Monday, September 23, 2013 6:29:55 PM UTC+10, A. Robert S. wrote:
Impressive documentation... You will find my take at AllTests.cpp, which I called AllTestsForTarget.cpp, at [ \project\CCStudio\tests ]

I do think that they are a bit hard to find there, and since they would basically work the same for all embedded targets, maybe we can find a better place to keep them, so they can serve IAR, CCStudio or what have you.
Ah yes, I see that now. Yep - I completely overlooked those files because I thought the CCStudio directory was not for me.


Thanks for the discussion. I'd love to parse down my work into a readme and suitable project files, but my employer might start to raise their eyebrows. We'll certainly be using CppUTest in greater depth in the short term, so I should be able to squeeze a few contributions in on the side.

Bas Vodde

unread,
Sep 25, 2013, 5:16:39 AM9/25/13
to cppu...@googlegroups.com

Hiya,

> Sorry for the delay in responding, priorities are fickle beasts around here. Thank you for all the replies. I'll try to respond to each in turn:
>
> On Wednesday, September 18, 2013 7:26:14 PM UTC+10, Bas Vodde wrote:
> As long as the changes are improvements, sure we'll accept them. I suggest to work with them one at the time via pull requests on github. Have you used github before?
>
> Unfortunately no. In fact, cpputest is the first time I actually used the git client for something more than a learning exercise. I'll look into it.

I believe this worked out. Thanks for the changes!

>
> > Question back: Do you know if there is an ability to generate the AIR files via CMake? That might save some startup work.
>
> As far as I know, no. This was a major drama with other UT packages - unless an IAR project could be created manually it was unlikely to work. The project files are proprietary (although conveniently, in XML) so unless IAR support some programmatic method, it's unlikely to be reliable.

Ok. Too bad, maintaining more project files is a pain :(

Thanks!

Bas

>
>
> On Saturday, September 21, 2013 2:00:07 PM UTC+10, Terry Yin wrote:
> Heath, do you mind if I put your report on the cpputest webpages?
>
> Not at all! Would be happy to contribute. I'm nervous about contributing to the splintered nature of crowd-sourced documentation, but it's better than nothing.
>
>
> On Monday, September 23, 2013 6:29:55 PM UTC+10, A. Robert S. wrote:
> Impressive documentation... You will find my take at AllTests.cpp, which I called AllTestsForTarget.cpp, at [ \project\CCStudio\tests ]
>
> I do think that they are a bit hard to find there, and since they would basically work the same for all embedded targets, maybe we can find a better place to keep them, so they can serve IAR, CCStudio or what have you.
> Ah yes, I see that now. Yep - I completely overlooked those files because I thought the CCStudio directory was not for me.
>
>
> Thanks for the discussion. I'd love to parse down my work into a readme and suitable project files, but my employer might start to raise their eyebrows. We'll certainly be using CppUTest in greater depth in the short term, so I should be able to squeeze a few contributions in on the side.
>

Terry Yin

unread,
Oct 5, 2013, 11:04:26 PM10/5/13
to cppu...@googlegroups.com
Hi,

I've created this page:

But I haven't put any link to it yet. Is there any update about the story?


br, Terry

Heath Raftery

unread,
Oct 6, 2013, 5:53:26 PM10/6/13
to cppu...@googlegroups.com
Terry,

Only update is that a couple of my changes have been merged with the master - the time fix in Iar/UtestPlatform and the explicit casting in AllocLetTestFree.c.

Regards,
Heath

Mariano Colabraro

unread,
Oct 29, 2013, 5:07:17 AM10/29/13
to cppu...@googlegroups.com
Hello Heath,

I found this thread while searching how to use CppUtest with IAR compiler. I wonder if you can help me.
I'm using Windows 7 x64. IAR Workbench 6.3.3. We use AVR UC3C0512C.

The first issue I encounter while compiling the library for CppUtest is that the std::string is not defined. so I get 190 Errors.

In the file SimpleString.h I get the following error regarding the std namespace.

Error[Pe276]: name followed by "::" must be a class or namespace name
C:\COM\SRC\cpputest35\include\CppUTest\SimpleString.h 143 
I tried the following line in order to silence the error, it seems to work because it reduce the errors to 11.
 
#define std // Nothing here
Anyway, I don't think I'm on the right path because then I get errors relating to Try catch blocks. If this is not supported then I guess most of other structures are not supported either. 
Here is the complain about try-catch blocks:

Error[Pe540]: support for exception handling is disabled C:\COM\SRC\cpputest35\src\CppUTest\MemoryLeakWarningPlugin.cpp 110

Did you have as many issue I had when compiling CppUTest?
Thank you in advance, I really appreciate you are sharing these guides.



Best regards,

Mariano
Message has been deleted

Heath Raftery

unread,
Oct 29, 2013, 7:36:36 AM10/29/13
to cppu...@googlegroups.com
Mariano,

Yep, ran into all those problems and more. The fixes are in my original post. In particular the problems you mention are to do with the C++ dialect settings.

Heath

north...@moonrock.ca

unread,
Feb 14, 2014, 4:35:39 PM2/14/14
to cppu...@googlegroups.com
Hi Heath:

Thanks for posting this detailed article for getting CppUTest running on IAR. I am doing a similar exercise with IAR 6.5 and CppUTest 3.5  trying to get it to work in our environment using the generic Cortex -M3 settings. I'm running into some problems though with linking and running out of memory. I've been able to compile the cppUTest.a library and was now trying to build the CppUTest Test suite. However, I seem to be getting a linker error where it is reporting that the size limit has been exceeded: 203509 > 32768. From what I can tell reading the map file, everything should fit. Here are some of the entries in my .map file:
"A1":  place at 0x00000000 { ro section .intvec };
"P1":  place in [from 0x00000000 to 0x0007ffff] { ro };
"P2":  place in [from 0x20000000 to 0x2000ffff] { rw, block CSTACK, block HEAP };

.data          0xAC
.bss           0x4fb2
.iar.dynexit 0x2238
stack         0x600
heap         0x8000

Did you run into any such problems yourself initially?

Robert
Message has been deleted
Message has been deleted

wate...@gmail.com

unread,
Nov 12, 2014, 5:31:36 PM11/12/14
to cppu...@googlegroups.com
Heath,
I think I am running into the same issues Mariano was. I do not have the same dialect settings you have. I am compiling using Embedded Workbench for MSP430.

Here are the options I have:

As of right now I do not see a way around this. It looks like we will have to run IAR in parallel with Cygwin+GCC+Makefiles. I am going to look into cunit to see if I can compile that from IAR.

Heath Raftery

unread,
Nov 21, 2014, 12:45:50 AM11/21/14
to cppu...@googlegroups.com
Looks like you’re right. If you need that particular Dialect to build your project then you might be at a roadblock. I forget - can you build the CppUTest library with the Dialect set one way, then build your tests with it set the way you need it? Otherwise you might be in a world of pain making exceptions either way.

Heath

> On 13 Nov 2014, at 9:31 am, wate...@gmail.com wrote:
>
> Heath,
> I think I am running into the same issues Mariano was. I do not have the same dialect settings you have. I am compiling using Embedded Workbench for MSP430.
>
> Here are the options I have:
>
>

Juho Routakorpi

unread,
May 5, 2015, 8:04:35 AM5/5/15
to cppu...@googlegroups.com
Hi

Posting in an ancient thread, but I just would like to update my experience with CppUTest & IAR EWARM. Thanks for the instructions by the way!

I managed to build CppUTest 3.6 with IAR EWARM 7.40 according to your instructions. I am also able to run the tests in Eclipse (but no test runner support -- only console output).

I found out that it's possible to also compile CppUTest successfully without the exceptions support (which adds quite a bit to the memory requirements). I made these changes:

  • Select dialect to Extended Embedded C++ (Embedded C++ might work as well, didn't try)
  • Select language conformance to Standard with IAR extensions (others might work as well)
  • Add the following defined symbols in the Preprocessor tab:
    CPPUTEST_USE_STD_CPP_LIB=0
    CPPUTEST_USE_MEM_LEAK_DETECTION=0
    std

The caveat is that memory leakage checks may not work any more, and static objects might not be destroyed. Still if this modification enables any unit testing, I'd say it's worth the price.

I still didn't manage to get CppUTest runner to work in Eclipse. If I have the spare time some day, maybe I'll try again. Problem seems to be in how Eclipse runs the simulator; CSspyBat yields different output when run from command line and from Eclipse.

Juho

akash garg

unread,
May 19, 2015, 2:35:23 AM5/19/15
to cppu...@googlegroups.com
hi Heath Raftery 
I got following  errors after building a project using below step you mention--
1. Error[Pe137]: expression must be a modifiable lvalue C:\....cpputest\tests\CommandLineTestRunnerTest.cpp 169 
2. Error[Pe137]: expression must be a modifiable lvalue C:\....\cpputest\tests\JUnitOutputTest.cpp 299 
3. Error[Pe101]: "allocator" has already been declared in the current scope (at line 120 of "C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0\ C:\...\cpputest\tests\MemoryLeakWarningTest.cpp 55 
4. Error[Pe441]: argument list for class template "allocator" is missing C:\....\cpputest\tests\MemoryLeakWarningTest.cpp 91 
please help me in this case.

Heath Raftery

unread,
May 19, 2015, 3:08:43 AM5/19/15
to cppu...@googlegroups.com
Hi akash,

Can you also provide the source code that the errors refer to? I'm afraid I haven't memorised the source!

Heath

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Juho Routakorpi

unread,
May 19, 2015, 3:13:17 AM5/19/15
to cppu...@googlegroups.com
For what it's worth, I was unable to get CppUTest 3.7 to compile with IAR EWARM 7.40, and couldn't be arsed to solve the compiler errors. 3.6 compiles fine though, and includes all the functionality I need.

Juho

--
You received this message because you are subscribed to a topic in the Google Groups "cpputest" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cpputest/WxCfnVZYGHw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cpputest+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Juho Routakorpi           |   ``Ever tried. Ever failed.
routsikka@ircnet          |      No matter. Try again.
juho.ro...@iki.fi    |       Fail again. Fail better.``
041-4347807               |   -- Samuel Beckett: "Worstward Ho"

akash garg

unread,
May 19, 2015, 4:47:57 AM5/19/15
to cppu...@googlegroups.com
hi Heath 
 am using above attached source directory for integration between IAR IDE and CppUTest and after using steps provided for integration i got following errors:
1. Error[Pe137]: expression must be a modifiable lvalue C:\....cpputest\tests\CommandLineTestRunnerTest.cpp 169 
2. Error[Pe137]: expression must be a modifiable lvalue C:\....\cpputest\tests\JUnitOutputTest.cpp 299 
3. Error[Pe101]: "allocator" has already been declared in the current scope (at line 120 of "C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0\ C:\...\cpputest\tests\MemoryLeakWarningTest.cpp 55 
4. Error[Pe441]: argument list for class template "allocator" is missing C:\....\cpputest\tests\MemoryLeakWarningTest.cpp 91   

sir my main aim is to integrate cpputest with iar and keil for unit testing purpose. And MSP430 and ARM cortex are  my main core  
cpputest-3.7.1.zip

Reddy B

unread,
Jun 2, 2015, 1:12:31 AM6/2/15
to cppu...@googlegroups.com
Dear All,



I am new to IAR Embedded Workbench development IDE and we are using 6.4 version. We are developing a embedded microcontroller software in c language and i am trying to build Cpputest.3.7.1 with IAR. I downloaded the source code from the git and extracted it. I could see that there IAR project under cpputest-3.7.1\platforms\IAR-STR912\. I opened it and trying to build it and i am getting the following errors. I would greatly thankful If you have any idea or clue about the error....




*****************************************************************************************************************************
ERROR DURING 
*****************************************************************************************************************************

Building configuration: CppUTest-STR912-Main - Debug 
Updating build tree... 
CommandLineArguments.cpp  
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\SimpleString.h 158 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 36 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 37 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 38 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 39 
Error while running C/C++ Compiler 
CommandLineArgumentsTest.cpp  
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\SimpleString.h 158 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 36 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 37 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 38 
Error[Pe276]: name followed by "::" must be a class or namespace name E:\cpputest-master\include\CppUTest\MemoryLeakDetectorNewMacros.h 39 
Error while running C/C++ Compiler 
...
...
...

Thanks in advance...


Reddy
IAR Build errors.txt

Heath Raftery

unread,
Jun 2, 2015, 7:37:49 AM6/2/15
to cppu...@googlegroups.com
Hi Reddy,

I'm guessing from the subject line you've read my original post? Did you follow those steps? I'm afraid I haven't memorised the code base, but I'm guessing those errors all refer to use of the "std" namespace? If so, you need to ensure you've selected the C++ Dialect. The Embedded C++ Dialect doesn't include the std namespace.

Check my original post for the details. You can find a copy here:

Heath

Sent from my iPad
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<IAR Build errors.txt>

Reddy B

unread,
Jun 3, 2015, 3:26:02 AM6/3/15
to cppu...@googlegroups.com, juho.ro...@iki.fi
HI Juho,

 I am trying to compile CppUTest 3.6 using IAR-STR912 platform setting for IAR and i got below error on compiling... Did you use the existing IAR-STR912 project or did you follow the Heath Raftery  instructions?

Fatal Error[Li001]: could not open file "E:\cpputest-3.6\platforms\IAR-STR912\Debug\Exe\IAR-STR912-Lib.a" 
Error while running Linker 

Thanks in advance..


Reddy

Adam Honeybell

unread,
Mar 9, 2016, 9:10:58 AM3/9/16
to cpputest
Hi Heath, this is a very interesting article. I've been developing on IAR for while, but I need to start unit testing properly. I don't suppose you have a .ewp project and/or workspace you could share? I've never used the simulator, but I can see this would be useful.

Heath Raftery

unread,
Mar 9, 2016, 1:32:24 PM3/9/16
to cppu...@googlegroups.com
Hi Adam,

Sorry, I don’t even have access to IAR, let alone the project I built any more. There’s a lot of value in running through the steps I wrote though, so you learn a bit about what makes it tick and you get the latest version of CppUTest. That way you’ll have your very own project to work from.

Depending on how you want to work, you might try a workspace that has CppUTest and CppUTestTest in it, while your working project just links to the library.

The simulator is a great place to get started because you can use your normal target compiler/build process, and you don’t have to go through the Flash cycle. As discussed on the cpputest mailing list elsewhere, you’ll eventually probably want to test on the target.

Give it a crack and if there’s any issues let me know.

Heath

Adam Honeybell

unread,
Mar 11, 2016, 4:04:48 AM3/11/16
to cpputest
Hi Heath, ok. I'm just trying to work out what is possible and what is suitable for my project. There are a few that would benefit from this. Anyway, i've been able to compile V3.6 of CppUTest, CppUTestTest, and the ext tests too. But when I run them I get nothing shown on the terminal I/O window and its not obvious why. Probably a configuration setting somewhere, but I'm not sure. Any ideas?
Adam

Heath Raftery

unread,
Mar 11, 2016, 5:14:24 AM3/11/16
to cppu...@googlegroups.com
Yeah I sympathise. I considered contributing my project file back when I wrote that article, but given that it was not tested on anything other than my PC and that I was not prepared to maintain it, I figured it would quickly become less than useless.

Only thing I can suggest is to double check this setting:


  • Project -> Options -> General Options -> Library Configuration -> Library low-level interface implementation = Semihosted

That's the setting that redirects stdio to the debugger. Try inserting a printf or cout statement in main somewhere to test it's working.

Sent from my iPad

Betzaida González Ramírez

unread,
Jul 21, 2016, 6:29:53 PM7/21/16
to cpputest
Hello Heath,
Thank you for your information!

Can you help me? I want generate Junit output file, I tried the next code:

But I CANT see some .xml file :(
-------------------------------------------
int main(int ac, char** av)
{
    const char * av_override[] = {"exe", "-ojunit"};

    return CommandLineTestRunner::RunAllTests(2, av_override);
}
------------------------------------

Heath Raftery

unread,
Jul 22, 2016, 8:58:43 PM7/22/16
to cppu...@googlegroups.com
Hi Betzaida,

I’m afraid I have no experience with JUnit. What you’ve done looks right, so I don’t know what else to suggest.

Heath

Juho Routakorpi

unread,
Jul 23, 2016, 3:09:16 AM7/23/16
to cppu...@googlegroups.com
Hi Betzaida

I'm not currently at work so can't check the details. I have managed to get CppUTest to generate Junit XML output so I know it is possible.

Junit output will be in the standard output of the program, so you probably need to pipe it to a file in order to use it. I'm using the IAR simulator for running the project and capturing its output.

You can first verify that this works by observing the Terminal window in IAR Embedded Workbench. Same output should be available there (along with any error messages in case your command line options are incorrect for some reason). If there's no output in the Terminal window, then you need to review the project options.

Hope this helps

Juho

Betzaida González Ramírez

unread,
Jul 25, 2016, 11:45:32 AM7/25/16
to cpputest, juho.ro...@iki.fi
Hello Juno!!!


Thank you for your answer! 

When I write:

int main(int ac, char** av)
{
    const char * av_override[] = {"exe", "-v"};

    return CommandLineTestRunner::RunAllTests(2, av_override);
}
The IAR Terminal IO shows me all test and results. When I change "-v" by "-ojunit"  , the terminal output don´t show me some error ( I can see message error when bad use of command line options), but i can´t see the junit output.


Any suggestions for "project options" that I must review?

I want junit output because I want integrate me with jenkins.


-------------------------------------------------------------------------------------------------------------

Betzaida González Ramírez

unread,
Jul 25, 2016, 11:45:52 AM7/25/16
to cpputest
Thank you Heath!

Cristopher Lubay

unread,
Jun 29, 2017, 4:08:08 AM6/29/17
to cpputest, juho.ro...@iki.fi
Hi Betzaida,

Were you able to produce an xml output?
Please teach me how to do it.
Thank you.

-- Cris

Cameron Fedde

unread,
Aug 1, 2017, 10:57:53 AM8/1/17
to cpputest
Hey, this is a great resource you've made for Unit Testing in IAR! I think I've followed the steps you've outlined here, but I can't seem to get the Tests to build, coming up with an "Expected a ';'" error:

CommandLineTestRunnerTest.cpp  
Error[Pe065]: expected a ";"      C:\Users\cfedde\Documents\Git\Instrument\instrument-frameworks\ATSAM4L\Workspace\UnitTestWorkspace\include\CppUTestExt\MockCheckedActualCall.h 87 
Error[Pe065]: expected a ";"      C:\Users\cfedde\Documents\Git\Instrument\instrument-frameworks\ATSAM4L\Workspace\UnitTestWorkspace\include\CppUTestExt\MockCheckedActualCall.h 88 
Error[Pe065]: expected a ";"      C:\Users\cfedde\Documents\Git\Instrument\instrument-frameworks\ATSAM4L\Workspace\UnitTestWorkspace\include\CppUTestExt\MockCheckedActualCall.h 199 
Error[Pe065]: expected a ";"      C:\Users\cfedde\Documents\Git\Instrument\instrument-frameworks\ATSAM4L\Workspace\UnitTestWorkspace\include\CppUTestExt\MockCheckedActualCall.h 200 
Error[Pe065]: expected a ";"      C:\Users\cfedde\Documents\Git\Instrument\instrument-frameworks\ATSAM4L\Workspace\UnitTestWorkspace\include\CppUTestExt\MockCheckedActualCall.h 264 
Warning[Pe012]: parsing restarts here after previous syntax error C:\Users\cfedde\Documents\Git\Instrument\instrument-frameworks\ATSAM4L\Workspace\UnitTestWorkspace\include\CppUTestExt\MockCheckedActualCall.h 269 
Error while running C/C++ Compiler 

Here are the lines in question (in order):

    virtual void (* returnFunctionPointerValue())() _override;
    virtual void (* returnFunctionPointerValueOrDefault(void (*)()))() _override;

    virtual void (*returnFunctionPointerValue())() _override;
    virtual void (*returnFunctionPointerValueOrDefault(void (*)()))() _override;

    virtual void (*returnFunctionPointerValue())() _override { return NULL; }
    virtual void (*returnFunctionPointerValueOrDefault(void (*value)()))() _override { return value; }

They are all the same lines, so I'm confused as to why they aren't building correctly. 
Have you run into this issue before, or do you know of the base problem that I might be able to fix? Thanks!

--Cameron 
int main(int ac, char** av)
{

Heath Raftery

unread,
Aug 1, 2017, 4:03:49 PM8/1/17
to cppu...@googlegroups.com
Sounds like the compiler is choking on “_override”. That’s probably what it means by expected a “;”’ - it got to _override and didn’t know what to do with it.

_override is defined in include/CppUTest/CppUTestConfig.h. I don’t think IAR’s compiler is C++11 compatible, so line 271 should define _override to nothing. I don’t remember having to do anything associated with these aspects, but it has been a long time and IAR’s compiler might have changed.

Hope that helps you track it down, or someone else might have some better advice.

Heath

Cameron Fedde

unread,
Aug 2, 2017, 10:49:28 AM8/2/17
to cpputest
Hey Heath, thanks so much for the fast response! You're right, I changed line 258 of CppUTestConfig.h to define _override to nothing:

>258 #define _override

and I'm no longer getting the number of errors as I was getting before. However, now I'm running into another error:

Error[Pe167]: argument of type "void *" is incompatible with parameter of type "unsigned char const *" C:\Users\...\cpputest-3.8\tests\CppUTestExt\MockSupport_cTestCFile.c 61 
Error[Pe167]: argument of type "void *" is incompatible with parameter of type "unsigned char const *" C:\Users\...\cpputest-3.8\tests\CppUTestExt\MockSupport_cTestCFile.c 74 

with lines 61 and 74 being:

>61            withMemoryBufferParameter("name", (void*) 1, 0UL)->
>74            withMemoryBufferParameter("name", (void*) 1, 0UL)->

so I will try to debug it, but if you know of this issue as well, I appreciate any input! Thanks!

--Cameron

Heath Raftery

unread,
Aug 2, 2017, 5:20:24 PM8/2/17
to cppu...@googlegroups.com
Cameron,

On 3 Aug 2017, at 12:49 am, Cameron Fedde <crf...@gmail.com> wrote:

Hey Heath, thanks so much for the fast response! You're right, I changed line 258 of CppUTestConfig.h to define _override to nothing:

>258 #define _override

and I'm no longer getting the number of errors as I was getting before. However, now I'm running into another error:

Great to hear! I always get worried when I have to modify code line by line - often leads to an endless process chasing your tail. Would be better to know why the "#if defined(“ thing failed, but if it works, it works!

Error[Pe167]: argument of type "void *" is incompatible with parameter of type "unsigned char const *" C:\Users\...\cpputest-3.8\tests\CppUTestExt\MockSupport_cTestCFile.c 61 
Error[Pe167]: argument of type "void *" is incompatible with parameter of type "unsigned char const *" C:\Users\...\cpputest-3.8\tests\CppUTestExt\MockSupport_cTestCFile.c 74 

with lines 61 and 74 being:

>61            withMemoryBufferParameter("name", (void*) 1, 0UL)->
>74            withMemoryBufferParameter("name", (void*) 1, 0UL)->

so I will try to debug it, but if you know of this issue as well, I appreciate any input! Thanks!

No idea about that one I’m sorry! Seems like a very odd cast. It's safe to remove the “(void*)”, but again, you could be chasing your tail making little changes like that.

Hope you get to the bottom of it. I’m sure the developers would be interested in your results, and maybe you could even provide an update to the IAR guide.

Cheers,
Heath

Cameron Fedde

unread,
Aug 3, 2017, 11:17:40 AM8/3/17
to cpputest
So I was able to fix that error by changing it from (void*) to (unsigned char const*), and that seemed to take care of the error. It looks like it might be a known issue: https://github.com/cpputest/cpputest/issues/1101 

After this, it came up with a number of new errors though, but it seems to be an issue with the files included or a library somewhere:

Error[Li005]: no definition for "MockActualCallTrace::returnFunctionPointerValue()" [referenced from C:\Users\...\Debug\Obj\MockActualCallTest.o]  x 101 times...

so hopefully it's just an issue of file placement and including the right files, though I'm pretty sure I followed the process laid out in the OP pretty closely. I'll report back if I figure this one out.

Cameron Fedde

unread,
Aug 23, 2017, 7:27:36 PM8/23/17
to cpputest
So I figured out that I just needed to put the correct path for the .cpp and .c files, and it seemed to fix the problems I was having before. Tests are running now, which is great! Thanks for the guide. 

One more question/problem though, how do I pass multiple command line flags to the test runner? it doesn't seem to like putting them all together as one string within av_override, but passing it separate strings doesn't work either. I'll keep trying different combinations.

Heath Raftery

unread,
Aug 23, 2017, 8:43:45 PM8/23/17
to cppu...@googlegroups.com
Did you change the 2? For example:

const char * av_override[] = { "exe", "-v”, “-another-option" }; 
return CommandLineTestRunner::RunAllTests(/*2*/ 3, av_override);

Heath

Cameron Fedde

unread,
Aug 24, 2017, 10:22:07 AM8/24/17
to cpputest
Ah ha! I hadn't tried that, works like a charm! I've got it up and running as I want it now, so I can start implementing the unit tests! Thanks so much for your help Heath!

Akshata Bagwe

unread,
Jul 11, 2019, 5:19:34 AM7/11/19
to cpputest
Hi Heath,

First of all thanks a lot for this detailed description of your experience on CPPUTest. I am currently trying to use CPPUtest for atollic for K60 for a very huge code. The problem that I am facing is that the test cases are not getting registered and so in the end no test case is getting executed. I am calling the functions after RTOS init so that I have memory pools initialized I have tried everything but I am not able to understand where that solution lies. Can you help?

Heath Raftery

unread,
Jul 11, 2019, 6:52:22 AM7/11/19
to cppu...@googlegroups.com
Hi Akshata,

I’m afraid I might not be much help! I don’t know what K60 is and it’s been years since I’ve used IAR or CppUTest. And there’s not much to go on in your question. All I can suggest is that you make sure your source files with the TEST_GROUP and TEST macros are linked into the build. From memory that’s really all there is to it - RunAllTests just executes each of the TESTs in each of the TEST_GROUPs.

Good luck!
Heath

Sent from my iPad
--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.

James Grenning

unread,
Jul 11, 2019, 9:22:17 AM7/11/19
to cpputest

Hello Akshata

I might be able to help you find a solution. CppUTest relies on file scope initialization to install test cases into the test runner.

Sparing some of the details, the TEST macro causes a static instance of a TestInstaller to be defined for each TEST. The C++ compiler is responsible for initializing file-scope static data and objects before main starts. This means that file-scope constructors must be called before main for C++ file-scope static objects. Running the TestInstaller constructor adds a TestShell to the list of all tests. RUN_ALL_TESTS uses that list.

I suspect that there is a function that you need to call that runs all the constructors your pre-main initialization. I've seen this function before another compiler with has ctor in its name. Hopefully with these clues you can find the function that your per-main need to call to do its job. If you have production code C++ file-scope objects they probably are not being constructed either.

Here's the TEST macro if you really want to look under the hood.

#define TEST(testGroup, testName) \
  /* External declarations for strict compilers */ \
  class TEST_##testGroup##_##testName##_TestShell; \
  extern TEST_##testGroup##_##testName##_TestShell TEST_##testGroup##_##testName##_TestShell_instance; \
  \
  class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \
{ public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \
       void testBody(); }; \
  class TEST_##testGroup##_##testName##_TestShell : public UtestShell { \
      virtual Utest* createTest() _override { return new TEST_##testGroup##_##testName##_Test; } \
  } TEST_##testGroup##_##testName##_TestShell_instance; \
  static TestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \
    void TEST_##testGroup##_##testName##_Test::testBody()

I hope that helps, James


James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
Ask me about my web delivered TDD training.
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
wingman software

Akshata Bagwe

unread,
Jul 13, 2019, 1:54:04 AM7/13/19
to cpputest
Thanks a lot James. 
This idea worked for me. As I was running the tests before the running the static constructors. 
:) 
To unsubscribe from this group and stop receiving emails from it, send an email to cppu...@googlegroups.com.

James Grenning

unread,
Jul 14, 2019, 11:16:23 AM7/14/19
to cpputest

Great! Glad you fixed it.

Cheers, James

To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/42a6a96b-5c55-4aed-b683-4805b7ea6fbb%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages