tests: add scalar_stat dumps

The new field in struct scalar_stat allows recording all tested values
into a file. This is intended to replace ad hoc dumping code like in
alpha-blending-test.c.

To make it easy to set up, also offer a helper to open a writable file
whose name consists of a custom prefix and test name.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 2 years ago committed by Pekka Paalanen
parent f31d26669d
commit 912ea2cb20
  1. 5
      tests/color_util.c
  2. 12
      tests/color_util.h
  3. 31
      tests/weston-test-client-helper.c
  4. 3
      tests/weston-test-client-helper.h

@ -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

@ -28,6 +28,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
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 {

@ -38,6 +38,7 @@
#include "test-config.h"
#include "shared/os-compatibility.h"
#include "shared/string-helpers.h"
#include "shared/xalloc.h"
#include <libweston/zalloc.h>
#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;

@ -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,

Loading…
Cancel
Save