Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concept of TDD Test Driven Development

Similar presentations


Presentation on theme: "Concept of TDD Test Driven Development"— Presentation transcript:

1 Concept of TDD Test Driven Development
Test driven development concepts required for embedded systems (Lab. 1) 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

2 Tackled today Why test? Difference between
TLD – Test Last Development TDD – Test Driven Development (Test First Development) Examples used in Lab. 1 marking The required program for Lab. 1 involves minor modification of the functions developed in the first assignment. More details on the testing process Design of custom TESTs and ASSERTS 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

3 “Normal” code development
The customer talks to you You think you have an idea of what you need to develop and what the expected results will be You develop the code, hopefully in an incremental fashion You design some UNIT tests to see if the code works and then remove the test code before delivery as it gets in the way of running the program You develop new tests when the code comes for maintance 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

4 “Better” code development
The customer talks to you You think you have an idea of what you need to develop and what the expected results will be You develop the code, hopefully in an incremental fashion You design some UNIT tests to see if the code works. These tests are designed so that they don’t interfere – with the running of the code The test environment is designed for automatic running of the tests You REUSE the tests whenever you make changes in the code or when the code comes for in maintance 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

5 New ideas – Test Driven Development
The customer talks to you PROVIDES SOME TESTS THAT WILL WORK WHEN YOU PROVIDE THE CORRECT CODE – CUSTOMER TESTS You think you have an idea of what you need to develop and what the expected results will be. SINCE YOU KNOW THE EXPECTED RESULTS, DESIGN THE TESTS You develop the simplest code to satisfy the tests These tests are designed so that they don’t interfere – with the running of the code The test environment is designed for automatic running of the tests Once the code is running, you “refactor” and check that the tests still run You REUSE the tests whenever you make changes in the code or when the code comes for in for maintance 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

6 Test Driven Development with Embedded Systems
Many issues to be resolved include Do you have the skills to be able to design tests? Many people don’t get above an elementary level here – job prospects Embedded Systems are “real-time-systems”. Can you design automated tests that don’t interfere with the running of the system? Embedded Systems have limited memory. Can you designs automated tests that don’t “hog” all the memory? Embedded Systems are a mixture of hardware and software components. Can you design tests that handle these different components? Embedded Systems hardware often “does not exist” and must be evaluated using architectural (highly accurate) simulators Will the tests work in the simulator and on the real system? 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

7 VDSP-Lite This is a version of an open source product called CPP-Lite
We have modified the code to work for ENCM415 for the Analog Devices ADSP-BF533 Blackfin Processor This has special features including a BTC – background telemetry channel – designed for high speed communication Going to demonstrate how to test for the software needed in Lab. 1. This software will be needed for all Labs, whether they involve hardware or software. 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

8 Lab. 1 Part 1 – Requirements on Web
Build a file main.cpp with C++ stubs for the following programs int main(void); char *HelloWorld(const unsigned short int choice); Define the following constants #define WORLD 1 #define MOON 2 Call the HelloWorld( ) function from main( ), Correct errors until the stud programs compile, link and run. Design and test the HelloWorld( ) function so that the call HelloWorld(WORLD) builds a copy of the string "Hello World", outputs the string to the screen, and returns a pointer to the string. HelloWorld(MOON) builds a copy of the string "Hello Moon", outputs the string to the screen, and returns a pointer to the string. NOTE: -- You can build the code in any fashion you wish (except by plagiarism) as long as it has valid functionality. 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

9 Lab. 1 Part 1 – TDD approach The customer provides tests in the form of a .doj file to check that the function char *HelloWorld(const unsigned short int choice); performs as expected. The requirements are #define WORLD 1 #define MOON 2 HelloWorld(WORLD) builds a copy of the string "Hello World", outputs the string to the screen, and returns a pointer to the string. HelloWorld(MOON) builds a copy of the string "Hello Moon", outputs the string to the screen, and returns a pointer to the string. NOTE: -- You can build the code in any fashion you wish (except by plagiarism) as long as it has valid functionality. NOTE: -- Details of the tests are also provided to you in “open source” format so that you can develop variants for your self 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

