Post on 07-Aug-2015
transcript
IOT BEST PRATICES: TESTING THINGS
(for embedded development that sucks less)
@farmckon @BuLogics
EMBEDDED DEVELOPMENT IS PAINFULIt doesn’t have to be.
EMBEDDED DEVELOPMENT TESTING IS PAINFULIt doesn’t have to be.
About Me
• Far McKon• 10+ years in Embedded System &
Firmware• Lead Engineer @ BuLogics, Inc
About Here
• Arcweb• arcweb.co • Smart Businesses Need Smarter
Software• BuLogics & StratIS
• bulogics.com & stratisems.com• Your Wireless Partners
• HT Gabe Torres • (first draft of talk, not at Automatic)
We are going to talk about
• What are Embedded Systems• Unit Testing• Unity/cmock/Ceedling tools.• Example test setup
What are embedded systems?
• 8-bit microCs to powerful ARM cores• Interface with physical systems• Programmed in C• Memory constrained• Single function (not general purpose)• Designs usually price driven, or power-limits driven
What is Unit Testing
• Test driven development (TDD)• Functional , Integration, Unit tests • Write test Functional tests first, (it will fail) • Write the unit tests (they will fail) • Write the code then write code
• Success?
• Success? • Clean Design• Sometimes hard in embedded projects
Example:uint8_t AddNumbers(uint8_t x, uint8_t y) { return x+y; }
void test_AddNumbersShouldAddCorrectly(void) { uint8_t result = AddNumbers(2, 4); TEST_ASSERT_EQUAL(6, result); }
void test_AddNumbersShouldHandleOverflow(void) { uint8_t result = AddNumbers(0xFF, 1); TEST_ASSERT_EQUAL(0, result); }
Test Output:prompt$ rake test:simple
Test 'test_simple.c'--------------------Running test_simple.out.------------------------- OVERALL UNIT TEST SUMMARY -------------------------TESTED: 2 PASSED: 2 FAILED: 0 IGNORED: 0
Lions, Tigers, and Bears
• Cmock• Mock/stub generator for C (C++).
•Unity • simple Unit Testing for C (C).
• Ceedling• Ruby/Rake-based build and test system for C projects
•Unity uses cmock,
• Ceedling uses unity
• Just use ceedling
Example Creating Setup (ceedling)Git clone SOME_PROJECTcd SOME_PROJECT git submodule update –init cd ..Ceedling new SOME_PROJECT(skip duplicates if any warning of dup files)
cd SOME_PROJECT ceedling test:all
Example Project Setup (ceedling)- build # Temporary build files- project.yml # Ceedling configuration- rakefile.rb # Rakefile to invoke ceedling- src # C source files - simple.c - simple.h- test # Test files, all prefixed by test_ - support # tools, fakes, etc - test_simple.c
Example test_simple.cvoid setUp(void){ //runs before every test}
void tearDown(void){ //runs after every test}
void test_ShouldDoSomething(void){ TEST_MESSAGE("This test should do something");}
$Live code
I don’t usually make a fool of myself during my talks, but when I do, I do it as a live demo….
ON DEVICE DEBUGGING IS YOUR LAST RESORT
Questions? Comments?
Now Go Eat Snacks.@farmckon
Bulogics.comFarMcKon.net
arcweb.co