Added test case for inparams.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 23 Sep 2010 00:24:27 +0000 (20:24 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 23 Sep 2010 00:24:27 +0000 (20:24 -0400)
test/Makefile.am
test/inparam-hooks.c [new file with mode: 0644]
test/inparam-target.c [new file with mode: 0644]
test/inparam.xml [new file with mode: 0644]
test/plugin-inparam.c [new file with mode: 0644]

index d600a10f220ac233ebb15420610726d9ba507201..7426101b7339cdf3dc35aa3ea374bb8e78f8b13b 100644 (file)
@@ -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
+       reinst.xml noinstrument.xml duplicate.xml inparam.xml
 endif
diff --git a/test/inparam-hooks.c b/test/inparam-hooks.c
new file mode 100644 (file)
index 0000000..5e51636
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdint.h>
+#include <stdio.h>
+
+void _advice_foo(int64_t a, double b)
+{
+  printf("Foo entry advice: (%d, %f)\n", (int)a, (double)b);
+}
diff --git a/test/inparam-target.c b/test/inparam-target.c
new file mode 100644 (file)
index 0000000..c8af30b
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+void foo(int a, float b)
+{
+  printf("In foo: (%d, %f)\n", a, (double)b);
+}
+
+void run_test()
+{
+  foo(12, 1.2);
+  foo(34, 3.4);
+}
diff --git a/test/inparam.xml b/test/inparam.xml
new file mode 100644 (file)
index 0000000..de3c1de
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="In params">
+  <plugin id="plugin-inparam" source="plugin-inparam.c" />
+  <run name="Entry parameter capture" target="inparam-target.c" hooks="inparam-hooks.c">
+    <using plugin="plugin-inparam" />
+    <output>
+      Foo entry advice: (12, 1.200000)
+      In foo: (12, 1.200000)
+      Foo entry advice: (34, 3.400000)
+      In foo: (34, 3.400000)
+    </output>
+    <prototypes>
+      void _advice_foo(ALL_SIGNED_T, ALL_FP_T);
+    </prototypes>
+  </run>
+</testcase>
diff --git a/test/plugin-inparam.c b/test/plugin-inparam.c
new file mode 100644 (file)
index 0000000..bb08381
--- /dev/null
@@ -0,0 +1,47 @@
+#include <aop.h>
+#include <stdio.h>
+#include <string.h>
+
+AOP_I_AM_GPL_COMPATIBLE();
+
+static void plugin_join_on_call(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_function_entry();
+  aop_filter_entry_by_name(pc, "foo");
+  aop_filter_entry_by_in_param(pc, 0, aop_t_all_signed());
+  aop_filter_entry_by_in_param(pc, 1, aop_t_all_fp());
+  aop_join_on(pc, plugin_join_on_call, "_advice_foo");
+
+  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);
+}