Software testing-code coverage

Source: Internet
Author: User
Tags gcov

 

Key words: Software Testing code coverage quality

Test environment: Ubuntu 12.04

 

The Code overwrites the CFG (Control Flow Graph) graph. The control flow chart (CFG) is a directed graph abstract data structure. It is an abstract representation of a process or program. Each node in the graph represents a basic block, for example, a straight line code block without any jump or jump target. The jump target starts with one block and ends with one block. The directed edge is used to represent the jump in the control flow. Each node in CFG can have at most two direct successors.

 

Plug-in technology

In the process of coverage testing, you often need to know some information, such as the execution of executable statements (that is, overwriting) in the program, the path of program execution, variables. To obtain such information, you must track the execution process of the program under test, or automatically record the execution process of the program under test by a computer. You need to insert the code that completes the corresponding work in the tested program, that is, the Code plug-in technology. Most of today's coverage testing tools use the code plug-in technology.

It inserts some probes in the program to ensure the original logic integrity of the program to be tested, and throws the program running feature data through the execution of the probe. Through the analysis of the data, the program control flow and data flow information can be obtained, and dynamic information such as logical coverage can be obtained to achieve the purpose of testing. The Probe insertion time can be divided into the target code plug-in and source code plug-in.

Source code plug-in

The source code plug-in is based on the complete lexical analysis and syntax analysis of the source file, which ensures that the plug-in of the source file can achieve high accuracy and pertinence. However, the source code plug-in must be exposed to the source code, and must be modified according to the encoding language and version.

 

Target code plug-in

For example, insert GDB to the stub proxy of the target machine to implement embedded remote debugging. The target operating system provides communication modules and multi-task debugging interfaces that support remote debugging protocols, and rewrite the relevant sections of exception handling. In addition, a breakpoint setting function needs to be defined for the target operating system, because some hardware platforms provide debugging traps to generate specific exceptions (debug traps) breakpoint commands to support debugging (such as x86 INT 3), while other machines do not have similar commands, they are replaced by any illegal (Reserved) commands that cannot be interpreted and executed. These modules added to the target operating system are collectively referred to as "plug-ins ".

 

 

 

Gcov Tool

Gcov is GCC coverage, a tool for testing code coverage and a console program in the command line mode.

 

Testcov. c

#include <stdio.h> int main(void){         int i, total;                 total = 0;         for(i=0; i<10; i++){                   total += i;         }                 if (total != 45){                   printf("failure\n");         } else {                   printf("success\n");         }                 return 0;}

 

 

Compile and execute.

gcc -fprofile-arcs -ftest-coverage -o testcov testcov.c./testcov

 

 

View the code coverage of the testcov Program

$ gcov testcov.cFile ‘testcov.c‘Lines executed:87.50% of 8testcov.c:creating ‘testcov.c.gcov‘

 

 

Software testing-code coverage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.