diff options
author | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-01-16 19:13:52 +0300 |
---|---|---|
committer | Jocelyn Turcotte <jturcotte@woboq.com> | 2017-01-26 01:26:23 +0300 |
commit | 605a18ff738afc3951dfaedf9068a921b77bebc7 (patch) | |
tree | 451054dfbe4fa6ae213401b6b2b53e66b6136ef8 | |
parent | 92e86641d1b7cf09d5fda617295b21e6543d3e72 (diff) |
Tests: Add a large sync benchmark
This simulates a ~50k files sync that can be used to measure memory
usage without having to wait for a server.
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/benchmarks/benchlargesync.cpp | 43 | ||||
-rw-r--r-- | test/owncloud_add_test.cmake | 27 | ||||
-rw-r--r-- | test/syncenginetestutils.h | 25 |
4 files changed, 84 insertions, 12 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cfad8e61e..5c577cfa9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -50,6 +50,7 @@ if(HAVE_QT5 AND NOT BUILD_WITH_QT4) owncloud_add_test(SyncFileStatusTracker "syncenginetestutils.h") owncloud_add_test(ChunkingNg "syncenginetestutils.h") owncloud_add_test(UploadReset "syncenginetestutils.h") + owncloud_add_benchmark(LargeSync "syncenginetestutils.h") endif(HAVE_QT5 AND NOT BUILD_WITH_QT4) SET(FolderMan_SRC ../src/gui/folderman.cpp) diff --git a/test/benchmarks/benchlargesync.cpp b/test/benchmarks/benchlargesync.cpp new file mode 100644 index 000000000..88a774b90 --- /dev/null +++ b/test/benchmarks/benchlargesync.cpp @@ -0,0 +1,43 @@ +/* + * This software is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * + */ + +#include "syncenginetestutils.h" +#include <syncengine.h> + +using namespace OCC; + +int numDirs = 0; +int numFiles = 0; + +template<int filesPerDir, int dirPerDir, int maxDepth> +void addBunchOfFiles(int depth, const QString &path, FileModifier &fi) { + for (int fileNum = 1; fileNum <= filesPerDir; ++fileNum) { + QString name = QStringLiteral("file") + QString::number(fileNum); + fi.insert(path.isEmpty() ? name : path + "/" + name); + numFiles++; + } + if (depth >= maxDepth) + return; + for (char dirNum = 1; dirNum <= dirPerDir; ++dirNum) { + QString name = QStringLiteral("dir") + QString::number(dirNum); + QString subPath = path.isEmpty() ? name : path + "/" + name; + fi.mkdir(subPath); + numDirs++; + addBunchOfFiles<filesPerDir, dirPerDir, maxDepth>(depth + 1, subPath, fi); + } +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + FakeFolder fakeFolder{FileInfo{}}; + addBunchOfFiles<10, 8, 4>(0, "", fakeFolder.localModifier()); + + qDebug() << "NUMFILES" << numFiles; + qDebug() << "NUMDIRS" << numDirs; + return fakeFolder.syncOnce() ? 0 : -1; +} diff --git a/test/owncloud_add_test.cmake b/test/owncloud_add_test.cmake index 8406c2dfe..338526d87 100644 --- a/test/owncloud_add_test.cmake +++ b/test/owncloud_add_test.cmake @@ -24,3 +24,30 @@ macro(owncloud_add_test test_class additional_cpp) add_definitions(-DOWNCLOUD_BIN_PATH=${CMAKE_BINARY_DIR}/bin) add_test(NAME ${OWNCLOUD_TEST_CLASS}Test COMMAND ${OWNCLOUD_TEST_CLASS}Test) endmacro() + +macro(owncloud_add_benchmark test_class additional_cpp) + include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${QT_INCLUDES} + "${PROJECT_SOURCE_DIR}/src/gui" + "${PROJECT_SOURCE_DIR}/src/libsync" + "${CMAKE_BINARY_DIR}/src/libsync" + "${CMAKE_CURRENT_BINARY_DIR}" + ) + + set(CMAKE_AUTOMOC TRUE) + set(OWNCLOUD_TEST_CLASS ${test_class}) + string(TOLOWER "${OWNCLOUD_TEST_CLASS}" OWNCLOUD_TEST_CLASS_LOWERCASE) + + add_executable(${OWNCLOUD_TEST_CLASS}Bench benchmarks/bench${OWNCLOUD_TEST_CLASS_LOWERCASE}.cpp ${additional_cpp}) + qt5_use_modules(${OWNCLOUD_TEST_CLASS}Bench Test Sql Xml Network) + + target_link_libraries(${OWNCLOUD_TEST_CLASS}Bench + updater + ${APPLICATION_EXECUTABLE}sync + ${QT_QTTEST_LIBRARY} + ${QT_QTCORE_LIBRARY} + ) + + add_definitions(-DOWNCLOUD_TEST) + add_definitions(-DOWNCLOUD_BIN_PATH=${CMAKE_BINARY_DIR}/bin) +endmacro() diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 0c4bf6cae..59d5e5b14 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -267,6 +267,15 @@ public: return (parentPath.isEmpty() ? QString() : (parentPath + '/')) + name; } + void fixupParentPathRecursively() { + auto p = path(); + for (auto it = children.begin(); it != children.end(); ++it) { + Q_ASSERT(it.key() == it->name); + it->parentPath = p; + it->fixupParentPathRecursively(); + } + } + QString name; bool isDir = true; bool isShared = false; @@ -285,15 +294,6 @@ private: return find(pathComponents, true); } - void fixupParentPathRecursively() { - auto p = path(); - for (auto it = children.begin(); it != children.end(); ++it) { - Q_ASSERT(it.key() == it->name); - it->parentPath = p; - it->fixupParentPathRecursively(); - } - } - friend inline QDebug operator<<(QDebug dbg, const FileInfo& fi) { return dbg << "{ " << fi.path() << ": " << fi.children; } @@ -791,6 +791,7 @@ public: QDir rootDir{_tempDir.path()}; FileInfo rootTemplate; fromDisk(rootDir, rootTemplate); + rootTemplate.fixupParentPathRecursively(); return rootTemplate; } @@ -834,7 +835,7 @@ public: bool execUntilFinished() { QSignalSpy spy(_syncEngine.get(), SIGNAL(finished(bool))); - bool ok = spy.wait(60000); + bool ok = spy.wait(3600000); Q_ASSERT(ok && "Sync timed out"); return spy[0][0].toBool(); } @@ -867,8 +868,8 @@ private: if (diskChild.isDir()) { QDir subDir = dir; subDir.cd(diskChild.fileName()); - templateFi.children.insert(diskChild.fileName(), FileInfo{diskChild.fileName()}); - fromDisk(subDir, templateFi.children.last()); + FileInfo &subFi = templateFi.children[diskChild.fileName()] = FileInfo{diskChild.fileName()}; + fromDisk(subDir, subFi); } else { QFile f{diskChild.filePath()}; f.open(QFile::ReadOnly); |