summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-09-19 12:32:03 +0300
committerJuha Vuolle <juha.vuolle@insta.fi>2022-10-04 07:53:07 +0300
commit46441888164208ed09ce144f3df0ac9713648db8 (patch)
tree83d2b82bbbc871426e16bad40cafbfa91a860883
parent3284614452f011b1788f7500e22c297f9c801633 (diff)
Skip few Bluetooth autotests on Android emulator6.3
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)
-rw-r--r--tests/auto/CMakeLists.txt5
-rw-r--r--tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp14
-rw-r--r--tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp36
-rw-r--r--tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp22
-rw-r--r--tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp11
-rw-r--r--tests/shared/bttestutil_p.h48
6 files changed, 87 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 e16e2405..af2e1c8e 100644
--- a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp
+++ b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp
@@ -33,6 +33,7 @@
#include <QList>
#include <QLoggingCategory>
+#include "../../shared/bttestutil_p.h"
#include <private/qtbluetoothglobal_p.h>
#include <qbluetoothaddress.h>
#include <qbluetoothdevicediscoveryagent.h>
@@ -153,10 +154,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);
@@ -429,10 +428,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 153d515d..32f8448d 100644
--- a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp
+++ b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp
@@ -30,6 +30,7 @@
#include <QDebug>
#include <QVariant>
+#include "../../shared/bttestutil_p.h"
#include <private/qtbluetoothglobal_p.h>
#include <qbluetoothaddress.h>
@@ -70,14 +71,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);
@@ -102,10 +104,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
@@ -138,10 +138,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
@@ -200,10 +198,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
@@ -282,6 +278,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
@@ -383,10 +381,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 d265bccc..9015345b 100644
--- a/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp
+++ b/tests/auto/qbluetoothserver/tst_qbluetoothserver.cpp
@@ -30,6 +30,7 @@
#include <QDebug>
+#include "../../shared/bttestutil_p.h"
#include <private/qtbluetoothglobal_p.h>
#include <qbluetoothserver.h>
#include <qbluetoothsocket.h>
@@ -59,7 +60,7 @@ private slots:
void setHostMode(const QBluetoothAddress &localAdapter, QBluetoothLocalDevice::HostMode newHostMode);
private:
- QBluetoothLocalDevice localDevice;
+ QBluetoothLocalDevice *localDevice = nullptr;
QBluetoothLocalDevice::HostMode initialHostMode;
};
@@ -107,9 +108,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;
@@ -122,15 +127,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()
@@ -169,11 +174,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)
@@ -189,10 +189,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 8d790357..27827da3 100644
--- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
+++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
@@ -32,6 +32,7 @@
#include <QLoggingCategory>
#include <QVariant>
#include <QList>
+#include "../../shared/bttestutil_p.h"
#include <qbluetoothaddress.h>
#include <qbluetoothdevicediscoveryagent.h>
@@ -75,7 +76,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();
@@ -115,10 +117,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..9d470c29
--- /dev/null
+++ b/tests/shared/bttestutil_p.h
@@ -0,0 +1,48 @@
+// 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 auto isQemu = QJniObject::callStaticObjectMethod(
+ "android.os.SystemProperties", "get",
+ "(Ljava/lang/String;)Ljava/lang/String;",
+ property.object<jstring>());
+ if (isQemu.toString() == "1")
+ return true;
+ }
+#endif
+ return false;
+}
+
+QT_END_NAMESPACE
+
+#endif // BTTESTUTIL_P_H