C++ and Embedded Linux - a perfect match

Preview:

Citation preview

COPYRIGHT 2016 – Fundação CERTI

C++ and Embedded Linux: a perfect matchVinicius Zein | Fundação CERTI

COPYRIGHT 2016 – Fundação CERTI

https://br.linkedin.com/in/viniciuszein

Vinicius Tadeu Zein R&D Coordinator @CERTI Foundation

• Responsible for the Embedded Systems team

• More than 10 years developing Embedded Systems

• In companies like Atmel, LG Electronics and CERTI

COPYRIGHT 2016 – Fundação CERTI

R&D Institute

Founded in 1984 with the mission to develop technology solutions for products and processes

500 employees

Private, but results are reinvested in R&D

MCTI and SUFRAMA accredited – projects with “Lei de Informática”, “Lei do Bem” and Embrapii

More than 500 clients around the world

COPYRIGHT 2016 – Fundação CERTI

The information in this presentation was compiled from sources believed to be reliable for informational purposes only.Content includes opinions, presentations, articles, hyperlinks or other third party content (“Third Party Material”) that is not intended to, nor constitutes an endorsement by CERTI of the author or the Third Party Materials. The content and views within the Third Party Material are solely those of the third party and do not reflect the opinions of CERTI.The opinions expressed in this presentation and on the following slides are solely those of thepresenter and not necessarily those of CERTI. CERTI does not guarantee the accuracy orreliability of the information provided herein.

.Disclaimer

COPYRIGHT 2016 – Fundação CERTI

SUMMARY

CHAPTER 1

Embedded Linux

CHAPTER 2

C++

CHAPTER 3

Development tools and debugging

CHAPTER 4

Test frameworksCHAPTER 5

Test driven developmentCHAPTER 6

Final considerations

COPYRIGHT 2016 – Fundação CERTI

Embedded Linux

Chapter 1

COPYRIGHT 2016 – Fundação CERTI

CAPÍTULO 1 | LINUX EMBARCADO

COPYRIGHT 2016 – Fundação CERTI

Telephone exchangesIP Phones and SmartphonesTVs and Set-top boxesPrintersElectronic Control Units for carsCamerasAndroid systems

CHAPTER 1 | EMBEDDED LINUX

COPYRIGHT 2016 – Fundação CERTI

C++CHAPTER 2

COPYRIGHT 2016 – Fundação CERTI

C++“cee plus plus” CHAPTER 2 Multi-paradigm

Object orientedTemplates, inline functionsMetaprogrammingHigh-performative and powerfullLots of toolsCompatibility with C - just in case ;)STL, Boost, ACEEvolving language

CHAPTER 2 | C++

C++85 style "C with Classes”, C++98, C++03, C++11, C++14, C++17

COPYRIGHT 2016 – Fundação CERTI

Don’t loweryour level of abstraction

without a good reason!

Low-

leve

l im

plie

sM

ore

code

Mor

e bu

gsHi

gher

mai

nten

ance

cos

ts

COPYRIGHT 2016 – Fundação CERTI

Embedded Linux

C++

Perfect match

CHAPTER 2 | C++

COPYRIGHT 2016 – Fundação CERTI

DEVELOPMENT TOOLS AND DEBUGGING

CHAPTER 3

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

“Making Embedded Linux Easy

Buildroot is a simple, efficient and easy-to-use tool to

generate embedded Linux systems through cross-

compilation.”

Build systems > Buildroot

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

Build systems > Yocto Project

“It's not an embedded Linux distribution

– it creates a custom one for you”

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

Build systems >AutoconfRakeBoost.BuildQmakeSconsCMake

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

IDEs * Code edition and navigation

VimEmacsSublime Text 2 Eclipse CDT

NetbeansSlickEditQtCreatorJetBrains AppCode

If debugging is the process of removing bugs, then programming must be the process of putting them inEdsger Dijkstra

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

Debugging

