SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Intelligent Testing 2015
Bristol, 18th June 2015
Dr Guillem Bernat
bernat@rapitasystems.com
How to get to 100% code
coverage
Introduction
 Code coverage is important
 Sometimes 100% is difficult
 What do we do if we can't get 100%
Code coverage defined
What does it mean to get 100% code coverage?
“Testing shows the presence of bugs, not their absence”
Edsger Dijkstra (1969)
100% code coverage does not mean:
your code is correct
100% code coverage does not mean:
your software requirements are correct
100% code coverage does not mean:
the compiler translated your code correctly
const volatile int x;
volatile int y;
void foo(void){
for(y=0; y>10; y++)
{
int z = x;
}
}
foo:
mov1 $0, y
mov1 x, %eax
jmp .L2
.L3:
mov1 y, %eax
incl %eax
mov1 %eax, y
.L2:
mov1 y, %eax
cmp1 $10, %eax
jg .L3
ret
At the -0s optimization level, GCC 4.3.0 for IA32
compiles the C code on the left to the assembly on
the right.
The compiler output is wrong: the access to volatile-
qualified variable x should not be hoisted out of the
loop.
100% code coverage does not mean:
you have covered 100% of your object code
Source code Object codeCompiled to
Does it matter which code coverage criteria I'm
using?
Coverage type DO-178B/C
ISO 26262
(Software architecture)
ISO 26262
(unit test)
Function Used with MC/DC
ASIL C, D Highly
Recommended
ASIL A, B Recommended
-
Call Coverage Not required
ASIL C, D Highly
Recommended
ASIL A, B Recommended
-
Statement
Level A, B, C
Required
-
ASIL A, B Highly
Recommended
ASIL C, D Recommended
Decision
Level A, B
Required
- -
Branch Not required -
ASIL B, C, D Highly
Recommended
ASIL A Recommended
MC/DC Level A Required -
ASIL D Highly Recommended
ASIL A, B, C Recommended
What are the barriers to 100% code coverage?
 Missing requirements.
 Missing or incorrect tests.
 Dead code.
 Deactivated code.
 Defensive programming.
 Impossible combinations of events.
 Compiler-introduced errors.
Barrier #1: Missing Requirements
 Add new requirements
 Develop tests
 Run the tests
What to do about it
Barrier #2: Missing/incorrect tests
What to do about it
 Implement additional tests
 Ensure that they trace to
the correct requirement(s)
 Run the new tests
 Implement additional tests
 Ensure that they trace to
the correct requirement(s)
 Run the new tests
What to do about it
Barrier #3: Dead code
foo(a,c){
int b;
mode = MOVING;
if(mode == STATIONARY){
b = 1 + a;
}
c = a;
return c;
}
 Remove the dead code if
possible or
 Justify why the code cannot
be run
What to do about it
DO-178C recommends "The [dead] code should be removed and
an analysis performed to assess the effect and the need for
reverification." [6.4.4.3c]
For ISO 26262, the general guidance for "insufficient" coverage
applies, namely to provide a rationale for why the dead code is
acceptable [6:9.4.5].
What to do about it…
Barrier #4: Deactivated code
settings = read_input(CONFIG_PINS);
if ((settings & CONFIG_MASK_A) == CONFIG_A) {
/* code to execute in configuration A */
...
} else if ((settings & CONFIG_MASK_B) == CONFIG_B) {
/* code to execute in configuration B */
...
}
 Justify why code won’t be
executed
 Never executed
during normal
operation
 Will not affect the
execution of the
system
What to do about it
Barrier #5: Defensive Programming
switch(a % 4){
case 0:
..........
break;
case 1:
..........
break;
case 2:
..........
break;
case 3:
..........
break;
default:
..........
break;
}
 Justify why defensive
programming cannot be
executed
 Provide evidence that if
triggered, the defensive
programming works
correctly
What to do about it
Barrier #6: Impossible Combinations of Events
-- “enabled” might already be set at this point
if speed < 1700 then
enabled := true;
end if;
if speed < 1500 and enabled then
...
end if;
 Simplify the condition?
or
 Justify why 100% could not
be achieved
What to do about it
Barrier #7: Compiler Introduced Errors
int a,x;
if a < 10{ /*Compiler generates “a <=10”*/
result = x / 5;
} else {
result = x / 10;
}
a x
Test case 1 3 4
Test case 2 10 4
 Review existing code base
 Add to coding guidelines /
