Added test case for dynval casting.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 7 Feb 2011 21:06:58 +0000 (16:06 -0500)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Mon, 7 Feb 2011 21:06:58 +0000 (16:06 -0500)
test/Makefile.am
test/cast-hooks.c [new file with mode: 0644]
test/cast-target.c [new file with mode: 0644]
test/cast.xml [new file with mode: 0644]
test/plugin-cast.c [new file with mode: 0644]

index 4ef2dfa570ac5e0b5be4683e4cb534ad9bfc4532..08ccc93c9d0542f4994aa0eb9892170ade5ba148 100644 (file)
@@ -4,5 +4,5 @@ TESTS_ENVIRONMENT = $(PYTHON) $(srcdir)/run-testcase.py --with-gcc=$(CC) \
        --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 \
-       return.xml
+       return.xml cast.xml
 endif
diff --git a/test/cast-hooks.c b/test/cast-hooks.c
new file mode 100644 (file)
index 0000000..81ce142
--- /dev/null
@@ -0,0 +1,7 @@
+#include <inttypes.h>
+#include <stdio.h>
+
+void _advice(void *param)
+{
+  printf("In advice function: %s\n", *(const char **)param);
+}
diff --git a/test/cast-target.c b/test/cast-target.c
new file mode 100644 (file)
index 0000000..1547bb7
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+struct foo {
+  const char *common;
+  int a;
+};
+
+struct bar {
+  const char *common;
+  double a;
+};
+
+void print_foo(struct foo *foo)
+{
+  printf("foo: %d\n", foo->a);
+}
+
+void print_bar(struct bar *bar)
+{
+  printf("bar: %f\n", bar->a);
+}
+
+void run_test()
+{
+  struct foo foo = { "l33t", 1337 };
+  struct bar bar = { "h4x0r", 1.337 };
+
+  print_foo(&foo);
+  print_bar(&bar);
+}
diff --git a/test/cast.xml b/test/cast.xml
new file mode 100644 (file)
index 0000000..7e2528c
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="Dynval Casting">
+  <plugin id="plugin-cast" source="plugin-cast.c" />
+  <run name="Integer parameter captures" target="cast-target.c" hooks="cast-hooks.c">
+    <using plugin="plugin-cast" />
+    <output>
+      In advice function: l33t
+      foo: 1337
+      In advice function: h4x0r
+      bar: 1.337000
+    </output>
+    <prototypes>
+      void _advice(ALL_POINTER_T);
+    </prototypes>
+  </run>
+</testcase>
diff --git a/test/plugin-cast.c b/test/plugin-cast.c
new file mode 100644 (file)
index 0000000..4c5f587
--- /dev/null
@@ -0,0 +1,55 @@
+#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)
+{
+  struct aop_dynval *param;
+
+  param = aop_capture_call_param(jp, 0);
+  aop_assert(aop_is_pointer_type(aop_get_dynval_type(param)));
+  aop_cast_to_all_pointer(param);
+
+  aop_insert_advice(jp, "_advice", AOP_INSERT_BEFORE, AOP_DYNVAL(param), AOP_TERM_ARG);
+}
+
+static unsigned int plugin_cast()
+{
+  struct aop_pointcut *pc;
+
+  const struct aop_type *foo_type;
+  const struct aop_type *bar_type;
+
+  foo_type = aop_t_struct_ptr("foo");
+  bar_type = aop_t_struct_ptr("bar");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, foo_type);
+  aop_join_on(pc, plugin_join_on_call, NULL);
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, bar_type);
+  aop_join_on(pc, plugin_join_on_call, NULL);
+
+  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, "_CAST_HEADER_", NULL, NULL);
+    if (res != 0)
+      perror(header);
+  }
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("cast", plugin_cast);
+}