diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2023-09-04 15:41:08 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-09-05 11:02:53 +0000 |
commit | 54b2946b55de1319cf4e11ee7c5311e79ab9bbf4 (patch) | |
tree | 8da3e538a9ca0add5e410e19088c484eb33a252d | |
parent | 22b4a6833122a6d05e38a901e3c25586482e8776 (diff) |
Bluetooth autotests: do _not_ request permissions to use BT
When running in "ci" test environment, only check them. Normally,
requesting a permission may trigger a system (such as macOS) to
show a popup/alert, requesting a permission to use Bluetooth. But
on CI there is nobody to click 'Allow' button. Even worse
though, the 'trick' with a nested loop was quite useless there, test
was essentially timing out after 15m instead of interrupting the loop
after 30 seconds. Now the part requesting permission is conditional with
testing QTEST_ENVIRONMENT env. variable (which contains "ci"
when running on CI.
Task-number: QTBUG-115945
Change-Id: If7ec8e2bd7a7aa9602a31c5a0f00b756e9523012
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit b0344c5cf3fb85ad26a0cb36b86e085ffe80ee5b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
3 files changed, 18 insertions, 14 deletions
diff --git a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp index b192e120..32da7da8 100644 --- a/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp +++ b/tests/auto/qbluetoothdevicediscoveryagent/tst_qbluetoothdevicediscoveryagent.cpp @@ -82,16 +82,18 @@ tst_QBluetoothDeviceDiscoveryAgent::tst_QBluetoothDeviceDiscoveryAgent() qRegisterMetaType<QBluetoothDeviceDiscoveryAgent::Error>(); #if QT_CONFIG(permissions) permissionStatus = qApp->checkPermission(QBluetoothPermission{}); - if (permissionStatus == Qt::PermissionStatus::Undetermined) { + + const bool ciRun = qEnvironmentVariable("QTEST_ENVIRONMENT").split(' ').contains("ci"); + if (!ciRun && permissionStatus == Qt::PermissionStatus::Undetermined) { QTestEventLoop loop; qApp->requestPermission(QBluetoothPermission{}, [this, &loop](const QPermission &permission){ permissionStatus = permission.status(); loop.exitLoop(); }); - if (permissionStatus == Qt::PermissionStatus::Undetermined) // Did not return immediately? + if (permissionStatus == Qt::PermissionStatus::Undetermined) loop.enterLoopMSecs(30000); } -#endif +#endif // QT_CONFIG(permissions) } tst_QBluetoothDeviceDiscoveryAgent::~tst_QBluetoothDeviceDiscoveryAgent() diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index a304d91a..77530c6b 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -96,19 +96,20 @@ tst_QLowEnergyController::tst_QLowEnergyController() // FIXME: for Android, set additional parameters for scan and connect // permissions. permissionStatus = qApp->checkPermission(QBluetoothPermission{}); - if (permissionStatus == Qt::PermissionStatus::Undetermined) { - QTestEventLoop eventLoop; - qApp->requestPermission(QBluetoothPermission{}, [this, &eventLoop](const QPermission &permission){ + // Note: even with missing Bluetooth permission, we still can run tests on + // LE controller to test its logic/errors it emits, even if we cannot scan + // and cannot connect. + const bool ciRun = qEnvironmentVariable("QTEST_ENVIRONMENT").split(' ').contains("ci"); + if (!ciRun && permissionStatus == Qt::PermissionStatus::Undetermined) { + QTestEventLoop loop; + qApp->requestPermission(QBluetoothPermission{}, [this, &loop](const QPermission &permission){ permissionStatus = permission.status(); - eventLoop.exitLoop(); + loop.exitLoop(); }); if (permissionStatus == Qt::PermissionStatus::Undetermined) - eventLoop.enterLoop(30000); + loop.enterLoopMSecs(30000); } - // Note: even with missing Bluetooth permission, we still can run tests on - // LE controller to test its logic/errors it emits, even if we cannot scan - // and cannot connect. -#endif // permission +#endif // QT_CONFIG(permissions) } tst_QLowEnergyController::~tst_QLowEnergyController() diff --git a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp index 80ad9938..854babb3 100644 --- a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp +++ b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp @@ -52,7 +52,8 @@ tst_QLowEnergyDescriptor::tst_QLowEnergyDescriptor() : QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); #if QT_CONFIG(permissions) permissionStatus = qApp->checkPermission(QBluetoothPermission{}); - if (permissionStatus == Qt::PermissionStatus::Undetermined) { + const bool ciRun = qEnvironmentVariable("QTEST_ENVIRONMENT").split(' ').contains("ci"); + if (!ciRun && permissionStatus == Qt::PermissionStatus::Undetermined) { QTestEventLoop loop; qApp->requestPermission(QBluetoothPermission{}, [this, &loop](const QPermission &permission){ permissionStatus = permission.status(); @@ -61,7 +62,7 @@ tst_QLowEnergyDescriptor::tst_QLowEnergyDescriptor() : if (permissionStatus == Qt::PermissionStatus::Undetermined) loop.enterLoopMSecs(30000); } -#endif +#endif // QT_CONFIG(permissions) } tst_QLowEnergyDescriptor::~tst_QLowEnergyDescriptor() |