Skip to content

Commit f84c2d6

Browse files
committed
Exclude more lines from test coverage
These fall into a few categories: - `_unreachable()` - Verbose print messages - Errors that should never practically occur (alloc/read/write failure, more than UINT32_MAX anonymous labels, etc)
1 parent 632342b commit f84c2d6

File tree

10 files changed

+84
-10
lines changed

10 files changed

+84
-10
lines changed

src/fix/main.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,12 @@ static char const *mbcName(MbcType type) {
698698
case MBC_WRONG_FEATURES:
699699
case MBC_BAD_RANGE:
700700
case MBC_BAD_TPP1:
701+
// LCOV_EXCL_START
701702
unreachable_();
702703
}
703704

704705
unreachable_();
706+
// LCOV_EXCL_STOP
705707
}
706708

707709
static bool hasRAM(MbcType type) {
@@ -763,7 +765,7 @@ static bool hasRAM(MbcType type) {
763765
break;
764766
}
765767

766-
unreachable_();
768+
unreachable_(); // LCOV_EXCL_LINE
767769
}
768770

769771
static uint8_t const nintendoLogo[] = {
@@ -814,7 +816,7 @@ static ssize_t readBytes(int fd, uint8_t *buf, size_t len) {
814816
ssize_t ret = read(fd, buf, len);
815817

816818
if (ret == -1 && errno != EINTR) { // Return errors, unless we only were interrupted
817-
return -1;
819+
return -1; // LCOV_EXCL_LINE
818820
}
819821
// EOF reached
820822
if (ret == 0) {
@@ -841,7 +843,7 @@ static ssize_t writeBytes(int fd, uint8_t *buf, size_t len) {
841843
ssize_t ret = write(fd, buf, len);
842844

843845
if (ret == -1 && errno != EINTR) { // Return errors, unless we only were interrupted
844-
return -1;
846+
return -1; // LCOV_EXCL_LINE
845847
}
846848
// If anything was written, accumulate it, and continue
847849
if (ret != -1) {
@@ -895,8 +897,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
895897
ssize_t headerSize = (cartridgeType & 0xFF00) == TPP1 ? 0x154 : 0x150;
896898

897899
if (rom0Len == -1) {
900+
// LCOV_EXCL_START
898901
report("FATAL: Failed to read \"%s\"'s header: %s\n", name, strerror(errno));
899902
return;
903+
// LCOV_EXCL_STOP
900904
} else if (rom0Len < headerSize) {
901905
report(
902906
"FATAL: \"%s\" too short, expected at least %jd ($%jx) bytes, got only %jd\n",
@@ -1134,8 +1138,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
11341138
// write the header
11351139
if (input == output) {
11361140
if (lseek(output, 0, SEEK_SET) == static_cast<off_t>(-1)) {
1141+
// LCOV_EXCL_START
11371142
report("FATAL: Failed to rewind \"%s\": %s\n", name, strerror(errno));
11381143
return;
1144+
// LCOV_EXCL_STOP
11391145
}
11401146
// If modifying the file in-place, we only need to edit the header
11411147
// However, padding may have modified ROM0 (added padding), so don't in that case
@@ -1146,16 +1152,20 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
11461152
writeLen = writeBytes(output, rom0, rom0Len);
11471153

11481154
if (writeLen == -1) {
1155+
// LCOV_EXCL_START
11491156
report("FATAL: Failed to write \"%s\"'s ROM0: %s\n", name, strerror(errno));
11501157
return;
1158+
// LCOV_EXCL_STOP
11511159
} else if (writeLen < rom0Len) {
1160+
// LCOV_EXCL_START
11521161
report(
11531162
"FATAL: Could only write %jd of \"%s\"'s %jd ROM0 bytes\n",
11541163
static_cast<intmax_t>(writeLen),
11551164
name,
11561165
static_cast<intmax_t>(rom0Len)
11571166
);
11581167
return;
1168+
// LCOV_EXCL_STOP
11591169
}
11601170

11611171
// Output ROMX if it was buffered
@@ -1164,25 +1174,31 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
11641174
// so it's fine to cast to `size_t`
11651175
writeLen = writeBytes(output, romx.data(), totalRomxLen);
11661176
if (writeLen == -1) {
1177+
// LCOV_EXCL_START
11671178
report("FATAL: Failed to write \"%s\"'s ROMX: %s\n", name, strerror(errno));
11681179
return;
1180+
// LCOV_EXCL_STOP
11691181
} else if (static_cast<size_t>(writeLen) < totalRomxLen) {
1182+
// LCOV_EXCL_START
11701183
report(
11711184
"FATAL: Could only write %jd of \"%s\"'s %zu ROMX bytes\n",
11721185
static_cast<intmax_t>(writeLen),
11731186
name,
11741187
totalRomxLen
11751188
);
11761189
return;
1190+
// LCOV_EXCL_STOP
11771191
}
11781192
}
11791193

11801194
// Output padding
11811195
if (padValue != UNSPECIFIED) {
11821196
if (input == output) {
11831197
if (lseek(output, 0, SEEK_END) == static_cast<off_t>(-1)) {
1198+
// LCOV_EXCL_START
11841199
report("FATAL: Failed to seek to end of \"%s\": %s\n", name, strerror(errno));
11851200
return;
1201+
// LCOV_EXCL_STOP
11861202
}
11871203
}
11881204
memset(bank, padValue, sizeof(bank));
@@ -1196,8 +1212,10 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
11961212
// The return value is either -1, or at most `thisLen`,
11971213
// so it's fine to cast to `size_t`
11981214
if (static_cast<size_t>(ret) != thisLen) {
1215+
// LCOV_EXCL_START
11991216
report("FATAL: Failed to write \"%s\"'s padding: %s\n", name, strerror(errno));
12001217
break;
1218+
// LCOV_EXCL_STOP
12011219
}
12021220
len -= thisLen;
12031221
}
@@ -1224,12 +1242,16 @@ static bool processFilename(char const *name) {
12241242
Defer closeInput{[&] { close(input); }};
12251243
struct stat stat;
12261244
if (fstat(input, &stat) == -1) {
1245+
// LCOV_EXCL_START
12271246
report("FATAL: Failed to stat \"%s\": %s\n", name, strerror(errno));
1228-
} else if (!S_ISREG(stat.st_mode)) { // TODO: Do we want to support other types?
1247+
// LCOV_EXCL_STOP
1248+
} else if (!S_ISREG(stat.st_mode)) { // TODO: Do we want to support FIFOs or symlinks?
1249+
// LCOV_EXCL_START
12291250
report(
12301251
"FATAL: \"%s\" is not a regular file, and thus cannot be modified in-place\n",
12311252
name
12321253
);
1254+
// LCOV_EXCL_STOP
12331255
} else if (stat.st_size < 0x150) {
12341256
// This check is in theory redundant with the one in `processFile`, but it
12351257
// prevents passing a file size of 0, which usually indicates pipes
@@ -1423,16 +1445,20 @@ int main(int argc, char *argv[]) {
14231445
}
14241446

14251447
case 'V':
1448+
// LCOV_EXCL_START
14261449
printf("rgbfix %s\n", get_package_version_string());
14271450
exit(0);
1451+
// LCOV_EXCL_STOP
14281452

14291453
case 'v':
14301454
fixSpec = FIX_LOGO | FIX_HEADER_SUM | FIX_GLOBAL_SUM;
14311455
break;
14321456

14331457
default:
1458+
// LCOV_EXCL_START
14341459
printUsage();
14351460
exit(1);
1461+
// LCOV_EXCL_STOP
14361462
}
14371463
}
14381464

src/gfx/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ void fatal(char const *fmt, ...) {
103103
}
104104

105105
void Options::verbosePrint(uint8_t level, char const *fmt, ...) const {
106+
// LCOV_EXCL_START
106107
if (verbosity >= level) {
107108
va_list ap;
108109

109110
va_start(ap, fmt);
110111
vfprintf(stderr, fmt, ap);
111112
va_end(ap);
112113
}
114+
// LCOV_EXCL_STOP
113115
}
114116

115117
// Short options
@@ -586,13 +588,17 @@ static char *parseArgv(int argc, char *argv[]) {
586588
options.tilemap = musl_optarg;
587589
break;
588590
case 'V':
591+
// LCOV_EXCL_START
589592
printf("rgbgfx %s\n", get_package_version_string());
590593
exit(0);
594+
// LCOV_EXCL_STOP
591595
case 'v':
596+
// LCOV_EXCL_START
592597
if (options.verbosity < Options::VERB_VVVVVV) {
593598
++options.verbosity;
594599
}
595600
break;
601+
// LCOV_EXCL_STOP
596602
case 'x':
597603
options.trim = parseNumber(arg, "Number of tiles to trim", 0);
598604
if (*arg != '\0') {
@@ -750,6 +756,7 @@ int main(int argc, char *argv[]) {
750756
parseExternalPalSpec(localOptions.externalPalSpec);
751757
}
752758

759+
// LCOV_EXCL_START
753760
if (options.verbosity >= Options::VERB_CFG) {
754761
fprintf(stderr, "rgbgfx %s\n", get_package_version_string());
755762

@@ -862,6 +869,7 @@ int main(int argc, char *argv[]) {
862869
printPath("Output palettes", options.palettes);
863870
fputs("Ready.\n", stderr);
864871
}
872+
// LCOV_EXCL_STOP
865873

866874
// Do not do anything if option parsing went wrong.
867875
requireZeroErrors();

src/gfx/pal_packing.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ std::tuple<DefaultInitVec<size_t>, size_t>
559559
}
560560
}
561561

562+
// LCOV_EXCL_START
562563
if (options.verbosity >= Options::VERB_INTERM) {
563564
for (auto &&assignment : assignments) {
564565
fprintf(stderr, "{ ");
@@ -571,11 +572,13 @@ std::tuple<DefaultInitVec<size_t>, size_t>
571572
fprintf(stderr, "} (volume = %zu)\n", assignment.volume());
572573
}
573574
}
575+
// LCOV_EXCL_STOP
574576

575577
// "Decant" the result
576578
decant(assignments, protoPalettes);
577579
// Note that the result does not contain any empty palettes
578580

581+
// LCOV_EXCL_START
579582
if (options.verbosity >= Options::VERB_INTERM) {
580583
for (auto &&assignment : assignments) {
581584
fprintf(stderr, "{ ");
@@ -588,6 +591,7 @@ std::tuple<DefaultInitVec<size_t>, size_t>
588591
fprintf(stderr, "} (volume = %zu)\n", assignment.volume());
589592
}
590593
}
594+
// LCOV_EXCL_STOP
591595

592596
DefaultInitVec<size_t> mappings(protoPalettes.size());
593597
for (size_t i = 0; i < assignments.size(); ++i) {

src/gfx/pal_sorting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void sortIndexed(
4040
return true;
4141
}
4242
}
43-
unreachable_(); // This should not be possible
43+
unreachable_(); // LCOV_EXCL_LINE
4444
});
4545
}
4646
}

0 commit comments

Comments
 (0)