summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEven Oscar Andersen <even.oscar.andersen@qt.io>2024-02-22 09:52:27 +0100
committerEven Oscar Andersen <even.oscar.andersen@qt.io>2024-04-13 11:32:17 +0100
commitc0fdd4b4513a2cbf805ee05a29b31ecab1aa89bb (patch)
tree13239f91609428f1f13671df15750df955b75787
parent3e049f06557d0e3483b7fa40ecf8c9a918d8ac3a (diff)
wasm: Add auto test for qfile
Problems: * mmap of size 0 works, add test in QFSFileEnginePrivate::map to make sure wasm platform behaves as the other platforms * qwe// is a valid filename on wasm, QSKIP test * applicationFilePath does not exist on wasm. * /dev/zero does not exist on wasm, file bug, skip test * blocking pipes do not exist on wasm, QSKIP test * socketpair does not exist on wasm, QSKIP test Change-Id: I1705c543782cbcb92a7ebed2fc2792613524c686 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp4
-rw-r--r--tests/auto/CMakeLists.txt1
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp58
3 files changed, 42 insertions, 21 deletions
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 200e1af52f6..5806689182f 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -565,11 +565,11 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFla
}
if (offset < 0 || offset > maxFileOffset
- || size < 0 || quint64(size) > quint64(size_t(-1))) {
+ || size <= 0
+ || quint64(size) > quint64(size_t(-1))) {
q->setError(QFile::UnspecifiedError, qt_error_string(EINVAL));
return nullptr;
}
-
// If we know the mapping will extend beyond EOF, fail early to avoid
// undefined behavior. Otherwise, let mmap have its say.
if (doStat(QFileSystemMetaData::SizeAttribute)
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt
index 06e9b9ac6c5..74e7b2c5ddb 100644
--- a/tests/auto/CMakeLists.txt
+++ b/tests/auto/CMakeLists.txt
@@ -63,6 +63,7 @@ if(WASM)
add_subdirectory(corelib/io/qbuffer)
add_subdirectory(corelib/io/qabstractfileengine)
add_subdirectory(corelib/io/qsettings)
+ add_subdirectory(corelib/io/qfile)
add_subdirectory(corelib/serialization)
add_subdirectory(corelib/text)
add_subdirectory(corelib/thread)
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index e75fdade95b..00fc1b2aa4a 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -202,6 +202,7 @@ private slots:
void flush();
void bufferedRead();
#ifdef Q_OS_UNIX
+ void isSequential_data();
void isSequential();
#endif
void decodeName_data();
@@ -232,7 +233,7 @@ private slots:
void virtualFile_data();
void virtualFile();
#endif
-#ifdef Q_OS_UNIX
+#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
void unixPipe_data();
void unixPipe();
void unixFifo_data() { unixPipe_data(); }
@@ -645,7 +646,7 @@ void tst_QFile::open()
QFETCH( bool, ok );
-#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) && !defined(Q_OS_WASM)
if (::getuid() == 0)
// root and Chuck Norris don't care for file permissions. Skip.
QSKIP("Running this test as root doesn't make sense");
@@ -1219,6 +1220,11 @@ static inline QChar invalidDriveLetter()
void tst_QFile::invalidFile_data()
{
QTest::addColumn<QString>("fileName");
+
+#if defined(Q_OS_WASM)
+ QSKIP("No invalid files on wasm");
+#endif
+
#if !defined(Q_OS_WIN)
QTest::newRow( "x11" ) << QString( "qwe//" );
#else
@@ -1233,7 +1239,6 @@ void tst_QFile::invalidFile_data()
QTest::newRow( "pipe" ) << QString( "fail|invalid" );
#endif
}
-
void tst_QFile::invalidFile()
{
QFETCH( QString, fileName );
@@ -1376,7 +1381,10 @@ void tst_QFile::permissions_data()
QTest::addColumn<bool>("expected");
QTest::addColumn<bool>("create");
+#ifndef Q_OS_WASM
+ // Application path is empty on wasm
QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << uint(QFile::ExeUser) << true << false;
+#endif
QTest::newRow("data1") << m_testSourceFile << uint(QFile::ReadUser) << true << false;
QTest::newRow("readonly") << QString::fromLatin1("readonlyfile") << uint(QFile::WriteUser) << false << false;
QTest::newRow("longfile") << QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName"
@@ -1407,7 +1415,7 @@ void tst_QFile::permissions()
QFile::Permissions staticResult = QFile::permissions(file) & perms;
if (create) {
- QFile::remove(file);
+ QVERIFY(QFile::remove(file));
}
#if defined(Q_OS_WIN)
@@ -1911,20 +1919,26 @@ void tst_QFile::bufferedRead()
}
#ifdef Q_OS_UNIX
-void tst_QFile::isSequential()
+void tst_QFile::isSequential_data()
{
- QFile zero("/dev/zero");
- QVERIFY2(zero.open(QFile::ReadOnly), msgOpenFailed(zero).constData());
- QVERIFY(zero.isSequential());
+ QTest::addColumn<QString>("deviceName");
+ QTest::addColumn<bool>("acceptFailOpen");
+
+ QTest::newRow("/dev/null") << QString("/dev/null") << false;
+ QTest::newRow("/dev/tty") << QString("/dev/tty") << true;
+ QTest::newRow("/dev/zero") << QString("/dev/zero") << false;
+}
- QFile null("/dev/null");
- QVERIFY(null.open(QFile::ReadOnly));
- QVERIFY(null.isSequential());
+void tst_QFile::isSequential()
+{
+ QFETCH(QString, deviceName);
+ QFETCH(bool, acceptFailOpen);
- // /dev/tty will fail to open if we don't have a controlling TTY
- QFile tty("/dev/tty");
- if (tty.open(QFile::ReadOnly))
- QVERIFY(tty.isSequential());
+ if (access(deviceName.toUtf8().data(), R_OK) == 0) {
+ QFile device(deviceName);
+ QVERIFY2(device.open(QFile::ReadOnly) || acceptFailOpen, msgOpenFailed(device).constData());
+ QVERIFY(!device.isOpen() || device.isSequential());
+ }
}
#endif
@@ -2720,7 +2734,13 @@ void tst_QFile::virtualFile()
}
#endif // defined(Q_OS_LINUX) || defined(Q_OS_AIX) || defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
-#ifdef Q_OS_UNIX
+#if defined (Q_OS_UNIX) && !defined(Q_OS_WASM)
+// wasm does not have working fifo
+// https://github.com/nodejs/node/issues/38344
+// wasm does not have blocking pipe I/O
+// https://github.com/emscripten-core/emscripten/issues/13214
+// wasm does not, by default, have socketpair
+// https://emscripten.org/docs/porting/networking.html
static void unixPipe_helper(int pipes[2])
{
// start a thread and wait for it to write a first byte
@@ -2839,7 +2859,7 @@ void tst_QFile::socketPair()
qt_safe_close(pipes[1]);
#endif
}
-#endif
+#endif /* UNIX && !WASM; */
void tst_QFile::textFile()
{
@@ -3949,7 +3969,7 @@ void tst_QFile::moveToTrash_data()
if (!temp.open())
QSKIP("Failed to create temporary file!");
QTest::newRow("temporary file") << temp.fileName() << true << true;
-#ifdef Q_OS_UNIX
+#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
if (QDir::tempPath() == "/tmp")
QTest::newRow("var-temporary file") << "/var" + temp.fileName() << true << true;
#endif
@@ -3962,7 +3982,7 @@ void tst_QFile::moveToTrash_data()
QTest::newRow("temporary dir")
<< tempDir.path() + QLatin1Char('/')
<< true << true;
-#ifdef Q_OS_UNIX
+#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
if (QDir::tempPath() == "/tmp")
QTest::newRow("var-temporary dir") << "/var" + tempDir.path() << true << true;
#endif