57
TDD For Embedded Systems... All The Way Down To The Hardware Neil Johnson XtremeEDA [email protected] @nosnhojn 1

TDD For Embedded Systems All The Way Down To The Hardware

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TDD For Embedded Systems All The Way Down To The Hardware

TDD For Embedded Systems... All The Way Down To The

Hardware

Neil Johnson XtremeEDA

[email protected] @nosnhojn

1

Page 2: TDD For Embedded Systems All The Way Down To The Hardware

• ASIC

– Application Specific Integrated Circuit

– Static structure

– Digital or mixed signal

– High NRE/Low cost

• FPGA

– Field Programmable Gate Array

– Reprogrammable structure

– Primarily digital

– No NRE/High cost

• SoC

– Either of the above + embedded processor(s) + software

2

What Do I Mean By Hardware

Page 3: TDD For Embedded Systems All The Way Down To The Hardware

• Typical SoC design flow

– Specification

– Design

– Verification

– Physical design

– Fabrication

– Validation

– Integration

3

SoC Development Basics

Pre-silicon

Documentation

Code

“Stuff”

Chip

Board

System

Production

OS

Drivers

Application

Software

Page 4: TDD For Embedded Systems All The Way Down To The Hardware

Design and Verification

Design

Stimulus Monitor Model +

Checking

Verification Engineer

Design Engineer

Testbench

Page 5: TDD For Embedded Systems All The Way Down To The Hardware

5

Design and Verification – Planned?

Block Level design

Block Level Testbench

Top Level Testbench

Block Level

Top Level

Top Level Testing

Block Level Testing

DONE START

Page 6: TDD For Embedded Systems All The Way Down To The Hardware

Design and Verification – Actual!

Block Level design

Block Level Testbench

Block Level Testing

Top Level Testbench

Top Level Testing

Block Level

Top Level

START Oops! NOT

DONE

Page 7: TDD For Embedded Systems All The Way Down To The Hardware

Working Software (Hardware)

Page 8: TDD For Embedded Systems All The Way Down To The Hardware

Design and Verification – Incremental

DONE START

DO

NE

DO

NE

DO

NE

DO

NE

DO

NE

DO

NE

DO

NE

Block Level

Top Level

Page 9: TDD For Embedded Systems All The Way Down To The Hardware

• Feature-of-the-week

– “Tell your customer you’re going to give them something that works in a week”

• Jonathan Rassmuson, Agile in a Nutshell, APLN April 2009

– The Agilesoc Blog: Remote Development And The Feature-of-the-week

The Perfect Place To Start

9

The feature-of-the-week is not Agile, it’s

frequent delivery... which is hard to

argue against.

Page 10: TDD For Embedded Systems All The Way Down To The Hardware

• Client experience

– Goal

• Convince myself that incremental development is possible

– Situation

• Functional testing of a sub-system

• Design was done, test harness was partially complete

– Planning

• 4 increments, 1 for each major feature

• Detailed plan included 1-2 week sub-milestones

• 2 increments planned in detail

Feature Of The Week

10

Page 11: TDD For Embedded Systems All The Way Down To The Hardware

• Client experience - Highlights

– Planning

• The planning was different but no convincing was required

– Increment 1

• Uh oh… I’ve committed to delivering something in a week

• First up: remove everything I don’t need

Feature Of The Week

11

Page 12: TDD For Embedded Systems All The Way Down To The Hardware

• Client experience – Highlights (con’t)

– Increment 2

• I was focused and delivering on time

• Functional milestones allowed me to react to new priorities

– Increment 3

• Functioning code was great for gaining confidence and/or being corrected

• I wasn’t so concerned with building infrastructure

Feature Of The Week

Page 13: TDD For Embedded Systems All The Way Down To The Hardware

• Client experience – Highlights (con’t)

– Increment 2

• I was focused and delivering on time

• Functional milestones allowed me to react to new priorities

– Increment 3

• Functioning code was great for gaining confidence and/or being corrected

• I wasn’t so concerned with building infrastructure

– Summary

• Convince myself incremental development can work

Feature Of The Week

13

DONE START

DO

NE

DO

NE

DO

NE

DO

NE

DO

NE

DO

NE

DO

NE

Page 14: TDD For Embedded Systems All The Way Down To The Hardware

Emphasis on Bug Hunting

Page 15: TDD For Embedded Systems All The Way Down To The Hardware

TDD Mechanics

Write a test

Implement

your design

Run the test

(must fail) Run the test

(must pass)

Page 16: TDD For Embedded Systems All The Way Down To The Hardware

Unit Testing Mechanics

Write a test

Implement

your design

Run the test

(must pass)

Page 17: TDD For Embedded Systems All The Way Down To The Hardware

