Line data Source code
1 : /*--------------------------------------------------------------------------
2 : *
3 : * test_checksums.c
4 : * Test data checksums
5 : *
6 : * Copyright (c) 2026, PostgreSQL Global Development Group
7 : *
8 : * IDENTIFICATION
9 : * src/test/modules/test_checksums/test_checksums.c
10 : *
11 : * -------------------------------------------------------------------------
12 : */
13 : #include "postgres.h"
14 :
15 : #include "funcapi.h"
16 : #include "miscadmin.h"
17 : #include "postmaster/datachecksum_state.h"
18 : #include "storage/latch.h"
19 : #include "utils/injection_point.h"
20 : #include "utils/wait_event.h"
21 :
22 2 : PG_MODULE_MAGIC;
23 :
24 : extern PGDLLEXPORT void dc_delay_barrier(const char *name, const void *private_data, void *arg);
25 : extern PGDLLEXPORT void dc_modify_db_result(const char *name, const void *private_data, void *arg);
26 : extern PGDLLEXPORT void dc_fake_temptable(const char *name, const void *private_data, void *arg);
27 :
28 : /*
29 : * Test for delaying emission of procsignalbarriers.
30 : */
31 : void
32 0 : dc_delay_barrier(const char *name, const void *private_data, void *arg)
33 : {
34 : (void) name;
35 : (void) private_data;
36 :
37 0 : (void) WaitLatch(MyLatch,
38 : WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
39 : (3 * 1000),
40 : WAIT_EVENT_PG_SLEEP);
41 0 : }
42 :
43 2 : PG_FUNCTION_INFO_V1(dcw_inject_delay_barrier);
44 : Datum
45 0 : dcw_inject_delay_barrier(PG_FUNCTION_ARGS)
46 : {
47 : #ifdef USE_INJECTION_POINTS
48 0 : bool attach = PG_GETARG_BOOL(0);
49 :
50 0 : if (attach)
51 0 : InjectionPointAttach("datachecksums-enable-checksums-delay",
52 : "test_checksums",
53 : "dc_delay_barrier",
54 : NULL,
55 : 0);
56 : else
57 0 : InjectionPointDetach("datachecksums-enable-checksums-delay");
58 : #else
59 : elog(ERROR,
60 : "test is not working as intended when injection points are disabled");
61 : #endif
62 0 : PG_RETURN_VOID();
63 : }
64 :
65 2 : PG_FUNCTION_INFO_V1(dcw_inject_launcher_delay);
66 : Datum
67 0 : dcw_inject_launcher_delay(PG_FUNCTION_ARGS)
68 : {
69 : #ifdef USE_INJECTION_POINTS
70 0 : bool attach = PG_GETARG_BOOL(0);
71 :
72 0 : if (attach)
73 0 : InjectionPointAttach("datachecksumsworker-launcher-delay",
74 : "test_checksums",
75 : "dc_delay_barrier",
76 : NULL,
77 : 0);
78 : else
79 0 : InjectionPointDetach("datachecksumsworker-launcher-delay");
80 : #else
81 : elog(ERROR,
82 : "test is not working as intended when injection points are disabled");
83 : #endif
84 0 : PG_RETURN_VOID();
85 : }
86 :
87 2 : PG_FUNCTION_INFO_V1(dcw_inject_startup_delay);
88 : Datum
89 0 : dcw_inject_startup_delay(PG_FUNCTION_ARGS)
90 : {
91 : #ifdef USE_INJECTION_POINTS
92 0 : bool attach = PG_GETARG_BOOL(0);
93 :
94 0 : if (attach)
95 0 : InjectionPointAttach("datachecksumsworker-startup-delay",
96 : "test_checksums",
97 : "dc_delay_barrier",
98 : NULL,
99 : 0);
100 : else
101 0 : InjectionPointDetach("datachecksumsworker-startup-delay");
102 : #else
103 : elog(ERROR,
104 : "test is not working as intended when injection points are disabled");
105 : #endif
106 0 : PG_RETURN_VOID();
107 : }
|