Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_pipe_cache_auto_destroy.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
27
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/* Create a line the way a module creates a side-band output: referenced once and write-locked. */
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);
65 return entry;
66}
67
78
98
101{
105
106 dt_pixel_cache_entry_t *held = NULL;
107 assert_true(dt_dev_pixelpipe_cache_ref_entry_by_hash(HASH_A, NULL, &held));
108 assert_ptr_equal(held, entry);
110}
111
112int main(int argc, char *argv[])
113{
114 const struct CMUnitTest tests[] = {
115 cmocka_unit_test_setup_teardown(_flagged_line_goes_with_its_release, _setup, _teardown),
116 cmocka_unit_test_setup_teardown(_flagged_line_goes_with_its_last_holder, _setup, _teardown),
117 cmocka_unit_test_setup_teardown(_unflagged_line_outlives_its_release, _setup, _teardown),
118 };
119 return cmocka_run_group_tests(tests, NULL, NULL);
120}
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
int dt_atomic_get_int(dt_atomic_int *var)
void * data
Definition geometry.h:111
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_cleanup(void)
Release everything dt_dev_pixelpipe_cache_init() created, the instance included. Only after a success...
void dt_dev_pixelpipe_cache_ref_count_entry(gboolean lock, dt_pixel_cache_entry_t *cache_entry)
Take or release one reference on a cache line. A referenced line is never evicted,...
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.
gboolean dt_dev_pixelpipe_cache_ref_entry_by_hash(const uint64_t hash, void **data, dt_pixel_cache_entry_t **entry)
Resolve and retain an existing cache entry by hash.
void dt_dev_pixelpipe_cache_flag_auto_destroy(dt_pixel_cache_entry_t *cache_entry)
Flag a cache line as disposable (auto_destroy), for short-lived lines nothing will need again: the re...
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 int _teardown(void **state __attribute__((unused)))
static int _setup(void **state __attribute__((unused)))
static int _teardown(void **state __attribute__((unused)))
static void _flagged_line_goes_with_its_release(void **state __attribute__((unused)))
static void _unflagged_line_outlives_its_release(void **state __attribute__((unused)))
static int _setup(void **state __attribute__((unused)))
#define LINE_BYTES
static void _flagged_line_goes_with_its_last_holder(void **state __attribute__((unused)))
static dt_pixel_cache_entry_t * _create(void)