Added test case for passing constants to advice.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 20 Oct 2010 20:03:51 +0000 (16:03 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Wed, 20 Oct 2010 20:03:51 +0000 (16:03 -0400)
test/Makefile.am
test/constants-hooks.c [new file with mode: 0644]
test/constants-target.c [new file with mode: 0644]
test/constants.xml [new file with mode: 0644]
test/plugin-constants.c [new file with mode: 0644]

index 7426101b7339cdf3dc35aa3ea374bb8e78f8b13b..9f495b8a714842f2986333d3fbf01b99127a5e0e 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 inparam.xml
+       reinst.xml noinstrument.xml duplicate.xml inparam.xml constants.xml
 endif
diff --git a/test/constants-hooks.c b/test/constants-hooks.c
new file mode 100644 (file)
index 0000000..04cc3aa
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdint.h>
+#include <stdio.h>
+
+void _foo_advice(const char *str1, int32_t int1, double double1, void *voidp1, const char *str2)
+{
+  printf("In advice: %s, %d, %f, %p, %s\n", str1, int1, double1, voidp1, str2);
+}
diff --git a/test/constants-target.c b/test/constants-target.c
new file mode 100644 (file)
index 0000000..2527583
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+static void foo()
+{
+  printf("In foo\n");
+}
+
+void run_test()
+{
+  foo();
+}
diff --git a/test/constants.xml b/test/constants.xml
new file mode 100644 (file)
index 0000000..6154a40
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="Constants">
+  <plugin id="plugin-constants" source="plugin-constants.c" />
+  <run name="Passing constants to advice" target="constants-target.c" hooks="constants-hooks.c">
+    <using plugin="plugin-constants" />
+    <output>
+      In advice: dead, 10, 2.500000, 0xdeadbeef, beef
+      In foo
+    </output>
+    <prototypes>
+      void _foo_advice(signed char *, int32_t, double, ALL_POINTER_T, signed char *);
+    </prototypes>
+  </run>
+</testcase>
diff --git a/test/plugin-constants.c b/test/plugin-constants.c
new file mode 100644 (file)
index 0000000..05d8b85
--- /dev/null
@@ -0,0 +1,41 @@
+#include <aop.h>
+#include <stdio.h>
+
+AOP_I_AM_GPL_COMPATIBLE();
+
+static void plugin_join_on_entry(struct aop_joinpoint *jp, void *data)
+{
+  double blah = 2.5;
+  aop_insert_advice(jp, "_foo_advice", AOP_INSERT_BEFORE, AOP_STR_CST("dead"), AOP_INT_CST(10),
+                   AOP_DOUBLE_CST(blah), AOP_VOIDP_CST((void *)0xdeadbeef), AOP_STR_CST("beef"),
+                   AOP_TERM_ARG);
+}
+
+static unsigned int plugin_cst()
+{
+  struct aop_pointcut *pc;
+
+  pc = aop_match_function_entry();
+  aop_filter_entry_by_name(pc, "foo");
+  aop_join_on(pc, plugin_join_on_entry, 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, "_INT_HEADER_", NULL, NULL);
+    if (res != 0)
+      perror(header);
+  }
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("cst", plugin_cst);
+}