From 138160fccdd8eec6acb78044330b35a0a7f9b258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81o=C5=9B?= Date: Fri, 6 Dec 2024 10:31:09 +0100 Subject: [PATCH] Fix exception in memory heavy QLatin1StringMatcher test tst_QLatin1StringMatcher::haystacksWithMoreThan4GiBWork test requires a lot of memory to run (over 12GiB total) when run on 64bit platform. This is addressed in try-catch block starting in line 535, in which check for std::bad_alloc is added, skipping the test when it occurs. Unfortunately, this helps with scenario where system has 4GiB or less of memory, because in line 567 conversion of 4GiB+ std::string to QString occurs, which requires additional 8GiB+ of memory. This ends up with std::bad_alloc exception happening when system has less than 12GiB bytes, failing the test. This was found during tests of VxWorks for Intel x64. Fix this by extracting allocation and surrounding it with try-catch bock, skipping test if std::bad_alloc occurs. Task-number: QTBUG-115777 Change-Id: Ie6df4d702f061b1d17cb0eab84228819d294a379 Reviewed-by: Thiago Macieira --- .../qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp b/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp index ba098fd23cd..d4a151452e0 100644 --- a/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp +++ b/tests/auto/corelib/text/qlatin1stringmatcher/tst_qlatin1stringmatcher.cpp @@ -562,9 +562,15 @@ void tst_QLatin1StringMatcher::haystacksWithMoreThan4GiBWork() { qsizetype dynamicResult; + QString toSearch; + try { + toSearch = QString::fromLatin1(large); + } catch (const std::bad_alloc &) { + QSKIP("Could not allocate additional 8GiB plus a couple hundred bytes of RAM."); + } auto t = std::thread{ [&] { QLatin1StringMatcher m(QLatin1StringView(needle), Qt::CaseSensitive); - dynamicResult = m.indexIn(QStringView(QString::fromLatin1(large))); + dynamicResult = m.indexIn(QStringView(toSearch)); } }; t.join();