[jit] Avoid overwhelming expect's buffer

David Malcolm dmalcolm@redhat.com
Mon Oct 13 14:45:00 GMT 2014


Committed to git branch dmalcolm/jit:

"expect" has a default buffer size of 2000 bytes ("match_max").

If the testsuite programs send large amounts of data to stdout/stderr,
they could overwhelm this buffer.

Avoid this.

gcc/testsuite/ChangeLog.jit:
	* jit.dg/harness.h [MAKE_DEJAGNU_H_THREADSAFE] (note): Redefine
	"note" from dejagnu.h to new function dejagnu_note so that we can
	make "note" be threadsafe.
	(set_options): Don't enable GCC_JIT_BOOL_OPTION_DUMP_SUMMARY,
	since it can generate large amounts of output that could overwhelm
	expect's buffer.
	* jit.dg/test-dot-product.c (verify_code): Use "note" rather than
	"printf", to give DejaGnu more chances to parse this log data,
	rather than overflowing its buffer.
	* jit.dg/test-factorial.c (verify_code): Likewise.
	* jit.dg/test-fibonacci.c (verify_code): Likewise.
	* jit.dg/test-fuzzer.c (main): Likewise.
	* jit.dg/test-nested-loops.c (verify_code): Likewise.
	* jit.dg/test-sum-of-squares.c (verify_code): Likewise.
	* jit.dg/test-threads.c (note): New function, adding thread-safety
	on top of "dejagnu_note", the latter being the implementation
	found in dejagnu.h.
	(run_threaded_test): Use "note" rather than "printf".
---
 gcc/testsuite/ChangeLog.jit                | 21 +++++++++++++++++++++
 gcc/testsuite/jit.dg/harness.h             |  4 +++-
 gcc/testsuite/jit.dg/test-dot-product.c    |  2 +-
 gcc/testsuite/jit.dg/test-factorial.c      |  2 +-
 gcc/testsuite/jit.dg/test-fibonacci.c      |  2 +-
 gcc/testsuite/jit.dg/test-fuzzer.c         |  4 ++--
 gcc/testsuite/jit.dg/test-nested-loops.c   |  2 +-
 gcc/testsuite/jit.dg/test-sum-of-squares.c |  2 +-
 gcc/testsuite/jit.dg/test-threads.c        | 26 +++++++++++++++++++++-----
 9 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit
index 798f7c9..7703212 100644
--- a/gcc/testsuite/ChangeLog.jit
+++ b/gcc/testsuite/ChangeLog.jit
@@ -1,3 +1,24 @@
+2014-10-13  David Malcolm  <dmalcolm@redhat.com>
+
+	* jit.dg/harness.h [MAKE_DEJAGNU_H_THREADSAFE] (note): Redefine
+	"note" from dejagnu.h to new function dejagnu_note so that we can
+	make "note" be threadsafe.
+	(set_options): Don't enable GCC_JIT_BOOL_OPTION_DUMP_SUMMARY,
+	since it can generate large amounts of output that could overwhelm
+	expect's buffer.
+	* jit.dg/test-dot-product.c (verify_code): Use "note" rather than
+	"printf", to give DejaGnu more chances to parse this log data,
+	rather than overflowing its buffer.
+	* jit.dg/test-factorial.c (verify_code): Likewise.
+	* jit.dg/test-fibonacci.c (verify_code): Likewise.
+	* jit.dg/test-fuzzer.c (main): Likewise.
+	* jit.dg/test-nested-loops.c (verify_code): Likewise.
+	* jit.dg/test-sum-of-squares.c (verify_code): Likewise.
+	* jit.dg/test-threads.c (note): New function, adding thread-safety
+	on top of "dejagnu_note", the latter being the implementation
+	found in dejagnu.h.
+	(run_threaded_test): Use "note" rather than "printf".
+
 2014-10-07  David Malcolm  <dmalcolm@redhat.com>
 
 	* jit.dg/jit.exp (jit-dg-test): Prepend the installed bindir to
