From: Justin Seyster Date: Mon, 7 Feb 2011 21:06:58 +0000 (-0500) Subject: Added test case for dynval casting. X-Git-Tag: release-v1.1~9^2~30 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=8317bc2d983dca17dbd968857c825c8808c8cfc1;p=interaspect.git Added test case for dynval casting. --- diff --git a/test/Makefile.am b/test/Makefile.am index 4ef2dfa..08ccc93 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -4,5 +4,5 @@ TESTS_ENVIRONMENT = $(PYTHON) $(srcdir)/run-testcase.py --with-gcc=$(CC) \ --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 \ - return.xml + return.xml cast.xml endif diff --git a/test/cast-hooks.c b/test/cast-hooks.c new file mode 100644 index 0000000..81ce142 --- /dev/null +++ b/test/cast-hooks.c @@ -0,0 +1,7 @@ +#include +#include + +void _advice(void *param) +{ + printf("In advice function: %s\n", *(const char **)param); +} diff --git a/test/cast-target.c b/test/cast-target.c new file mode 100644 index 0000000..1547bb7 --- /dev/null +++ b/test/cast-target.c @@ -0,0 +1,30 @@ +#include + +struct foo { + const char *common; + int a; +}; + +struct bar { + const char *common; + double a; +}; + +void print_foo(struct foo *foo) +{ + printf("foo: %d\n", foo->a); +} + +void print_bar(struct bar *bar) +{ + printf("bar: %f\n", bar->a); +} + +void run_test() +{ + struct foo foo = { "l33t", 1337 }; + struct bar bar = { "h4x0r", 1.337 }; + + print_foo(&foo); + print_bar(&bar); +} diff --git a/test/cast.xml b/test/cast.xml new file mode 100644 index 0000000..7e2528c --- /dev/null +++ b/test/cast.xml @@ -0,0 +1,17 @@ + + + + + + + + In advice function: l33t + foo: 1337 + In advice function: h4x0r + bar: 1.337000 + + + void _advice(ALL_POINTER_T); + + + diff --git a/test/plugin-cast.c b/test/plugin-cast.c new file mode 100644 index 0000000..4c5f587 --- /dev/null +++ b/test/plugin-cast.c @@ -0,0 +1,55 @@ +#include +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static void plugin_join_on_call(struct aop_joinpoint *jp, void *data) +{ + struct aop_dynval *param; + + param = aop_capture_call_param(jp, 0); + aop_assert(aop_is_pointer_type(aop_get_dynval_type(param))); + aop_cast_to_all_pointer(param); + + aop_insert_advice(jp, "_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(param), AOP_TERM_ARG); +} + +static unsigned int plugin_cast() +{ + struct aop_pointcut *pc; + + const struct aop_type *foo_type; + const struct aop_type *bar_type; + + foo_type = aop_t_struct_ptr("foo"); + bar_type = aop_t_struct_ptr("bar"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, foo_type); + aop_join_on(pc, plugin_join_on_call, NULL); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, bar_type); + aop_join_on(pc, plugin_join_on_call, NULL); + + return 0; +} + +void aop_finish() +{ + const char *header; + header = aop_get_arg_value("header"); + + if (header != NULL) { + int res; + res = aop_write_c_header(header, "_CAST_HEADER_", NULL, NULL); + if (res != 0) + perror(header); + } +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("cast", plugin_cast); +}