SlideShare a Scribd company logo
Automated Testing for Embedded Software in C or C++
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
Agenda
●   What is automated testing?

●   Unity, test framework for embedded C

●   Code example

●   Why should we write automated tests?

●   Questions
What is automated testing?
●   Developers write test   ●   Automated execution of all
    programs                    test programs
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
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
Dependencies, on device
                       main.c

            Listen
                             GetRate

    flowSensor.c                    flow.c
                     Pulse



                        GetTime

              timerImpl.c



                                        Increment

                                counterImpl.c
Dependencies, in test
                                      flowTest.c
                        Pulse



                               GetRate

                      flow.c                 SetTime



                          GetTime

                                         timerStub.c



                          Increment

                  counterImpl.c
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
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
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/
Questions

More Related Content

PPT
Software Testing Fundamentals
PPT
Story Cards
PPT
Automated hardware testing using python
PDF
How and what to unit test
PPT
AUTOMATED TESTING USING PYTHON (ATE)
PPTX
Software Testing Basics
PPTX
SOFTWARE TESTING
PPT
Basic software-testing-concepts
Software Testing Fundamentals
Story Cards
Automated hardware testing using python
How and what to unit test
AUTOMATED TESTING USING PYTHON (ATE)
Software Testing Basics
SOFTWARE TESTING
Basic software-testing-concepts

What's hot (20)

PPTX
C++ Unit testing - the good, the bad & the ugly
PPTX
Off the-shelf components (cots)
ODP
Beginners - Get Started With Unit Testing in .NET
PPT
Software Testing 101
PPT
Basic Guide to Manual Testing
PPT
White box testing
PPT
Automated Testing with Agile
PPTX
formal verification
PPTX
High Level Language (HLL)
PPTX
Structural and functional testing
PPTX
Software testing methods
PDF
Introduction to pairwise testing
PPTX
WHITE BOX TESTING ashu.pptx
PPTX
Introduction to basic programming repetition
PPT
Interpreters & Debuggers
PPTX
Software Quality Models: A Comparative Study paper
PPT
Test automation process
PPT
Software Testing
PPT
Software Quality Assurance
PPTX
source code metrics and other maintenance tools and techniques
C++ Unit testing - the good, the bad & the ugly
Off the-shelf components (cots)
Beginners - Get Started With Unit Testing in .NET
Software Testing 101
Basic Guide to Manual Testing
White box testing
Automated Testing with Agile
formal verification
High Level Language (HLL)
Structural and functional testing
Software testing methods
Introduction to pairwise testing
WHITE BOX TESTING ashu.pptx
Introduction to basic programming repetition
Interpreters & Debuggers
Software Quality Models: A Comparative Study paper
Test automation process
Software Testing
Software Quality Assurance
source code metrics and other maintenance tools and techniques
Ad

Similar to Automated Testing for Embedded Software in C or C++ (20)

PDF
Unit testing on embedded target with C++Test
PDF
Bdd and-testing
PDF
Behaviour Driven Development and Thinking About Testing
 
PDF
Insights and Lessons Learned Verifying the QoS Engine of a Network Processor
PDF
Boston 2009 q1_kappler_chris
PPTX
Coding Naked
ZIP
Becoming Indie
PDF
Unit testing (eng)
PPTX
Analysis of Testability of a Flight Software Product Line
DOC
SOFTWARE VERIFICATION & VALIDATION
PDF
Test and Behaviour Driven Development (TDD/BDD)
PPTX
Unit Testing
PPTX
Testing
PPTX
Reverse Architecting of a Medical Device Software
PDF
TDD (with FLOW3)
PPTX
Software Testing_mmmmmmmmmmmmmmmmmmmmmmm
PDF
2012 mobile testingsummit-moet
PDF
Webapp acceptance testing a case study
KEY
Test-Driven Development for TYPO3
PDF
Test-Driven Development with FLOW3
Unit testing on embedded target with C++Test
Bdd and-testing
Behaviour Driven Development and Thinking About Testing
 
Insights and Lessons Learned Verifying the QoS Engine of a Network Processor
Boston 2009 q1_kappler_chris
Coding Naked
Becoming Indie
Unit testing (eng)
Analysis of Testability of a Flight Software Product Line
SOFTWARE VERIFICATION & VALIDATION
Test and Behaviour Driven Development (TDD/BDD)
Unit Testing
Testing
Reverse Architecting of a Medical Device Software
TDD (with FLOW3)
Software Testing_mmmmmmmmmmmmmmmmmmmmmmm
2012 mobile testingsummit-moet
Webapp acceptance testing a case study
Test-Driven Development for TYPO3
Test-Driven Development with FLOW3
Ad

More from Lars Thorup (18)

PDF
100 tests per second - 40 releases per week
PDF
SQL or NoSQL - how to choose
PDF
Super fast end-to-end-tests
PDF
Extreme Programming - to the next-level
PDF
Advanced Javascript Unit Testing
PDF
Unit testing legacy code
PDF
Advanced QUnit - Front-End JavaScript Unit Testing
PDF
Put "fast" back in "fast feedback"
PDF
Database Schema Evolution
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
Javascript unit testing with QUnit and Sinon
PDF
Continuous Integration for front-end JavaScript
PDF
Automated Performance Testing
PDF
Agile Contracts
PDF
High Performance Software Engineering Teams
PDF
Elephant Carpaccio
PDF
Unit Testing in JavaScript with MVC and QUnit
PDF
Introduction to Automated Testing
100 tests per second - 40 releases per week
SQL or NoSQL - how to choose
Super fast end-to-end-tests
Extreme Programming - to the next-level
Advanced Javascript Unit Testing
Unit testing legacy code
Advanced QUnit - Front-End JavaScript Unit Testing
Put "fast" back in "fast feedback"
Database Schema Evolution
Advanced Jasmine - Front-End JavaScript Unit Testing
Javascript unit testing with QUnit and Sinon
Continuous Integration for front-end JavaScript
Automated Performance Testing
Agile Contracts
High Performance Software Engineering Teams
Elephant Carpaccio
Unit Testing in JavaScript with MVC and QUnit
Introduction to Automated Testing

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Reach Out and Touch Someone: Haptics and Empathic Computing
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectroscopy.pptx food analysis technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Automated Testing for Embedded Software in C or C++

  • 2. 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
  • 3. Agenda ● What is automated testing? ● Unity, test framework for embedded C ● Code example ● Why should we write automated tests? ● Questions
  • 4. What is automated testing? ● Developers write test ● Automated execution of all programs test programs
  • 5. 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
  • 6. 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, on device main.c Listen GetRate flowSensor.c flow.c Pulse GetTime timerImpl.c Increment counterImpl.c
  • 8. Dependencies, in test flowTest.c Pulse GetRate flow.c SetTime GetTime timerStub.c Increment counterImpl.c
  • 9. 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
  • 10. 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
  • 11. 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/