Added test case for in_param support on all pointcut types.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 23 Sep 2010 22:36:35 +0000 (18:36 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 23 Sep 2010 22:36:35 +0000 (18:36 -0400)
test/allpc-inparam-hooks.c [new file with mode: 0644]
test/allpc-inparam-target.c [new file with mode: 0644]
test/inparam.xml
test/plugin-allpc-inparam.c [new file with mode: 0644]

diff --git a/test/allpc-inparam-hooks.c b/test/allpc-inparam-hooks.c
new file mode 100644 (file)
index 0000000..78d634a
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdint.h>
+#include <stdio.h>
+
+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 (file)
index 0000000..72e3c5e
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdint.h>
+#include <stdio.h>
+
+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);
+}
index de3c1de0b9c875a909173ada722620ed6f2d05fc..1fad808ae389ad6b9cc5537f6198c0a41dac62e7 100644 (file)
@@ -2,6 +2,7 @@
 <!DOCTYPE testcase SYSTEM "testcase.dtd">
 <testcase name="In params">
   <plugin id="plugin-inparam" source="plugin-inparam.c" />
+  <plugin id="plugin-allpc-inparam" source="plugin-allpc-inparam.c" />
   <run name="Entry parameter capture" target="inparam-target.c" hooks="inparam-hooks.c">
     <using plugin="plugin-inparam" />
     <output>
       void _advice_foo(ALL_SIGNED_T, ALL_FP_T);
     </prototypes>
   </run>
+  <run name="Entry parameter capture" target="allpc-inparam-target.c" hooks="allpc-inparam-hooks.c">
+    <using plugin="plugin-allpc-inparam" />
+    <output>
+      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)
+    </output>
+    <prototypes>
+      void _advice_assign(ALL_SIGNED_T, double);
+      void _advice_exit(ALL_SIGNED_T, double);
+      void _advice_printf(ALL_SIGNED_T, double);
+    </prototypes>
+  </run>
 </testcase>
diff --git a/test/plugin-allpc-inparam.c b/test/plugin-allpc-inparam.c
new file mode 100644 (file)
index 0000000..b4f7ae0
--- /dev/null
@@ -0,0 +1,57 @@
+#include <aop.h>
+#include <stdio.h>
+#include <string.h>
+
+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);
+}