AtlatestRepositorysigil-wm
1
/* SPDX-License-Identifier: BSD-3-Clause */2
/* Separate test interposer: product code has no commit-failure switch. */3
#define _GNU_SOURCE4
#include <dlfcn.h>5
#include <stdatomic.h>6
#include <stdio.h>7
#include <stdlib.h>8
#include <wlr/backend.h>9
static _Thread_local unsigned depth;10
static unsigned batches;11
static atomic_int partials;12
int wm_test_partial_commits(void) { return atomic_load(&partials); }13
bool wlr_backend_commit(struct wlr_backend *backend,14
const struct wlr_backend_output_state *states,size_t count) {15
typedef bool (*commit_fn)(struct wlr_backend *,const struct wlr_backend_output_state *,size_t);16
commit_fn commit=(commit_fn)dlsym(RTLD_NEXT,"wlr_backend_commit");17
if(!commit) abort();18
if(depth) return commit(backend,states,count);19
depth++;20
if(count==2) batches++;21
bool result;22
if(count==2 && batches==2) {23
result=commit(backend,states,1);24
int width,height;25
wlr_output_effective_resolution(states[0].output,&width,&height);26
if(!result || width!=800 || height!=600) abort();27
atomic_fetch_add(&partials,1);28
fprintf(stderr,"PARTIAL_COMMIT_INJECTED=1 first=%dx%d\n",width,height);29
result=false;30
} else if(count==2 && batches==3 && getenv("SIGIL_WM_TEST_ROLLBACK_FAILURE")) {31
fprintf(stderr,"ROLLBACK_FAILURE_INJECTED=1\n");32
result=false;33
} else result=commit(backend,states,count);34
depth--;35
return result;36
}