Skip to content

Commit e77ce1b

Browse files
authored
fpcmp: Dump inputs on comparison failure (#160)
There are occasionally spurious failures in llvm-test-suite, and you end up with a phenomenally unhelpful message like: tools/fpcmp-target: Comparison failed, textual difference between '0' and '7' This is good enough if you can inspect the inputs to fpcmp locally, but unhelpful for CI failures. Improve things by dumping the inputs to fpcmp on a textual comparison failure.
1 parent 093c09f commit e77ce1b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/fpcmp.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,27 @@ char *load_file(const char *path, long *size_out) {
247247
return data;
248248
}
249249

250+
static bool contains_non_printable_characters(const char *data) {
251+
size_t len = strlen(data);
252+
for (size_t i = 0; i < len; ++i)
253+
if (!isprint(data[i]) && !isspace(data[i]))
254+
return true;
255+
return false;
256+
}
257+
258+
static void dump_input(const char *label, const char *data) {
259+
if (contains_non_printable_characters(data)) {
260+
fprintf(stderr, "\n%s: Contains binary data.\n", label);
261+
} else {
262+
fprintf(stderr, "\n%s:\n%s", label, data);
263+
}
264+
}
265+
266+
static void dump_inputs(const char *data_a, const char *data_b) {
267+
dump_input("Input 1", data_a);
268+
dump_input("Input 2", data_b);
269+
}
270+
250271
int diff_file(const char *path_a, const char *path_b, bool parse_fp,
251272
double absolute_tolerance, double relative_tolerance,
252273
bool ignore_whitespace) {
@@ -356,6 +377,7 @@ int diff_file(const char *path_a, const char *path_b, bool parse_fp,
356377
fprintf(stderr,
357378
"%s: Comparison failed, textual difference between '%c' and '%c'\n",
358379
g_program, F1P[0], F2P[0]);
380+
dump_inputs(data_a, data_b);
359381
free(data_a);
360382
free(data_b);
361383
return 1;
@@ -364,6 +386,7 @@ int diff_file(const char *path_a, const char *path_b, bool parse_fp,
364386
fprintf(stderr,
365387
"%s: Comparison failed, unexpected end of one of the files\n",
366388
g_program);
389+
dump_inputs(data_a, data_b);
367390
free(data_a);
368391
free(data_b);
369392
return 1;

0 commit comments

Comments
 (0)