From 90e551d0a56987ebec1a5f8a89c11f3cea8ffe3c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 12 Oct 2023 14:56:53 -0700 Subject: [PATCH] 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 Reviewed-by: Volker Hilsheimer (cherry picked from commit ae03ffaffdcc8b2a0589b846e16ad016691dec29) Reviewed-by: Qt Cherry-pick Bot --- .../io/qstorageinfo/tst_qstorageinfo.cpp | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp index 94acef6bd47..c2edc5a7f04 100644 --- a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp +++ b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include +#include #include #include @@ -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(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);