From 8004db9c12483f4984857e15cb6cbc63054f4f5c Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Wed, 20 Oct 2010 23:22:09 -0400 Subject: [PATCH] Added test case for capturing return value at exit join point. --- test/Makefile.am | 3 ++- test/plugin-return.c | 43 +++++++++++++++++++++++++++++++++++++++++++ test/return-hooks.c | 11 +++++++++++ test/return-target.c | 16 ++++++++++++++++ test/return.xml | 13 +++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 test/plugin-return.c create mode 100644 test/return-hooks.c create mode 100644 test/return-target.c create mode 100644 test/return.xml diff --git a/test/Makefile.am b/test/Makefile.am index 9f495b8..4ef2dfa 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -3,5 +3,6 @@ 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 pointer-types.xml struct-types.xml \ - reinst.xml noinstrument.xml duplicate.xml inparam.xml constants.xml + reinst.xml noinstrument.xml duplicate.xml inparam.xml constants.xml \ + return.xml endif diff --git a/test/plugin-return.c b/test/plugin-return.c new file mode 100644 index 0000000..fce9adf --- /dev/null +++ b/test/plugin-return.c @@ -0,0 +1,43 @@ +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static void plugin_join_on_float_exit(struct aop_joinpoint *jp, void *data) +{ + struct aop_dynval *retval = aop_capture_exit_return_value(jp); + aop_insert_advice(jp, "_float_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(retval), AOP_TERM_ARG); +} + +static void plugin_join_on_string_exit(struct aop_joinpoint *jp, void *data) +{ + const struct aop_type *char_star; + struct aop_dynval *retval; + + char_star = aop_t_pointer_to(aop_t_signed8()); + + retval = aop_capture_exit_return_value_by_type(jp, char_star); + if (retval != NULL) + aop_insert_advice(jp, "_string_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(retval), AOP_TERM_ARG); +} + +static unsigned int plugin_return() +{ + struct aop_pointcut *pc; + + pc = aop_match_function_exit(); + aop_filter_exit_by_return_type(pc, aop_t_all_fp()); + aop_join_on(pc, plugin_join_on_float_exit, NULL); + + pc = aop_match_function_exit(); + /* Do the filtering inside the join iterator instead. */ + /* aop_filter_exit_by_return_type(pc, char_star); */ + aop_join_on(pc, plugin_join_on_string_exit, NULL); + + return 0; +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("return", plugin_return); +} diff --git a/test/return-hooks.c b/test/return-hooks.c new file mode 100644 index 0000000..595b28c --- /dev/null +++ b/test/return-hooks.c @@ -0,0 +1,11 @@ +#include + +void _string_advice(const char *str) +{ + printf("In string advice: %s\n", str); +} + +void _float_advice(double num) +{ + printf("In float advice: %f\n", num); +} diff --git a/test/return-target.c b/test/return-target.c new file mode 100644 index 0000000..2d4b5fc --- /dev/null +++ b/test/return-target.c @@ -0,0 +1,16 @@ +#include + +static const char *foo() +{ + return "bro"; +} + +static float bar() +{ + return 1.2; +} + +void run_test() +{ + printf("Don't tase me, %s. %f\n", foo(), (double)bar()); +} diff --git a/test/return.xml b/test/return.xml new file mode 100644 index 0000000..4c0d1b3 --- /dev/null +++ b/test/return.xml @@ -0,0 +1,13 @@ + + + + + + + + In float advice: 1.200000 + In string advice: bro + Don't tase me, bro. 1.200000 + + + -- 2.34.1