mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Add performance test case
This requires the user to manually copy the large test file into the dives directory (because I really don't want to add this to the repo); instructions how to do that are displayed if the file is missing. Next it uses the git version of that same file (but prefetches it to try and remove the network speed from what is being measured). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
59a68fe9b5
commit
78cd2f4e09
3 changed files with 104 additions and 0 deletions
|
@ -92,6 +92,7 @@ TEST(TestUnitConversion testunitconversion.cpp)
|
|||
TEST(TestProfile testprofile.cpp)
|
||||
TEST(TestGpsCoords testgpscoords.cpp)
|
||||
TEST(TestParse testparse.cpp)
|
||||
TEST(TestParsePerformance testparseperformance.cpp)
|
||||
TEST(TestPlan testplan.cpp)
|
||||
TEST(TestDiveSiteDuplication testdivesiteduplication.cpp)
|
||||
TEST(TestRenumber testrenumber.cpp)
|
||||
|
|
85
tests/testparseperformance.cpp
Normal file
85
tests/testparseperformance.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "testparseperformance.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelist.h"
|
||||
#include "core/git-access.h"
|
||||
#include "core/settings/qPref.h"
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
#define LARGE_TEST_REPO "https://github.com/Subsurface-divelog/large-anonymous-sample-data"
|
||||
|
||||
void TestParsePerformance::initTestCase()
|
||||
{
|
||||
/* we need to manually tell that the resource exists, because we are using it as library. */
|
||||
Q_INIT_RESOURCE(subsurface);
|
||||
|
||||
// Set UTF8 text codec as in real applications
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
|
||||
|
||||
// first, setup the preferences an proxy information
|
||||
copy_prefs(&default_prefs, &prefs);
|
||||
QCoreApplication::setOrganizationName("Subsurface");
|
||||
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
||||
QCoreApplication::setApplicationName("Subsurface");
|
||||
qPrefProxy::load();
|
||||
qPrefCloudStorage::load();
|
||||
|
||||
QNetworkProxy proxy;
|
||||
proxy.setType(QNetworkProxy::ProxyType(prefs.proxy_type));
|
||||
proxy.setHostName(prefs.proxy_host);
|
||||
proxy.setPort(prefs.proxy_port);
|
||||
if (prefs.proxy_auth) {
|
||||
proxy.setUser(prefs.proxy_user);
|
||||
proxy.setPassword(prefs.proxy_pass);
|
||||
}
|
||||
QNetworkProxy::setApplicationProxy(proxy);
|
||||
|
||||
// now cleanup the cache dir in case there's something weird from previous runs
|
||||
QString localCacheDir(get_local_dir(LARGE_TEST_REPO, "git"));
|
||||
QDir localCacheDirectory(localCacheDir);
|
||||
QCOMPARE(localCacheDirectory.removeRecursively(), true);
|
||||
|
||||
}
|
||||
|
||||
void TestParsePerformance::init()
|
||||
{
|
||||
}
|
||||
|
||||
void TestParsePerformance::cleanup()
|
||||
{
|
||||
clear_dive_file_data();
|
||||
}
|
||||
|
||||
void TestParsePerformance::parseSsrf()
|
||||
{
|
||||
// parsing of a V2 file should work
|
||||
QFile largeSsrfFile(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf");
|
||||
if (!largeSsrfFile.exists()) {
|
||||
qDebug() << "missing large sample data file - available at " LARGE_TEST_REPO;
|
||||
qDebug() << "clone the repo, uncompress the file and copy it to " SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf";
|
||||
return;
|
||||
}
|
||||
QBENCHMARK {
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table);
|
||||
}
|
||||
}
|
||||
|
||||
void TestParsePerformance::parseGit()
|
||||
{
|
||||
// some more necessary setup
|
||||
git_libgit2_init();
|
||||
|
||||
// first parse this once to populate the local cache - this way network
|
||||
// effects don't dominate the parse time
|
||||
parse_file(LARGE_TEST_REPO "[git]", &dive_table);
|
||||
|
||||
cleanup();
|
||||
|
||||
QBENCHMARK {
|
||||
parse_file(LARGE_TEST_REPO "[git]", &dive_table);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestParsePerformance)
|
18
tests/testparseperformance.h
Normal file
18
tests/testparseperformance.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#ifndef TESTPARSEPERFORMANCE_H
|
||||
#define TESTPARSEPERFORMANCE_H
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
class TestParsePerformance : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void parseSsrf();
|
||||
void parseGit();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue