From 5c1a4982b7dbde694e12a971c5851f969f206086 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Wed, 8 Sep 2010 20:34:13 -0400 Subject: [PATCH] Added duplication test case. --- test/Makefile.am | 2 +- test/duplicate-hooks.c | 28 +++++++++++++++ test/duplicate-target.c | 24 +++++++++++++ test/duplicate.xml | 21 ++++++++++++ test/plugin-duplicate.c | 75 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 test/duplicate-hooks.c create mode 100644 test/duplicate-target.c create mode 100644 test/duplicate.xml create mode 100644 test/plugin-duplicate.c diff --git a/test/Makefile.am b/test/Makefile.am index 8add357..d600a10 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -3,5 +3,5 @@ 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 + reinst.xml noinstrument.xml duplicate.xml endif diff --git a/test/duplicate-hooks.c b/test/duplicate-hooks.c new file mode 100644 index 0000000..e7c601f --- /dev/null +++ b/test/duplicate-hooks.c @@ -0,0 +1,28 @@ +#include + +int _distrib() +{ + static int n = 0; + + return (n++ % 2); +} + +void _bar_advice() +{ + printf("In bar advice!\n"); +} + +void _assign_advice() +{ + printf("In assign advice!\n"); +} + +void _entry_advice(const char *name, int lineno) +{ + printf("In entry advice: %s (line %d)\n", name, lineno); +} + +void _exit_advice(const char *name) +{ + printf("In exit advice: %s\n", name); +} diff --git a/test/duplicate-target.c b/test/duplicate-target.c new file mode 100644 index 0000000..c7db8ca --- /dev/null +++ b/test/duplicate-target.c @@ -0,0 +1,24 @@ +#include + +void bar(int a) +{ + printf("In bar: %d!\n", a); +} + +/* The duplication plug-in duplicates this funcion and puts different + instrumentation in each copy. */ +void foo(int b) +{ + int a = 10; + b = a; + + bar(a); +} + +int run_test() +{ + foo(5); + foo(6); + + return 0; +} diff --git a/test/duplicate.xml b/test/duplicate.xml new file mode 100644 index 0000000..e60fc24 --- /dev/null +++ b/test/duplicate.xml @@ -0,0 +1,21 @@ + + + + + + + + In entry advice: Before distributor (line 12) + In entry advice: Zero (line 12) + In bar advice! + In bar: 10! + In exit advice: Zero + In entry advice: Before distributor (line 12) + In entry advice: One (line 12) + In assign advice! + In assign advice! + In bar: 10! + In exit advice: One + + + diff --git a/test/plugin-duplicate.c b/test/plugin-duplicate.c new file mode 100644 index 0000000..53658f9 --- /dev/null +++ b/test/plugin-duplicate.c @@ -0,0 +1,75 @@ +#include +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +int duplicated = 0; + +static void plugin_join_on_entry(struct aop_joinpoint *jp, void *data) +{ + const char *name; + + name = aop_capture_function_name(jp); + if (name != NULL && strcmp(name, "foo") == 0) { + aop_duplicate(jp, "_distrib", AOP_TERM_ARG); + duplicated = 1; + } + else { + duplicated = 0; + } +} + +static void plugin_join_on_bar(struct aop_joinpoint *jp, void *data) +{ + aop_insert_advice(jp, "_bar_advice", AOP_INSERT_BEFORE, AOP_TERM_ARG); +} + +static void plugin_join_on_assign(struct aop_joinpoint *jp, void *data) +{ + aop_insert_advice(jp, "_assign_advice", AOP_INSERT_BEFORE, AOP_TERM_ARG); +} + +static void plugin_join_on_entry2(struct aop_joinpoint *jp, void *data) +{ + int line = aop_capture_lineno(jp); + aop_insert_advice(jp, "_entry_advice", AOP_INSERT_BEFORE, AOP_STR_CST((const char *)data), AOP_INT_CST(line), AOP_TERM_ARG); +} + +static void plugin_join_on_exit(struct aop_joinpoint *jp, void *data) +{ + aop_insert_advice(jp, "_exit_advice", AOP_INSERT_BEFORE, AOP_STR_CST((const char *)data), AOP_TERM_ARG); +} + +static unsigned int plugin_duplicate() +{ + struct aop_pointcut *pc; + + pc = aop_match_function_entry(); + aop_join_on(pc, plugin_join_on_entry, NULL); + + if (duplicated) { + pc = aop_match_function_call(); + aop_filter_call_pc_by_name(pc, "bar"); + aop_join_on_copy(pc, 0, plugin_join_on_bar, NULL); + + pc = aop_match_assignment_by_type(aop_t_all_signed()); + aop_join_on_copy(pc, 1, plugin_join_on_assign, NULL); + + pc = aop_match_function_entry(); + aop_join_on_copy(pc, 0, plugin_join_on_entry2, "Zero"); + aop_join_on_copy(pc, 1, plugin_join_on_entry2, "One"); + aop_join_on(pc, plugin_join_on_entry2, "Before distributor"); + + pc = aop_match_function_exit(); + aop_join_on_copy(pc, 0, plugin_join_on_exit, "Zero"); + aop_join_on_copy(pc, 1, plugin_join_on_exit, "One"); + } + + return 0; +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("duplicate", plugin_duplicate); +} -- 2.43.0