diff --git a/gcc/testsuite/jit.dg/harness.h b/gcc/testsuite/jit.dg/harness.h
index cee42f3..f326891 100644
--- a/gcc/testsuite/jit.dg/harness.h
+++ b/gcc/testsuite/jit.dg/harness.h
@@ -22,6 +22,7 @@
 #ifdef MAKE_DEJAGNU_H_THREADSAFE
 #define pass dejagnu_pass
 #define fail dejagnu_fail
+#define note dejagnu_note
 #endif
 
 #include <dejagnu.h>
@@ -29,6 +30,7 @@
 #ifdef MAKE_DEJAGNU_H_THREADSAFE
 #undef pass
 #undef fail
+#undef note
 #endif
 
 static char test[1024];
@@ -165,7 +167,7 @@ static void set_options (gcc_jit_context *ctxt, const char *argv0)
   gcc_jit_context_set_bool_option (
     ctxt,
     GCC_JIT_BOOL_OPTION_DUMP_SUMMARY,
-    1);
+    0);
 }
 
 #ifndef TEST_ESCHEWS_TEST_JIT
diff --git a/gcc/testsuite/jit.dg/test-dot-product.c b/gcc/testsuite/jit.dg/test-dot-product.c
index 2cde66d..a41109a 100644
--- a/gcc/testsuite/jit.dg/test-dot-product.c
+++ b/gcc/testsuite/jit.dg/test-dot-product.c
@@ -123,7 +123,7 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
   CHECK_NON_NULL (my_dot_product);
   double test_array[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
   double val = my_dot_product (10, test_array, test_array);
-  printf("my_dot_product returned: %f\n", val);
+  note ("my_dot_product returned: %f", val);
   CHECK_VALUE (val, 385.0);
 }
 
diff --git a/gcc/testsuite/jit.dg/test-factorial.c b/gcc/testsuite/jit.dg/test-factorial.c
index eecd831..b2aaece 100644
--- a/gcc/testsuite/jit.dg/test-factorial.c
+++ b/gcc/testsuite/jit.dg/test-factorial.c
@@ -97,7 +97,7 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
     (my_factorial_fn_type)gcc_jit_result_get_code (result, "my_factorial");
   CHECK_NON_NULL (my_factorial);
   int val = my_factorial (10);
-  printf("my_factorial returned: %d\n", val);
+  note ("my_factorial returned: %d", val);
   CHECK_VALUE (val, 3628800);
 }
 
diff --git a/gcc/testsuite/jit.dg/test-fibonacci.c b/gcc/testsuite/jit.dg/test-fibonacci.c
index 03c13c6..607bd56 100644
--- a/gcc/testsuite/jit.dg/test-fibonacci.c
+++ b/gcc/testsuite/jit.dg/test-fibonacci.c
@@ -131,6 +131,6 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
     (my_fibonacci_fn_type)gcc_jit_result_get_code (result, "my_fibonacci");
   CHECK_NON_NULL (my_fibonacci);
   int val = my_fibonacci (10);
-  printf("my_fibonacci returned: %d\n", val);
+  note ("my_fibonacci returned: %d", val);
   CHECK_VALUE (val, 55);
 }
diff --git a/gcc/testsuite/jit.dg/test-fuzzer.c b/gcc/testsuite/jit.dg/test-fuzzer.c
index 8cd0d75..f363f8f 100644
--- a/gcc/testsuite/jit.dg/test-fuzzer.c
+++ b/gcc/testsuite/jit.dg/test-fuzzer.c
@@ -454,8 +454,8 @@ main (int argc, char **argv)
 	}
     }
   pass ("%s: survived running all tests", extract_progname (argv[0]));
-  printf ("%s: num completed compilations: %d\n", extract_progname (argv[0]),
-	  num_completed_compilations);
+  note ("%s: num completed compilations: %d", extract_progname (argv[0]),
+	num_completed_compilations);
   totals ();
 
   return 0;