LogsCommand Line Interface (CLI)gdb (post morten)gdb + gdbserverdddGoogle BreakPad

For each bug found, a new unit test.

COPYRIGHT 2016 – Fundação CERTI

CAPÍTULO 3 | FERRAMENTAS DESENVOLVIMENTO E DEBUGGING

Debugging > GDB

Post mortengdb <program> -c <core_file>bt full -> backtraceprint <variable>frame <frame_id>thread <thread_id>

COPYRIGHT 2016 – Fundação CERTI

COPYRIGHT 2016 – Fundação CERTI

COPYRIGHT 2016 – Fundação CERTI

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

Debugging > Breakpad

COPYRIGHT 2016 – Fundação CERTI

Debugging > Breakpad

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

COPYRIGHT 2016 – Fundação CERTI

Continuos integration

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

COPYRIGHT 2016 – Fundação CERTI

Other tools > Static annalysis coverity, cppcheckCoverage– ccccValgrind, tcmalloc

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

COPYRIGHT 2016 – Fundação CERTI

COPYRIGHT 2016 – Fundação CERTI

Code coverage

CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING

COPYRIGHT 2016 – Fundação CERTI

Test frameworks for C++

CHAPTER 4

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 4 | TEST FRAMEWORKS FOR C++

Unit tests – gtest > Well documentedMultiplatformLinux, Windows, Mac OS XEasy to use, easy to configure1 execution > multiple failures

COPYRIGHT 2016 – Fundação CERTI Unit tests – gtest

COPYRIGHT 2016 – Fundação CERTI Unit tests – gtest

COPYRIGHT 2016 – Fundação CERTI Unit tests – gtest

COPYRIGHT 2016 – Fundação CERTI Unit tests – gtest

COPYRIGHT 2016 – Fundação CERTI Unit tests – gtest

COPYRIGHT 2016 – Fundação CERTI

gmock >Google Mocking Framework for tests in C++

Real targets are not always available

Simulating behaviorCreating emulators

CHAPTER 4 | TEST FRAMEWORKS FOR C++

COPYRIGHT 2016 – Fundação CERTI gmock

COPYRIGHT 2016 – Fundação CERTI gmock

COPYRIGHT 2016 – Fundação CERTI gmock

COPYRIGHT 2016 – Fundação CERTI gmock

COPYRIGHT 2016 – Fundação CERTI gmock

COPYRIGHT 2016 – Fundação CERTI

Google Benchmarkhttps://github.com/google/benchmarkFunction benchmarking

CHAPTER 4 | TEST FRAMEWORKS FOR C++

COPYRIGHT 2016 – Fundação CERTI Google Benchmark

Test driven development

CHAPTER 5

COPYRIGHT 2016 – Fundação CERTI

CHAPTER 5 | TEST DRIVEN DEVELOPMENT

Final considerations

CHAPTER 6

COPYRIGHT 2016 – Fundação CERTI

Use smart pointers

std::shared_ptr, std::scoped_ptr, std::unique_ptr

COPYRIGHT 2016 – Fundação CERTI

RAIIRAII

COPYRIGHT 2016 – Fundação CERTI

CAPÍTULO 6 | Final considerations

RAII

RAIIResource Acquisition Is Initialization

COPYRIGHT 2016 – Fundação CERTI

Use a code standardhttp://www.chromium.org/developers/coding-stylehttp://google-styleguide.googlecode.com/svn/trunk/cppguide.xmlhttp://clang.llvm.org/docs/ClangFormat.html

COPYRIGHT 2016 – Fundação CERTI

Unit test firstThen code

>TDD

COPYRIGHT 2016 – Fundação CERTI

Prefere

STL/Boost

algorithms

COPYRIGHT 2016 – Fundação CERTI

?

COPYRIGHT 2016 – Fundação CERTI

Thanks!Vinicius Zeinvtz@certi.org.b

r

Recommended