Added test case for matching floating point types.
authorJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 2 Sep 2010 21:46:46 +0000 (17:46 -0400)
committerJustin Seyster <jseyster@cs.sunysb.edu>
Thu, 2 Sep 2010 21:46:46 +0000 (17:46 -0400)
test/Makefile.am
test/float-types-hooks.c [new file with mode: 0644]
test/float-types-target.c [new file with mode: 0644]
test/float-types.xml [new file with mode: 0644]
test/plugin-float-types.c [new file with mode: 0644]

index ba7b3dbef04ced35adfbaa22c809ae82dd87b564..60cfc7955001634b7caa0aeed76ae19ecc8dd3a0 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
+TESTS = int-types.xml float-types.xml
 endif
diff --git a/test/float-types-hooks.c b/test/float-types-hooks.c
new file mode 100644 (file)
index 0000000..6282702
--- /dev/null
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+void _advice_all(const char *func, double n1, double n2)
+{
+  printf("ALL advice in %s (%.20f, %.20f)\n", func, n1, n2);
+}
+
+void _advice_32(const char *func, float n1, float n2)
+{
+  printf("32 advice in %s (%.20f, %.20f)\n", func, (double)n1, (float)n2);
+}
+
+void _advice_64(const char *func, double n1, double n2)
+{
+  printf("64 advice in %s (%.20f, %.20f)\n", func, n1, n2);
+}
+
+void _advice_128(const char *func, long double n1, long double n2)
+{
+  printf("128 advice in %s (%.20Lf, %.20Lf)\n", func, n1, n2);
+}
diff --git a/test/float-types-target.c b/test/float-types-target.c
new file mode 100644 (file)
index 0000000..c9fcc1d
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+void binary32(float n)
+{
+  printf("single:\t%.20f\n", (double)n);
+}
+
+void binary64(double n)
+{
+  printf("double:\t%.20f\n", n);
+}
+
+void binary128(long double n)
+{
+  printf("quad:\t%.20Lf\n", n);
+}
+
+void run_test()
+{
+  binary32((float)1/3);
+  binary64((double)1/3);
+  binary128((long double)1/3);
+}
diff --git a/test/float-types.xml b/test/float-types.xml
new file mode 100644 (file)
index 0000000..1deb6a4
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE testcase SYSTEM "testcase.dtd">
+<testcase name="Float Types">
+  <plugin id="plugin-float-types" source="plugin-float-types.c" />
+  <run name="Float parameter captures" target="float-types-target.c" hooks="float-types-hooks.c">
+    <using plugin="plugin-float-types" />
+    <output>
+      ALL advice in binary32 (0.33333334326744079590, 0.33333334326744079590)
+      32 advice in binary32 (0.33333334326744079590, 0.33333334326744079590)
+      single:  0.33333334326744079590
+      ALL advice in binary64 (0.33333333333333331483, 0.33333333333333331483)
+      64 advice in binary64 (0.33333333333333331483, 0.33333333333333331483)
+      double:  0.33333333333333331483
+      128 advice in binary128 (0.33333333333333333334, 0.33333333333333333334)
+      quad:    0.33333333333333333334
+    </output>
+  </run>
+</testcase>
diff --git a/test/plugin-float-types.c b/test/plugin-float-types.c
new file mode 100644 (file)
index 0000000..e6902e1
--- /dev/null
@@ -0,0 +1,44 @@
+#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_float()
+{
+  struct aop_pointcut *pc;
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_all_fp());
+  aop_join_on(pc, plugin_join_on_call, "_advice_all");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_float32());
+  aop_join_on(pc, plugin_join_on_call, "_advice_32");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_float64());
+  aop_join_on(pc, plugin_join_on_call, "_advice_64");
+
+  pc = aop_match_function_call();
+  aop_filter_call_pc_by_param(pc, 0, aop_t_float128());
+  aop_join_on(pc, plugin_join_on_call, "_advice_128");
+
+  return 0;
+}
+
+AOP_MAIN_PROTO aop_main()
+{
+  aop_register_pass("float", plugin_float);
+}