diff --git a/tests/color_util.c b/tests/color_util.c index 4b1471d6..da2f5c6b 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -390,6 +390,11 @@ scalar_stat_update(struct scalar_stat *stat, stat->sum += val; stat->count++; + + if (stat->dump) { + fprintf(stat->dump, "%.8g %.5g %.5g %.5g %.5g\n", + val, pos->r, pos->g, pos->b, pos->a); + } } float diff --git a/tests/color_util.h b/tests/color_util.h index 724ff04a..1bb7297a 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -28,6 +28,7 @@ #include #include +#include enum color_chan_index { COLOR_CHAN_R = 0, @@ -131,6 +132,17 @@ struct scalar_stat { double sum; unsigned count; + + /** Debug dump into file + * + * Initialize this to a writable file to get a record of all values + * ever fed through this statistics accumulator. The file shall be + * text with one value and its position per line: + * val pos.r pos.g pos.b pos.a + * + * Set to NULL to not record. + */ + FILE *dump; }; struct rgb_diff_stat { diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 89713e17..ca49a04d 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -38,6 +38,7 @@ #include "test-config.h" #include "shared/os-compatibility.h" +#include "shared/string-helpers.h" #include "shared/xalloc.h" #include #include "weston-test-client-helper.h" @@ -1144,6 +1145,36 @@ image_filename(const char *basename) return filename; } +/** Open a writable file + * + * \param suffix Custom file name suffix. + * \return FILE pointer, or NULL on failure. + * + * The file name consists of output path, test name, and the given suffix. + * If environment variable WESTON_TEST_OUTPUT_PATH is set, it is used as the + * directory path, otherwise the current directory is used. + * + * The file will be writable. If it exists, it is truncated, otherwise it is + * created. Failures are logged. + */ +FILE * +fopen_dump_file(const char *suffix) +{ + char *fname; + FILE *fp; + + str_printf(&fname, "%s/%s-%s.txt", output_path(), + get_test_name(), suffix); + fp = fopen(fname, "w"); + if (!fp) { + testlog("Error: failed to open file '%s' for writing: %s\n", + fname, strerror(errno)); + } + free(fname); + + return fp; +} + struct format_map_entry { cairo_format_t cairo; pixman_format_code_t pixman; diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index dd20d514..34183249 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -250,6 +250,9 @@ screenshot_reference_filename(const char *basename, uint32_t seq); char * image_filename(const char *basename); +FILE * +fopen_dump_file(const char *suffix); + bool check_images_match(pixman_image_t *img_a, pixman_image_t *img_b, const struct rectangle *clip,