New with CppUTest and need help with my first steps

760 views
Skip to first unread message

Jorge Sola

unread,
Jul 14, 2016, 11:54:42 AM7/14/16
to cpputest
Dear all,

I am new to Test Driven Development and I am following the book "Test driven development for embedded C". Thus, I downloaded CppUTest and Cygwin, and built the CppUTest as it says in the instructions. Actually, the example tests are run and everything seems ok.

My question comes now: what do I have to do to run my own tests? Lets assume that I already have my Module.c, Module.h and ModuleTest.cpp, ok. What do I have to do to compile it and run the test? Because right now, I am really really lost, and everything I see is like Chinese for me.

Could anyone help me with that?

Thank you and best regards.

James Grenning

unread,
Jul 14, 2016, 12:43:36 PM7/14/16
to cpputest
Hi Jorge

I replied to you at progprog too. So I'll put my reply here too.

I suggest you start with CppUTest and follow the instructions in my
[starter project on github](https://github.com/jwgrenning/tddec-code).
You can also fond that [book
examples](https://github.com/jwgrenning/tddec-code) on github.

In case you are interested, I will be hosting a [TDD for Embedded C web
delivered training
class](https://wingman-sw.com/training/remote-delivered-tdd) in early
August. It would be a good way to get a jump start on TDD.

Hope that helps.

thanks for buying and reading my book!

James

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)
> --
> 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.

James Grenning

unread,
Jul 14, 2016, 1:22:17 PM7/14/16
to cpputest
Ooop, copy/paste error

here is my [starter project on
github](https://github.com/jwgrenning/cpputest-starter-project)

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)

Jorge Sola

unread,
Jul 15, 2016, 3:36:01 AM7/15/16
to cpputest
Hello James,

Thank you very much for your answer. I followed your suggestions and downloaded the code from both links (starter project and the 'new version' of the book code). The first thing I did was to try to compile the t0 of the book code, and this is what I get:


/cygdrive/g/users/j/jsolamer/desktop/tddec-code-master/tddec- code-master/code-t0
$ make
compiling AllTests.cpp
In file included from <command-line>:0:0:
G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/include/CppUTest/MemoryLea kDetectorNewMacros.h:45:10: error: ‘void operator delete(void*, size_t)’ is a us ual (non-placement) deallocation function in C++14 (or with -fsized-deallocation ) [-Werror=c++14-compat] 
void operator delete (void* mem, size_t size) UT_NOTHROW; 
^
G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/include/CppUTest/MemoryLea kDetectorNewMacros.h:46:10: error: ‘void operator delete [](void*, size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocat ion) [-Werror=c++14-compat] 
void operator delete[] (void* mem, size_t size) UT_NOTHROW; 
^
cc1plus: all warnings being treated as errors
make: *** [G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/build/MakefileW orker.mk:504: objs/tests/AllTests.o] Error 1

Do you know how to get rid of these errors?
Thank you and best regards,
Jorge.



Jorge Sola

unread,
Jul 15, 2016, 4:37:30 AM7/15/16
to cpputest
Hello again,

After spending some more time trying to make this work, I managed to the following:

- In order to get rid of the error on my previous message, I went to MemoryLeakDetectorNewMacros.h and commented out the corresponding lines with the  "void operator delete[] (void* mem, size_t size) UT_NOTHROW".
- After doing so, I got rid of the error, but I got a new error message:

$ make

compiling AllTests.cpp

compiling LightSchedulerRandomizeTest.cpp

compiling LightSchedulerTest.cpp

compiling RandomMinuteTest.cpp

compiling LightControllerTestSpy.cpp

compiling FakeTimeServiceTest.cpp

compiling LightControllerSpy.c

In file included from G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/include /CppUTest/MemoryLeakDetectorMallocMacros.h:12:0,

from <command-line>:0:

G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/include/CppUTest/CppUTestConf ig.h:222:14: error: ISO C90 does not support ‘long long’ [-Werror=long-long]

typedef long long cpputest_longlong;

^

G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/include/CppUTest/CppUTestConf ig.h:223:23: error: ISO C90 does not support ‘long long’ [-Werror=long-long]

typedef unsigned long long cpputest_ulonglong;

^

cc1: all warnings being treated as errors

make: *** [G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/build/MakefileWork er.mk:509: objs/mocks/LightControllerSpy.o] Error 1


- In order to get rid of that, and after googling a while, I added this line to the makefile: CPPUTEST_CFLAGS += -std=c99


- After doing so, I got rid of that error, but I got the following error:



$ make
compiling LightControllerSpy.c
compiling FakeRandomMinute.c
compiling FakeTimeService.c
compiling RandomMinute.c
compiling LightScheduler.c
Building archive lib/libt0.a
a - objs/src/HomeAutomation/RandomMinute.o
a - objs/src/HomeAutomation/LightScheduler.o
make: *** No rule to make target 'G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/lib/libCpp UTest.a', needed by 't0_tests'. Stop.


I got rid of the error by copying the /lib folder from the /cpputest-3.8/cpputest_build to the /cpputest-3.8 folder (which is the main cpputest folder). And I managed to compile the code t0, showing the following:



$ make
Linking t0_tests
Running t0_tests
.............................................
OK (45 tests, 45 ran, 407 checks, 0 ignored, 0 filtered out, 2 ms)

I did the same for the project t1, however, I get one more error message:


$ make
compiling FakeMicroTime.c
compiling LightDriverSpyTest.cpp
compiling FakeTimeServiceTest.cpp
compiling LightDriverSpy.c
compiling FakeRandomMinute.c
compiling FakeTimeService.c
compiling AcmeWirelessLightDriver.c
compiling MemMappedLightDriver.c
compiling X10LightDriver.c
compiling LightController.c
compiling RandomMinute.c
compiling LightScheduler.c
compiling Flash.c
compiling IO.c
compiling MyOsHelpers.c
compiling TimeService.c
compiling TimeService_Helpers.c
compiling common.c
In file included from src/util/common.c:29:0:
src/util/common.c: In function ‘explodesInTestEnvironment’:
src/util/common.c:33:11: error: comparison with string literal results in unspecified behavior [-Werror=address]
 assert(p == "Explode - intercepted call that cannot be made in test environment");
 ^
cc1: all warnings being treated as errors
make: *** [G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/build/MakefileWorker.mk:509: objs/src/util/common.o] Error 1

Some tip about that error?




 





James Grenning

unread,
Jul 15, 2016, 9:33:45 AM7/15/16
to cpputest
Try removing this from the makefile

CPPUTEST_CFLAGS += -std=c89

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)
On 15 Jul 2016, at 3:37, Jorge Sola wrote:

> Hello again,
>
> After spending some more time trying to make this work, I managed to
> the following:
>
> - In order to get rid of the error on my previous message, I went to
> MemoryLeakDetectorNewMacros.h and commented out the corresponding
> lines
> with the "*void operator delete[] (void* mem, size_t size)
> UT_NOTHROW".*
> *- *After doing so, I got rid of the error, but I got a new error
> line to the makefile: *CPPUTEST_CFLAGS += -std=c99*
>
>
> *- *After doing so, I got rid of that error, but I got the following
> error:
>
>
>
>
>
>
>
>
>
>
>
>
> *$ makecompiling LightControllerSpy.ccompiling
> FakeRandomMinute.ccompiling
> FakeTimeService.ccompiling RandomMinute.ccompiling
> LightScheduler.cBuilding
> archive lib/libt0.aa - objs/src/HomeAutomation/RandomMinute.oa -
> objs/src/HomeAutomation/LightScheduler.omake: *** No rule to make
> target
> 'G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/lib/libCpp
> UTest.a',
> needed by 't0_tests'. Stop.*
>
>
> I got rid of the error by copying the /lib folder from the
> /cpputest-3.8/cpputest_build to the /cpputest-3.8 folder (which is the
> main cpputest folder). And I managed to compile the code t0, showing
> the
> following:
>
>
>
>
>
>
> *$ makeLinking t0_testsRunning
> t0_tests.............................................OK (45 tests, 45
> ran,
> 407 checks, 0 ignored, 0 filtered out, 2 ms)*
>
> I did the same for the project t1, however, I get one more error
> message:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *$ makecompiling FakeMicroTime.ccompiling
> LightDriverSpyTest.cppcompiling
> FakeTimeServiceTest.cppcompiling LightDriverSpy.ccompiling
> FakeRandomMinute.ccompiling FakeTimeService.ccompiling
> AcmeWirelessLightDriver.ccompiling MemMappedLightDriver.ccompiling
> X10LightDriver.ccompiling LightController.ccompiling
> RandomMinute.ccompiling LightScheduler.ccompiling Flash.ccompiling
> IO.ccompiling MyOsHelpers.ccompiling TimeService.ccompiling
> TimeService_Helpers.ccompiling common.cIn file included from
> src/util/common.c:29:0:src/util/common.c: In function
> ‘explodesInTestEnvironment’:src/util/common.c:33:11: error:
> comparison with
> string literal results in unspecified behavior [-Werror=address]
> assert(p
> == "Explode - intercepted call that cannot be made in test
> environment"); ^cc1: all warnings being treated as errorsmake: ***
> [G:/Users/j/jsolamer/Desktop/cpputest-3.8/cpputest-3.8/build/MakefileWorker.mk:509:
> objs/src/util/common.o] Error 1*
>
> Some tip about that error?
>
>
>
>
>
>
>
>
>
>

Bas Vodde

unread,
Jul 17, 2016, 7:04:56 AM7/17/16
to cppu...@googlegroups.com

Hi Jorge,

Did you try building CppUtest with “configure” and then “make” or just tried using the MakefileHelper?

Thanks!

Bas

nigelg...@gmail.com

unread,
Dec 15, 2017, 9:25:59 AM12/15/17
to cpputest
I have exactly this error using 64 bit cygwin on 64 bit windows 7.

After adding the following to cygwin (adding again for Perl)
  autoreconf
  autoconf
  libtool
  automake
  Perl

Then using 
   autoreconf .. -i
   ../configure
   make
   make check-coverage

which were successful,


Then changing to the project folders for tddec, with CPUTEST_HOME correct
  make everything

Gives the following results
$ make everything
make -i -C t0
make[1]: Entering directory '/cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/code/t0'
compiling AllTests.cpp
compiling LightSchedulerRandomizeTest.cpp
compiling LightSchedulerTest.cpp
compiling RandomMinuteTest.cpp
compiling LightControllerTestSpy.cpp
compiling FakeTimeServiceTest.cpp
compiling LightControllerSpy.c
In file included from /cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/tools/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h:12:0,
                 from <command-line>:0:
/cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/tools/cpputest/include/CppUTest/CppUTestConfig.h:222:14: error: ISO C90 does not support ‘long long’ [-Werror=long-long]
 typedef long long cpputest_longlong;
              ^~~~
/cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/tools/cpputest/include/CppUTest/CppUTestConfig.h:223:23: error: ISO C90 does not support ‘long long’ [-Werror=long-long]
 typedef unsigned long long cpputest_ulonglong;
                       ^~~~
cc1: all warnings being treated as errors
make[1]: [/cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/tools/cpputest/build/MakefileWorker.mk:509: objs/mocks/LightControllerSpy.o] Error 1 (ignored)
compiling FakeRandomMinute.c
In file included from /cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/tools/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h:12:0,
                 from <command-line>:0:
/cygdrive/c/Users/ndavies/ZephyrTest/tdd4ec_cygwin/tools/cpputest/include/CppUTest/CppUTestConfig.h:222:14: error: ISO C90 does not support ‘long long’ [-Werror=long-long]
 typedef long long cpputest_longlong;

(and so on)

I hope this is useful extra information.

Nigel

Keith Hill

unread,
Aug 13, 2019, 4:52:30 PM8/13/19
to cpputest
Jorge, 

   I found that by editing book/code/t1/Makefile and removing CPPUTEST_WARNINGFLAGS += -Werror it built (with warning) and passed all checks. I'm using Windows 10 vers 1903 with MSYS2 and gcc 9.

best belated wishes
Keith
Reply all
Reply to author
Forward
0 new messages