GNU gcov (1/4) [from Wikipedia]

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

Computer Science 2212a/b - UWO1 Structural Testing Motivation The gcov Tool An example using gcov How does gcov do it gcov subtleties Further structural.
Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Coverage analysis using gcc (or g++) source code source code executable run results coverage gcc –ftest-coverage –fprofile-arcs myprogram.exe myprogram.cpp.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Using Set Operations on Code Coverage Data to Discover Program Properties by Nick Rutar.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement- by-statement profiling tool. gcov generates exact counts of the.
Adv. UNIX: Profile/151 Advanced UNIX v Objectives –introduce profiling based on execution times and line counts Special Topics in Comp.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr Jonas M. Larsen Memory debugging Recipe profiling.
1 Announcements  Homework 4 out today  Dec 7 th is the last day you can turn in Lab 4 and HW4, so plan ahead.
OPERATING SYSTEMS 1 - HARDWARE PIETER HARTEL 1. Hardware 2.
The Problem If someone were to write a unit test with the goal of 90% coverage over the code, how is this 90% coverage verified? Not reaching test coverage.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
HW7: Due Dec 5th 23:59 1.Describe test cases to reach full path coverage of the triangle program by completing the path condition table below. Also, draw.
CSE 333 – SECTION 2 Memory Management. Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Homework 1 – START EARLY!
© Dr. A. Williams, Fall Present Software Quality Assurance – Clover Lab 1 Tutorial / lab 2: Code instrumentation Goals of this session: 1.Create.
White-Box Testing Statement coverage Branch coverage Path coverage
White Box Testing. Agenda White-box vs Black-box Program Flow Controls White-box Test Methods Exercises Complexity Q&A.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
July 10, 2016ISA's, Compilers, and Assembly1 CS232 roadmap In the first 3 quarters of the class, we have covered 1.Understanding the relationship between.
KYC - Know your compiler Introduction to GCC
Content Coverity Static Analysis Use cases of Coverity Examples
Lab 7 Control-Flow Testing
How to Start Programming in Linux Environment
The Machine Model Memory
SPI Software Process & Infrastructure
Optimizing Compilers Background
Command line arguments
Command Line Arguments
Understand argc and argv
Structure of C Programs
Lecture 13 & 14.
CSE 351 Section 1: HW 0 + Intro to C
White-Box Testing.
Command Line Arguments
Repetition Statements
Fork and Exec Unix Model
Code Coverage David Inglis November 18, 2018.
An Introduction to Java – Part I, language basics
GNU gcov (1/4) [from Wikipedia]
Govt. Polytechnic,Dhangar
CSc 352: Testing and Code Coverage
Sridhar Narayan Java Basics Sridhar Narayan
Command Line Parameters
Summary.
Program Breakdown, Variables, Types, Control Flow, and Input/Output
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Introduction to Static Analyzer
GNU gcov gcov is a test coverage program running with gcc.
Whitebox Testing.
Appendix F C Programming Environment on UNIX Systems
C. M. Overstreet Old Dominion University Spring 2006
White-Box Testing.
Programming with Shared Memory - 2 Issues with sharing data
Chapter 11 Programming in C
Whitebox Testing.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
Testing grep.c (200 pts) For grep.c, generate 10,000 test cases through the (reverse) DFS search strategy. You are requested to modify grep.c to create.
C. M. Overstreet Old Dominion University Fall 2007
Compile and run c files.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2010.
HW#7 Describe test cases to reach full path coverage of the triangle program by completing the path condition table below. Also, draw the complete execution.
Software Testing.
Presentation transcript:

GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement-by-statement profiling tool. gcov generates exact counts of the number of times each statement in a program has been executed gcov does not produce any time-based data (you should use gprof for this purpose) and works only on code compiled with the GCC suite.

GNU gcov (2/4) To use gcov, each source file should be compiled with -fprofile–arcs and –ftest-coverage, which generates a .gcno file that is a graph file of the source file. After the instrumented target program completes its execution, execution statistics is recorded in a .gcda file. gcov creates a human readable logfile .gcov from a binary.gcda file, which indicates how many times each line of a source file has executed. gcov [-b] [-c] [-v] [-n] [-l] [-f] [-o directory] sourcefile -a: Write individual execution counts for every basic block. -b: Write branch frequencies to the output file -c: Write branch frequencies as the number of branches taken -f: Output summaries for each function in addition to the file level summary. -o The directory where the object files live. Gcov will search for `.bb', `.bbg', and `.da' files in this directory

GNU gcov (3/4) For example, if you measure coverage of example.c, [moonzoo@verifier gcov]$ l example.c [moonzoo@verifier gcov]$ gcc -fprofile-arcs -ftest-coverage example.c [moonzoo@verifier gcov]$ a.out 5 i=5 j=2 [moonzoo@verifier gcov]$ gcov -b example.c File 'example.c' Lines executed:78.57% of 14 Branches executed:100.00% of 10 Taken at least once:50.00% of 10 Calls executed:60.00% of 5 example.c:creating 'example.c.gcov' 1 #include <stdio.h> 2 int main(int argc, char **argv){ 3 int i=0,j=0; 4 if (argc < 2) { 5 printf("Usage:…\n”);exit(-1);} 6 i = atoi(argv[1]); 7 printf("i=%d\n",i); 8 9 if( i == 0) 10 j=0; 11 else { 12 if (i == 1) 13 j=1; 14 if (i > 1 && i < 10) 15 j=2; 16 } 17 printf("j=%d\n",j); 18 }

GNU gcov (4/4) Executed function info Not executed Call info -: 0:Source:example.c -: 0:Graph:example.gcno -: 0:Data:example.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdio.h> function main called 1 returned 100% blocks executed 71% 1: 2:int main(int argc, char **argv){ 1: 3: int i=0,j=0; 1: 4: if (argc < 2) { branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 5: printf("Usage:…\n");exit(-1);} call 0 never executed call 1 never executed 1: 6: i=atoi(argv[1]); call 0 returned 100% 1: 7: printf("i=%d\n",i); -: 8: 1: 9: if( i == 0) #####: 10: j=0; -: 11: else { 1: 12: if (i == 1) #####: 13: j=1; 1: 14: if(i>1&&i<10) branch 0 taken 100% (fallthrough) branch 1 taken 0% branch 2 taken 100% (fallthrough) branch 3 taken 0% 1: 15: j=2; -: 16: } 1: 17: printf("j=%d\n",j); 1: 18:} Executed function info 1 #include <stdio.h> 2 int main(int argc, char **argv){ 3 int i=0,j=0; 4 if (argc < 2) { 5 printf("Usage:…\n”);exit(-1);} 6 i = atoi(argv[1]); 7 printf("i=%d\n",i); 8 9 if( i == 0) 10 j=0; 11 else { 12 if (i == 1) 13 j=1; 14 if (i > 1 && i < 10) 15 j=2; 16 } 17 printf("j=%d\n",j); 18 } Not executed Call info Non-executable statement Note that a "branch" for gcov is anything that causes the code to execute non-straight line Conditional statement with a compound condition (i.e., a Boolean formula containing && or ||) has more than 2 branches Branch info for each condition

“Branches executed” vs. “Taken at least once” For measuring branch coverage, be careful to use “Taken at least once”, not “Branches executed” execution Ex. Branch executed: 100% Taken at least once: 50%