17
IOT BEST PRATICES: TESTING THINGS (for embedded development that sucks less) @farmckon @BuLogics

IoT Best Practices: Unit Testing

Embed Size (px)

Citation preview

Page 1: IoT Best Practices: Unit Testing

IOT BEST PRATICES: TESTING THINGS

(for embedded development that sucks less)

@farmckon @BuLogics

Page 2: IoT Best Practices: Unit Testing

EMBEDDED DEVELOPMENT IS PAINFULIt doesn’t have to be.

Page 3: IoT Best Practices: Unit Testing

EMBEDDED DEVELOPMENT TESTING IS PAINFULIt doesn’t have to be.

Page 4: IoT Best Practices: Unit Testing

About Me

• Far McKon• 10+ years in Embedded System &

Firmware• Lead Engineer @ BuLogics, Inc

Page 5: IoT Best Practices: Unit Testing

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)

Page 6: IoT Best Practices: Unit Testing

We are going to talk about

• What are Embedded Systems• Unit Testing• Unity/cmock/Ceedling tools.• Example test setup

Page 7: IoT Best Practices: Unit Testing

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

Page 8: IoT Best Practices: Unit Testing

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

Page 9: IoT Best Practices: Unit Testing

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); }

Page 10: IoT Best Practices: Unit Testing

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

Page 11: IoT Best Practices: Unit Testing

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

Page 12: IoT Best Practices: Unit Testing

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

Page 13: IoT Best Practices: Unit Testing

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

Page 14: IoT Best Practices: Unit Testing

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");}

Page 15: IoT Best Practices: Unit Testing

$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….

Page 16: IoT Best Practices: Unit Testing

ON DEVICE DEBUGGING IS YOUR LAST RESORT

Page 17: IoT Best Practices: Unit Testing

Questions? Comments?

Now Go Eat Snacks.@farmckon

Bulogics.comFarMcKon.net

arcweb.co