diff --git a/gcc/testsuite/jit.dg/test-nested-loops.c b/gcc/testsuite/jit.dg/test-nested-loops.c
index a4cda68..1d1a2ba 100644
--- a/gcc/testsuite/jit.dg/test-nested-loops.c
+++ b/gcc/testsuite/jit.dg/test-nested-loops.c
@@ -174,6 +174,6 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
   double test_a[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
   double test_b[] = {5., 6., 7., 8., 9., 10., 1., 2., 3., 4.};
   double val = test_nested_loops (10, test_a, test_b);
-  printf("test_nested_loops returned: %f\n", val);
+  note ("test_nested_loops returned: %f", val);
   CHECK_VALUE (val, 3025.0);
 }
diff --git a/gcc/testsuite/jit.dg/test-sum-of-squares.c b/gcc/testsuite/jit.dg/test-sum-of-squares.c
index ae411e0..d6fdcf6 100644
--- a/gcc/testsuite/jit.dg/test-sum-of-squares.c
+++ b/gcc/testsuite/jit.dg/test-sum-of-squares.c
@@ -121,6 +121,6 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
     (loop_test_fn_type)gcc_jit_result_get_code (result, "loop_test");
   CHECK_NON_NULL (loop_test);
   int val = loop_test (10);
-  printf("loop_test returned: %d\n", val);
+  note ("loop_test returned: %d", val);
   CHECK_VALUE (val, 285);
 }
diff --git a/gcc/testsuite/jit.dg/test-threads.c b/gcc/testsuite/jit.dg/test-threads.c
index efa146d..7c248cc 100644
--- a/gcc/testsuite/jit.dg/test-threads.c
+++ b/gcc/testsuite/jit.dg/test-threads.c
@@ -18,13 +18,14 @@ static pthread_mutex_t dg_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 /* By defining MAKE_DEJAGNU_H_THREADSAFE before we include harness.h,
    harness.h injects macros before including <dejagnu.h> so that the
-   pass/fail functions become "dejagnu_pass"/"dejagnu_fail".  */
+   pass/fail functions become "dejagnu_pass"/"dejagnu_fail" etc.  */
 
 void dejagnu_pass (const char* fmt, ...);
 void dejagnu_fail (const char* fmt, ...);
+void dejagnu_note (const char* fmt, ...);
 
-/* We now provide our own implementations of "pass"/"fail", which call
-   the underlying dejagnu implementations, but with a mutex.  */
+/* We now provide our own implementations of "pass"/"fail"/"note", which
+   call the underlying dejagnu implementations, but with a mutex.  */
 
 inline void
 pass (const char* fmt, ...)
@@ -56,6 +57,21 @@ fail (const char* fmt, ...)
   pthread_mutex_unlock (&dg_mutex);
 }
 
+inline void
+note (const char* fmt, ...)
+{
+  va_list ap;
+  char buffer[512];
+
+  va_start (ap, fmt);
+  vsnprintf (buffer, sizeof (buffer), fmt, ap);
+  va_end (ap);
+
+  pthread_mutex_lock (&dg_mutex);
+  dejagnu_note (buffer);
+  pthread_mutex_unlock (&dg_mutex);
+}
+
 #define MAKE_DEJAGNU_H_THREADSAFE
 
 /* We also need to provide our own version of TEST_NAME.  */
@@ -174,8 +190,8 @@ run_threaded_test (void *data)
       gcc_jit_context *ctxt;
       gcc_jit_result *result;
 
-      printf ("run_threaded_test: %s iteration: %d\n",
-	      thread->m_testcase->m_name, i);
+      note ("run_threaded_test: %s iteration: %d",
+	    thread->m_testcase->m_name, i);
 
       ctxt = gcc_jit_context_acquire ();
 
-- 
1.7.11.7



More information about the Gcc-patches mailing list