Added struct/union/enum types test.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 2 Sep 2010 22:24:20 +0000 (18:24 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 2 Sep 2010 22:24:20 +0000 (18:24 -0400)
test/Makefile.am
test/plugin-struct-types.c [new file with mode: 0644]
test/struct-types-hooks.c [new file with mode: 0644]
test/struct-types-target.c [new file with mode: 0644]
test/struct-types.xml [new file with mode: 0644]

index aeb742907dc0d326c7f5c6a928fa1e8d0abd0e1e..ccc4cffcee1cd870025f027e06106889fbf442fa 100644 (file)
@@ -2,5 +2,5 @@ if HAVE_PYTHON
 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
+TESTS = int-types.xml float-types.xml pointer-types.xml struct-types.xml
 endif
diff --git a/test/plugin-struct-types.c b/test/plugin-struct-types.c
new file mode 100644 (file)
index 0000000..870ef68
--- /dev/null
@@ -0,0 +1,48 @@
+#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;
+  const char *name;
+  struct aop_dynval *n;
+
+  name = aop_capture_called_function_name(jp);
+  n = aop_capture_param(jp, 0);
+  aop_insert_advice(jp, advice_name, AOP_INSERT_BEFORE, AOP_STR_CST(name), AOP_DYNVAL(n), AOP_DYNVAL(n), AOP_TERM_ARG);
+}
+
+static unsigned int plugin_struct()
+{
+  struct aop_pointcut *pc;
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_struct("foo"));
+  aop_join_on(pc, plugin_join_on_call, "_advice_struct");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_union("bar"));
+  aop_join_on(pc, plugin_join_on_call, "_advice_union");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_enum("baz"));
+  aop_join_on(pc, plugin_join_on_call, "_advice_enum");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_struct_ptr("foo"));
+  aop_join_on(pc, plugin_join_on_call, "_advice_struct_ptr");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_pointer_to(aop_t_union("bar")));
+  aop_join_on(pc, plugin_join_on_call, "_advice_union_ptr");
+
+  return 0;
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("struct", plugin_struct);
+}
diff --git a/test/struct-types-hooks.c b/test/struct-types-hooks.c
new file mode 100644 (file)
index 0000000..2045075
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdio.h>
+
+struct foo
+{
+  int a;
+  double b;
+};
+
+union bar
+{
+  int a;
+  double b;
+};
+
+enum baz
+{
+  FOO,
+  BAR,
+  BAZ,
+};
+
+void _advice_struct(const char *func, struct foo foo1, struct foo foo2)
+{
+  printf("struct advice (%s): %d, %f -- %d, %f\n", func, foo1.a, foo1.b, foo2.a, foo2.b);
+}
+
+void _advice_union(const char *func, union bar bar1, union bar bar2)
+{
+  printf("union advice (%s): %d, %f -- %d, %f\n", func, bar1.a, bar1.b, bar2.a, bar2.b);
+}
+
+void _advice_enum(const char *func, enum baz baz1, enum baz baz2)
+{
+  printf("enum advice (%s): %d, %d\n", func, (int)baz1, (int)baz2);
+}
+
+void _advice_struct_ptr(const char *func, struct foo *foo1, struct foo *foo2)
+{
+  printf("struct * advice (%s): %d, %f -- %d, %f\n", func, foo1->a, foo1->b, foo2->a, foo2->b);
+}
+
+void _advice_union_ptr(const char *func, union bar *bar1, union bar *bar2)
+{
+  printf("union * advice (%s): %d, %f -- %d, %f\n", func, bar1->a, bar1->b, bar2->a, bar2->b);
+}
diff --git a/test/struct-types-target.c b/test/struct-types-target.c
new file mode 100644 (file)
index 0000000..0b40e11
--- /dev/null
@@ -0,0 +1,63 @@
+#include <stdio.h>
+
+struct foo
+{
+  int a;
+  double b;
+};
+
+union bar
+{
+  int a;
+  double b;
+};
+
+enum baz
+{
+  FOO,
+  BAR,
+  BAZ,
+};
+
+static void struct_func(struct foo foo)
+{
+  printf("struct: %d, %f\n", foo.a, foo.b);
+}
+
+static void union_func(union bar bar)
+{
+  printf("union: %d, %f\n", bar.a, bar.b);
+}
+
+static void enum_func(enum baz baz)
+{
+  printf("enum: %d\n", (int)baz);
+}
+
+static void struct_func_ptr(struct foo *foo)
+{
+  printf("struct *: %d, %f\n", foo->a, foo->b);
+}
+
+static void union_func_ptr(union bar *bar)
+{
+  printf("union: %d, %f\n", bar->a, bar->b);
+}
+
+void run_test()
+{
+  struct foo foo;
+  union bar bar;
+
+  foo.a = 808;
+  foo.b = 8.08;
+
+  bar.b = 1.1;
+
+  struct_func(foo);
+  union_func(bar);
+  enum_func(BAZ);
+
+  struct_func_ptr(&foo);
+  union_func_ptr(&bar);
+}
diff --git a/test/struct-types.xml b/test/struct-types.xml
new file mode 100644 (file)
index 0000000..5d53994
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="Struct, Union, and Enum Types">
+  <plugin id="plugin-struct-types" source="plugin-struct-types.c" />
+  <run name="Struct/union/enum parameter captures" target="struct-types-target.c" hooks="struct-types-hooks.c">
+    <using plugin="plugin-struct-types" />
+    <output>
+      struct advice (struct_func): 808, 8.080000 -- 808, 8.080000
+      struct: 808, 8.080000
+      union advice (union_func): -1717986918, 1.100000 -- -1717986918, 1.100000
+      union: -1717986918, 1.100000
+      enum advice (enum_func): 2, 2
+      enum: 2
+      struct * advice (struct_func_ptr): 808, 8.080000 -- 808, 8.080000
+      struct *: 808, 8.080000
+      union * advice (union_func_ptr): -1717986918, 1.100000 -- -1717986918, 1.100000
+      union: -1717986918, 1.100000
+    </output>
+  </run>
+</testcase>