Speech presented on "The Development Conference 2016 - São Paulo" about the development of software in C++ for an Embedded Linux system. The presentation goes through a brief introduction of Linux and its history, the power of C++ and the tools for testing and debugging C++ applications on Embedded Linux Operating Systems.
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
C++ and Embedded Linux - a perfect match
1. COPYRIGHT 2016 – Fundação CERTI
C++ and
Embedded Linux:
a perfect match
Vinicius Zein | Fundação CERTI
2. 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
3. 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
4. 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 the
presenter and not necessarily those of CERTI. CERTI does not guarantee the
accuracy or
reliability of the information provided herein.
.Disclaimer
5. COPYRIGHT 2016 – Fundação CERTI
SU
MMA
RY
CHAPTER 1
Embedded
Linux
CHAPTER 2
C++
CHAPTER 3
Development
tools and
debugging
CHAPTER 4
Test
frameworks
CHAPTER 5
Test driven
development
CHAPTER 6
Final
considerations
8. COPYRIGHT 2016 – Fundação CERTI
Telephone exchanges
IP Phones and Smartphones
TVs and Set-top boxes
Printers
Electronic Control Units for cars
Cameras
Android systems
CHAPTER 1 | EMBEDDED LINUX
11. COPYRIGHT 2016 – Fundação CERTI
C++“cee plus plus”
CHAPTER 2 Multi-paradigm
Object oriented
Templates, inline functions
Metaprogramming
High-performative and powerfull
Lots of tools
Compatibility with C - just in case ;)
STL, Boost, ACE
Evolving language
CHAPTER 2 | C++
C++85 style "C with Classes”, C++98, C++03,
C++11, C++14, C++17
12. COPYRIGHT 2016 – Fundação CERTI
Don’t lower
your level of
abstraction
without a good reason!
Low-levelimplies
Morecode
Morebugs
Highermaintenancecosts
13. COPYRIGHT 2016 – Fundação CERTI
Embedded
Linux
C+
+
Perfect match
CHAPTER 2 | C++
14. COPYRIGHT 2016 – Fundação CERTI
DEVELOPMENT
TOOLS AND
DEBUGGING
CHAPTER 3
15. 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
16. 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”
17. COPYRIGHT 2016 – Fundação CERTI
CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING
Build systems > Autoconf
Rake
Boost.Build
Qmake
Scons
CMake
18. COPYRIGHT 2016 – Fundação CERTI
CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING
IDEs * Code edition and navigation
Vim
Emacs
Sublime Text 2
Eclipse CDT
Netbeans
SlickEdit
QtCreator
JetBrains AppCode
19. If debugging is the
process of removing
bugs,
then programming must
be the process of putting
them in Edsger Dijkstra
20. COPYRIGHT 2016 – Fundação CERTI
CHAPTER 3 | DEVELOPMENT TOOLS AND DEBUGGING
Debugging
Logs
Command Line Interface (CLI)
gdb (post morten)
gdb + gdbserver
ddd
Google BreakPad
For each
bug found,
a new unit
test.
21. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 3 | FERRAMENTAS DESENVOLVIMENTO E DEBUGGING
Debugging > GDB
Post morten
gdb <program> -c <core_file>
bt full -> backtrace
print <variable>
frame <frame_id>
thread <thread_id>
33. COPYRIGHT 2016 – Fundação CERTI
CHAPTER 4 | TEST FRAMEWORKS FOR C++
Unit tests – gtest > Well documented
Multiplatform
Linux, Windows, Mac OS X
Easy to use, easy to configure
1 execution > multiple failures
39. COPYRIGHT 2016 – Fundação CERTI
gmock > Google Mocking Framework for tests
in C++
Real targets are not always available
Simulating behavior
Creating emulators
CHAPTER 4 | TEST FRAMEWORKS FOR C++
52. COPYRIGHT 2016 – Fundação CERTI
CAPÍTULO 6 | Final considerations
RAII
RAII
Resource
Acquisition Is
Initialization
53. COPYRIGHT 2016 – Fundação CERTI
Use a
code standard
http://www.chromium.org/developers/coding-style
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
http://clang.llvm.org/docs/ClangFormat.html
By 1995 Linux was already attracting attention beyond desktop and server
It just needed a few more steps to make it a real contender…
BusyBox:
Originally written by Bruce Perens in 1995 and declared complete for his intended usage in 1996,[14] BusyBox originally aimed to put a complete bootable system on a single floppy that would serve both as a rescue disk and as an installer for the Debian distribution. Since that time, it has been extended to become the de facto standard core userspace toolset for embedded Linux devices and Linux distribution installers. Since each Linux executable requires several kilobytes of overhead, having the BusyBox program combine over two hundred programs together often saves substantial disk space and system memory.
Making the Linux code portable
1995 Mips
1996 m68k, ppc
1998 ucLinux portadk pra Dragonball
1999 ARM
Where are we today?
Android has 1.5 million activations per day, installed base 900 million
250 million set top boxes and smart TVs per annum
Embedded Linux is the default OS
2005 Nokia 770 Internet Tablet running Maemo Linux
2002: December: Linksys release the WRT54G
2003: July Linksys post GPL source components of the WRT54G firmware
2004: OpenWRT project starts
2004 onwards: a large proportion of WiFi routers run Linux
Where are we today?
Android has 1.5 million activations per day, installed base 900 million
250 million set top boxes and smart TVs per annum
Embedded Linux is the default OS
When was C++ invented?
I started work on what became C++ in 1979. The initial version was called "C with Classes". The first version of C++ was used internally in AT&T in August 1983. The name "C++" was used late that year. The first commercial implementation was released October 1985 at the same time as the publication of the 1st edition of The C++ Programming Language. Templates and exception handling were included later in the 1980's and documented in The Annotated C++ Reference Manual and The C++ Programming Language (2rd Edition). The first ISO C++ standard was C++98 as described in The C++ Programming Language (3rd Edition).
The current definition of C++ The 2011 ISO C++ Standard described in The C++ Programming Language (4th Edition).
You can find a more complete timeline and more detailed explanations in The Design and Evolution of C++ and A History of C++: 1979-1991 and Evolving a language in and for the real world: C++ 19.
Different projects have different constraints
– Hardware resources
– Reliability constraints
– Efficiency constraints
• Time
• Power
– Time to completion
– Developer skills
Extremes
– All that matters is to get to the market first!
– If the program fails, people die
– A 50% overhead implies the need for another $50M server farm
-> para gerar fs básico, compilar bibliotecas de terceiros,
-> permite adicionar novas bibliotecas
Buildroot is a set of Makefiles and patches that makes it easy to generate a complete embedded Linux system. Buildroot can generate any or all of a cross-compilation toolchain, a root filesystem, a kernel image and a bootloader image. Buildroot is useful mainly for people working with small or embedded systems, using various CPU architectures (x86, ARM, MIPS, PowerPC, etc.) : it automates the building process of your embedded system and eases the cross-compilation process.
The major Buildroot features are:
Can handle everything in your embedded system development project: cross-compiling toolchain, root filesystem generation, kernel image compilation and bootloader compilation. Buildroot is also sufficiently flexible that it can also be used for only one or several of these steps.
Is very easy to set up, thanks to its menuconfig, gconfig and xconfig configuration interfaces, familiar to all embedded Linux developers. Building a basic embedded Linux system with Buildroot typically takes 15-30 minutes.
Supports several hundreds of packages for userspace applications and libraries: X.org stack, Gtk2, Qt, DirectFB, SDL, GStreamer and a large number of network-related and system-related utilities and libraries are supported.
Supports multiple filesystem types for the root filesystem image: JFFS2, UBIFS, tarballs, romfs, cramfs, squashfs and more.
Can generate an (e)glibc or uClibc cross-compilation toolchain, or re-use your existing glibc, eglibc or uClibc cross-compilation toolchain
Has a simple structure that makes it easy to understand and extend. It relies only on the well-known Makefile language.
Buildroot is maintained by Peter Korsgaard, and licensed under the GNU GENERAL PUBLIC LICENSE V2 (Or later). Stable releases are delivered every three months.
The Yocto Project is an open-source collaboration project focused on embedded Linux developers. Among other things, the Yocto Project uses a build system based on the OpenEmbedded (OE) project, which uses the BitBake tool, to construct complete Linux images. The BitBake and OE components are combined together to form Poky, a reference build system.
Intel
Linux Foundation
-> Autoconf -> complexo, curva de aprendizagem é alta
-> Rake -> não escala bem, depende das ferramentas do Ruby
-> Boost.build – Bjam
-> Qmake -> qt make
-> Cmake -> escala bem, é rápido, não tem outras dependências
*** 1-click / 1-line build -> alterou o código, com 1 clique ou 1 linha, reconstrói tudo
?? Falar do ninja?
Uma ferramenta de logs com informações como timestamp, thread id, file name e line number facilita muito a investigação de problemas.
Gdb para analise após o crash -> geração de stack trace, verificação de estados de objetos e seus atributos
Gdb+gdbserver -> breakpoints, debugging em real time
Breakpad ->
strace
-> gerar um core dump
-> investigar com o gdb na hr
Ulimit –c unlimited
Framework do Google para testes em C++
Google Test is designed to be portable: it doesn't require exceptions or RTTI; it works around various bugs in various compilers and environments; etc. As a result, it works on Linux, Mac OS X, Windows and several embedded operating systems.
Nonfatal assertions (EXPECT_*) have proven to be great time savers, as they allow a test to report multiple failures in a single edit-compile-test cycle.
It's easy to write assertions that generate informative messages: you just use the stream syntax to append any additional information, e.g.ASSERT_EQ(5, Foo(i)) << " where i = " << i;. It doesn't require a new set of macros or special functions.
Google Test automatically detects your tests and doesn't require you to enumerate them in order to run them.
Death tests are pretty handy for ensuring that your asserts in production code are triggered by the right conditions.
SCOPED_TRACE helps you understand the context of an assertion failure when it comes from inside a sub-routine or loop.
You can decide which tests to run using name patterns. This saves time when you want to quickly reproduce a test failure.
Google Test can generate XML test result reports that can be parsed by popular continuous build system like Hudson.
Simple things are easy in Google Test, while hard things are possible: in addition to advanced features like global test environments and tests parameterized by values or types, Google Test supports various ways for the user to extend the framework -- if Google Test doesn't do something out of the box, chances are that a user can implement the feature using Google Test's public API, without changing Google Test itself. In particular, you can:
expand your testing vocabulary by defining custom predicates,
teach Google Test how to print your types,
define your own testing macros or utilities and verify them using Google Test's Service Provider Interface, and
reflect on the test cases or change the test output format by intercepting the test events.
Antes de implementar uma nova feature, implementar testes para essa nova feature
Novo bug -> novo caso de teste
Como fazer isso em C++ e embarcados?