SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Automated Testing for Embedded Software in C or C++
When software developers write automated tests for their software, the quality increases, the design improves and the project becomes more manageable. The development also becomes more fun!
In this presentation you will learn how to write automated tests for embedded software. You will see a live demonstration of writing an automated test for a feedback control algorithm in C. I will also talk about the benefits of writing tests and why it can actually improve your design and save you time.
When having a large set of automated tests it becomes valuable to run all tests automatically every time the code is changed. I will touch upon what is the best continuous integration setup for embedded software projects.
Sample code can be downloaded from http://www.zealake.com/public/embedded-autotest.zip
When software developers write automated tests for their software, the quality increases, the design improves and the project becomes more manageable. The development also becomes more fun!
In this presentation you will learn how to write automated tests for embedded software. You will see a live demonstration of writing an automated test for a feedback control algorithm in C. I will also talk about the benefits of writing tests and why it can actually improve your design and save you time.
When having a large set of automated tests it becomes valuable to run all tests automatically every time the code is changed. I will touch upon what is the best continuous integration setup for embedded software projects.
Sample code can be downloaded from http://www.zealake.com/public/embedded-autotest.zip
Automated Testing for Embedded Software in C or C++
1.
Who is Lars Thorup?
● Software developer
● Web: C# and JavaScript
● Embedded C++ for several
devices using agile and
automated testing
● Coach: Teaching agile and
automated testing
● Advisor: Assesses software
projects and companies
● Founder and CEO of
BestBrains and ZeaLake
2.
Agenda
● What is automated testing?
● Unity, test framework for embedded C
● Code example
● Why should we write automated tests?
● Questions
3.
What is automated testing?
● Developers write test ● Automated execution of all
programs test programs
4.
The Unity testing framework
● Small memory footprint ● Many test functions
● ASSERT_TRUE
● Pure C ● FAIL
● ASSERT_EQUAL
● Optional tools to generate ● ASSERT_WITHIN
test runners automatically ● ASSERT_BITS
● ASSERT_NOT_NULL
● Alternatives in C++
● ASSERT_MEMORY
● CppUnit
● Google Test
5.
How do we handle dependencies?
● The flow example
● a flow sensor
● generates pulse counts proportional to actual flow
● calculate average flow rate with regular intervals
● The dependencies in the flow example
● the sensor creating the pulse interrupt
● recurring timer event
● thread safe counting
● Decouple the dependencies
● Pulse: provide a callback to the FlowSensor component
● Timer and Counting: inject components into the Flow component
● flow.c
7.
Dependencies, in test
flowTest.c
Pulse
GetRate
flow.c SetTime
GetTime
timerStub.c
Increment
counterImpl.c
8.
Strategy for testing embedded software
● Continuous Integration
● Automate build and test execution
● On desktop, simulator and/or the device
● Break dependencies
● Hardware Abstraction Layer
● Simulate time measurements and timer events
● Standardize on frequently used stubs
● Use mock objects for testing protocols
● Dependency injection
● Link time, where possible
● Run time, using function pointers, where necessary
9.
Why should we write unit tests?
● Speed up development
● Because of all the things we no longer have to waste time on
● Test Driven Development vs Debug Later Programming
● Avoid piling up technical dept (manual testing, bug fixing)
● Typing code is not where the bottleneck is
● Find bugs faster
● Trivial bugs found immediately
● QA can do exploratory testing earlier and more extensively
● Prevent bugs from reappearing
● Never fix a bug until we have a failing test
● Improve the software design
● Loose coupling is required to write tests
10.
Links to further resources
● List of testing tools for C and C++
● http://www.opensourcetesting.org/unit_c.php
● Book
● http://pragprog.com/titles/jgade/test-driven-development-for-
embedded-c
● Experiement on the benefits of TDD
● http://www.infoq.com/news/2009/03/TDD-Improves-Quality
● Meetup groups
● http://www.meetup.com/Test-Driven-Developers-Bay-Area/