code review guidelines
What to do about it
Justifying code: in-line justifications
void fatal_error (void)
{
#pragma RVS justification( "COV_FUNCTIONS", "The fatal_error
function cannot be executed during normal execution")
/* some code */
}
...
void check_status (int status)
{
if ( (check_enabled) && (FATAL_ERROR == status) ) {
#pragma RVS justification( "COV_DECISIONS", "Variable 'status'
cannot take value FATAL_ERROR during normal execution")
fatal_error();
}
}
...
Justifying code: justifications in a separate file
#pragma RVS [selftest.c:34] justification("COV_MCDC", "2: (RAM_ERROR ==
status)", "RAM_ERROR cannot be triggered during normal test");
#pragma RVS [selftest.c:439] justification("COV_FUNCTIONS", "Cannot trigger
emergency_shutdown() during normal test");
Justifications editor
Review – establish
missing coverage
Identify cause Identify action to take
Dealing with less than 100% code coverage
Review – establish
missing coverage
Identify cause Identify action to take
Dealing with less than 100% code coverage
 Missing requirements.
 Missing or incorrect tests.
 Dead code.
 Deactivated code.
 Defensive programming.
 Impossible combinations of events.
 Compiler-introduced errors.
Review – establish
missing coverage
Identify cause Identify action to take
Dealing with less than 100% code coverage
Remove code
Add (or fix)
requirements
Justify why code
won't be executed
Justify why it isn't
possible to test
 reduce testing timescales by running fewer on-target tests
 reduce risk through greater tool flexibility
 reduced effort for certification activities
Structural coverage analysis to DO-178B/C Level A and ISO 26262
Logos and images can be positioned within this area.
Change layout to blank (without position box) before use
Q A

Weitere ähnliche Inhalte

Was ist angesagt?

Code Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoCode Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCo
Evgeny Mandrikov
 
Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)
Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)
Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)
Sung Kim
 
REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...
REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...
REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...
Sung Kim
 

Was ist angesagt? (19)

Parasoft fda software compliance part2
Parasoft fda software compliance   part2Parasoft fda software compliance   part2
Parasoft fda software compliance part2
 
Using gcov and lcov
Using gcov and lcovUsing gcov and lcov
Using gcov and lcov
 
Code Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoCode Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCo
 
Personalized Defect Prediction
Personalized Defect PredictionPersonalized Defect Prediction
Personalized Defect Prediction
 
Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)
Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)
Automatically Generated Patches as Debugging Aids: A Human Study (FSE 2014)
 
Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)Crowd debugging (FSE 2015)
Crowd debugging (FSE 2015)
 
Parasoft fda software compliance part1
Parasoft fda software compliance   part1Parasoft fda software compliance   part1
Parasoft fda software compliance part1
 
REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...
REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...
REMI: Defect Prediction for Efficient API Testing (

ESEC/FSE 2015, Industria...
 
Manual testing interview questions and answers
Manual testing interview questions and answersManual testing interview questions and answers
Manual testing interview questions and answers
 
Combinatorial testing
Combinatorial testingCombinatorial testing
Combinatorial testing
 
Static Analysis of Your OSS Project with Coverity
Static Analysis of Your OSS Project with CoverityStatic Analysis of Your OSS Project with Coverity
Static Analysis of Your OSS Project with Coverity
 
Tech talks annual 2015 izzet mustafayev_performance testing - the way to make...
Tech talks annual 2015 izzet mustafayev_performance testing - the way to make...Tech talks annual 2015 izzet mustafayev_performance testing - the way to make...
Tech talks annual 2015 izzet mustafayev_performance testing - the way to make...
 
Unit testing
Unit testing Unit testing
Unit testing
 
Automation and Technical Debt
Automation and Technical DebtAutomation and Technical Debt
Automation and Technical Debt
 
Block 1 ms-034 unit-1
Block 1 ms-034 unit-1Block 1 ms-034 unit-1
Block 1 ms-034 unit-1
 
Combinatorial testing ppt
Combinatorial testing pptCombinatorial testing ppt
Combinatorial testing ppt
 
Staroletov testing TDD BDD MBT
Staroletov testing TDD BDD MBTStaroletov testing TDD BDD MBT
Staroletov testing TDD BDD MBT
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++
 
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
Case Study: Automated Code Reviews In A Grown SAP Application Landscape At EW...
 

Andere mochten auch

What's with All This Talk About Coverage?
What's with All This Talk About Coverage?What's with All This Talk About Coverage?
What's with All This Talk About Coverage?
DVClub
 
Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective   Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective
Engineering Software Lab
 
Session 7 code_functional_coverage
Session 7 code_functional_coverageSession 7 code_functional_coverage
Session 7 code_functional_coverage
Nirav Desai
 

Andere mochten auch (12)

Comparing model coverage and code coverage in Model Driven testing: an explor...
Comparing model coverage and code coverage in Model Driven testing: an explor...Comparing model coverage and code coverage in Model Driven testing: an explor...
Comparing model coverage and code coverage in Model Driven testing: an explor...
 
What's with All This Talk About Coverage?
What's with All This Talk About Coverage?What's with All This Talk About Coverage?
What's with All This Talk About Coverage?
 
Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
 
Functional Coverage Development Tips - Mentor Graphics
Functional Coverage Development Tips - Mentor GraphicsFunctional Coverage Development Tips - Mentor Graphics
Functional Coverage Development Tips - Mentor Graphics
 
Tools and techniques of code coverage testing
Tools and techniques of code coverage testingTools and techniques of code coverage testing
Tools and techniques of code coverage testing
 
Pragmatic Code Coverage
Pragmatic Code CoveragePragmatic Code Coverage
Pragmatic Code Coverage
 
Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective   Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective
 
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
IoT 개발자를 위한 Embedded C에서 Test Coverage를 추출해보자
 
Session 7 code_functional_coverage
Session 7 code_functional_coverageSession 7 code_functional_coverage
Session 7 code_functional_coverage
 
Code coverage analysis in testing
Code coverage analysis in testingCode coverage analysis in testing
Code coverage analysis in testing
 
Code coverage
Code coverageCode coverage
Code coverage
 
Test Strategy
Test StrategyTest Strategy
Test Strategy
 

Ähnlich wie Presentation slides: "How to get 100% code coverage"

MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian GötzingerMASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
Ievgenii Katsan
 

Ähnlich wie Presentation slides: "How to get 100% code coverage" (20)

Wtf per lineofcode
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcode
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded c
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Code coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspectiveCode coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspective
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Mathematically Guaranteed C and C++ Code
Mathematically Guaranteed C and C++ CodeMathematically Guaranteed C and C++ Code
Mathematically Guaranteed C and C++ Code
 
6-Error Handling.pptx
6-Error Handling.pptx6-Error Handling.pptx
6-Error Handling.pptx
 
CodeChecker summary 21062021
CodeChecker summary 21062021CodeChecker summary 21062021
CodeChecker summary 21062021
 
Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]
 
How to write clean & testable code without losing your mind
How to write clean & testable code without losing your mindHow to write clean & testable code without losing your mind
How to write clean & testable code without losing your mind
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
embeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptxembeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptx
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazy
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy
 
The CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitThe CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGit
 
A exception ekon16
A exception ekon16A exception ekon16
A exception ekon16
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
 
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian GötzingerMASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
 

