Added duplication test case.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 9 Sep 2010 00:34:13 +0000 (20:34 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 9 Sep 2010 00:34:13 +0000 (20:34 -0400)
test/Makefile.am
test/duplicate-hooks.c [new file with mode: 0644]
test/duplicate-target.c [new file with mode: 0644]
test/duplicate.xml [new file with mode: 0644]
test/plugin-duplicate.c [new file with mode: 0644]

index 8add3574591698f62484b24065f3705c766d073b..d600a10f220ac233ebb15420610726d9ba507201 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
+       reinst.xml noinstrument.xml duplicate.xml
 endif
diff --git a/test/duplicate-hooks.c b/test/duplicate-hooks.c
new file mode 100644 (file)
index 0000000..e7c601f
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+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 (file)
index 0000000..c7db8ca
--- /dev/null
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+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 (file)
index 0000000..e60fc24
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="Duplication">
+  <plugin id="plugin-duplicate" source="plugin-duplicate.c" />
+  <run name="Duplicated function" target="duplicate-target.c" hooks="duplicate-hooks.c">
+    <using plugin="plugin-duplicate" />
+    <output>
+      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
+    </output>
+  </run>
+</testcase>
diff --git a/test/plugin-duplicate.c b/test/plugin-duplicate.c
new file mode 100644 (file)
index 0000000..53658f9
--- /dev/null
@@ -0,0 +1,75 @@
+#include <aop.h>
+#include <stdio.h>
+#include <string.h>
+
+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);
+}