From 7490937609dc6a46ab33dc7195ab78e02bd50e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Pet=C3=A4j=C3=A4j=C3=A4rvi?= Date: Wed, 17 Nov 2021 18:31:48 +0200 Subject: Fix test when accessing patched plugin too fast At least one OS (QNX) can't dlopen() a library that is still open for writing elsewhere Pick-to: 6.2 Change-Id: I2d4425d8c69162cdfa43c2523c7459def7839eb9 Reviewed-by: Thiago Macieira --- .../plugin/qpluginloader/tst_qpluginloader.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp') diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index 7d95004709..8994835471 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "theplugin/plugininterface.h" #if defined(QT_BUILD_INTERNAL) && defined(Q_OF_MACH_O) @@ -983,11 +984,25 @@ void tst_QPluginLoader::loadSectionTableStrippedElf() f->seek(f->size()); f->write(reinterpret_cast(&badHeader), sizeof(badHeader)); } }; - std::unique_ptr tmplib = - patchElf(sys_qualifiedLibraryName("theplugin"), patcher); + + QString tmpLibName; + { + std::unique_ptr tmplib = + patchElf(sys_qualifiedLibraryName("theplugin"), patcher); + + tmpLibName = tmplib->fileName(); + tmplib->setAutoRemove(false); + } +#if defined(Q_OS_QNX) + // On QNX plugin access is still too early, even when QTemporaryFile is closed + QTest::qSleep(1000); +#endif + auto removeTmpLib = qScopeGuard([=]{ + QFile::remove(tmpLibName); + }); // now attempt to load it - QPluginLoader loader(tmplib->fileName()); + QPluginLoader loader(tmpLibName); QVERIFY2(loader.load(), qPrintable(loader.errorString())); PluginInterface *instance = qobject_cast(loader.instance()); QVERIFY(instance); -- cgit v1.2.3