jwgrenning / tddec-code Goto Github PK
View Code? Open in Web Editor NEWBook code for Test-Driven Development for Embedded C
Book code for Test-Driven Development for Embedded C
When running from a Windows cmd.exe command line, slightly modified settings are needed to set the environment variables and use these when kicking off Docker. I found the following to work in Windows. It assumes you have pulled the sources into folder C:\Users\YourName\tddec-code.
set PWD=/c/Users/YourName
set MOUNT_DIR=%PWD%:/usr/src
set WORKING_DIR=/usr/src/tddec-code
set CPPUTEST_HOME=%WORKING_DIR%/cpputest
Check things out with a bash invocation as follows:
C:\Users\YourName>docker run -it -v %MOUNT_DIR% -w %WORKING_DIR% -e CPPUTEST_HOME gcc:7 /bin/bash
then do the usual things like make etc.
Maybe obvious but...
Running make
in tddec-code builds cpputest. Is required in order to build the rest of the code in the sub folders. Executing make clean
in tddec-code removes cpputest and it will not longer be possible to build the code in the sub folders. Running make clean
in sub folders does not touch cpputest.
Thank's for a great book!
After cloning the repo, and attempting to enter tddec-code/code to begin build, mutliple errors and warnings are immediately obstructive. A basic installation of cpputest using apt-get
will not satisfy the build dependences for tddec-code/code/MakefileCppUtest.mk
.
The first issue includes setting to the CPPUTEST_HOME, and results in:
MakefileCppUTest.mk:60: /build/MakefileWorker.mk: No such file or directory
However, I may be mistaken, but I don't see a clear indication in the tddec book that this is where CPPUTEST_HOME should be set. In fact, even the online cpputest documentation is quite unclear on what value CPPUTEST_HOME should have.
Once the user determines that CPPUTEST_HOME should be set, not to an install directory available from the apt package cpputest
, but only from the cpputest source, then they encounter a new link in the error chain, seen here:
Thank you
On compile in the /code/ directory with a newer compiler you will get:
compiling DvRecorder.c
src/dvr/DvRecorder.c: In function ‘DvRecorder_RestorePrograms’:
src/dvr/DvRecorder.c:39:1: error: C++ style comments are not allowed in ISO C90 [-Werror]
// programs = programs;
^
src/dvr/DvRecorder.c:39:1: error: (this will be reported only once per input file) [-Werror]
cc1: all warnings being treated as errors
make[1]: *** [objs/src/dvr/DvRecorder.o] Error 1
make[1]: Leaving directory `/home/dmiller/scratch/tddec-code/code'
make: *** [all] Error 2
Changing from C++ style comments to C style fixes.
⟫ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
diff --git a/code/src/dvr/DvRecorder.c b/code/src/dvr/DvRecorder.c
index db06bb1..2ad9745 100644
--- a/code/src/dvr/DvRecorder.c
+++ b/code/src/dvr/DvRecorder.c
@@ -36,7 +36,7 @@ void DvrRecorder_Create(void)
void DvRecorder_RestorePrograms(DvRecorder * programs)
{
-// programs = programs;
+/* programs = programs;*/
}
void DvRecorder_Destroy(void)
They refer to $MYPROJECTS and then later to $PWD and $WORKING_DIR. Are these all different directories? Or should $PWD and $WORKING_DIR be $MYPROJECTS?
The Docker setup instructions can include a little text about proper starting folder before the docker run command.
Example. Say you cloned to folder tddec-code, and you are in folder ~/github,. Then the ttd code is in folder ~/github/tddec-code. While you are in ~/github execute:
WORKING_DIR=/usr/src/tddec-code
export CPPUTEST_HOME=$WORKING_DIR/cpputest
docker run -it -v $MOUNT_DIR -w $WORKING_DIR -e CPPUTEST_HOME gcc:7 make
I am follwing the book Test-Driven Development for Embedded C to learn about TDD. Recently I come across the usage of IGNORE_TEST, which is based on unity.framework, the test case is quite simple, just the same as the code shown in the end of Section 4.1(I am using the Chinese version).
#include "unity_fixture.h"
TEST_GROUP_RUNNER(LedDriver)
{
RUN_TEST_CASE(LedDriver, LedsOffAfterCreate);
RUN_TEST_CASE(LedDriver, TurnOnLedOne);
RUN_TEST_CASE(LedDriver, TurnOffLedOne);
RUN_TEST_CASE(LedDriver, TurnOnMultipleLeds);
RUN_TEST_CASE(LedDriver, AllOn);
RUN_TEST_CASE(LedDriver, TurnOffAnyLed);
RUN_TEST_CASE(LedDriver, LedMemoryIsNotReadable);
RUN_TEST_CASE(LedDriver, UpperAndLowerBounds);
RUN_TEST_CASE(LedDriver, OutOfBoundsTurnOnDoesNoHarm);
RUN_TEST_CASE(LedDriver, OutOfBoundsTurnOffDoesNoHarm);
RUN_TEST_CASE(LedDriver, OutOfBoundsProducesRuntimeError);
RUN_TEST_CASE(LedDriver, OutOfBoundsToDo);
}
here is the output of the original code:
you can see that the ignore test case was marked but not counted.
I have search the net to figure out the reason, and I check the source code of unity atThrowTheSwitch/Unity, at line 120, the code is different from code here, after I change it:
//Unity.CurrentTestIgnored = 1;
Unity.TestIgnores ++;
It worked and I get the right ignored test count number. So I think may be there is something wrong.
A
In the first line where I run make in code-t2 I was initially getting an error of no directory found. At the bottom of the makefile in this directory there was an include
This seems to be similar to pull request #9 but not sure what it can be.
If you follow the local installation instructions as in: "If you want to try without docker, you might run into the problem of moving targets for CppUTest, gcc and clang."
You will ran into a make error.
tddec-code/Makefile requires the cpputest to be in tddec-code/cpputest
following the git clone instructions solves the problem:
MYPROJECTS=myprojects
mkdir -p $MYPROJECTS
cd $MYPROJECTS
git clone --recurse-submodules https://github.com/jwgrenning/tddec-code.git
WORKING_DIR=$MYPROJECTS/tddec-code
export CPPUTEST_HOME=$WORKING_DIR/cpputest
cd $WORKING_DIR
make
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.