Your SlideShare is downloading. ×
Os Fletcher Bereza
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Os Fletcher Bereza

901
views

Published on

Published in: Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
901
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Improving the Embedded Development Process Matt Fletcher, Developer William Bereza, Co-founder Atomic Object, LLC {fletcher, bereza}@atomicobject.com OSCON 2007 Room D137-138
  • 2. About this presentation - Test-driven development of embedded systems - Target audience is developers - Audience is familiar with test-driven development (TDD) Matt Fletcher and William Bereza OSCON 2007 2
  • 3. Atomic and Savant Automation - Atomic Object develops custom software - Savant Automation produces automated-guided vehicles Matt Fletcher and William Bereza OSCON 2007 3
  • 4. Battery monitor board - Monitors the onboard battery’s overall state of charge - Vehicle’s main computer decides when to charge or get back to work Matt Fletcher and William Bereza OSCON 2007 4
  • 5. Feature development Choose a new feature Matt Fletcher and William Bereza OSCON 2007 5
  • 6. Feature development Develop a system test for it Matt Fletcher and William Bereza OSCON 2007 6
  • 7. Feature development See the system test fail Matt Fletcher and William Bereza OSCON 2007 7
  • 8. Feature development Create unit tests for a module Matt Fletcher and William Bereza OSCON 2007 8
  • 9. Feature development See the unit tests fail Matt Fletcher and William Bereza OSCON 2007 9
  • 10. Feature development Make the tests pass Matt Fletcher and William Bereza OSCON 2007 10
  • 11. Feature development Develop modules as needed Matt Fletcher and William Bereza OSCON 2007 11
  • 12. Feature development See system test pass Matt Fletcher and William Bereza OSCON 2007 12
  • 13. Feature development Choose the next feature... Matt Fletcher and William Bereza OSCON 2007 13
  • 14. Example system tests - Battery level output based on input voltages - Battery level mode vs. diagnostic data mode - Calibration commands adjust battery level values Matt Fletcher and William Bereza OSCON 2007 14
  • 15. Matt Fletcher and William Bereza OSCON 2007 15
  • 16. Battery voltage test proves quot;the battery voltage reported via CAN is correct.quot; set_battery_voltage 51.0 verify_can_reports_battery_voltage 51.0 set_battery_voltage 2.0 verify_can_reports_battery_voltage 2.0 Matt Fletcher and William Bereza OSCON 2007 16
  • 17. Under the covers set_battery_voltage 51.0 verify_can_reports_battery_voltage 51.0 def set_battery_voltage(voltage) @minilab.write_analog(VOLTAGE_OUTPUT_PIN, voltage / BATTERY_VOLTAGE_DIVIDER) sleep 0.1 end Matt Fletcher and William Bereza OSCON 2007 17
  • 18. Under the covers set_battery_voltage 51.0 verify_can_reports_battery_voltage 51.0 def verify_can_reports_battery_voltage(voltage) last_message = @pcan.receive_message assert_in_delta(voltage / CAN_VOLTAGE_BIT_WEIGHT, last_message.BatteryVoltage, CAN_VOLTAGE_DELTA) end Matt Fletcher and William Bereza OSCON 2007 18
  • 19. Keys to system testing - Test automation - Choosing support hardware with command line and programmatic interfaces - Diligence. System test-first! Matt Fletcher and William Bereza OSCON 2007 19
  • 20. Develop code unit test-first - Interaction-based testing - Modules are composed with delegates - Tests compose the target module with mocks - Composition is done at link time Matt Fletcher and William Bereza OSCON 2007 20
  • 21. Rake - Ruby make - Automates building units and executables - Easy injection of Ruby scripts into the build system Matt Fletcher and William Bereza OSCON 2007 21
  • 22. Argent - Ruby inline code generation - Finds and sets up tests - Invoked against files by the build system Matt Fletcher and William Bereza OSCON 2007 22
  • 23. Generated mocks - Mocks created automatically - Ruby script scans header file - Creates mock header and source Matt Fletcher and William Bereza OSCON 2007 23
  • 24. Generated mocks - Regular expression used to parse functions FUNC_MAGIC =/(w*s+)*(w+)s+(w+)s*(([^)]*))/ - Naming conventions dictate how to declare functions and how to call mock functions Matt Fletcher and William Bereza OSCON 2007 24
  • 25. Code to be mocked MessageCreator.h CANMessage MessageCreator_GetNextMessage(void) MessageSender.h void MessageSender_SendMessage(CANMessage message) StatusOutputter.c Needs to send the latest messages! Matt Fletcher and William Bereza OSCON 2007 25
  • 26. Mock with return MessageCreator.h CANMessage MessageCreator_GetNextMessage(void) MockMessageCreator.h CANMessage MessageCreator_GetNextMessage(void) void MessageCreator_GetNextMessage_Return(CANMessage toReturn) Matt Fletcher and William Bereza OSCON 2007 26
  • 27. Mock expecting a value MessageSender.h void MessageSender_SendMessage(CANMessage message) MockMessageSender.h void MessageSender_SendMessage(CANMessage message) void MessageSender_SendMessage_Expect(CANMessage message) Matt Fletcher and William Bereza OSCON 2007 27
  • 28. The test! static void testShouldSendTheNewestMessage(void) { CANMessage someMessage = {0x0b, 0x0e, 0x0e, 0x0f}; MessageCreator_GetNextMessage_Return(someMessage); MessageSender_SendMessage_Expect(someMessage); StatusOutputter_SendNewestMessage(); } Mocks are automatically verified during tearDown Matt Fletcher and William Bereza OSCON 2007 28
  • 29. The code! void StatusOutputter_SendNewestMessage(void) { CANMessage newestMessage; newestMessage = MessageCreator_GetNextMessage(); MessageSender_SendMessage(newestMessage); } Matt Fletcher and William Bereza OSCON 2007 29
  • 30. Continuous integration - Automatically builds the system and runs tests on check-in - Build status is published to monitors throughout the office Matt Fletcher and William Bereza OSCON 2007 30
  • 31. Summary - Automated system testing - Automated unit testing - Automated build system - Continuous integration - Ruby scripts and extensions played a key role! Matt Fletcher and William Bereza OSCON 2007 31
  • 32. Embedded development - fun Imagine frustated engineer vs. a productive pair Matt Fletcher and William Bereza OSCON 2007 32
  • 33. Build your own tools - Solve specific problems with custom tools - Automate tedious processes - Generate repetitive code Matt Fletcher and William Bereza OSCON 2007 33
  • 34. Resources - Rake - rake.rubyforge.org - Argent - rubyforge.org/project/argent - Minilab Ruby gem - minilab.rubyforge.org Matt Fletcher and William Bereza OSCON 2007 34
  • 35. Resources - Atomic Object embedded - www.atomicobject.com/pages/Embedded+Software - papers - Embedded System Conference 2007 demo project - Agile Embedded Yahoo! group: - tech.groups.yahoo.com/group/AgileEmbedded Matt Fletcher and William Bereza OSCON 2007 35
  • 36. Questions? Matt Fletcher and William Bereza OSCON 2007 36