• Each module in a design has a list of dedicated unit tests

– tests exhaustively cover functionality of the module (“exhaustively” within reason)

– unit tests are automated

• anytime the code changes for a given module, the corresponding tests are run to make sure it isn’t broken

• Unit tests informally increase quality, not red tape

– tests are planned/written while building a component

– documentation/tracking requirements are very light

• “Use-this” modules are integrated when their unit tests pass

17

TDD To Improve Initial Code Quality

Page 18: TDD For Embedded Systems All The Way Down To The Hardware

• Unit testing happens before anything else

– then block and/or top level testing

– Unit testing does not replace current verification practices

• change... perhaps. replace... no.

18

TDD To Improve Initial Code Quality

Unit 2

Unit 3

Block B

Top

TStart TEnd TIME

Unit 0

Unit 1

Block A

Page 19: TDD For Embedded Systems All The Way Down To The Hardware

19

SVUnit Testing Framework

Testrunner

<ID_a>_testsuite <ID_n>_testsuite

<ID_x>_unit_test <ID_y>_unit_test

test_<a>() test_<b>()

Test Runner Object

Test Suite Objects

Unit Test Objects

Test Methods write code here

Page 20: TDD For Embedded Systems All The Way Down To The Hardware

SVUnit In Practice - Mechanics

20

Page 21: TDD For Embedded Systems All The Way Down To The Hardware

SVUnit In Practice - Mechanics

21

Write unit test for

new test bench

feature

Ensure the new

unit test passes

Ensure the new

unit test fails

Write model code

for new feature

START

Verify the

Testbench

(TDD w/SVUnit)

Page 22: TDD For Embedded Systems All The Way Down To The Hardware

SVUnit In Practice - Mechanics

22

Write unit test for

new test bench

feature

Ensure the new

unit test passes

Write

test

Ensure the new

unit test fails

Write model code

for new feature

Run

test File BUG

START END

Verify the

Testbench

(TDD w/SVUnit)

Verify the

Design

(Directed Test)

Page 23: TDD For Embedded Systems All The Way Down To The Hardware

• TDD for Testbench Code

– UVM testbench for SoC subsystem

• ~3000 lines of code total

– SVUnit unit tests for almost every line

• 116 unit tests

• ~5000 lines of test code total

23

TDD To Improve Initial Code Quality

Page 24: TDD For Embedded Systems All The Way Down To The Hardware

• TDD for Testbench Code

– UVM testbench for SoC subsystem

• ~3000 lines of code total

– SVUnit unit tests for almost every line

• 116 unit tests

• ~5000 lines of test code total

– 9 weeks of effort

– Bugs found:

• 30 RTL bugs

• 2 testbench bugs

24

TDD To Improve Initial Code Quality

15:1

Page 25: TDD For Embedded Systems All The Way Down To The Hardware

• Can TDD be effective given low level interactions?

• Is code partitioning TDD-friendly?

• Can concurrency be hidden/simplified?

25

Design Lessons Learned

Page 26: TDD For Embedded Systems All The Way Down To The Hardware

Problem: Low Level Hardware Interactions

26

Page 27: TDD For Embedded Systems All The Way Down To The Hardware

Problem: Low Level Hardware Interactions

27

Page 28: TDD For Embedded Systems All The Way Down To The Hardware

Solution: Create Higher Level API

28

Page 29: TDD For Embedded Systems All The Way Down To The Hardware

29

Problem: Not Structured for Unit Testing

FIFO

Memory

ingress() expect

egress()

test path

Page 30: TDD For Embedded Systems All The Way Down To The Hardware

Memory

FIFO

Memory

30

Problem: Not Structured for Unit Testing

ingress() expect

egress()

test path

A unit test

should fail for

exactly 1

reason

Page 31: TDD For Embedded Systems All The Way Down To The Hardware

31

Solution: Restructure/Isolate Functionality

FIFO ingress() expect

egress()

expectWr()

read()

write() expect

read()

get() set()

A unit test

should fail for

exactly 1

reason

Memory Memory

Page 32: TDD For Embedded Systems All The Way Down To The Hardware

32

Problem: Hardware is Multi-Threaded

action()

response()

clock

2

1

3

UUT

Page 33: TDD For Embedded Systems All The Way Down To The Hardware

33

Solution: Maintain a Single Thread

action()

response() 1

FIFO

Page 34: TDD For Embedded Systems All The Way Down To The Hardware

• Low level interactions can work with TDD

• Design partitioning can be TDD-friendly

• Concurrency can be hidden/simplified in unit tests

• Hardware is special... but TDD still fits

34

Design Lessons Learned

Page 35: TDD For Embedded Systems All The Way Down To The Hardware

