Added test case for capturing return value at exit join point.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 21 Oct 2010 03:22:09 +0000 (23:22 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 21 Oct 2010 03:22:09 +0000 (23:22 -0400)
test/Makefile.am
test/plugin-return.c [new file with mode: 0644]
test/return-hooks.c [new file with mode: 0644]
test/return-target.c [new file with mode: 0644]
test/return.xml [new file with mode: 0644]

index 9f495b8a714842f2986333d3fbf01b99127a5e0e..4ef2dfa570ac5e0b5be4683e4cb534ad9bfc4532 100644 (file)
@@ -3,5 +3,6 @@ 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 constants.xml
+       reinst.xml noinstrument.xml duplicate.xml inparam.xml constants.xml \
+       return.xml
 endif
diff --git a/test/plugin-return.c b/test/plugin-return.c
new file mode 100644 (file)
index 0000000..fce9adf
--- /dev/null
@@ -0,0 +1,43 @@
+#include <aop.h>
+#include <stdio.h>
+
+AOP_I_AM_GPL_COMPATIBLE();
+
+static void plugin_join_on_float_exit(struct aop_joinpoint *jp, void *data)
+{
+  struct aop_dynval *retval = aop_capture_exit_return_value(jp);
+  aop_insert_advice(jp, "_float_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(retval), AOP_TERM_ARG);
+}
+
+static void plugin_join_on_string_exit(struct aop_joinpoint *jp, void *data)
+{
+  const struct aop_type *char_star;
+  struct aop_dynval *retval;
+
+  char_star = aop_t_pointer_to(aop_t_signed8());
+
+  retval = aop_capture_exit_return_value_by_type(jp, char_star);
+  if (retval != NULL)
+    aop_insert_advice(jp, "_string_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(retval), AOP_TERM_ARG);
+}
+
+static unsigned int plugin_return()
+{
+  struct aop_pointcut *pc;
+
+  pc = aop_match_function_exit();
+  aop_filter_exit_by_return_type(pc, aop_t_all_fp());
+  aop_join_on(pc, plugin_join_on_float_exit, NULL);
+
+  pc = aop_match_function_exit();
+  /* Do the filtering inside the join iterator instead. */
+  /* aop_filter_exit_by_return_type(pc, char_star); */
+  aop_join_on(pc, plugin_join_on_string_exit, NULL);
+
+  return 0;
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("return", plugin_return);
+}
diff --git a/test/return-hooks.c b/test/return-hooks.c
new file mode 100644 (file)
index 0000000..595b28c
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+void _string_advice(const char *str)
+{
+  printf("In string advice: %s\n", str);
+}
+
+void _float_advice(double num)
+{
+  printf("In float advice: %f\n", num);
+}
diff --git a/test/return-target.c b/test/return-target.c
new file mode 100644 (file)
index 0000000..2d4b5fc
--- /dev/null
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+static const char *foo()
+{
+  return "bro";
+}
+
+static float bar()
+{
+  return 1.2;
+}
+
+void run_test()
+{
+  printf("Don't tase me, %s.  %f\n",  foo(), (double)bar());
+}
diff --git a/test/return.xml b/test/return.xml
new file mode 100644 (file)
index 0000000..4c0d1b3
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="Return Values">
+  <plugin id="plugin-return" source="plugin-return.c" />
+  <run name="Capturing return value from exit join point" target="return-target.c" hooks="return-hooks.c">
+    <using plugin="plugin-return" />
+    <output>
+      In float advice: 1.200000
+      In string advice: bro
+      Don't tase me, bro.  1.200000
+    </output>
+  </run>
+</testcase>