vmod_debug: obj fini test code to macro & unify

- use a custom fini function for all priv* tests
- unify naming to _fini
- move common code to macro

Mostly taken from #3472 to slim that PR
parent c2e89365
...@@ -54,7 +54,7 @@ logexpect l1 -v v1 -g raw -d 1 { ...@@ -54,7 +54,7 @@ logexpect l1 -v v1 -g raw -d 1 {
expect 0 * Debug {^objx.priv_task.*"something to remember".$} expect 0 * Debug {^objx.priv_task.*"something to remember".$}
expect 0 * VCL_Log {^obj something to remember} expect 0 * VCL_Log {^obj something to remember}
# string stored in obj priv_task has already been freed # string stored in obj priv_task has already been freed
expect ? * Debug {^priv_task_free} expect ? * Debug {^priv_task_fini}
expect ? * Debug {^obj_priv_task_fini} expect ? * Debug {^obj_priv_task_fini}
expect 0 * Debug {^vcl1: VCL_EVENT_WARM} expect 0 * Debug {^vcl1: VCL_EVENT_WARM}
} -start } -start
......
...@@ -120,7 +120,7 @@ logexpect l0 -v v1 -g raw -d 1 -m -q "vxid == 0" { ...@@ -120,7 +120,7 @@ logexpect l0 -v v1 -g raw -d 1 -m -q "vxid == 0" {
expect 0 = VCL_Log {^objc initX} expect 0 = VCL_Log {^objc initX}
expect 0 = Debug {^objb.priv_task.. = .*"initY"} expect 0 = Debug {^objb.priv_task.. = .*"initY"}
expect 0 = VCL_Log {^objb initY} expect 0 = VCL_Log {^objb initY}
expect ? = Debug {^priv_task_free} expect ? = Debug {^priv_task_fini}
expect ? = Debug {^obj_priv_task_fini.*"initX"} expect ? = Debug {^obj_priv_task_fini.*"initX"}
expect ? = Debug {^obj_priv_task_fini.*"initY"} expect ? = Debug {^obj_priv_task_fini.*"initY"}
expect 0 = Debug {^vcl1: VCL_EVENT_WARM} expect 0 = Debug {^vcl1: VCL_EVENT_WARM}
...@@ -134,10 +134,10 @@ logexpect l0 -v v1 -g raw -d 1 -m -q "vxid == 0" { ...@@ -134,10 +134,10 @@ logexpect l0 -v v1 -g raw -d 1 -m -q "vxid == 0" {
expect 0 = Debug {^test_priv_task.*exists.$} expect 0 = Debug {^test_priv_task.*exists.$}
# client task can race with backend fini, so all of these are # client task can race with backend fini, so all of these are
# in any order (? = alternatives) # in any order (? = alternatives)
expect ? = Debug {^priv_task_free} expect ? = Debug {^priv_task_fini}
expect ? = Debug {^obj_priv_task_fini.*"r1002"} expect ? = Debug {^obj_priv_task_fini.*"r1002"}
expect ? = Debug {^test_priv_task.*exists} expect ? = Debug {^test_priv_task.*exists}
expect ? = Debug {^priv_task_free} expect ? = Debug {^priv_task_fini}
expect ? = Debug {^obj_priv_task_fini.*"d1001"} expect ? = Debug {^obj_priv_task_fini.*"d1001"}
# 1003, but need to include in our alt to tolerate race # 1003, but need to include in our alt to tolerate race
...@@ -160,7 +160,7 @@ logexpect l0 -v v1 -g raw -d 1 -m -q "vxid == 0" { ...@@ -160,7 +160,7 @@ logexpect l0 -v v1 -g raw -d 1 -m -q "vxid == 0" {
expect 0 = Debug {^test_priv_task.*update.$} expect 0 = Debug {^test_priv_task.*update.$}
expect 0 = Debug {^test_priv_task.*exists.$} expect 0 = Debug {^test_priv_task.*exists.$}
expect 0 = Debug {^objc.priv_task.. = NULL} expect 0 = Debug {^objc.priv_task.. = NULL}
expect 0 = Debug {^priv_task_free} expect 0 = Debug {^priv_task_fini}
expect 0 = VCL_Log {^func cleaning up} expect 0 = VCL_Log {^func cleaning up}
expect 0 = VCL_Log {^obj } expect 0 = VCL_Log {^obj }
expect 0 = CLI {^Wr 200 0 } expect 0 = CLI {^Wr 200 0 }
......
...@@ -225,11 +225,31 @@ xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone) ...@@ -225,11 +225,31 @@ xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone)
WRONG("Illegal VMOD enum"); WRONG("Illegal VMOD enum");
} }
static const struct vmod_priv_methods xyzzy_test_priv_call_methods[1] = {{ #define AN0(x) (void) 0
.magic = VMOD_PRIV_METHODS_MAGIC, #define AN1(x) AN(x)
.type = "debug_test_priv_call", #define PRIV_FINI(name, assert) \
.fini = free static void v_matchproto_(vmod_priv_fini_f) \
}}; priv_ ## name ## _fini(void *ptr) \
{ \
const char * const fmt = "priv_" #name "_fini(%p)"; \
\
AN ## assert (ptr); \
VSL(SLT_Debug, 0, fmt, ptr); \
free(ptr); \
} \
\
static const struct vmod_priv_methods \
xyzzy_test_priv_ ## name ## _methods[1] = {{ \
.magic = VMOD_PRIV_METHODS_MAGIC, \
.type = "debug_test_priv_" #name, \
.fini = priv_ ## name ## _fini \
}};
PRIV_FINI(call, 0)
PRIV_FINI(task, 1)
PRIV_FINI(top, 1)
#undef PRIV_FINI
#undef AN0
#undef AN1
VCL_VOID v_matchproto_(td_debug_test_priv_call) VCL_VOID v_matchproto_(td_debug_test_priv_call)
xyzzy_test_priv_call(VRT_CTX, struct vmod_priv *priv) xyzzy_test_priv_call(VRT_CTX, struct vmod_priv *priv)
...@@ -252,20 +272,6 @@ xyzzy_test_priv_task_get(VRT_CTX) ...@@ -252,20 +272,6 @@ xyzzy_test_priv_task_get(VRT_CTX)
AZ(VRT_priv_task_get(ctx, NULL)); AZ(VRT_priv_task_get(ctx, NULL));
} }
static void
priv_task_free(void *ptr)
{
AN(ptr);
VSL(SLT_Debug, 0, "priv_task_free(%p)", ptr);
free(ptr);
}
static const struct vmod_priv_methods xyzzy_test_priv_task_methods[1] = {{
.magic = VMOD_PRIV_METHODS_MAGIC,
.type = "debug_test_priv_task",
.fini = priv_task_free
}};
VCL_STRING v_matchproto_(td_debug_test_priv_task) VCL_STRING v_matchproto_(td_debug_test_priv_task)
xyzzy_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s) xyzzy_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s)
{ {
...@@ -295,12 +301,6 @@ xyzzy_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s) ...@@ -295,12 +301,6 @@ xyzzy_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s)
return (priv->priv); return (priv->priv);
} }
static const struct vmod_priv_methods xyzzy_test_priv_top_methods[1] = {{
.magic = VMOD_PRIV_METHODS_MAGIC,
.type = "debug_test_priv_top",
.fini = free
}};
VCL_STRING v_matchproto_(td_debug_test_priv_top) VCL_STRING v_matchproto_(td_debug_test_priv_top)
xyzzy_test_priv_top(VRT_CTX, struct vmod_priv *priv, VCL_STRING s) xyzzy_test_priv_top(VRT_CTX, struct vmod_priv *priv, VCL_STRING s)
{ {
...@@ -403,7 +403,7 @@ xyzzy_fail2(VRT_CTX) ...@@ -403,7 +403,7 @@ xyzzy_fail2(VRT_CTX)
} }
static void v_matchproto_(vmod_priv_fini_f) static void v_matchproto_(vmod_priv_fini_f)
priv_vcl_free(void *priv) priv_vcl_fini(void *priv)
{ {
struct priv_vcl *priv_vcl; struct priv_vcl *priv_vcl;
...@@ -422,8 +422,8 @@ priv_vcl_free(void *priv) ...@@ -422,8 +422,8 @@ priv_vcl_free(void *priv)
static const struct vmod_priv_methods priv_vcl_methods[1] = {{ static const struct vmod_priv_methods priv_vcl_methods[1] = {{
.magic = VMOD_PRIV_METHODS_MAGIC, .magic = VMOD_PRIV_METHODS_MAGIC,
.type = "debug_priv_vcl_free", .type = "debug_priv_vcl_fini",
.fini = priv_vcl_free .fini = priv_vcl_fini
}}; }};
static int static int
......
...@@ -152,18 +152,25 @@ xyzzy_obj_test_priv_vcl(VRT_CTX, ...@@ -152,18 +152,25 @@ xyzzy_obj_test_priv_vcl(VRT_CTX,
xyzzy_test_priv_vcl(ctx, priv); xyzzy_test_priv_vcl(ctx, priv);
} }
static void #define PRIV_FINI(name) \
obj_priv_task_fini(void *ptr) static void v_matchproto_(vmod_priv_fini_f) \
{ obj_priv_ ## name ## _fini(void *ptr) \
AN(ptr); { \
VSL(SLT_Debug, 0, "obj_priv_task_fini(%p = \"%s\")", ptr, (char *)ptr); const char * const fmt = "obj_priv_" #name "_fini(%p = \"%s\")"; \
} \
AN(ptr); \
static const struct vmod_priv_methods xyzzy_obj_test_priv_task_methods[1] = {{ VSL(SLT_Debug, 0, fmt, ptr, ptr); \
.magic = VMOD_PRIV_METHODS_MAGIC, } \
.type = "debug_obj_test_priv_task", \
.fini = obj_priv_task_fini static const struct vmod_priv_methods \
}}; xyzzy_obj_test_priv_ ## name ## _methods[1] = {{ \
.magic = VMOD_PRIV_METHODS_MAGIC, \
.type = "debug_obj_test_priv_" #name, \
.fini = obj_priv_ ## name ## _fini \
}};
PRIV_FINI(task)
PRIV_FINI(top)
#undef PRIV_FINI
VCL_STRING v_matchproto_() VCL_STRING v_matchproto_()
xyzzy_obj_test_priv_task(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s) xyzzy_obj_test_priv_task(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s)
...@@ -216,19 +223,6 @@ xyzzy_obj_test_priv_task(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s) ...@@ -216,19 +223,6 @@ xyzzy_obj_test_priv_task(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s)
return (p->priv); return (p->priv);
} }
static void
obj_priv_top_fini(void *ptr)
{
AN(ptr);
VSL(SLT_Debug, 0, "obj_priv_top_fini(%p = \"%s\")", ptr, (char *)ptr);
}
static const struct vmod_priv_methods xyzzy_obj_test_priv_top_methods[1] = {{
.magic = VMOD_PRIV_METHODS_MAGIC,
.type = "debug_obj_test_priv_top",
.fini = obj_priv_top_fini
}};
VCL_STRING v_matchproto_() VCL_STRING v_matchproto_()
xyzzy_obj_test_priv_top(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s) xyzzy_obj_test_priv_top(VRT_CTX, struct xyzzy_debug_obj *o, VCL_STRING s)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment