Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_pipe_cache_flush.c
Go to the documentation of this file.
1/*
2 This file is part of Ansel,
3 Copyright (C) 2026 Guillaume Stutin.
4
5 Ansel is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Ansel is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17*/
18
29#include "system/atomic.h"
30
31#include <stdarg.h>
32#include <stddef.h>
33// cmocka.h declares `extern jmp_buf global_expect_assert_env' at file scope without including
34// <setjmp.h> itself. Same suppression as test_metadata_notify.c, and for the same reason.
35#include <setjmp.h> // NOLINT(misc-include-cleaner)
36#include <stdint.h>
37#include <cmocka.h>
38
39#ifdef _WIN32
40#include "win/main_wrapper.h"
41#endif
42
43#define LINE_BYTES (256 * 1024)
44#define HASH_A 0x0A0A0A0A0A0A0A0Aull
45
46static int _setup(void **state __attribute__((unused)))
47{
48 return dt_dev_pixelpipe_cache_init((size_t)64 * 1024 * 1024, FALSE, FALSE) ? 0 : -1;
49}
50
51static int _teardown(void **state __attribute__((unused)))
52{
54 return 0;
55}
56
57/* A written line, still referenced once by its creator and no longer locked: what a keepalive holds. */
59{
60 void *data = NULL;
61 dt_pixel_cache_entry_t *entry = NULL;
62 assert_int_equal(dt_dev_pixelpipe_cache_get(HASH_A, LINE_BYTES, "test line", 0, TRUE, &data, &entry), 1);
63 assert_non_null(entry);
64 assert_non_null(data);
66 return entry;
67}
68
71{
73
75 assert_ptr_equal(dt_dev_pixelpipe_cache_get_entry(HASH_A), entry);
76 assert_int_equal(dt_atomic_get_int(&entry->refcount), 1);
77
79}
80
90
91int main(int argc, char *argv[])
92{
93 const struct CMUnitTest tests[] = {
94 cmocka_unit_test_setup_teardown(_held_line_survives_the_flush, _setup, _teardown),
95 cmocka_unit_test_setup_teardown(_released_line_goes_with_the_flush, _setup, _teardown),
96 };
97 return cmocka_run_group_tests(tests, NULL, NULL);
98}
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
int dt_atomic_get_int(dt_atomic_int *var)
void dt_dev_pixelpipe_cache_wrlock_entry(gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Lock or release the write lock on the entry.
void dt_dev_pixelpipe_cache_unref_entry(dt_pixel_cache_entry_t *entry)
Release one reference held on entry, by POINTER.
void dt_dev_pixelpipe_cache_cleanup(void)
Release everything dt_dev_pixelpipe_cache_init() created, the instance included. Only after a success...
void dt_dev_pixelpipe_cache_flush(const int id)
Remove cache lines matching id. Entries locked in read/write or having reference count greater than 0...
int dt_dev_pixelpipe_cache_get(const uint64_t hash, const size_t size, const char *name, const int id, const gboolean alloc, void **data, dt_pixel_cache_entry_t **entry)
Get a cache line from the cache.
dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry(const uint64_t hash)
Get an internal reference to the cache entry matching hash. If you are going to access this entry mor...
gboolean dt_dev_pixelpipe_cache_init(size_t max_memory, const gboolean verbose, const gboolean verbose_detail)
Reserve the cache's arena and start it.
Pixelpipe cache for storing intermediate results in the pixelpipe.
int main()
Definition prova.c:47
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
Definition simd.h:55
const float uint32_t state[4]
dt_atomic_int refcount
static dt_pixel_cache_entry_t * _create_held(void)
static int _teardown(void **state __attribute__((unused)))
static int _setup(void **state __attribute__((unused)))
#define LINE_BYTES
static void _held_line_survives_the_flush(void **state __attribute__((unused)))
#define HASH_A
static void _released_line_goes_with_the_flush(void **state __attribute__((unused)))