Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_backbuf_publish.c File Reference
#include "develop/develop.h"
#include "develop/pixelpipe_hb.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>
#include <glib.h>
+ Include dependency graph for test_backbuf_publish.c:

Go to the source code of this file.

Data Structures

struct  publisher_t
 

Macros

#define SHAPE_A_W   4032
 
#define SHAPE_A_H   3024
 
#define SHAPE_A_HASH   0x1111111111111111ull
 
#define SHAPE_B_W   5104
 
#define SHAPE_B_H   3880
 
#define SHAPE_B_HASH   0x2222222222222222ull
 
#define HUNT_MICROSECONDS   400000
 

Typedefs

typedef struct publisher_t publisher_t
 

Functions

static gpointer _publisher_main (gpointer user_data)
 
static gboolean _pairing_is_coherent (const uint64_t hash, const size_t width, const size_t height)
 Is this (hash, width, height) triple one that was ever published together?
 
static void test_field_by_field_read_crosses_publications (void **state)
 
static void test_snapshot_never_crosses_publications (void **state)
 
static void test_single_field_setter_is_a_publication (void **state)
 A single-field setter must publish coherently too – the histogram backbuffers are invalidated that way when a view leaves.
 
int main (void)
 

Macro Definition Documentation

◆ HUNT_MICROSECONDS

#define HUNT_MICROSECONDS   400000

Definition at line 92 of file test_backbuf_publish.c.

◆ SHAPE_A_H

#define SHAPE_A_H   3024

Definition at line 57 of file test_backbuf_publish.c.

◆ SHAPE_A_HASH

#define SHAPE_A_HASH   0x1111111111111111ull

Definition at line 58 of file test_backbuf_publish.c.

◆ SHAPE_A_W

#define SHAPE_A_W   4032

The backbuffer publication is one fact, and a consumer must read it as one.

‘hash’ names a cacheline; ‘width’/‘height’ say what shape the pixels in it are. A consumer that pairs a hash from one publication with dimensions from the next computes a cairo stride from a width the data does not have and paints the diagonal striping of a stride error. The cacheline cannot help: it records how many BYTES it holds and nothing about their layout, and it is routinely LARGER than width x height x bpp (aligned allocation, pool reuse), so a size check passes.

The first test reproduces the cross-pairing against the fields read one at a time – the way every display path read them – and fails the day it stops being reproducible, which is the point: it is what says the second test is measuring something. The second asserts that a snapshot never crosses. Both run the same writer.

This is a race, so the first test is written to be overwhelmingly likely rather than certain: a writer flipping between two shapes as fast as it can, against a reader that reads the hash, does a little work, and then reads the dimensions – the same shape as "resolve the cacheline, then compute the stride". If it ever goes quiet on some machine, do not delete it: it is reporting that the window closed on that scheduler, not that the hazard is gone.

Definition at line 56 of file test_backbuf_publish.c.

◆ SHAPE_B_H

#define SHAPE_B_H   3880

Definition at line 60 of file test_backbuf_publish.c.

◆ SHAPE_B_HASH

#define SHAPE_B_HASH   0x2222222222222222ull

Definition at line 61 of file test_backbuf_publish.c.

◆ SHAPE_B_W

#define SHAPE_B_W   5104

Definition at line 59 of file test_backbuf_publish.c.

Typedef Documentation

◆ publisher_t

typedef struct publisher_t publisher_t

Function Documentation

◆ _pairing_is_coherent()

static gboolean _pairing_is_coherent ( const uint64_t  hash,
const size_t  width,
const size_t  height 
)
static

Is this (hash, width, height) triple one that was ever published together?

Definition at line 83 of file test_backbuf_publish.c.

References height, SHAPE_A_H, SHAPE_A_HASH, SHAPE_A_W, SHAPE_B_H, SHAPE_B_HASH, SHAPE_B_W, TRUE, and width.

Referenced by test_field_by_field_read_crosses_publications(), and test_snapshot_never_crosses_publications().

◆ _publisher_main()

static gpointer _publisher_main ( gpointer  user_data)
static

◆ main()

◆ test_field_by_field_read_crosses_publications()

static void test_field_by_field_read_crosses_publications ( void **  state)
static

◆ test_single_field_setter_is_a_publication()

static void test_single_field_setter_is_a_publication ( void **  state)
static

A single-field setter must publish coherently too – the histogram backbuffers are invalidated that way when a view leaves.

Definition at line 156 of file test_backbuf_publish.c.

References dt_dev_backbuf_set_hash(), dt_dev_backbuf_snapshot(), dt_dev_set_backbuf(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_backbuf_state_t::hash, dt_backbuf_state_t::height, SHAPE_A_H, SHAPE_A_HASH, SHAPE_A_W, state, void(), and dt_backbuf_state_t::width.

Referenced by main().

◆ test_snapshot_never_crosses_publications()