35

Where Would I be Without This Stuff? Where would I be without

TDD and incremental

development?

Page 36: TDD For Embedded Systems All The Way Down To The Hardware
Page 37: TDD For Embedded Systems All The Way Down To The Hardware
Page 38: TDD For Embedded Systems All The Way Down To The Hardware

38

[email protected]

@nosnhojn

Page 39: TDD For Embedded Systems All The Way Down To The Hardware

• Unit testing legacy code: UVM-1.1d

– Lock down functionality to ease maintenance

• finer granularity tests catch issues we don’t target directly

• unit tests provide a backstop when maintaining code

– UVM-1.1d == thousands and thousands of lines of code

– >550 unit tests total

– 6 weeks of effort

SVUnit Case Study: UVM-UTest

39

Page 40: TDD For Embedded Systems All The Way Down To The Hardware

• Unit testing legacy code: UVM-1.1d

– Lock down functionality to ease maintenance

• finer granularity tests catch issues we don’t target directly

• unit tests provide a backstop when maintaining code

– UVM-1.1d == thousands and thousands of lines of code

– >550 unit tests total

– 6 weeks of effort

– 10 defect reports filed

SVUnit Case Study: UVM-UTest

40

Page 41: TDD For Embedded Systems All The Way Down To The Hardware

SVUnit Case Study: UVM-UTest

41

START END

Write unit test for

existing model feature

Ensure the new

unit test fails

Ensure the new

unit test passes

Inject a defect

Writing Unit Tests

and

Refactoring Code

w/SVUnit

Remove the defect

Refactor the code Ensure the new

unit test passes

Page 42: TDD For Embedded Systems All The Way Down To The Hardware

“...showcase TDD as a

credible technique for doing

hw/sw co-development.”

“code quality and

synchronization between

hw/sw developers are of major

importance in embedded

systems development.”

“we’ll use an FPGA board to

implement some simple yet

visual application.”

Page 43: TDD For Embedded Systems All The Way Down To The Hardware

43

Page 44: TDD For Embedded Systems All The Way Down To The Hardware

Hardware Deliveries

• Step 0 – Wires

– placeholder for future development

• Step 1 – FIFO

– ingress/egress functions to a qpram

• Step 2 – Frame Processor

– add a shadow around living cells

– non-trivial hardware block built w/TDD

44

AgileHwBlock

Page 45: TDD For Embedded Systems All The Way Down To The Hardware

Hardware Deliveries

• Step 0 – Wires

– placeholder for future development

• Step 1 – FIFO

– ingress/egress functions to a qpram

• Step 2 – Frame Processor

– add a shadow around living cells

– non-trivial hardware block built w/TDD

45

AgileHwBlock

Iteration 1

Iteration 2

Iteration 3

Page 46: TDD For Embedded Systems All The Way Down To The Hardware

Problem: Design Doesn’t Meet Timing

ingress() expect

egress() FIFO

Memory

Page 47: TDD For Embedded Systems All The Way Down To The Hardware

47

Page 48: TDD For Embedded Systems All The Way Down To The Hardware

Problem: It’s Not Over With TDD

ingress() expect

egress() FIFO

Memory

Page 49: TDD For Embedded Systems All The Way Down To The Hardware

Solution: Integration Tests For Integration

ingress() expect

egress()

test path

FIFO

Memory

Page 50: TDD For Embedded Systems All The Way Down To The Hardware

Where Verification Engineers Spend There Time

50

36%

65%

Debug

Being Productive

Page 51: TDD For Embedded Systems All The Way Down To The Hardware

Where Verification Engineers Spend There Time

51

23.5% ~12.5%

65%

Debug

Being Productive

Riding Bikes

Page 52: TDD For Embedded Systems All The Way Down To The Hardware

Language Basics (Verification)

Classes

Inheritance

Class

Method

Constructor

Expressions

Operator

Branching

Method

Arguments

Page 53: TDD For Embedded Systems All The Way Down To The Hardware

Language Basics (Design)

Synchronous

Logic

Reset State

Flip-flop

Adder

AND/OR gates

Page 54: TDD For Embedded Systems All The Way Down To The Hardware

Hardware Simulation

Simulator

results.log

Page 55: TDD For Embedded Systems All The Way Down To The Hardware

Emphasis on Bug Hunting

REDO

REDO

Page 56: TDD For Embedded Systems All The Way Down To The Hardware

TDD is a great idea

that can save us a

lot of money by

helping us avoid

writing buggy code.

Page 57: TDD For Embedded Systems All The Way Down To The Hardware

We’re too busy to

save money.

This guy

is an idiot It’s lunch time.

Why are you

telling us this at

lunch time?