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>
This commit is contained in:
parent
3e049f0655
commit
c0fdd4b451
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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_data()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void tst_QFile::isSequential()
|
||||
{
|
||||
QFile zero("/dev/zero");
|
||||
QVERIFY2(zero.open(QFile::ReadOnly), msgOpenFailed(zero).constData());
|
||||
QVERIFY(zero.isSequential());
|
||||
QFETCH(QString, deviceName);
|
||||
QFETCH(bool, acceptFailOpen);
|
||||
|
||||
QFile null("/dev/null");
|
||||
QVERIFY(null.open(QFile::ReadOnly));
|
||||
QVERIFY(null.isSequential());
|
||||
|
||||
// /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
|
||||
|
Loading…
x
Reference in New Issue
Block a user