core timer code development how you could have done the take- home quiz using a test driven...

29
Core Timer Code Development How you could have done the Take-Home Quiz using a test driven development (TDD) approach

Post on 19-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

Core Timer Code Development

How you could have done the Take-Home Quiz using a test driven development (TDD) approach

Page 2: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

2 / 28

To be tackled today

Test driven development example

Customer requirementsPossible system test provided by

customer’s FAE (field application engineer)Development of your unit tests

Page 3: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

3 / 28

Customer Requirements

Long term goal is that we will be using devices that need to be activated at certain reliable times. Seems like we need a library of timer functions

Page 4: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

4 / 28

Customer Test – example code

Put system into knownstate

We already have theseLED utilities (Lab. 2)

Here is the sort of thing we need

This sort of test detailmay indicate thatFAE has alreadytried and failed.

Be polite when youdeliver code

Page 5: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

5 / 28

Define the functions

To be coded in assembly code Convention when dealing with hardware

ulong SetCoreTimer(initial, reload, scale) Initializes the core timer registers, returns old control setting,

places timer in low power mode, stops the clock void StartCoreTimer(void), void StopCoreTimer(void)

Starts and stops the timer. When started the timer is to run continuously.

ulong ReadCoreTimer(void) Returns current value from the timer

bool CheckIfCoreTimerExpired(void) Determines whether or not the core timer registers have been

reloaded

Page 6: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

6 / 28

Step 1A – Get a main( ) and a test to compile and link – Design the test

Page 7: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

7 / 28

Step 1B – Get a main( ) and a test to compile and link – Design main

Bring a copy of your Take-Home Quiz code to compare

Page 8: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

8 / 28

Recode till pasts the test

Page 9: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

9 / 28

Step2A – Write the test for void StopCoreTimer(void);

Page 10: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

10 / 28

Step 2B – Write and Test void StopCoreTimerASM(void);

Bring a copy of your Take-Home Quiz code to compare

Page 11: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

11 / 28

Step 2C – Fix the test

Page 12: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

12 / 28

3A – Write a test -- unsigned long int ReadCoreTimer( )

Page 13: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

13 / 28

3B – Write the code to pass the test

Bring a copy of your Take-Home Quiz code to compare

Page 14: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

14 / 28

4 Write the Test for void StartCoreTimerASM(void)

Page 15: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

15 / 28

4 – Write the code to satisfy the test

Bring a copy of your Take-Home Quiz code to compare

Page 16: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

16 / 28

Test failed because

Page 17: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

17 / 28

4 Rewrite the test – prefer new -- unsigned long int StartCoreTimer(void)

Page 18: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

18 / 28

4 -- Need to add unsigned long int SetCoreTimer(ulong, ulong, ulong)

Page 19: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

19 / 28

Needed code – run the tests

Bring a copy of your Take-Home Quiz code to compare

Page 20: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

20 / 28

New tests pass – old tests now fail

Page 21: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

21 / 28

Fix StopCoreTimer( )

Page 22: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

22 / 28

Re-examine ReadCoreTimerASM

Page 23: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

23 / 28

4 – Re-examine Test

Page 24: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

24 / 28

Final Test

Page 25: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

25 / 28

Customer Test

Put system into knownstate

We already have theseLED utilities (Lab. 2)

Here is the sort of thing we need

This sort of test detailmay indicate thatFAE has alreadytried and failed.

Be polite when youdeliver code

Page 26: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

26 / 28

Oops -- Still missing code forbool CheckIfCoreTimerExpiredASM( )

First – write the test

Page 27: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

27 / 28

Oops - Still missing code forbool CheckIfCoreTimerExpiredASM( )

Now write the code

Page 28: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

28 / 28

Tackled today

Test driven development example

Customer requirements Possible system test provided by customer’s FAE

(field application engineer)

Development of your unit tests

You still need to design the test and the code for bool CheckIfCoreTimerExpiredASM(void);

Page 29: Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach

04/18/23 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada

29 / 28

Information taken from Analog Devices On-line Manuals with permission http://www.analog.com/processors/resources/technicalLibrary/manuals/

Information furnished by Analog Devices is believed to be accurate and reliable. However, Analog Devices assumes no responsibility for its use or for any infringement of any patent other rights of any third party which may result from its use. No license is granted by implication or otherwise under any patent or patent right of Analog Devices. Copyright Analog Devices, Inc. All rights reserved.