summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-04-08 17:22:22 -0300
committerThiago Macieira <thiago.macieira@intel.com>2020-05-05 12:24:35 -0700
commitc377bb385c3581da86eacaf257f88da50e98dec8 (patch)
tree026a21c842c1025e1da98801c9f0fb6517ef6629 /tests/auto/corelib/io
parentff6d2cb0d5779d81e89d94d65c8d164602fa2567 (diff)
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>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp b/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp
index 262db73d72..298a74d2b0 100644
--- a/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp
+++ b/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp
@@ -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 @@
**
****************************************************************************/
+void crashFallback(volatile int *ptr = nullptr)
+{
+ *ptr = 0;
+}
+
+#if defined(_MSC_VER)
+# include <intrin.h>
-struct Foo
+int main()
{
- int 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()
{
- *(volatile char*)0 = 0;
- Foo *f = 0;
- return f->i;
+ abort();
}
+#endif