10 Provided Tests TEST(helloWORLD, DEVELOPER) { char *pt = NULL;
pt = HelloWorld(WORLD); EXPECTED_FALSE(pt == NULL); CHECK(strcmp(pt, "Hello World") == 0); } TEST(helloMOON, DEVELOPER) { pt = HelloWorld(MOON); CHECK(strcmp(pt, "Hello Moon") == 0); Add notes 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

11 Where to start? Step 1 Step 2
Develop a VisualDSP++ project for the Blackfin Step 2 Add to the project the “simplest possible code” that includes the tests and will compile, link and run – and not crash the system Note we know that this code will fail all the tests except the test that it will “compile, link and run – and not crash the system 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

12 Required minimum header
#include “VDSP_TDD_TestsBF533.h” #define SCREEN_OUTPUT 0x1 #define SHOW_SUCCESSES 0x100 #define SHOW_FAILURES 0x200 #define ALL_TESTS 0x1 void run_tests(int output_code, int tests_code); TEST(helloWORLD, DEVELOPER) { char *pt = NULL; pt = HelloWorld(WORLD); EXPECTED_FALSE(pt == NULL); CHECK(strcmp(pt, "Hello World") == 0); } OTHER TESTS 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

13 Additional Code needed
#define WORLD 1 #define MOON 2 int main(void); char *HelloWorld(const unsigned short int choice); int main(void) { run_tests(SCREEN_OUTPUT | SHOW_FAILURES | SHOW_SUCCESSES , ALL_TESTS); } char *HelloWorld(const unsigned short int choice) { char *pt ; WHAT CODE IS NEEDED HERE AS A MINIMUM? 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

14 Where next? Step 1 Develop a VisualDSP++ project for the Blackfin
Add to the project the “simplest possible code” that includes the tests and will compile, link and run – and not crash the system Note we know that this code will fail all the tests except the test that it will “compile, link and run – and not crash the system Step 3 Modify your stubs so final program satisfies the tests you have developed Refine (refactor) the code so “quality” is present Step 4 Add all the customer tests provided (see write-up) Modify the code so that it satisfies both your test and the customer tests 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

15 The TEST MACRO Add notes here MACRO implies?
#include “VDSP_TDD_TestsBF533.h” TEST(TEST_NAME, GROUP_NAME) { } TEST(helloWORLD, DEVELOPER) { char *pt = NULL; pt = HelloWorld(WORLD); EXPECTED_FALSE(pt == NULL); CHECK(strcmp(pt, "Hello World") == 0); 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

16 Available ASSERTS DOUBLES_EQUAL(expected,actual,threshold)
Long int tests – 32 bit – typical for “C++” CHECK(condition) – Success if passes CHECK_EQUAL(expected,actual) EXPECTED_FALSE(condition) – Success if fails ARRAYS_EQUAL(expected, actual, length) CHECK_VALUES(expectedTemp, condition, actualTemp) DOUBLES_EQUAL(expected,actual,threshold) 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

17 Embedded ASSERTS Timing of routine – Blackfin Specific
Short int tests – 16 bit – typical for embedded systems SHORTS_EQUAL(expected, actual) SHORTS_CHECK(expected, condition, actual) USHORTS_EQUAL(expected, actual) USHORTS_CHECK(expected, condition, actual) Timing of routine – Blackfin Specific MAXTIME_ASSERT(BF533, max_time, function) Useful utility MEASURE_EXECUTION_TIME(BF533, timetaken, function) Examples available in the tests associated with Lab. 1 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

18 ASSERT FORMAT #define CHECK_VALUES(expectedTemp, condition, actualTemp)\ if (!((expectedTemp) condition (actualTemp))) \ {\ FAILURE1(#expectedTemp##" !"#condition##" "#actualTemp);\ }\ else {\ SUCCESS1(#expectedTemp##”""#condition##" "#actualTemp);\ } 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

19 Practice – Test design Design a test that will – details in class
2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

20 Practice – Assert Design
Design an assert that will determine whether the lower 8 bits of a variable is identical to the lower 8 bits of a second variable. The two variables should remain unchanged by the assert (since they may be reused later) The upper 24 bits of each variable MUST be ignored in the assert 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

21 Tackled today Why test? Difference between
TLD – Test Last Development TDD – Test Driven Development (Test First Development) Examples used in Lab. 1 marking The required program for Lab. 1 involves minor modification of the functions developed in the first assignment. More details on the testing process Design of custom TESTs and ASSERTS 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada

22 Information taken from Analog Devices On-line Manuals with permission 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. 2/23/2019 Concept of Test Driven Development applied to Embedded Systems M. Smith University of Calgary, Canada


Download ppt "Concept of TDD Test Driven Development"

Similar presentations


Ads by Google