Kürzlich hochgeladen

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Kürzlich hochgeladen (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Presentation slides: "How to get 100% code coverage"

  • 1. Intelligent Testing 2015 Bristol, 18th June 2015 Dr Guillem Bernat bernat@rapitasystems.com How to get to 100% code coverage
  • 2. Introduction  Code coverage is important  Sometimes 100% is difficult  What do we do if we can't get 100%
  • 4. What does it mean to get 100% code coverage?
  • 5. “Testing shows the presence of bugs, not their absence” Edsger Dijkstra (1969) 100% code coverage does not mean: your code is correct
  • 6. 100% code coverage does not mean: your software requirements are correct
  • 7. 100% code coverage does not mean: the compiler translated your code correctly const volatile int x; volatile int y; void foo(void){ for(y=0; y>10; y++) { int z = x; } } foo: mov1 $0, y mov1 x, %eax jmp .L2 .L3: mov1 y, %eax incl %eax mov1 %eax, y .L2: mov1 y, %eax cmp1 $10, %eax jg .L3 ret At the -0s optimization level, GCC 4.3.0 for IA32 compiles the C code on the left to the assembly on the right. The compiler output is wrong: the access to volatile- qualified variable x should not be hoisted out of the loop.
  • 8. 100% code coverage does not mean: you have covered 100% of your object code Source code Object codeCompiled to
  • 9. Does it matter which code coverage criteria I'm using? Coverage type DO-178B/C ISO 26262 (Software architecture) ISO 26262 (unit test) Function Used with MC/DC ASIL C, D Highly Recommended ASIL A, B Recommended - Call Coverage Not required ASIL C, D Highly Recommended ASIL A, B Recommended - Statement Level A, B, C Required - ASIL A, B Highly Recommended ASIL C, D Recommended Decision Level A, B Required - - Branch Not required - ASIL B, C, D Highly Recommended ASIL A Recommended MC/DC Level A Required - ASIL D Highly Recommended ASIL A, B, C Recommended
  • 10. What are the barriers to 100% code coverage?  Missing requirements.  Missing or incorrect tests.  Dead code.  Deactivated code.  Defensive programming.  Impossible combinations of events.  Compiler-introduced errors.
  • 11. Barrier #1: Missing Requirements  Add new requirements  Develop tests  Run the tests What to do about it
  • 12. Barrier #2: Missing/incorrect tests What to do about it  Implement additional tests  Ensure that they trace to the correct requirement(s)  Run the new tests  Implement additional tests  Ensure that they trace to the correct requirement(s)  Run the new tests What to do about it
  • 13. Barrier #3: Dead code foo(a,c){ int b; mode = MOVING; if(mode == STATIONARY){ b = 1 + a; } c = a; return c; }  Remove the dead code if possible or  Justify why the code cannot be run What to do about it DO-178C recommends "The [dead] code should be removed and an analysis performed to assess the effect and the need for reverification." [6.4.4.3c] For ISO 26262, the general guidance for "insufficient" coverage applies, namely to provide a rationale for why the dead code is acceptable [6:9.4.5]. What to do about it…
  • 14. Barrier #4: Deactivated code settings = read_input(CONFIG_PINS); if ((settings & CONFIG_MASK_A) == CONFIG_A) { /* code to execute in configuration A */ ... } else if ((settings & CONFIG_MASK_B) == CONFIG_B) { /* code to execute in configuration B */ ... }  Justify why code won’t be executed  Never executed during normal operation  Will not affect the execution of the system What to do about it
  • 15. Barrier #5: Defensive Programming switch(a % 4){ case 0: .......... break; case 1: .......... break; case 2: .......... break; case 3: .......... break; default: .......... break; }  Justify why defensive programming cannot be executed  Provide evidence that if triggered, the defensive programming works correctly What to do about it
  • 16. Barrier #6: Impossible Combinations of Events -- “enabled” might already be set at this point if speed < 1700 then enabled := true; end if; if speed < 1500 and enabled then ... end if;  Simplify the condition? or  Justify why 100% could not be achieved What to do about it
  • 17. Barrier #7: Compiler Introduced Errors int a,x; if a < 10{ /*Compiler generates “a <=10”*/ result = x / 5; } else { result = x / 10; } a x Test case 1 3 4 Test case 2 10 4  Review existing code base  Add to coding guidelines / code review guidelines What to do about it
  • 18. Justifying code: in-line justifications void fatal_error (void) { #pragma RVS justification( "COV_FUNCTIONS", "The fatal_error function cannot be executed during normal execution") /* some code */ } ... void check_status (int status) { if ( (check_enabled) && (FATAL_ERROR == status) ) { #pragma RVS justification( "COV_DECISIONS", "Variable 'status' cannot take value FATAL_ERROR during normal execution") fatal_error(); } } ...
  • 19. Justifying code: justifications in a separate file #pragma RVS [selftest.c:34] justification("COV_MCDC", "2: (RAM_ERROR == status)", "RAM_ERROR cannot be triggered during normal test"); #pragma RVS [selftest.c:439] justification("COV_FUNCTIONS", "Cannot trigger emergency_shutdown() during normal test");
  • 21.
  • 22. Review – establish missing coverage Identify cause Identify action to take Dealing with less than 100% code coverage
  • 23. Review – establish missing coverage Identify cause Identify action to take Dealing with less than 100% code coverage  Missing requirements.  Missing or incorrect tests.  Dead code.  Deactivated code.  Defensive programming.  Impossible combinations of events.  Compiler-introduced errors.
  • 24. Review – establish missing coverage Identify cause Identify action to take Dealing with less than 100% code coverage Remove code Add (or fix) requirements Justify why code won't be executed Justify why it isn't possible to test
  • 25.  reduce testing timescales by running fewer on-target tests  reduce risk through greater tool flexibility  reduced effort for certification activities Structural coverage analysis to DO-178B/C Level A and ISO 26262
  • 26. Logos and images can be positioned within this area. Change layout to blank (without position box) before use
  • 27. Q A