From: Justin Seyster Date: Thu, 2 Sep 2010 22:24:20 +0000 (-0400) Subject: Added struct/union/enum types test. X-Git-Tag: release-v1.0~49^2 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=fdb32a7f6eb420659c0e6f958c3f292b1768a1d9;p=interaspect.git Added struct/union/enum types test. --- diff --git a/test/Makefile.am b/test/Makefile.am index aeb7429..ccc4cff 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 pointer-types.xml +TESTS = int-types.xml float-types.xml pointer-types.xml struct-types.xml endif diff --git a/test/plugin-struct-types.c b/test/plugin-struct-types.c new file mode 100644 index 0000000..870ef68 --- /dev/null +++ b/test/plugin-struct-types.c @@ -0,0 +1,48 @@ +#include +#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 *name; + struct aop_dynval *n; + + name = aop_capture_called_function_name(jp); + n = aop_capture_param(jp, 0); + aop_insert_advice(jp, advice_name, AOP_INSERT_BEFORE, AOP_STR_CST(name), AOP_DYNVAL(n), AOP_DYNVAL(n), AOP_TERM_ARG); +} + +static unsigned int plugin_struct() +{ + struct aop_pointcut *pc; + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_struct("foo")); + aop_join_on(pc, plugin_join_on_call, "_advice_struct"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_union("bar")); + aop_join_on(pc, plugin_join_on_call, "_advice_union"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_enum("baz")); + aop_join_on(pc, plugin_join_on_call, "_advice_enum"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_struct_ptr("foo")); + aop_join_on(pc, plugin_join_on_call, "_advice_struct_ptr"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_pointer_to(aop_t_union("bar"))); + aop_join_on(pc, plugin_join_on_call, "_advice_union_ptr"); + + return 0; +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("struct", plugin_struct); +} diff --git a/test/struct-types-hooks.c b/test/struct-types-hooks.c new file mode 100644 index 0000000..2045075 --- /dev/null +++ b/test/struct-types-hooks.c @@ -0,0 +1,45 @@ +#include + +struct foo +{ + int a; + double b; +}; + +union bar +{ + int a; + double b; +}; + +enum baz +{ + FOO, + BAR, + BAZ, +}; + +void _advice_struct(const char *func, struct foo foo1, struct foo foo2) +{ + printf("struct advice (%s): %d, %f -- %d, %f\n", func, foo1.a, foo1.b, foo2.a, foo2.b); +} + +void _advice_union(const char *func, union bar bar1, union bar bar2) +{ + printf("union advice (%s): %d, %f -- %d, %f\n", func, bar1.a, bar1.b, bar2.a, bar2.b); +} + +void _advice_enum(const char *func, enum baz baz1, enum baz baz2) +{ + printf("enum advice (%s): %d, %d\n", func, (int)baz1, (int)baz2); +} + +void _advice_struct_ptr(const char *func, struct foo *foo1, struct foo *foo2) +{ + printf("struct * advice (%s): %d, %f -- %d, %f\n", func, foo1->a, foo1->b, foo2->a, foo2->b); +} + +void _advice_union_ptr(const char *func, union bar *bar1, union bar *bar2) +{ + printf("union * advice (%s): %d, %f -- %d, %f\n", func, bar1->a, bar1->b, bar2->a, bar2->b); +} diff --git a/test/struct-types-target.c b/test/struct-types-target.c new file mode 100644 index 0000000..0b40e11 --- /dev/null +++ b/test/struct-types-target.c @@ -0,0 +1,63 @@ +#include + +struct foo +{ + int a; + double b; +}; + +union bar +{ + int a; + double b; +}; + +enum baz +{ + FOO, + BAR, + BAZ, +}; + +static void struct_func(struct foo foo) +{ + printf("struct: %d, %f\n", foo.a, foo.b); +} + +static void union_func(union bar bar) +{ + printf("union: %d, %f\n", bar.a, bar.b); +} + +static void enum_func(enum baz baz) +{ + printf("enum: %d\n", (int)baz); +} + +static void struct_func_ptr(struct foo *foo) +{ + printf("struct *: %d, %f\n", foo->a, foo->b); +} + +static void union_func_ptr(union bar *bar) +{ + printf("union: %d, %f\n", bar->a, bar->b); +} + +void run_test() +{ + struct foo foo; + union bar bar; + + foo.a = 808; + foo.b = 8.08; + + bar.b = 1.1; + + struct_func(foo); + union_func(bar); + enum_func(BAZ); + + struct_func_ptr(&foo); + union_func_ptr(&bar); +} diff --git a/test/struct-types.xml b/test/struct-types.xml new file mode 100644 index 0000000..5d53994 --- /dev/null +++ b/test/struct-types.xml @@ -0,0 +1,20 @@ + + + + + + + + struct advice (struct_func): 808, 8.080000 -- 808, 8.080000 + struct: 808, 8.080000 + union advice (union_func): -1717986918, 1.100000 -- -1717986918, 1.100000 + union: -1717986918, 1.100000 + enum advice (enum_func): 2, 2 + enum: 2 + struct * advice (struct_func_ptr): 808, 8.080000 -- 808, 8.080000 + struct *: 808, 8.080000 + union * advice (union_func_ptr): -1717986918, 1.100000 -- -1717986918, 1.100000 + union: -1717986918, 1.100000 + + +