Skip to content

Commit d1d3024

Browse files
authored
genhtml/genpng/lcov: add missing rc support and man page entries
* Add rcfile support and man page entries for --dark-mode and --fail-under-lines options * Add PNG support for 'dark-mode' feature Signed-off-by: Henry Cox <[email protected]>
1 parent e023d6a commit d1d3024

File tree

6 files changed

+88
-14
lines changed

6 files changed

+88
-14
lines changed

bin/genhtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ sub write_overview_line(*$$$);
246246
sub write_overview(*$$$$);
247247

248248
# External prototype (defined in genpng)
249-
sub gen_png($$$@);
249+
sub gen_png($$$$@);
250250

251251

252252
# Global variables & initialization
@@ -384,6 +384,7 @@ if ($config || %opt_rc)
384384
"genhtml_demangle_cpp" => \$demangle_cpp,
385385
"genhtml_demangle_cpp_tool" => \$demangle_cpp_tool,
386386
"genhtml_demangle_cpp_params" => \$demangle_cpp_params,
387+
"genhtml_dark_mode" => \$dark_mode,
387388
"genhtml_missed" => \$opt_missed,
388389
"lcov_function_coverage" => \$lcov_func_coverage,
389390
"lcov_branch_coverage" => \$lcov_branch_coverage,
@@ -1356,7 +1357,7 @@ sub process_file($$$)
13561357
}
13571358

13581359
# Create overview png file
1359-
gen_png("$rel_dir/$base_name.gcov.png", $overview_width, $tab_size,
1360+
gen_png("$rel_dir/$base_name.gcov.png", $dark_mode, $overview_width, $tab_size,
13601361
@source);
13611362

13621363
# Create frameset page

bin/genpng

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ our $tool_name = basename($0);
4444

4545

4646
# Prototypes
47-
sub gen_png($$$@);
47+
sub gen_png($$$$@);
4848
sub check_and_load_module($);
4949
sub genpng_print_usage(*);
5050
sub genpng_process_file($$$$);
@@ -215,12 +215,12 @@ sub genpng_process_file($$$$)
215215
}
216216
close(HANDLE);
217217

218-
gen_png($out_filename, $width, $tab_size, @source);
218+
gen_png($out_filename, 0, $width, $tab_size, @source);
219219
}
220220

221221

222222
#
223-
# gen_png(filename, width, tab_size, source)
223+
# gen_png(filename, dark, width, tab_size, source)
224224
#
225225
# Write an overview PNG file to FILENAME. Source code is defined by SOURCE
226226
# which is a list of lines <count>:<source code> per source code line.
@@ -232,9 +232,10 @@ sub genpng_process_file($$$$)
232232
# Die on error.
233233
#
234234

235-
sub gen_png($$$@)
235+
sub gen_png($$$$@)
236236
{
237237
my $filename = shift(@_); # Filename for PNG file
238+
my $dark_mode = shift(@_); # dark-on-light, if set
238239
my $overview_width = shift(@_); # Imagewidth for image
239240
my $tab_size = shift(@_); # Replacement string for tab signs
240241
my @source = @_; # Source code as passed via argument 2
@@ -271,14 +272,28 @@ sub gen_png($$$@)
271272
or die("ERROR: cannot allocate overview image!\n");
272273

273274
# Define colors
274-
$col_plain_back = $overview->colorAllocate(0xff, 0xff, 0xff);
275-
$col_plain_text = $overview->colorAllocate(0xaa, 0xaa, 0xaa);
276-
$col_cov_back = $overview->colorAllocate(0xaa, 0xa7, 0xef);
277-
$col_cov_text = $overview->colorAllocate(0x5d, 0x5d, 0xea);
278-
$col_nocov_back = $overview->colorAllocate(0xff, 0x00, 0x00);
279-
$col_nocov_text = $overview->colorAllocate(0xaa, 0x00, 0x00);
280-
$col_hi_back = $overview->colorAllocate(0x00, 0xff, 0x00);
281-
$col_hi_text = $overview->colorAllocate(0x00, 0xaa, 0x00);
275+
# overview->colorAllocate(red, green, blue)
276+
if ($dark_mode) {
277+
# just reverse foregrond and background
278+
# there is probably a better color scheme than this.
279+
$col_plain_text = $overview->colorAllocate(0xaa, 0xaa, 0xaa); # light grey
280+
$col_plain_back = $overview->colorAllocate(0x00, 0x00, 0x00);
281+
$col_cov_text = $overview->colorAllocate(0xaa, 0xa7, 0xef);
282+
$col_cov_back = $overview->colorAllocate(0x5d, 0x5d, 0xea);
283+
$col_nocov_text = $overview->colorAllocate(0xff, 0x00, 0x00);
284+
$col_nocov_back = $overview->colorAllocate(0xaa, 0x00, 0x00);
285+
$col_hi_text = $overview->colorAllocate(0x00, 0xff, 0x00);
286+
$col_hi_back = $overview->colorAllocate(0x00, 0xaa, 0x00);
287+
} else {
288+
$col_plain_back = $overview->colorAllocate(0xff, 0xff, 0xff);
289+
$col_plain_text = $overview->colorAllocate(0xaa, 0xaa, 0xaa);
290+
$col_cov_back = $overview->colorAllocate(0xaa, 0xa7, 0xef);
291+
$col_cov_text = $overview->colorAllocate(0x5d, 0x5d, 0xea);
292+
$col_nocov_back = $overview->colorAllocate(0xff, 0x00, 0x00);
293+
$col_nocov_text = $overview->colorAllocate(0xaa, 0x00, 0x00);
294+
$col_hi_back = $overview->colorAllocate(0x00, 0xff, 0x00);
295+
$col_hi_text = $overview->colorAllocate(0x00, 0xaa, 0x00);
296+
}
282297

283298
# Visualize each line
284299
foreach $line (@source)

bin/lcov

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ if ($config || %opt_rc)
256256
"lcov_list_truncate_max"=> \$opt_list_truncate_max,
257257
"lcov_branch_coverage" => \$br_coverage,
258258
"lcov_function_coverage"=> \$func_coverage,
259+
"lcov_fail_under_lines" => \$opt_fail_under_lines,
259260
});
260261
}
261262

lcovrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
# Specify an external style sheet file (same as --css-file option of genhtml)
99
#genhtml_css_file = gcov.css
1010

11+
# use 'dark' mode display (light foreground, dark background) instead of default
12+
# same as 'genhtml --dark-mode ....'
13+
#genhtml_dark_mode = 1
14+
1115
# Specify coverage rate limits (in %) for classifying file entries
1216
# HI: hi_limit <= rate <= 100 graph color: green
1317
# MED: med_limit <= rate < hi_limit graph color: orange
@@ -179,3 +183,7 @@ lcov_function_coverage = 1
179183

180184
# Specify if branch coverage data should be collected and processed.
181185
lcov_branch_coverage = 0
186+
187+
# Ask LCOV to return non-zero exit code if line coverage is below threshold
188+
# Default is 0.0 - i.e., do not check threshold.
189+
#lcov_fail_under_lines = 97.5

man/genhtml.1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ genhtml \- Generate HTML view from LCOV coverage data files
6868
.IR num ]
6969
.RB [ \-\-missed ]
7070
.br
71+
.RB [ \-\-dark\-mode ]
72+
.br
7173
.IR tracefile(s)
7274
.RE
7375
.SH DESCRIPTION
@@ -577,6 +579,13 @@ option
577579
.IR genhtml_missed .
578580
.RE
579581

582+
.B \-\-dark\-mode
583+
.RS
584+
Use a light-display-on-dark-background color scheme rather than the default dark-display-on-light-background.
585+
586+
The idea is to reduce eye strain due to viewing dark text on a bright screen - particularly at night.
587+
588+
580589
.SH FILES
581590

582591
.I /etc/lcovrc

man/lcovrc.5

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ section 'OPTIONS' below.
4747
#genhtml_css_file = gcov.css
4848
.br
4949

50+
# Use 'dark' mode display (light foreground/dark background)
51+
.br
52+
# rather than default
53+
.br
54+
#genhtml_dark_mode = 1
55+
.br
56+
5057
# Coverage rate limits
5158
.br
5259
genhtml_hi_limit = 90
@@ -281,6 +288,14 @@ lcov_function_coverage = 1
281288
.br
282289
lcov_branch_coverage = 0
283290
.br
291+
292+
# Ask LCOV to return non-zero exit code if line coverage is
293+
.br
294+
# below specified threshold percentage.
295+
.br
296+
lcov_fail_under_lines = 97.5
297+
.br
298+
284299
.PP
285300

286301
.SH OPTIONS
@@ -301,6 +316,19 @@ This option corresponds to the \-\-css\-file command line option of
301316
By default, a standard CSS file is generated.
302317
.PP
303318

319+
.BR genhtml_dark_mode " ="
320+
.IR 0 | 1
321+
.IP
322+
If non-zero, display using light text on dark background rather than dark text on light background.
323+
.br
324+
325+
This option corresponds to the \-\-dark\-mode command line option of
326+
.BR genhtml .
327+
.br
328+
329+
By default, a 'light' palette is used.
330+
.PP
331+
304332
.BR genhtml_hi_limit " ="
305333
.I hi_limit
306334
.br
@@ -971,6 +999,18 @@ Specify the regular expression of lines to exclude from exception branch coverag
971999
Default is 'LCOV_EXCL_EXCEPTION_BR_LINE'.
9721000
.PP
9731001

1002+
.BR lcov_fail_under_lines " ="
1003+
.I percentage
1004+
.IP
1005+
Specify line coverage threshold to lcov. If the line coverage is below this threshold, lcov will generate all the normal result files and messages, but will return a non-zero exit code.
1006+
.br
1007+
1008+
This option is equivalent to the \-\-fail\-under\-lines lcov command line option.
1009+
1010+
.br
1011+
The default is 0 (no threshold).
1012+
.PP
1013+
9741014
.SH FILES
9751015

9761016
.TP

0 commit comments

Comments
 (0)