[Piglit] [PATCH 2/2] framework, util: Disable error message boxes on Windows.

jfonseca at vmware.com jfonseca at vmware.com
Tue Jun 3 10:58:38 PDT 2014


From: José Fonseca <jfonseca at vmware.com>

This (plus a corresponding Mesa change) enables to run the piglit
testsuite through piglit-run without human intervention.
---
 framework/programs/run.py        | 18 ++++++++++++++++++
 tests/util/piglit-framework-gl.h |  2 ++
 tests/util/piglit-util.c         | 37 +++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util.h         |  2 ++
 4 files changed, 59 insertions(+)

diff --git a/framework/programs/run.py b/framework/programs/run.py
index 2337b8e..0c3ec01 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -98,6 +98,24 @@ def run(input_):
                         help="Path to results folder")
     args = parser.parse_args(input_)
 
+    # Disable Windows error message boxes for this and all child processes.
+    if sys.platform == 'win32':
+        # This disables messages boxes for uncaught exceptions, but it will not
+        # disable the message boxes for assertion failures or abort().  Those
+        # are created not by the system but by the CRT itself, and must be
+        # disabled by the child processes themselves.
+        import ctypes
+	SEM_FAILCRITICALERRORS     = 0x0001
+	SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
+	SEM_NOGPFAULTERRORBOX      = 0x0002
+	SEM_NOOPENFILEERRORBOX     = 0x8000
+        uMode = ctypes.windll.kernel32.SetErrorMode(0)
+        uMode |= SEM_FAILCRITICALERRORS \
+	      |  SEM_NOALIGNMENTFAULTEXCEPT \
+	      |  SEM_NOGPFAULTERRORBOX \
+	      |  SEM_NOOPENFILEERRORBOX
+        ctypes.windll.kernel32.SetErrorMode(uMode)
+
     # Set the platform to pass to waffle
     if args.platform:
         os.environ['PIGLIT_PLATFORM'] = args.platform
diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index 6033897..cff4533 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -260,6 +260,8 @@ piglit_gl_test_run(int argc, char *argv[],
         {                                                                    \
                 struct piglit_gl_test_config config;                         \
                                                                              \
+                piglit_disable_error_message_boxes();                        \
+                                                                             \
                 piglit_gl_test_config_init(&config);                         \
                                                                              \
                 config.init = piglit_init;                                   \
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index cefc303..9f09ba2 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -277,6 +277,43 @@ char *strndup(const char *s, size_t n)
 
 
 void
+piglit_disable_error_message_boxes(void)
+{
+	/* When Windows' error message boxes are disabled for this process (as
+	 * is always the case when running through `piglit run`) we disable CRT
+	 * message boxes too.
+	 *
+	 * This will disable the CRT message boxes for the main executable, but
+	 * it will not disable message boxes for assertion failures inside
+	 * OpenGL ICD, unless this test's executable and the OpenGL ICD DLL are
+	 * both dynamically linked to the same CRT DLL.  If the OpenGL ICD is
+	 * statically linked to the CRT then it must do these calls itself.
+	 */
+#ifdef _WIN32
+	UINT uMode;
+#if _WIN32_WINNT >= 0x0600
+	uMode = GetErrorMode();
+#else
+	uMode = SetErrorMode(0);
+	SetErrorMode(uMode);
+#endif
+	if (uMode & SEM_FAILCRITICALERRORS) {
+		/* Disable assertion failure message box.
+		 * http://msdn.microsoft.com/en-us/library/sas1dkb2.aspx
+		 */
+		_set_error_mode(_OUT_TO_STDERR);
+#ifdef _MSC_VER
+		/* Disable abort message box.
+		 * http://msdn.microsoft.com/en-us/library/e631wekh.aspx
+		 */
+		_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
+#endif
+	}
+#endif /* _WIN32 */
+}
+
+
+void
 piglit_set_rlimit(unsigned long lim)
 {
 #if defined(USE_SETRLIMIT) && defined(RLIMIT_AS)
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 86b5c18..0f112ab 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -222,6 +222,8 @@ char *strchrnul(const char *s, int c);
 char *strndup(const char *s, size_t n);
 #endif
 
+void piglit_disable_error_message_boxes(void);
+
 extern void piglit_set_rlimit(unsigned long lim);
 
 char *piglit_load_text_file(const char *file_name, unsigned *size);
-- 
1.9.1



More information about the Piglit mailing list