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 <thiago.macieira@intel.com>
This commit is contained in:
Michał Łoś 2024-12-06 10:31:09 +01:00
parent a77a7c157d
commit 138160fccd

View File

@ -562,9 +562,15 @@ void tst_QLatin1StringMatcher::haystacksWithMoreThan4GiBWork()
{ {
qsizetype dynamicResult; 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{ [&] { auto t = std::thread{ [&] {
QLatin1StringMatcher m(QLatin1StringView(needle), Qt::CaseSensitive); QLatin1StringMatcher m(QLatin1StringView(needle), Qt::CaseSensitive);
dynamicResult = m.indexIn(QStringView(QString::fromLatin1(large))); dynamicResult = m.indexIn(QStringView(toSearch));
} }; } };
t.join(); t.join();