diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2022-09-19 12:32:03 +0300 |
---|---|---|
committer | Daniel Smith <Daniel.Smith@qt.io> | 2022-09-27 10:13:58 +0000 |
commit | e8c64a130986a1f75f0231dc468091c8bbf8a7f2 (patch) | |
tree | 60af30f54410fe42d3632579f469c9fe53cc617b | |
parent | 72f85f9efff04cfe180846912f81c32d818ef312 (diff) | |
download | qtconnectivity-e8c64a130986a1f75f0231dc468091c8bbf8a7f2.tar.gz |
Skip few Bluetooth autotests on Android emulator
This is to unblock Android-12 emulator deployment on CI which, unlike
the earlier emulators, has a bluetooth emulation. This means that the
emulator triggers permission confirmation dialogues which would timeout
on CI.
This commit replaces the
1ef066bf7d7a67d1b381443b9ecfa60f9204aca8, which attempted to solve the
issue by compile-time configuration.
Task-number: QTBUG-106614
Change-Id: Idc155bb8617802054d6ab19993f5417cc254f16e
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 90251f51be3af2d6db994b92993f2944345e10a6)
Reviewed-by: Daniel Smith <Daniel.Smith@qt.io>
6 files changed, 86 insertions, 49 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 672a550e..96222438 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -1,9 +1,4 @@ if(TARGET Qt::Bluetooth) - if(ANDROID) - if("$ENV{QTEST_ENVIRONMENT}" STREQUAL "ci") - add_compile_definitions(ANDROID_CI_TEST_ENVIRONMENT) - endif() - endif() add_subdirectory(qbluetoothaddress) add_subdirectory(qbluetoothdevicediscoveryagent) add_subdirectory(qbluetoothdeviceinfo) diff --git a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp index 4cd2ddf9..daa14e45 100644 --- a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp +++ b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp @@ -8,6 +8,7 @@ #include <QList> #include <QLoggingCategory> +#include "../../shared/bttestutil_p.h" #include <private/qtbluetoothglobal_p.h> #include <qbluetoothaddress.h> #include <qbluetoothdevicediscoveryagent.h> @@ -128,10 +129,8 @@ void tst_QBluetoothDeviceDiscoveryAgent::deviceDiscoveryDebug(const QBluetoothDe void tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); QBluetoothDeviceDiscoveryAgent discoveryAgent; QVERIFY(discoveryAgent.error() == discoveryAgent.NoError); @@ -404,10 +403,9 @@ void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryTimeout() void tst_QBluetoothDeviceDiscoveryAgent::tst_discoveryMethods() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); + const QBluetoothLocalDevice localDevice; if (localDevice.allDevices().size() != 1) { // On iOS it returns 0 but we still have working BT. diff --git a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp index d395379c..f8ed2b5e 100644 --- a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp +++ b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp @@ -5,6 +5,7 @@ #include <QDebug> #include <QVariant> +#include "../../shared/bttestutil_p.h" #include <private/qtbluetoothglobal_p.h> #include <qbluetoothaddress.h> @@ -46,14 +47,15 @@ private slots: private: QBluetoothAddress remoteDevice; - qsizetype numDevices; - bool expectRemoteDevice; + qsizetype numDevices = 0; + bool expectRemoteDevice = false; }; tst_QBluetoothLocalDevice::tst_QBluetoothLocalDevice() - : numDevices(QBluetoothLocalDevice::allDevices().size()), - expectRemoteDevice(false) { + if (androidBluetoothEmulator()) + return; + numDevices = QBluetoothLocalDevice::allDevices().size(); const QString remote = qgetenv("BT_TEST_DEVICE"); if (!remote.isEmpty()) { remoteDevice = QBluetoothAddress(remote); @@ -78,10 +80,8 @@ void tst_QBluetoothLocalDevice::initTestCase() void tst_QBluetoothLocalDevice::tst_powerOn() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #ifdef Q_OS_OSX QSKIP("Not possible on OS X"); #endif @@ -114,10 +114,8 @@ void tst_QBluetoothLocalDevice::tst_powerOn() void tst_QBluetoothLocalDevice::tst_powerOff() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #ifdef Q_OS_OSX QSKIP("Not possible on OS X"); #endif @@ -192,10 +190,8 @@ void tst_QBluetoothLocalDevice::tst_hostModes_data() void tst_QBluetoothLocalDevice::tst_hostModes() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #ifdef Q_OS_OSX QSKIP("Not possible on OS X"); #endif @@ -270,6 +266,8 @@ void tst_QBluetoothLocalDevice::tst_name() } void tst_QBluetoothLocalDevice::tst_isValid() { + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #if defined(Q_OS_MACOS) || QT_CONFIG(winrt_bt) // On OS X we can have a valid device (device.isValid() == true), // that has neither a name nor a valid address - this happens @@ -371,10 +369,8 @@ void tst_QBluetoothLocalDevice::tst_pairDevice_data() void tst_QBluetoothLocalDevice::tst_pairDevice() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); #if defined(Q_OS_MACOS) QSKIP("The pair device test fails on macOS"); #endif diff --git a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp index bf1a55b9..291b9eef 100644 --- a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp +++ b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp @@ -5,6 +5,7 @@ #include <QDebug> +#include "../../shared/bttestutil_p.h" #include <private/qtbluetoothglobal_p.h> #include <qbluetoothserver.h> #include <qbluetoothsocket.h> @@ -34,7 +35,7 @@ private slots: void setHostMode(const QBluetoothAddress &localAdapter, QBluetoothLocalDevice::HostMode newHostMode); private: - QBluetoothLocalDevice localDevice; + QBluetoothLocalDevice *localDevice = nullptr; QBluetoothLocalDevice::HostMode initialHostMode; }; @@ -82,9 +83,13 @@ void tst_QBluetoothServer::setHostMode(const QBluetoothAddress &localAdapter, void tst_QBluetoothServer::initTestCase() { + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); qRegisterMetaType<QBluetooth::SecurityFlags>(); qRegisterMetaType<QBluetoothServer::Error>(); + localDevice = new QBluetoothLocalDevice(this); + QBluetoothLocalDevice device; if (!device.isValid()) return; @@ -97,15 +102,15 @@ void tst_QBluetoothServer::initTestCase() setHostMode(device.address(), QBluetoothLocalDevice::HostConnectable); - QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode(); + QBluetoothLocalDevice::HostMode hostMode= localDevice->hostMode(); QVERIFY(hostMode != QBluetoothLocalDevice::HostPoweredOff); } void tst_QBluetoothServer::cleanupTestCase() { - QBluetoothLocalDevice device; - setHostMode(device.address(), initialHostMode); + if (localDevice) + setHostMode(localDevice->address(), initialHostMode); } void tst_QBluetoothServer::tst_construction() @@ -144,11 +149,6 @@ void tst_QBluetoothServer::tst_receive() { QFETCH(QBluetoothLocalDevice::HostMode, hostmode); -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif - QBluetoothLocalDevice localDev; #ifdef Q_OS_OSX if (localDev.hostMode() == QBluetoothLocalDevice::HostPoweredOff) @@ -164,10 +164,10 @@ void tst_QBluetoothServer::tst_receive() if (hostmode == QBluetoothLocalDevice::HostPoweredOff) { #if !defined(Q_OS_OSX) && !QT_CONFIG(winrt_bt) - QCOMPARE(localDevice.hostMode(), hostmode); + QCOMPARE(localDevice->hostMode(), hostmode); #endif } else { - QVERIFY(localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff); + QVERIFY(localDevice->hostMode() != QBluetoothLocalDevice::HostPoweredOff); } } QBluetoothServer server(QBluetoothServiceInfo::RfcommProtocol); diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp index a2979dc1..b9e0dfb3 100644 --- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp +++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp @@ -7,6 +7,7 @@ #include <QLoggingCategory> #include <QVariant> #include <QList> +#include "../../shared/bttestutil_p.h" #include <qbluetoothaddress.h> #include <qbluetoothdevicediscoveryagent.h> @@ -50,7 +51,8 @@ private: tst_QBluetoothServiceDiscoveryAgent::tst_QBluetoothServiceDiscoveryAgent() { QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); - + if (androidBluetoothEmulator()) + return; // start Bluetooth if not started #ifndef Q_OS_OSX QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); @@ -90,10 +92,9 @@ void tst_QBluetoothServiceDiscoveryAgent::serviceError(const QBluetoothServiceDi void tst_QBluetoothServiceDiscoveryAgent::initTestCase() { -#ifdef ANDROID_CI_TEST_ENVIRONMENT - if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) - QSKIP("Skipping test on Android 12+, emulator on CI can timeout waiting for user input"); -#endif + if (androidBluetoothEmulator()) + QSKIP("Skipping test on Android 12+ emulator, CI can timeout waiting for user input"); + if (localDeviceAvailable) { QBluetoothDeviceDiscoveryAgent discoveryAgent; diff --git a/tests/shared/bttestutil_p.h b/tests/shared/bttestutil_p.h new file mode 100644 index 00000000..026d7750 --- /dev/null +++ b/tests/shared/bttestutil_p.h @@ -0,0 +1,47 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef BTTESTUTIL_P_H +#define BTTESTUTIL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qcoreapplication.h> + +#ifdef Q_OS_ANDROID +#include <QtCore/QJniObject> +#endif + +QT_BEGIN_NAMESPACE + +bool androidBluetoothEmulator() +{ +#ifdef Q_OS_ANDROID + // QTBUG-106614, the Android-12+ emulator (API level 31+) emulates bluetooth. + // We need to skip tests on the CI to avoid timeouts when Android waits for bluetooth + // permission confirmation from the user. Currently the check below skips generally + // on emulator though, not only on CI + if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31) { + const auto property = QJniObject::fromString("ro.kernel.qemu"); + const char sysPropsClass[] = "android.os.SystemProperties"; + const auto isQemu = QJniObject::callStaticObjectMethod<jstring>( + sysPropsClass, "get", property.object<jstring>()); + if (isQemu.toString() == "1") + return true; + } +#endif + return false; +} + +QT_END_NAMESPACE + +#endif // BTTESTUTIL_P_H |