From 0ce443691fac1188103e5eaa66be40278d5d5e97 Mon Sep 17 00:00:00 2001 From: Samuli Piippo Date: Thu, 11 Feb 2021 10:51:55 +0200 Subject: Move QEMU emulation detector to QTest The emulation detection has been usable only on qtbase tests, move it to QTest so that it can be used in other modules as well. Pick-to: 6.1 Change-Id: I4b2321b7856414d7b1cfd5e6b1405a633c6bb878 Reviewed-by: Edward Welbourne --- tests/auto/corelib/io/largefile/CMakeLists.txt | 5 +- tests/auto/corelib/io/largefile/tst_largefile.cpp | 4 +- tests/auto/corelib/io/qfile/CMakeLists.txt | 4 +- tests/auto/corelib/io/qfile/tst_qfile.cpp | 6 +- tests/auto/corelib/io/qprocess/test/CMakeLists.txt | 4 +- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 5 +- .../serialization/qtextstream/test/CMakeLists.txt | 4 +- .../serialization/qtextstream/tst_qtextstream.cpp | 4 +- tests/auto/corelib/thread/qthread/CMakeLists.txt | 5 +- tests/auto/corelib/thread/qthread/tst_qthread.cpp | 4 +- .../gui/itemmodels/qfilesystemmodel/CMakeLists.txt | 4 +- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 4 +- tests/auto/gui/text/qfont/CMakeLists.txt | 3 +- tests/auto/gui/text/qfont/tst_qfont.cpp | 4 +- tests/auto/network/access/http2/CMakeLists.txt | 4 +- tests/auto/network/access/http2/tst_http2.cpp | 4 +- .../network/socket/qudpsocket/test/CMakeLists.txt | 3 +- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 4 +- tests/auto/other/qobjectrace/CMakeLists.txt | 5 +- tests/auto/other/qobjectrace/tst_qobjectrace.cpp | 4 +- tests/auto/testlib/selftests/CMakeLists.txt | 3 - tests/auto/testlib/selftests/float/CMakeLists.txt | 4 +- tests/auto/testlib/selftests/float/tst_float.cpp | 4 +- tests/auto/testlib/selftests/tst_selftests.cpp | 6 +- tests/shared/emulationdetector.h | 123 --------------------- 25 files changed, 40 insertions(+), 184 deletions(-) delete mode 100644 tests/shared/emulationdetector.h (limited to 'tests') diff --git a/tests/auto/corelib/io/largefile/CMakeLists.txt b/tests/auto/corelib/io/largefile/CMakeLists.txt index be4b21033f..a82aa0c985 100644 --- a/tests/auto/corelib/io/largefile/CMakeLists.txt +++ b/tests/auto/corelib/io/largefile/CMakeLists.txt @@ -6,8 +6,7 @@ qt_internal_add_test(tst_largefile SOURCES - ../../../../shared/emulationdetector.h tst_largefile.cpp - INCLUDE_DIRECTORIES - ../../../../shared + PUBLIC_LIBRARIES + Qt::TestPrivate ) diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index 98bb985c02..fcc0a31763 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -48,7 +48,7 @@ # endif #endif // Q_OS_WIN -#include "emulationdetector.h" +#include class tst_LargeFile : public QObject @@ -73,7 +73,7 @@ public: #endif // QEMU only supports < 4GB files - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) maxSizeBits = qMin(maxSizeBits, 28); } diff --git a/tests/auto/corelib/io/qfile/CMakeLists.txt b/tests/auto/corelib/io/qfile/CMakeLists.txt index 7a0102bfd9..4d9a0d2598 100644 --- a/tests/auto/corelib/io/qfile/CMakeLists.txt +++ b/tests/auto/corelib/io/qfile/CMakeLists.txt @@ -19,12 +19,10 @@ list(APPEND test_data "resources/file1.ext1") qt_internal_add_test(tst_qfile SOURCES - ../../../../shared/emulationdetector.h tst_qfile.cpp - INCLUDE_DIRECTORIES - ../../../../shared PUBLIC_LIBRARIES Qt::CorePrivate + Qt::TestPrivate TESTDATA ${test_data} ) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 2019afaf66..bdfcc2d350 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -46,7 +46,7 @@ #include #include -#include "emulationdetector.h" +#include #ifdef Q_OS_WIN QT_BEGIN_NAMESPACE @@ -2553,10 +2553,10 @@ void tst_QFile::virtualFile() // open the file QFile f(fname); QVERIFY2(f.open(QIODevice::ReadOnly), msgOpenFailed(f).constData()); - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QEXPECT_FAIL("","QEMU does not read /proc/self/maps size correctly", Continue); QCOMPARE(f.size(), Q_INT64_C(0)); - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QEXPECT_FAIL("","QEMU does not read /proc/self/maps size correctly", Continue); QVERIFY(f.atEnd()); diff --git a/tests/auto/corelib/io/qprocess/test/CMakeLists.txt b/tests/auto/corelib/io/qprocess/test/CMakeLists.txt index 249cb089cf..75cddf41a8 100644 --- a/tests/auto/corelib/io/qprocess/test/CMakeLists.txt +++ b/tests/auto/corelib/io/qprocess/test/CMakeLists.txt @@ -7,13 +7,11 @@ qt_internal_add_test(tst_qprocess OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES - ../../../../../shared/emulationdetector.h ../tst_qprocess.cpp - INCLUDE_DIRECTORIES - ../../../../../shared PUBLIC_LIBRARIES Qt::CorePrivate Qt::Network + Qt::TestPrivate ) #### Keys ignored in scope 1:.:.:test.pro:: diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index b6ba4e546c..41172a10dd 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -27,11 +27,10 @@ ** ****************************************************************************/ -#include - #include #include #include +#include #include #include @@ -1237,7 +1236,7 @@ void tst_QProcess::processInAThread() void tst_QProcess::processesInMultipleThreads() { - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("Flakily hangs in QEMU. QTBUG-67760"); for (int i = 0; i < 10; ++i) { // run from 1 to 10 threads, but run at least some tests diff --git a/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt b/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt index 61d594900f..c90a6f12c5 100644 --- a/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt +++ b/tests/auto/corelib/serialization/qtextstream/test/CMakeLists.txt @@ -15,12 +15,10 @@ list(APPEND test_data "../BLACKLIST") qt_internal_add_test(tst_qtextstream OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES - ../../../../../shared/emulationdetector.h ../tst_qtextstream.cpp - INCLUDE_DIRECTORIES - ../../../../../shared PUBLIC_LIBRARIES Qt::Network + Qt::TestPrivate TESTDATA ${test_data} ) diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 3ab095827f..c02da8efe1 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -45,7 +45,7 @@ # include #endif #include "../../../network-settings.h" -#include "emulationdetector.h" +#include QT_BEGIN_NAMESPACE template<> struct QMetaTypeId @@ -1417,7 +1417,7 @@ void tst_QTextStream::pos2() // ------------------------------------------------------------------------------ void tst_QTextStream::pos3LargeFile() { - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("Running QTextStream::pos() in tight loop is too slow on emulator"); { diff --git a/tests/auto/corelib/thread/qthread/CMakeLists.txt b/tests/auto/corelib/thread/qthread/CMakeLists.txt index b3662f31da..96c649f106 100644 --- a/tests/auto/corelib/thread/qthread/CMakeLists.txt +++ b/tests/auto/corelib/thread/qthread/CMakeLists.txt @@ -6,10 +6,9 @@ qt_internal_add_test(tst_qthread SOURCES - ../../../../shared/emulationdetector.h tst_qthread.cpp - INCLUDE_DIRECTORIES - ../../../../shared + PUBLIC_LIBRARIES + Qt::TestPrivate ) ## Scopes: diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index a34129d59a..7e06e7f51f 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -55,7 +55,7 @@ #include #endif -#include "emulationdetector.h" +#include class tst_QThread : public QObject { @@ -951,7 +951,7 @@ void tst_QThread::adoptMultipleThreadsOverlap() // Disconnects on WinCE void tst_QThread::stressTest() { - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("Qemu uses too much memory for each thread. Test would run out of memory."); QElapsedTimer timer; diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt b/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt index 375eb5b245..31fd8ca32d 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt @@ -6,15 +6,13 @@ qt_internal_add_test(tst_qfilesystemmodel SOURCES - ../../../../shared/emulationdetector.h tst_qfilesystemmodel.cpp - INCLUDE_DIRECTORIES - ../../../../shared PUBLIC_LIBRARIES Qt::CorePrivate Qt::Gui Qt::Widgets Qt::WidgetsPrivate + Qt::TestPrivate ) ## Scopes: diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp index a096fcd324..b9c44aa4c2 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -27,11 +27,11 @@ ****************************************************************************/ -#include #include #include #include #include +#include #ifdef QT_BUILD_INTERNAL #include @@ -792,7 +792,7 @@ void tst_QFileSystemModel::sort() QTreeView tree; tree.setWindowTitle(QTest::currentTestFunction()); - if (fileDialogMode && EmulationDetector::isRunningArmOnX86()) + if (fileDialogMode && QTestPrivate::isRunningArmOnX86()) QSKIP("Crashes in QEMU. QTBUG-70572"); #ifdef QT_BUILD_INTERNAL diff --git a/tests/auto/gui/text/qfont/CMakeLists.txt b/tests/auto/gui/text/qfont/CMakeLists.txt index 32cbed7aaf..05c6ca8270 100644 --- a/tests/auto/gui/text/qfont/CMakeLists.txt +++ b/tests/auto/gui/text/qfont/CMakeLists.txt @@ -11,8 +11,7 @@ qt_internal_add_test(tst_qfont Qt::CorePrivate Qt::Gui Qt::GuiPrivate - INCLUDE_DIRECTORIES - ../../../../shared + Qt::TestPrivate ) # Resources: diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index efd1215d70..aa9f8a8ce4 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -41,7 +41,7 @@ #include #endif #include -#include "emulationdetector.h" +#include class tst_QFont : public QObject { @@ -578,7 +578,7 @@ void tst_QFont::defaultFamily() } } #ifdef Q_PROCESSOR_ARM_32 - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QEXPECT_FAIL("", "Fails on ARMv7 QEMU (QTQAINFRA-4127)", Continue); #endif diff --git a/tests/auto/network/access/http2/CMakeLists.txt b/tests/auto/network/access/http2/CMakeLists.txt index 7ac1c8001c..735f95deff 100644 --- a/tests/auto/network/access/http2/CMakeLists.txt +++ b/tests/auto/network/access/http2/CMakeLists.txt @@ -6,15 +6,13 @@ qt_internal_add_test(tst_http2 SOURCES - ../../../../shared/emulationdetector.h http2srv.cpp http2srv.h tst_http2.cpp DEFINES SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\" - INCLUDE_DIRECTORIES - ../../../../shared PUBLIC_LIBRARIES Qt::CorePrivate Qt::Network Qt::NetworkPrivate + Qt::TestPrivate ) diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index d4ef1520a7..1aa012c6ac 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -55,7 +55,7 @@ #include #include -#include "emulationdetector.h" +#include #if (!defined(QT_NO_OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_TLSEXT)) \ || QT_CONFIG(schannel) @@ -379,7 +379,7 @@ void tst_Http2::flowControlServerSide() // to let all replies finish without any error. using namespace Http2; - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("Test is too slow to run on emulator"); clearHTTP2State(); diff --git a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt index 7bd9bd80fb..6a781aadc4 100644 --- a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt +++ b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt @@ -8,10 +8,9 @@ qt_internal_add_test(tst_qudpsocket OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case SOURCES ../tst_qudpsocket.cpp - INCLUDE_DIRECTORIES - ../../../../../shared PUBLIC_LIBRARIES Qt::Network + Qt::TestPrivate QT_TEST_SERVER_LIST "danted" "echo" # special case ) diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 1f3c8583f2..22f5f3f4c7 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -52,7 +52,7 @@ #include #include "../../../network-settings.h" -#include "emulationdetector.h" +#include #if defined(Q_OS_LINUX) #define SHOULD_CHECK_SYSCALL_SUPPORT @@ -302,7 +302,7 @@ void tst_QUdpSocket::initTestCase() qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups; m_workaroundLinuxKernelBug = shouldWorkaroundLinuxKernelBug(); - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("This test is unreliable due to QEMU emulation shortcomings."); } diff --git a/tests/auto/other/qobjectrace/CMakeLists.txt b/tests/auto/other/qobjectrace/CMakeLists.txt index 8069b40ad7..7a2be39d81 100644 --- a/tests/auto/other/qobjectrace/CMakeLists.txt +++ b/tests/auto/other/qobjectrace/CMakeLists.txt @@ -6,8 +6,7 @@ qt_internal_add_test(qobjectrace SOURCES - ../../../shared/emulationdetector.h tst_qobjectrace.cpp - INCLUDE_DIRECTORIES - ../../../shared + PUBLIC_LIBRARIES + Qt::TestPrivate ) diff --git a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp index cdf51f5d0c..ac33fa3ec3 100644 --- a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp +++ b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp @@ -30,7 +30,7 @@ #include #include -#include "emulationdetector.h" +#include enum { OneMinute = 60 * 1000, TwoMinutes = OneMinute * 2 }; @@ -260,7 +260,7 @@ public: void tst_QObjectRace::destroyRace() { - if (EmulationDetector::isRunningArmOnX86()) + if (QTestPrivate::isRunningArmOnX86()) QSKIP("Test is too slow to run on emulator"); enum { ThreadCount = 10, ObjectCountPerThread = 2777, diff --git a/tests/auto/testlib/selftests/CMakeLists.txt b/tests/auto/testlib/selftests/CMakeLists.txt index 7a352740da..ec321dc282 100644 --- a/tests/auto/testlib/selftests/CMakeLists.txt +++ b/tests/auto/testlib/selftests/CMakeLists.txt @@ -10,11 +10,8 @@ qt_internal_add_test(tst_selftests EXCEPTIONS CATCH SOURCES - ../../../shared/emulationdetector.h tst_selftests.cpp catch.cpp - INCLUDE_DIRECTORIES - ../../../shared PUBLIC_LIBRARIES Qt::TestPrivate # special case begin diff --git a/tests/auto/testlib/selftests/float/CMakeLists.txt b/tests/auto/testlib/selftests/float/CMakeLists.txt index 375cfe1e65..02c61acff3 100644 --- a/tests/auto/testlib/selftests/float/CMakeLists.txt +++ b/tests/auto/testlib/selftests/float/CMakeLists.txt @@ -8,12 +8,10 @@ qt_internal_add_executable(float NO_INSTALL # special case OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # special case SOURCES - ../../../../shared/emulationdetector.h tst_float.cpp - INCLUDE_DIRECTORIES - ../../../../shared PUBLIC_LIBRARIES Qt::Test + Qt::TestPrivate ) ## Scopes: diff --git a/tests/auto/testlib/selftests/float/tst_float.cpp b/tests/auto/testlib/selftests/float/tst_float.cpp index 97b76ccf47..6084b464e2 100644 --- a/tests/auto/testlib/selftests/float/tst_float.cpp +++ b/tests/auto/testlib/selftests/float/tst_float.cpp @@ -31,7 +31,7 @@ #include #include -#include "emulationdetector.h" +#include // Test proper handling of floating-point types class tst_float: public QObject @@ -182,7 +182,7 @@ void tst_float::float16Comparisons_data() const QTest::addColumn("operandLeft"); QTest::addColumn("operandRight"); const qfloat16 zero(0), one(1); - const qfloat16 tiny(EmulationDetector::isRunningArmOnX86() ? 0.00099f : 0.001f); + const qfloat16 tiny(QTestPrivate::isRunningArmOnX86() ? 0.00099f : 0.001f); QTest::newRow("should FAIL 1") << one << qfloat16(3); QTest::newRow("should PASS 1") << zero << zero; diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 4c5e56b97b..1b1ad50e9b 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -48,7 +48,7 @@ #include -#include "emulationdetector.h" +#include struct BenchmarkResult { @@ -345,7 +345,7 @@ bool compareLine(const QString &logger, const QString &subdir, return true; } - if (EmulationDetector::isRunningArmOnX86() && subdir == QLatin1String("float")) { + if (QTestPrivate::isRunningArmOnX86() && subdir == QLatin1String("float")) { // QEMU cheats at qfloat16, so outputs it as if it were a float. if (actualLine.endsWith(QLatin1String("Actual (operandLeft) : 0.001")) && expectedLine.endsWith(QLatin1String("Actual (operandLeft) : 0.000999"))) { @@ -787,7 +787,7 @@ void checkErrorOutput(const QString &test, const QByteArray &errorOutput) #ifdef Q_OS_LINUX // QEMU outputs to stderr about uncaught signals - if (EmulationDetector::isRunningArmOnX86() && + if (QTestPrivate::isRunningArmOnX86() && (test == "assert" || test == "blacklisted" || test == "crashes" diff --git a/tests/shared/emulationdetector.h b/tests/shared/emulationdetector.h deleted file mode 100644 index f691118464..0000000000 --- a/tests/shared/emulationdetector.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef EMULATIONDETECTOR_H -#define EMULATIONDETECTOR_H - -#include - -#if defined(Q_OS_LINUX) && defined(Q_PROCESSOR_ARM) -#define SHOULD_CHECK_ARM_ON_X86 - -#include - -#if QT_CONFIG(process) && QT_CONFIG(regularexpression) -#include -#include -#endif - -#endif - -QT_BEGIN_NAMESPACE - -// Helper functions for detecting if running emulated -namespace EmulationDetector { - -#ifdef SHOULD_CHECK_ARM_ON_X86 -static bool isX86SpecificFileAvailable(void); -static bool isReportedArchitectureX86(void); -#endif - -/* - * Check if we are running Arm binary on x86 machine. - * - * Currently this is only able to check on Linux. If not able to - * detect, return false. - */ -[[maybe_unused]] static bool isRunningArmOnX86() -{ -#ifdef SHOULD_CHECK_ARM_ON_X86 - if (isX86SpecificFileAvailable()) - return true; - - if (isReportedArchitectureX86()) - return true; -#endif - return false; -} - -#ifdef SHOULD_CHECK_ARM_ON_X86 -/* - * Check if we can find a file that's only available on x86 - */ -static bool isX86SpecificFileAvailable() -{ - // MTRR (Memory Type Range Registers) are a feature of the x86 architecture - // and /proc/mtrr is only present (on Linux) for that family. - // However, it's an optional kernel feature, so the absence of the file is - // not sufficient to conclude we're on real hardware. - QFileInfo mtrr("/proc/mtrr"); - if (mtrr.exists()) - return true; - return false; -} - -/* - * Check if architecture reported by the OS is x86 - */ -static bool isReportedArchitectureX86(void) -{ -#if QT_CONFIG(process) && QT_CONFIG(regularexpression) - QProcess unamer; - QString machineString; - - // Using syscall "uname" is not possible since that would be captured by - // QEMU and result would be the architecture being emulated (e.g. armv7l). - // By using QProcess we get the architecture used by the host. - unamer.start("uname -a"); - if (!unamer.waitForFinished()) { - return false; - } - machineString = unamer.readAll(); - - // Is our current host cpu x86? - if (machineString.contains(QRegularExpression("i386|i686|x86"))) { - return true; - } -#endif - - return false; -} -#endif // SHOULD_CHECK_ARM_ON_X86 - -} // EmulationDetector namespace - -QT_END_NAMESPACE - -#endif - -- cgit v1.2.3