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 = ðif.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.hu...@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/