tst_QStorageInfo::{tempFile,caching}: try a to find a non-btrfs storage

These tests skip when we're writing to a btrfs filesystem because, for
some reason, the amount of free space does not update synchronously with
file writing. But instead of giving up if $TMPDIR is a btrfs, let's try
and use the $XDG_RUNTIME_DIR, which is usually a tmpfs.

This will work in the CI for the openSUSE set ups, where / is btrfs,
/tmp is not a separate tmpfs, but /run/user/1000 is available.

FAIL!  : tst_QStorageInfo::tempFile() The computed value is expected to be different from the baseline, but is not
   Computed (free)                : 25510780928
   Baseline (storage2.bytesFree()): 25510780928
   Loc: [tst_qstorageinfo.cpp(234)]

Change-Id: I8f3ce163ccc5408cac39fffd178d7af1c67ec988
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit ae03ffaffdcc8b2a0589b846e16ad016691dec29)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2023-10-12 14:56:53 -07:00 committed by Qt Cherry-pick Bot
parent 8101f7316c
commit 90e551d0a5

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QStandardPaths>
#include <QStorageInfo>
#include <QTemporaryFile>
@ -156,16 +157,44 @@ void tst_QStorageInfo::storageList()
}
}
static bool checkFilesystemGoodForWriting(QTemporaryFile &file, QStorageInfo &storage)
{
#ifdef Q_OS_LINUX
auto reconstructAt = [](auto *where, auto &&... how) {
// it's very difficult to convince QTemporaryFile to change the path...
std::destroy_at(where);
q20::construct_at(where, std::forward<decltype(how)>(how)...);
};
if (storage.fileSystemType() == "btrfs") {
// let's see if we can find another, writable FS
QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
if (!runtimeDir.isEmpty()) {
reconstructAt(&file, runtimeDir + "/XXXXXX");
if (file.open()) {
storage.setPath(file.fileName());
if (storage.fileSystemType() != "btrfs")
return true;
}
}
QTest::qSkip("btrfs does not synchronously update free space; this test would fail",
__FILE__, __LINE__);
return false;
}
#else
Q_UNUSED(file);
Q_UNUSED(storage);
#endif
return true;
}
void tst_QStorageInfo::tempFile()
{
QTemporaryFile file;
QVERIFY2(file.open(), qPrintable(file.errorString()));
QStorageInfo storage1(file.fileName());
#ifdef Q_OS_LINUX
if (storage1.fileSystemType() == "btrfs")
QSKIP("This test doesn't work on btrfs, probably due to a btrfs bug");
#endif
if (!checkFilesystemGoodForWriting(file, storage1))
return;
qint64 free = storage1.bytesFree();
QCOMPARE_NE(free, -1);
@ -188,10 +217,8 @@ void tst_QStorageInfo::caching()
QVERIFY2(file.open(), qPrintable(file.errorString()));
QStorageInfo storage1(file.fileName());
#ifdef Q_OS_LINUX
if (storage1.fileSystemType() == "btrfs")
QSKIP("This test doesn't work on btrfs, probably due to a btrfs bug");
#endif
if (!checkFilesystemGoodForWriting(file, storage1))
return;
qint64 free = storage1.bytesFree();
QStorageInfo storage2(storage1);