public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: "Jørgen Kvalsvik" <jorgen.kvalsvik@woven-planet.global>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Add condition coverage profiling
Date: Fri, 8 Apr 2022 10:50:18 +0200	[thread overview]
Message-ID: <c0c292b4-299a-7724-c288-96b7a93cfc5c@embedded-brains.de> (raw)
In-Reply-To: <6b843d4e-d930-ec0d-10f7-32a3826ccd2c@woven-planet.global>

On 08/04/2022 09:33, Jørgen Kvalsvik wrote:
> On 08/04/2022 09:28, Jørgen Kvalsvik wrote:
>> On 07/04/2022 18:53, Sebastian Huber wrote:
>>> Hello Jørgen,
>>>
>>> there could be an issue with conditions in for loops:
>>>
>>>          3:  189:  for (int a = 0; a <= 1; ++a) {
>>> branch  0 taken 2
>>> branch  1 taken 1 (fallthrough)
>>> conditions covered 0/2
>>> condition  0 not covered (true)
>>> condition  0 not covered (false)
>>>
>> Hello,
>>
>> Thanks, I'll have a look at it. There should be a for loop in the test suite,
>> but I'll add this exact example and see if I can reproduce it. This should
>> obviously be 100% covered.
> Sebastian,
> 
> I added this exact example to the test suite, but it reports 2/2 for me (linux
> amd64). Do you have a very different system, and what flags did you use?

Thanks for having a look at this. My setup is a bit more complicated. I 
use an arm cross compiler and run an application on a simulator (Qemu). 
The *.gcda files are created by gcov-tool. It is probably an issue with 
my setup, so maybe we should ignore this issue at the moment.

When I move the code to a separate translation unit:

#include <stdio.h>

static __attribute__((__noinline__)) int f(int a, int b, int c, int d)
{
   if (a || (b && c) || d) {
     return 1;
   } else {
     return 2;
   }
}

void test(void)
{
   for (int a = 0; a <= 1; ++a) {
     for (int b = 0; b <= 1; ++b) {
       for (int c = 0; c <= 1; ++c) {
         for (int d = 0; d <= 1; ++d) {
           printf("%i\n", f(a, b, c, d));
         }
       }
     }
   }
}

I get the right report:

         -:    0:Source:conds.c
         -:    0:Graph:b-xilinx_zynq_a9_qemu/conds.gcno
         -:    0:Data:b-xilinx_zynq_a9_qemu/conds.gcda
         -:    0:Runs:0
         -:    1:#include <stdio.h>
         -:    2:
function f called 16 returned 100% blocks executed 100%
        16:    3:static __attribute__((__noinline__)) int f(int a, int 
b, int c, int d)
         -:    4:{
        16:    5:  if (a || (b && c) || d) {
branch  0 taken 8 (fallthrough)
branch  1 taken 8
branch  2 taken 4 (fallthrough)
branch  3 taken 4
branch  4 taken 2 (fallthrough)
branch  5 taken 2
branch  6 taken 3 (fallthrough)
branch  7 taken 3
conditions covered 8/8
        13:    6:    return 1;
         -:    7:  } else {
         3:    8:    return 2;
         -:    9:  }
         -:   10:}
         -:   11:
function test called 1 returned 100% blocks executed 100%
         1:   12:void test(void)
         -:   13:{
         3:   14:  for (int a = 0; a <= 1; ++a) {
branch  0 taken 2
branch  1 taken 1 (fallthrough)
conditions covered 2/2
         6:   15:    for (int b = 0; b <= 1; ++b) {
branch  0 taken 4
branch  1 taken 2 (fallthrough)
conditions covered 2/2
        12:   16:      for (int c = 0; c <= 1; ++c) {
branch  0 taken 8
branch  1 taken 4 (fallthrough)
conditions covered 2/2
        24:   17:        for (int d = 0; d <= 1; ++d) {
branch  0 taken 16
branch  1 taken 8 (fallthrough)
conditions covered 2/2
        16:   18:          printf("%i\n", f(a, b, c, d));
call    0 returned 16
call    1 returned 16
         -:   19:        }
         -:   20:      }
         -:   21:    }
         -:   22:  }
         1:   23:}

For exactly the same code in another translation unit with more other 
code I get this report:

function f called 16 returned 100% blocks executed 100%
        16:  172:static __attribute__((__noinline__)) int f(int a, int 
b, int c, int d)
         -:  173:{
        16:  174:  if (a || (b && c) || d) {
branch  0 taken 8 (fallthrough)
branch  1 taken 8
branch  2 taken 4 (fallthrough)
branch  3 taken 4
branch  4 taken 2 (fallthrough)
branch  5 taken 2
branch  6 taken 3 (fallthrough)
branch  7 taken 3
conditions covered 8/8
        13:  175:    return 1;
         -:  176:  } else {
         3:  177:    return 2;
         -:  178:  }
         -:  179:}
         -:  180:
function Init called 1 returned 0% blocks executed 93%
         1:  181:static void Init( rtems_task_argument arg )
         -:  182:{
         -:  183:  struct ethernetif ethif;
         -:  184:  struct netif *netif;
         -:  185:
         -:  186:  (void) arg;
         1:  187:  netif = &ethif.netif;
         -:  188:
         3:  189:  for (int a = 0; a <= 1; ++a) {
branch  0 taken 2
branch  1 taken 1 (fallthrough)
conditions covered 0/2
condition  0 not covered (true)
condition  0 not covered (false)
         6:  190:    for (int b = 0; b <= 1; ++b) {
branch  0 taken 4
branch  1 taken 2 (fallthrough)
conditions covered 0/2
condition  0 not covered (true)
condition  0 not covered (false)
        12:  191:      for (int c = 0; c <= 1; ++c) {
branch  0 taken 8
branch  1 taken 4 (fallthrough)
conditions covered 0/2
condition  0 not covered (true)
condition  0 not covered (false)
        24:  192:        for (int d = 0; d <= 1; ++d) {
branch  0 taken 16
branch  1 taken 8 (fallthrough)
conditions covered 0/2
condition  0 not covered (true)
condition  0 not covered (false)
        16:  193:          printf("%i\n", f(a, b, c, d));
call    0 returned 16
call    1 returned 16
         -:  194:        }
         -:  195:      }
         -:  196:    }
         -:  197:  }
         1:  198:  test();
call    0 returned 1

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

  reply	other threads:[~2022-04-08  8:50 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 11:55 Jørgen Kvalsvik
2022-03-24 16:08 ` Martin Liška
2022-03-25 19:44   ` Jørgen Kvalsvik
2022-03-28 13:39     ` Martin Liška
2022-03-28 13:52     ` Jørgen Kvalsvik
2022-03-28 14:40       ` Jørgen Kvalsvik
2022-04-07 12:04         ` Martin Liška
2022-04-19 14:22           ` Jørgen Kvalsvik
2022-04-07 16:53         ` Sebastian Huber
2022-04-08  7:28           ` Jørgen Kvalsvik
2022-04-08  7:33             ` Jørgen Kvalsvik
2022-04-08  8:50               ` Sebastian Huber [this message]
2022-04-04  8:14 ` Sebastian Huber
2022-04-05  7:04   ` Sebastian Huber
2022-04-05 20:07   ` Jørgen Kvalsvik
2022-04-06  7:35     ` Sebastian Huber
2022-04-17 11:27       ` Jørgen Kvalsvik
2022-04-22  5:37         ` Sebastian Huber
2022-04-22 10:13           ` Jørgen Kvalsvik
2022-07-08 13:45 ` Sebastian Huber
2022-07-11  7:26   ` Jørgen Kvalsvik
2022-07-11 10:02 Jørgen Kvalsvik
2022-07-12 14:05 ` Sebastian Huber
2022-07-13  2:04   ` Jørgen Kvalsvik
2022-07-15 11:39 Jørgen Kvalsvik
2022-07-15 11:47 ` Jørgen Kvalsvik
2022-07-15 13:31   ` Sebastian Huber
2022-07-15 13:47     ` Jørgen Kvalsvik
2022-08-02  7:58       ` Jørgen Kvalsvik
2022-08-04  7:43         ` Sebastian Huber
2022-08-04  9:13           ` Jørgen Kvalsvik
2022-10-12 10:16 Jørgen Kvalsvik
2022-10-18  0:17 ` Hans-Peter Nilsson
2022-10-18 10:13   ` Jørgen Kvalsvik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0c292b4-299a-7724-c288-96b7a93cfc5c@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jorgen.kvalsvik@woven-planet.global \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).