From: Justin Seyster Date: Thu, 23 Sep 2010 22:36:35 +0000 (-0400) Subject: Added test case for in_param support on all pointcut types. X-Git-Tag: release-v1.0~40^2~1 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=2a706f0252ca20f04218d6fc3ffbc3e4666fbbe2;p=interaspect.git Added test case for in_param support on all pointcut types. --- diff --git a/test/allpc-inparam-hooks.c b/test/allpc-inparam-hooks.c new file mode 100644 index 0000000..78d634a --- /dev/null +++ b/test/allpc-inparam-hooks.c @@ -0,0 +1,17 @@ +#include +#include + +void _advice_assign(int32_t a, double b) +{ + printf("Assign advice: (%d, %f)\n", (int)a, b); +} + +void _advice_printf(int32_t a, double b) +{ + printf("printf advice: (%d, %f)\n", (int)a, b); +} + +void _advice_exit(int32_t a, double b) +{ + printf("Exit advice: (%d, %f)\n", (int)a, b); +} diff --git a/test/allpc-inparam-target.c b/test/allpc-inparam-target.c new file mode 100644 index 0000000..72e3c5e --- /dev/null +++ b/test/allpc-inparam-target.c @@ -0,0 +1,23 @@ +#include +#include + +void foo(int a, double b) +{ + a = a + (int)b; + printf("In foo: (%d, %f)\n", a, b); +} + +/* Nothing in this function should get instrumented by + plugin-inparam-allpc because its parameters don't match the filter + parameters. */ +void bar(int a, int b) +{ + a = a + (int)b; + printf("In foo: (%d, %f)\n", a, (double)b); +} + +void run_test() +{ + foo(12, 1.2); + bar(34, 3.4); +} diff --git a/test/inparam.xml b/test/inparam.xml index de3c1de..1fad808 100644 --- a/test/inparam.xml +++ b/test/inparam.xml @@ -2,6 +2,7 @@ + @@ -14,4 +15,19 @@ void _advice_foo(ALL_SIGNED_T, ALL_FP_T); + + + + Assign advice: (12, 1.200000) + printf advice: (12, 1.200000) + In foo: (13, 1.200000) + Exit advice: (12, 1.200000) + In foo: (37, 3.000000) + + + void _advice_assign(ALL_SIGNED_T, double); + void _advice_exit(ALL_SIGNED_T, double); + void _advice_printf(ALL_SIGNED_T, double); + + diff --git a/test/plugin-allpc-inparam.c b/test/plugin-allpc-inparam.c new file mode 100644 index 0000000..b4f7ae0 --- /dev/null +++ b/test/plugin-allpc-inparam.c @@ -0,0 +1,57 @@ +#include +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static void plugin_join(struct aop_joinpoint *jp, void *data) +{ + const char *advice_name = data; + struct aop_dynval *p1; + struct aop_dynval *p2; + + p1 = aop_capture_in_param(jp, 0); + p2 = aop_capture_in_param(jp, 1); + aop_insert_advice(jp, advice_name, AOP_INSERT_BEFORE, AOP_DYNVAL(p1), AOP_DYNVAL(p2), AOP_TERM_ARG); +} + +static unsigned int plugin_int() +{ + struct aop_pointcut *pc; + + pc = aop_match_assignment_by_type(aop_t_all_signed()); + aop_filter_by_in_param(pc, 0, aop_t_all_signed()); + aop_filter_by_in_param(pc, 1, aop_t_float64()); + aop_join_on(pc, plugin_join, "_advice_assign"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_name(pc, "printf"); + aop_filter_by_in_param(pc, 0, aop_t_all_signed()); + aop_filter_by_in_param(pc, 1, aop_t_float64()); + aop_join_on(pc, plugin_join, "_advice_printf"); + + pc = aop_match_function_exit(); + aop_filter_by_in_param(pc, 0, aop_t_all_signed()); + aop_filter_by_in_param(pc, 1, aop_t_float64()); + aop_join_on(pc, plugin_join, "_advice_exit"); + + 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, NULL, NULL, NULL); + if (res != 0) + perror(header); + } +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("int", plugin_int); +}