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)] Pick-to: 6.6 Change-Id: I8f3ce163ccc5408cac39fffd178d7af1c67ec988 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
bef5d486d5
commit
ae03ffaffd
@ -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>
|
||||
|
||||
@ -167,16 +168,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);
|
||||
@ -199,10 +228,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);
|
||||
|
Loading…
Reference in New Issue
Block a user