Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

win32: fix assert-msg-test

On windows, libtool install a wrapper executable in "$(builddir)"
which is capable of correctly executing the real (and uninstalled)
executable living in "$(builddir)/.libs". We have to ensure
$msg_test points to the wrapper executable if it exists.

Additionally, g_assert() eventually calls g_assertion_message()
which calls abort(). msvcrt's abort() immediately exits the process
with this well known message:

  $ assert-msg-test.exe
  **
  ERROR:c:/dev/gnome.org/gnome-windows/checkout/glib/git/src/tests/assert-msg-test.c:7:main: assertion failed: (42 < 0)

  This application has requested the Runtime to terminate it in an unusual way.
  Please contact the application's support team for more information.

and presents the user with a "assert-msg-test.exe has stopped working"
dialog box. The message does not belong in the build output as all
we care about is "PASS: run-assert-msg-test.sh". The dialog currently
prevents the test suite to be run unattended (think build bots).
Calling SetErroMode() with the appropriate flags fixes both issues.

Additionally, the abort() call exits the application outside the
control of MinGW's gdb, so when we want to print the value of
(char*) __glib_assert_msg as is done in run-assert-msg-test.sh,
the process has already been torn down, the stack is gone and
we're basically left with nothing:

  $ libtool --mode=execute gdb --batch --ex run --ex "set print elements 0" --ex "print (char*) __glib_assert_msg" assert-msg-test.exe 2> /dev/null
  [New Thread 4384.0x130]
  [Inferior 1 (process 4384) exited with code 03]
  $1 = 0x0

However, adding a breakpoint on abort() does allow us to get at the value
of (char*) __glib_assert_msg:

  $ libtool --mode=execute gdb --batch --ex "break abort" --ex run --ex "set print elements 0" --ex "print (char*) __glib_assert_msg" assert-msg-test.exe 2> /dev/null
  Breakpoint 1 at 0x401b34
  [New Thread 8116.0x16b4]

  Breakpoint 1, 0x68675524 in abort () from c:\dev\gnome.org\gnome-windows\checkout\glib\git\build\glib\.libs\libglib-2.0-0.dll
  $1 = 0x3a21b0 "ERROR:c:/dev/gnome.org/gnome-windows/checkout/glib/git/src/tests/assert-msg-test.c:7:main: assertion failed: (42 < 0)"

Doing so finally makes the test pass on windows.
  • Loading branch information...
commit 1f0bfcf72e388c0a4333cd25e54cf531cf7f4c15 1 parent 6e20e0f
@dieterv authored
Showing with 14 additions and 4 deletions.
  1. +10 −2 tests/assert-msg-test.c
  2. +4 −2 tests/run-assert-msg-test.sh
View
12 tests/assert-msg-test.c
@@ -1,8 +1,16 @@
#include <glib.h>
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
int main(int argc, char **argv)
{
- g_assert(42 < 0);
- return 0;
+#ifdef G_OS_WIN32
+ SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
+#endif
+
+ g_assert(42 < 0);
+ return 0;
}
View
6 tests/run-assert-msg-test.sh
@@ -31,10 +31,12 @@ fi
msg_test="assert-msg-test"
if [ -e ".libs/lt-$msg_test" ]; then
- msg_test="lt-$msg_test"
+ msg_test=".libs/lt-$msg_test"
+elif [ -e "$msg_test.exe" ]; then
+ msg_test="$msg_test.exe"
fi
echo_v "Running gdb on assert-msg-test"
-OUT=$(libtool --mode=execute gdb --batch --ex run --ex "set print elements 0" --ex "print (char*) __glib_assert_msg" .libs/$msg_test 2> $error_out) || \
+OUT=$(libtool --mode=execute gdb --batch --ex "break abort" --ex run --ex "set print elements 0" --ex "print (char*) __glib_assert_msg" $msg_test 2> $error_out) || \
fail "failed to run gdb"
echo_v "Checking if assert message is in __glib_assert_msg"
Please sign in to comment.
Something went wrong with that request. Please try again.