mirror of
https://github.com/postgres/postgres.git
synced 2025-09-09 13:09:39 +03:00
Add test module injection_points
This provides basic coverage for injection points within a single process, while providing some callbacks that can be used for other tests. There are plans to extend this module later with more advanced capabilities for tests. Author: Michael Paquier, with comment fixes from Ashutosh Bapat. Reviewed-by: Ashutosh Bapat, Nathan Bossart, Álvaro Herrera, Dilip Kumar, Amul Sul, Nazir Bilal Yavuz Discussion: https://postgr.es/m/ZTiV8tn_MIb_H2rE@paquier.xyz
This commit is contained in:
95
src/test/modules/injection_points/injection_points.c
Normal file
95
src/test/modules/injection_points/injection_points.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/*--------------------------------------------------------------------------
|
||||
*
|
||||
* injection_points.c
|
||||
* Code for testing injection points.
|
||||
*
|
||||
* Injection points are able to trigger user-defined callbacks in pre-defined
|
||||
* code paths.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/test/modules/injection_points/injection_points.c
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "fmgr.h"
|
||||
#include "storage/lwlock.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/injection_point.h"
|
||||
#include "utils/wait_event.h"
|
||||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
extern PGDLLEXPORT void injection_error(const char *name);
|
||||
extern PGDLLEXPORT void injection_notice(const char *name);
|
||||
|
||||
|
||||
/* Set of callbacks available to be attached to an injection point. */
|
||||
void
|
||||
injection_error(const char *name)
|
||||
{
|
||||
elog(ERROR, "error triggered for injection point %s", name);
|
||||
}
|
||||
|
||||
void
|
||||
injection_notice(const char *name)
|
||||
{
|
||||
elog(NOTICE, "notice triggered for injection point %s", name);
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for creating an injection point.
|
||||
*/
|
||||
PG_FUNCTION_INFO_V1(injection_points_attach);
|
||||
Datum
|
||||
injection_points_attach(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *name = text_to_cstring(PG_GETARG_TEXT_PP(0));
|
||||
char *action = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||
char *function;
|
||||
|
||||
if (strcmp(action, "error") == 0)
|
||||
function = "injection_error";
|
||||
else if (strcmp(action, "notice") == 0)
|
||||
function = "injection_notice";
|
||||
else
|
||||
elog(ERROR, "incorrect action \"%s\" for injection point creation", action);
|
||||
|
||||
InjectionPointAttach(name, "injection_points", function);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for triggering an injection point.
|
||||
*/
|
||||
PG_FUNCTION_INFO_V1(injection_points_run);
|
||||
Datum
|
||||
injection_points_run(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *name = text_to_cstring(PG_GETARG_TEXT_PP(0));
|
||||
|
||||
INJECTION_POINT(name);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for dropping an injection point.
|
||||
*/
|
||||
PG_FUNCTION_INFO_V1(injection_points_detach);
|
||||
Datum
|
||||
injection_points_detach(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *name = text_to_cstring(PG_GETARG_TEXT_PP(0));
|
||||
|
||||
InjectionPointDetach(name);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
Reference in New Issue
Block a user