tst_QProcess: create a more reliable crashing

Turns out that crashing on purpose is more difficult than it seems. It
should be easy, given how often we do it accidentally...

Let the null pointer dereferencing be the fall back. Some compilers are
too smart for their own good and remove the fault. Instead, let's rely
on raise(SIGABRT) on Unix and on the UD2 instruction on Windows.

Pick-To: 5.15
Change-Id: Ibdc95e9af7bd456a94ecfffd1603f1c9b73b167d
Reviewed-by: Simon Hausmann <hausmann@gmail.com>
bb10
Thiago Macieira 2020-04-08 17:22:22 -03:00
parent ff6d2cb0d5
commit c377bb385c
1 changed files with 26 additions and 7 deletions

View File

@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2020 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@ -26,15 +27,33 @@
**
****************************************************************************/
struct Foo
void crashFallback(volatile int *ptr = nullptr)
{
int i;
};
*ptr = 0;
}
#if defined(_MSC_VER)
# include <intrin.h>
int main()
{
*(volatile char*)0 = 0;
Foo *f = 0;
return f->i;
# if defined(_M_IX86) || defined(_M_X64)
__ud2();
# endif
crashFallback();
}
#elif defined(__MINGW32__)
int main()
{
asm("ud2");
crashFallback();
}
#else
# include <stdlib.h>
int main()
{
abort();
}
#endif