Skip to content

Commit

Permalink
Fix exception in memory heavy QLatin1StringMatcher test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Michał Łoś committed Dec 9, 2024
1 parent a77a7c1 commit 138160f
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 138160f

Please sign in to comment.