GCC Code Coverage Report


Directory: ./
File: tests/unit/00_support/debug_00.c
Date: 2026-11-30 15:03:27
Exec Total Coverage
Lines: 46 46 100.0%
Functions: 1 1 100.0%
Branches: 15 30 50.0%

Line Branch Exec Source
1 /*********************************************************************************/
2 /* Copyright 2009-2021 Barcelona Supercomputing Center */
3 /* */
4 /* This file is part of the DLB library. */
5 /* */
6 /* DLB is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU Lesser General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* DLB is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU Lesser General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU Lesser General Public License */
17 /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18 /*********************************************************************************/
19
20 #include "support/debug.h"
21 #include "support/env.h"
22 #include "support/options.h"
23
24 #include <string.h>
25
26 1 int main( int argc, char **argv ) {
27
28 /* verbose function may be invoked before DLB_Init */
29 1 dlb_setenv("DLB_ARGS", "--verbose=drom", NULL, ENV_APPEND);
30
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 verbose(VB_DROM, "This message should be visible");
31
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 verbose(VB_TALP, "This one should not");
32
33 options_t options;
34 1 options_init(&options, "--verbose-format=node:thread");
35 1 debug_init(&options);
36 1 info("hello test %s", "!!");
37
38 1 options_init(&options, "--verbose-format=:");
39 1 debug_init(&options);
40 1 info("hello test %s", "!!");
41
42 1 options_init(&options, "--verbose-format=node:");
43 1 debug_init(&options);
44 1 info("hello test %s", "!!");
45
46 1 print_backtrace();
47
48 /*** printbuffer ***/
49 print_buffer_t b;
50
51 /* init */
52 1 printbuffer_init(&b);
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.addr != NULL );
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.size > 0 );
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.len == 0 );
56
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( strcmp(b.addr, "") == 0 );
57 1 printbuffer_destroy(&b);
58
59 /* append */
60 1 printbuffer_init(&b);
61 1 printbuffer_append(&b, "hello");
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( strcmp(b.addr, "hello\n") == 0 );
63 1 printbuffer_append(&b, "world");
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( strcmp(b.addr, "hello\nworld\n") == 0 );
65 1 printbuffer_destroy(&b);
66
67 /* append_no_newline */
68 1 printbuffer_init(&b);
69 1 printbuffer_append_no_newline(&b, "hello");
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( strcmp(b.addr, "hello") == 0 );
71 1 printbuffer_append_no_newline(&b, "world");
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( strcmp(b.addr, "helloworld") == 0 );
73 1 printbuffer_destroy(&b);
74
75 /* growth */
76 char large[5000];
77 1 memset(large, 'A', sizeof(large) - 1);
78 1 large[sizeof(large) - 1] = '\0';
79 1 printbuffer_init(&b);
80 1 printbuffer_append(&b, large);
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( strlen(b.addr) == strlen(large) + 1 ); // + '\n'
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.size >= strlen(b.addr) + 1 );
83 1 printbuffer_destroy(&b);
84
85 /* destroy */
86 1 printbuffer_init(&b);
87 1 printbuffer_append(&b, "test");
88 1 printbuffer_destroy(&b);
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.addr == NULL );
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.size == 0 );
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( b.len == 0 );
92
93 1 return 0;
94 }
95