From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 5B99E3858C83 for ; Fri, 8 Apr 2022 08:50:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5B99E3858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy05.your-server.de ([78.46.172.2]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nckJw-000HsI-JS; Fri, 08 Apr 2022 10:50:20 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nckJw-0004zX-Gw; Fri, 08 Apr 2022 10:50:20 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 377A84800B2; Fri, 8 Apr 2022 10:50:20 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id v8Va3eBCa35v; Fri, 8 Apr 2022 10:50:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id CAE394800B4; Fri, 8 Apr 2022 10:50:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id nKn6jGAlNdUS; Fri, 8 Apr 2022 10:50:19 +0200 (CEST) Received: from [10.10.171.14] (unknown [10.10.171.14]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 865A04800B2; Fri, 8 Apr 2022 10:50:19 +0200 (CEST) Message-ID: Date: Fri, 8 Apr 2022 10:50:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] Add condition coverage profiling Content-Language: en-US To: =?UTF-8?Q?J=c3=b8rgen_Kvalsvik?= , gcc-patches@gcc.gnu.org References: <8041d06d-219d-c83a-ff8f-9c75227cb072@woven-planet.global> <8ea26b0e-40e2-9e7c-4470-5add7a02a074@woven-planet.global> <38afdc2a-ed99-be14-969d-81afd64eddfa@embedded-brains.de> <4d385a5b-0b65-6740-b09c-4670801962f4@woven-planet.global> <6b843d4e-d930-ec0d-10f7-32a3826ccd2c@woven-planet.global> From: Sebastian Huber In-Reply-To: <6b843d4e-d930-ec0d-10f7-32a3826ccd2c@woven-planet.global> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26505/Thu Apr 7 10:25:37 2022) X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2022 08:50:24 -0000 On 08/04/2022 09:33, J=C3=B8rgen Kvalsvik wrote: > On 08/04/2022 09:28, J=C3=B8rgen Kvalsvik wrote: >> On 07/04/2022 18:53, Sebastian Huber wrote: >>> Hello J=C3=B8rgen, >>> >>> there could be an issue with conditions in for loops: >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 3:=C2=A0 189:=C2=A0 for (= int a =3D 0; a <=3D 1; ++a) { >>> branch=C2=A0 0 taken 2 >>> branch=C2=A0 1 taken 1 (fallthrough) >>> conditions covered 0/2 >>> condition=C2=A0 0 not covered (true) >>> condition=C2=A0 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 sh= ould >> obviously be 100% covered. > Sebastian, >=20 > 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=20 use an arm cross compiler and run an application on a simulator (Qemu).=20 The *.gcda files are created by gcov-tool. It is probably an issue with=20 my setup, so maybe we should ignore this issue at the moment. When I move the code to a separate translation unit: #include 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 =3D 0; a <=3D 1; ++a) { for (int b =3D 0; b <=3D 1; ++b) { for (int c =3D 0; c <=3D 1; ++c) { for (int d =3D 0; d <=3D 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 -: 2: function f called 16 returned 100% blocks executed 100% 16: 3:static __attribute__((__noinline__)) int f(int a, int=20 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 =3D 0; a <=3D 1; ++a) { branch 0 taken 2 branch 1 taken 1 (fallthrough) conditions covered 2/2 6: 15: for (int b =3D 0; b <=3D 1; ++b) { branch 0 taken 4 branch 1 taken 2 (fallthrough) conditions covered 2/2 12: 16: for (int c =3D 0; c <=3D 1; ++c) { branch 0 taken 8 branch 1 taken 4 (fallthrough) conditions covered 2/2 24: 17: for (int d =3D 0; d <=3D 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=20 code I get this report: function f called 16 returned 100% blocks executed 100% 16: 172:static __attribute__((__noinline__)) int f(int a, int=20 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 =3D ðif.netif; -: 188: 3: 189: for (int a =3D 0; a <=3D 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 =3D 0; b <=3D 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 =3D 0; c <=3D 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 =3D 0; d <=3D 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 --=20 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=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/