Introduction to Test Driven Development Building tests and code for a “software radio”
Dec 31, 2015
Introduction to Test Driven Development
Building tests and code for a“software radio”
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
2 / 28
Concepts
Stages in a conventional radio Stages in a software radio Goals for the “long term” project Concept of test driven development Digital rectification
Tests for integer array rectification Tests for float array rectification (C++
compiler) Tests for rectification in assembly code
More details of test driven development
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
3 / 28
Conventional “AM” radio
AntennaPickup
LocalOscillator
Mixer Low passFilter
RectifierLow pass
Filter+ amplifier
Audio out
RF STAGE
IF STAGE
AUDIO STAGE
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
4 / 28
Software “AM” radio concept
AntennaPickup
LocalOscillator
Mixer Low passFilter
Rectifier
Audio out
RF STAGE
IF STAGE
AUDIO STAGE
Most stages handled with high speed software
Low passFilter
+ amplifier
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
5 / 28
Software “FM” radio concept
AntennaPickup What ever
is neededRectifier
Audio out
RF STAGE AUDIO STAGE
Most stages handled with high speed software
Low passFilter
+ amplifier
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
6 / 28
Real “software” radio
Looking at RF stage to bring in wireless signal Software radio is the rest of it
Update communication protocols Change noise suppression characteristics “on the fly” Etc.
Excellent topic for individual presentation (8 minute talk – 10 slides max – at the end of term) or possible joint presentation (16 minute talk – 20 slides max)
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
7 / 28
Rectification algorithm
Choices are C++ compiler in DEBUG mode
int *RectifyDEBUG(int initial[ ], int final, int N); float *RectifyDEBUG (float initial[ ], float final, int N);
C++ compiler in RELEASE mode int *RectifyRELEASE(int initial[ ], int final, int N); float *RectifyRELEASE(float initial[ ], float final, int N);
“US” in ASSEMBLY mode int *RectifyASM(int initial[ ], int final, int N); float *RectifyASM(float initial[ ], float final, int N);
“US” in OPTIMIZED ASSEMBLY mode int *RectifyOPTASM (int initial[ ], int final, int N); float *RectifyOPTASM (float initial[ ], float final, int N);
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
8 / 28
Expected relative advantages
Compiler debug mode
Compiler release (optimized) mode
“US” – assembly mode
“US” – optimized assembly mode
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
9 / 28
Standard testing practice
Heavy on documentationDescribe
Requirements
Design Solution
Build Solution
Test Solution
WriteAnalysis Document
WriteDesign Document
WriteTest Plan Document
TLD
TestLast
Development
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
10 / 28
Test Driven Development
Customer Tests – personally find these hard to do Not clear if there is yet “a real process available”
Developer Tests – have found many advantages
DescribeRequirements
Design Solution
Build Solution Test Solution
WriteAcceptance Tests
WriteUnit Tests
CUSTOMER
DEVELOPER
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
11 / 28
Lets apply TDD to rectification issue
Overall technique Decide on a particular test action Write the test(s) Write the simplest possible code to satisfy the test(s) “Refactor” the code to improve “quality”
Definition of “quality” is unclear in the literature Ease of “use” or “reuse” of code Reliable to use – “robust” My additional idea – meets speed requirements for the
embedded situation
TDD in an embedded / ubiquitous computing environment is a major part of my current research with funding from NSERC and Analog Devices
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
12 / 28
First unit test
Can I link to a particular test file and activate the tests within that files?
This include file provides all the macros needed for the TDD environment
Simple test to indicate the test set being run.Also indicates that a link is possible
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
13 / 28
First unit test
Can I link to a particular test file and activate the tests within that files?
This include file provides defines needed for the project
Test control. Certain tests always need to be run (totally automated). Others are more difficult to automate
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
14 / 28
First unit test
Can I link to a particular test file and activate the tests within that files?
NOTE: REQUIREMENT – CUSTOMER TEST CODE MUST BE AVAILABLE TO DEVELOPER
(Does not mean customer might not have other test code
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
15 / 28
Running the tests Need a fast – easy to use – way of switching between running the tests,
and demonstrating the working customer product
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
16 / 28
Running the customer product code
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
17 / 28
Test code – Report Mode
Report all tests.Success and failures
Report successes only
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
18 / 28
Test code – test level control
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
19 / 28
Result of “link test”
Results in VisualDSP CONSOLE WINDOW
Disassemblerwindow
Source or“Mixed mode”
window
Editor tabs selected
Projectwindow
Twinprocessors
can be controlled
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
20 / 28
Obvious test – actually contained a hidden bug
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
21 / 28
Integer array tests ZERO-LENGTH ARRAY
Unspecified requirement – shown as part of test functionality Function return pointer = NULL if error
condition present
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
22 / 28
Float tests
You write the required tests for testing rectification of floating point arrays Test for correct zero-length error response Test for correct rectification operation
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
23 / 28
Zero-length test
Modify the integer test case
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
24 / 28
Float rectification test
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
25 / 28
Take notes from the screen
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
26 / 28
Speed tests – integer code versions
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
27 / 28
Using the tests – practical approach
Just because all the tests are known, does not mean that you use all of them immediately
If you use all of them immediately, you get a lot of failure messages, which is very soul destroying I bring first test in – write the code to satisfy that test
Keep track of “defects” and “errors” as QA Bring second test in – write the code to satisfy that test
Keep track of “defects” and “errors” as QA Run all available tests to make sure nothing “broke”
Keep track of “defects” and “errors” as QA Bring third test in – write the code to satisfy that test
Keep track of “defects” and “errors” as QA Run all available tests to make sure nothing “broke”
Keep track of “defects” and “errors” as QA
04/19/23 Concepts of TDD, M. Smith, ECE, University of Calgary, Canada
28 / 28
Concepts covered
Stages in a conventional radio Stages in a software radio Goals for the “long term” project Concept of test driven development Digital rectification
Tests for integer array rectification Tests for float array rectification (C++
compiler) Tests for rectification in assembly code
More details of test driven development