From 3d79b931f5758a7706d6847e0a193824171cfd41 Mon Sep 17 00:00:00 2001 From: Justin Seyster Date: Wed, 20 Oct 2010 16:03:51 -0400 Subject: [PATCH] Added test case for passing constants to advice. --- test/Makefile.am | 2 +- test/constants-hooks.c | 7 +++++++ test/constants-target.c | 11 +++++++++++ test/constants.xml | 15 +++++++++++++++ test/plugin-constants.c | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/constants-hooks.c create mode 100644 test/constants-target.c create mode 100644 test/constants.xml create mode 100644 test/plugin-constants.c diff --git a/test/Makefile.am b/test/Makefile.am index 7426101..9f495b8 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 duplicate.xml inparam.xml + reinst.xml noinstrument.xml duplicate.xml inparam.xml constants.xml endif diff --git a/test/constants-hooks.c b/test/constants-hooks.c new file mode 100644 index 0000000..04cc3aa --- /dev/null +++ b/test/constants-hooks.c @@ -0,0 +1,7 @@ +#include +#include + +void _foo_advice(const char *str1, int32_t int1, double double1, void *voidp1, const char *str2) +{ + printf("In advice: %s, %d, %f, %p, %s\n", str1, int1, double1, voidp1, str2); +} diff --git a/test/constants-target.c b/test/constants-target.c new file mode 100644 index 0000000..2527583 --- /dev/null +++ b/test/constants-target.c @@ -0,0 +1,11 @@ +#include + +static void foo() +{ + printf("In foo\n"); +} + +void run_test() +{ + foo(); +} diff --git a/test/constants.xml b/test/constants.xml new file mode 100644 index 0000000..6154a40 --- /dev/null +++ b/test/constants.xml @@ -0,0 +1,15 @@ + + + + + + + + In advice: dead, 10, 2.500000, 0xdeadbeef, beef + In foo + + + void _foo_advice(signed char *, int32_t, double, ALL_POINTER_T, signed char *); + + + diff --git a/test/plugin-constants.c b/test/plugin-constants.c new file mode 100644 index 0000000..05d8b85 --- /dev/null +++ b/test/plugin-constants.c @@ -0,0 +1,41 @@ +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static void plugin_join_on_entry(struct aop_joinpoint *jp, void *data) +{ + double blah = 2.5; + aop_insert_advice(jp, "_foo_advice", AOP_INSERT_BEFORE, AOP_STR_CST("dead"), AOP_INT_CST(10), + AOP_DOUBLE_CST(blah), AOP_VOIDP_CST((void *)0xdeadbeef), AOP_STR_CST("beef"), + AOP_TERM_ARG); +} + +static unsigned int plugin_cst() +{ + struct aop_pointcut *pc; + + pc = aop_match_function_entry(); + aop_filter_entry_by_name(pc, "foo"); + aop_join_on(pc, plugin_join_on_entry, 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, "_INT_HEADER_", NULL, NULL); + if (res != 0) + perror(header); + } +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("cst", plugin_cst); +} -- 2.34.1