From 47625978d8c7ec47615175850fd5fc10dd83f209 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Thu, 2 Sep 2010 18:20:20 -0400 Subject: [PATCH] Added pointer types test case. --- test/Makefile.am | 2 +- test/plugin-pointer-types.c | 69 +++++++++++++++++++++++++++++++++++++ test/pointer-types-hooks.c | 50 +++++++++++++++++++++++++++ test/pointer-types-target.c | 39 +++++++++++++++++++++ test/pointer-types.xml | 24 +++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 test/plugin-pointer-types.c create mode 100644 test/pointer-types-hooks.c create mode 100644 test/pointer-types-target.c create mode 100644 test/pointer-types.xml diff --git a/test/Makefile.am b/test/Makefile.am index 60cfc79..aeb7429 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,5 +2,5 @@ if HAVE_PYTHON TESTS_ENVIRONMENT = $(PYTHON) $(srcdir)/run-testcase.py --with-gcc=$(CC) \ --with-ia-lib-dir=$(top_builddir)/src/.libs \ --with-ia-src-dir=$(top_srcdir) --with-tests-dir=$(srcdir) -TESTS = int-types.xml float-types.xml +TESTS = int-types.xml float-types.xml pointer-types.xml endif diff --git a/test/plugin-pointer-types.c b/test/plugin-pointer-types.c new file mode 100644 index 0000000..3a9a0f0 --- /dev/null +++ b/test/plugin-pointer-types.c @@ -0,0 +1,69 @@ +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static void plugin_join_on_call(struct aop_joinpoint *jp, void *data) +{ + const char *advice_name = data; + const char *func; + const char *called; + struct aop_dynval *p; + + func = aop_capture_function_name(jp); + if (func == NULL || strcmp(func, "run_test") != 0) + return; + + called = aop_capture_called_function_name(jp); + + if (called == NULL || *called != '_') { + p = aop_capture_param(jp, 0); + aop_insert_advice(jp, advice_name, AOP_INSERT_BEFORE, AOP_STR_CST(called), AOP_DYNVAL(p), AOP_TERM_ARG); + } +} + +static unsigned int plugin_pointer() +{ + struct aop_pointcut *pc; + + const struct aop_type *intp; + const struct aop_type *intpp; + const struct aop_type *intppp; + const struct aop_type *char_star; + + intp = aop_t_pointer_to(aop_t_signed32()); + intpp = aop_t_pointer_to(intp); + intppp = aop_t_pointer_to(intpp); + char_star = aop_t_pointer_to(aop_t_signed8()); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, intp); + aop_join_on(pc, plugin_join_on_call, "_advice_p"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, intpp); + aop_join_on(pc, plugin_join_on_call, "_advice_pp"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, intppp); + aop_join_on(pc, plugin_join_on_call, "_advice_ppp"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, char_star); + aop_join_on(pc, plugin_join_on_call, "_advice_c_str"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_all_pointer()); + aop_join_on(pc, plugin_join_on_call, "_advice_any_ptr"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_pointer_to(aop_t_all_pointer())); + aop_join_on(pc, plugin_join_on_call, "_advice_any_ptr_ptr"); + + return 0; +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("float", plugin_pointer); +} diff --git a/test/pointer-types-hooks.c b/test/pointer-types-hooks.c new file mode 100644 index 0000000..eb2cbc6 --- /dev/null +++ b/test/pointer-types-hooks.c @@ -0,0 +1,50 @@ +#include + +extern int n; +extern int *p1; +extern int **p2; +extern int ***p3; + +static const char *pointer_name(void *ptr) +{ + if (ptr == &n) + return "&n"; + else if (ptr == &p1) + return "&p1"; + else if (ptr == &p2) + return "&p2"; + else if (ptr == &p3) + return "&p3"; + else + return "other pointer"; +} + +void _advice_p(const char *func, int *p) +{ + printf("In int * advice (%s): %d\n", func, *p); +} + +void _advice_pp(const char *func, int **p) +{ + printf("In int ** advice (%s): %d\n", func, **p); +} + +void _advice_ppp(const char *func, int ***p) +{ + printf("In int *** advice (%s): %d\n", func, ***p); +} + +void _advice_c_str(const char *func, const char *str) +{ + printf("In str advice (%s): %s\n", func, str); +} + +void _advice_any_ptr(const char *func, void *p) +{ + printf("In void * advice (%s): %s\n", func, pointer_name(p)); +} + +void _advice_any_ptr_ptr(const char *func, void **p) +{ + printf("In void ** advice (%s): %s\n", func, pointer_name(*p)); +} diff --git a/test/pointer-types-target.c b/test/pointer-types-target.c new file mode 100644 index 0000000..7d1c01b --- /dev/null +++ b/test/pointer-types-target.c @@ -0,0 +1,39 @@ +#include + +int n; +int *p1; +int **p2; +int ***p3; + +void intp(int *p) +{ + printf("int *: %d\n", *p); +} + +void intpp(int **p) +{ + printf("int **: %d\n", **p); +} + +void intppp(int ***p) +{ + printf("int ***: %d\n", ***p); +} + +void c_str(const char *str) +{ + printf("str: %s\n", str); +} + +void run_test() +{ + n = 1337; + p1 = &n; + p2 = &p1; + p3 = &p2; + + intp(p1); + intpp(p2); + intppp(p3); + c_str("h4x0r"); +} diff --git a/test/pointer-types.xml b/test/pointer-types.xml new file mode 100644 index 0000000..2bea475 --- /dev/null +++ b/test/pointer-types.xml @@ -0,0 +1,24 @@ + + + + + + + + In int * advice (intp): 1337 + In void * advice (intp): &n + int *: 1337 + In int ** advice (intpp): 1337 + In void * advice (intpp): &p1 + In void ** advice (intpp): &n + int **: 1337 + In int *** advice (intppp): 1337 + In void * advice (intppp): &p2 + In void ** advice (intppp): &p1 + int ***: 1337 + In str advice (c_str): h4x0r + In void * advice (c_str): other pointer + str: h4x0r + + + -- 2.43.0