Lcov for Linux Use

Source: Internet
Author: User
Tags gcov

  1. First install Lcov, I install the version is lcov-1.9

  2. write a app.c file with the following code:

    #include <stdio.h>
    # Include <time.h>
    #include <stdlib.h>
    Void Main ()
    {
     int a=3;
     int b=4;
     int c=5;

     if (a>b&&a>c)//Determine if A is the maximum
     {
      if (b>c)
      {
       printf ("A>b>c");
     }else
      {
       printf ("a>c>b");
     
     }
     else if (b>a&&b>c)//Determine if B is the maximum
     {
       if (a>c)
      {
       printf ("b>a>c");
     }else
      {
       printf ("B>c>a");
     
     }
     else if (c>b&&c>a)//Determine if C is the maximum
     {
       if (a>b)
      {
       printf ("c>a>b");
     }else
      {
       printf ("C>b>a");
     
     }
    }

  3. [Email protected] test]# Gcc-fprofile-arcs-ftest-coverage-o MYAPPAA app.c

  4. [Email protected] test]#./myapp

  5. [Email protected] test]# Gcov app.c
    File ' app.c '
    Lines executed:58.82% of 17
    App.c:creating ' App.c.gcov '

  6. [[email protected] test]# ls
    App.c App.c.gcov app.gcda app.gcno MyApp

  7. [Email protected] test]# lcov-d./-O Myapp.info-b. -C
    Capturing coverage data from./
    Found Gcov version:4.4.7
    Scanning./For. gcda files ...
    Found 1 data files in./
    Processing APP.GCDA
    Finished. Info-file Creation

  8. [[email protected] test]# ls
    App.c app.gcda app.gcno MyApp myapp.info

  9. [Email protected] test]# Genhtml-o Myapp_restul myapp.info
    Reading Data File Myapp.info
    Found 1 entries.
    Found common filename prefix "/opt"
    Writing. css and. png files.
    Generating output.
    Processing file zhaogh/test/app.c
    Writing Directory View page.
    Overall Coverage Rate:
    Lines ...: 58.8% (ten of lines)
    Functions.: 100.0% (1 of 1 function)
    Branches ...: 33.3% (6 of branches)

  10. SZ Myapp_restul

  11. Then open index to see the coverage of code execution

  12. 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/25/wKioL1WTTwmQpUaZAARDsYBm_gM973.jpg "title=" Lcov.png "alt=" Wkiol1wttwmqpuazaardsybm_gm973.jpg "/>

This article is from the "bad-kbase" blog, make sure to keep this source http://bad51men.blog.51cto.com/3141086/1669649

Lcov for Linux Use

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.