mirror of
https://github.com/status-im/qzxing.git
synced 2025-02-16 21:06:43 +00:00
Added blocking map-reduce concurrency when executing EncoderStressTest. (still has issues.)
This commit is contained in:
parent
83243790f8
commit
9dfa221563
@ -1,11 +1,15 @@
|
|||||||
#include "EncoderStressTest.h"
|
#include "EncoderStressTest.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QtConcurrent>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace tests{
|
namespace tests{
|
||||||
|
|
||||||
EncoderStressTest::EncoderStressTest(): TestCase(), decoder(QZXing::DecoderFormat_QR_CODE),
|
QMutex EncoderStressTest::mutex;
|
||||||
sumOfSuccessfullTests(0), totalExecutedTests(0)
|
QMutex EncoderStressTest::printLockMutex;
|
||||||
|
|
||||||
|
EncoderStressTest::EncoderStressTest(): TestCase(),
|
||||||
|
sumOfSuccessfullTests_(0), totalExecutedTests_(0)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
N A B
|
N A B
|
||||||
@ -15,20 +19,23 @@ EncoderStressTest::EncoderStressTest(): TestCase(), decoder(QZXing::DecoderForma
|
|||||||
H 3057 1852 1273
|
H 3057 1852 1273
|
||||||
*/
|
*/
|
||||||
|
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::L.name()][qrcode::Mode::NUMERIC.getName()] = 7089;
|
// 4 different error correction levels
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::M.name()][qrcode::Mode::NUMERIC.getName()] = 5596;
|
maxCharacterNumberMap_.resize(4);
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::Q.name()][qrcode::Mode::NUMERIC.getName()] = 3993;
|
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::H.name()][qrcode::Mode::NUMERIC.getName()] = 3057;
|
|
||||||
|
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::L.name()][qrcode::Mode::ALPHANUMERIC.getName()] = 4296;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_L][qrcode::Mode::NUMERIC.getName()] = 7089;
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::M.name()][qrcode::Mode::ALPHANUMERIC.getName()] = 3391;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_M][qrcode::Mode::NUMERIC.getName()] = 5596;
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::Q.name()][qrcode::Mode::ALPHANUMERIC.getName()] = 2420;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_Q][qrcode::Mode::NUMERIC.getName()] = 3993;
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::H.name()][qrcode::Mode::ALPHANUMERIC.getName()] = 1852;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_H][qrcode::Mode::NUMERIC.getName()] = 3057;
|
||||||
|
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::L.name()][qrcode::Mode::BYTE.getName()] = 2953;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_L][qrcode::Mode::ALPHANUMERIC.getName()] = 4296;
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::M.name()][qrcode::Mode::BYTE.getName()] = 2331;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_M][qrcode::Mode::ALPHANUMERIC.getName()] = 3391;
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::Q.name()][qrcode::Mode::BYTE.getName()] = 1663;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_Q][qrcode::Mode::ALPHANUMERIC.getName()] = 2420;
|
||||||
maxCharacterNumberMap_[qrcode::ErrorCorrectionLevel::H.name()][qrcode::Mode::BYTE.getName()] = 1273;
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_H][qrcode::Mode::ALPHANUMERIC.getName()] = 1852;
|
||||||
|
|
||||||
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_L][qrcode::Mode::BYTE.getName()] = 2953;
|
||||||
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_M][qrcode::Mode::BYTE.getName()] = 2331;
|
||||||
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_Q][qrcode::Mode::BYTE.getName()] = 1663;
|
||||||
|
maxCharacterNumberMap_[QZXing::EncodeErrorCorrectionLevel_H][qrcode::Mode::BYTE.getName()] = 1273;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zxing::tests::EncoderStressTest::execute()
|
void zxing::tests::EncoderStressTest::execute()
|
||||||
@ -37,14 +44,14 @@ void zxing::tests::EncoderStressTest::execute()
|
|||||||
runTests(zxing::qrcode::Mode::ALPHANUMERIC);
|
runTests(zxing::qrcode::Mode::ALPHANUMERIC);
|
||||||
runTests(zxing::qrcode::Mode::BYTE);
|
runTests(zxing::qrcode::Mode::BYTE);
|
||||||
|
|
||||||
std::cout << "total: successful: " << sumOfSuccessfullTests << ", total: " << totalExecutedTests << std::endl;
|
std::cout << "total: successful: " << sumOfSuccessfullTests_ << ", total: " << totalExecutedTests_ << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncoderStressTest::getMaxCharacterNumber(qrcode::ErrorCorrectionLevel &errorCorrectionLevel, qrcode::Mode &mode)
|
int EncoderStressTest::getMaxCharacterNumber(QZXing::EncodeErrorCorrectionLevel errorCorrectionLevel, qrcode::Mode &mode)
|
||||||
{
|
{
|
||||||
if(maxCharacterNumberMap_.contains(errorCorrectionLevel.name()) &&
|
if(maxCharacterNumberMap_.size() > errorCorrectionLevel &&
|
||||||
maxCharacterNumberMap_[errorCorrectionLevel.name()].contains(mode.getName()))
|
maxCharacterNumberMap_[errorCorrectionLevel].contains(mode.getName()))
|
||||||
return maxCharacterNumberMap_[errorCorrectionLevel.name()][mode.getName()];
|
return maxCharacterNumberMap_[errorCorrectionLevel][mode.getName()];
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -76,45 +83,54 @@ char EncoderStressTest::getCharacterForQrMode(qrcode::Mode &mode)
|
|||||||
|
|
||||||
void EncoderStressTest::runTests(qrcode::Mode &mode)
|
void EncoderStressTest::runTests(qrcode::Mode &mode)
|
||||||
{
|
{
|
||||||
runTests(zxing::qrcode::ErrorCorrectionLevel::L, mode);
|
runTests(QZXing::EncodeErrorCorrectionLevel_L, mode);
|
||||||
runTests(zxing::qrcode::ErrorCorrectionLevel::M, mode);
|
runTests(QZXing::EncodeErrorCorrectionLevel_M, mode);
|
||||||
runTests(zxing::qrcode::ErrorCorrectionLevel::Q, mode);
|
runTests(QZXing::EncodeErrorCorrectionLevel_Q, mode);
|
||||||
runTests(zxing::qrcode::ErrorCorrectionLevel::H, mode);
|
runTests(QZXing::EncodeErrorCorrectionLevel_H, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncoderStressTest::runTests(zxing::qrcode::ErrorCorrectionLevel &errorCorrectionLevel, zxing::qrcode::Mode &mode)
|
void EncoderStressTest::runTests(QZXing::EncodeErrorCorrectionLevel errorCorrectionLevel, zxing::qrcode::Mode &mode)
|
||||||
{
|
{
|
||||||
currentSetupExecutedTests = 0;
|
|
||||||
currentSetupSuccessfullTests = 0;
|
|
||||||
|
|
||||||
QString currentCharacters;
|
QString currentCharacters;
|
||||||
int maxCharLength = getMaxCharacterNumber(errorCorrectionLevel, mode);
|
int maxCharLength = getMaxCharacterNumber(errorCorrectionLevel, mode);
|
||||||
|
|
||||||
|
QList<TestRunData> testRunDataSet;
|
||||||
for(int i=1; i<=maxCharLength; ++i)
|
for(int i=1; i<=maxCharLength; ++i)
|
||||||
{
|
{
|
||||||
currentCharacters += getCharacterForQrMode(mode);
|
currentCharacters += getCharacterForQrMode(mode);
|
||||||
QImage generatedImage = QZXing::encodeData(currentCharacters);
|
|
||||||
|
|
||||||
|
TestRunData testData;
|
||||||
|
testData.data = currentCharacters;
|
||||||
|
testData.errorCorrectionLevel = errorCorrectionLevel;
|
||||||
|
testData.mode = mode;
|
||||||
|
testRunDataSet.append(testData);
|
||||||
|
}
|
||||||
|
|
||||||
|
QtConcurrent::blockingMap(testRunDataSet, EncoderStressTest::runTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EncoderStressTest::runTest(TestRunData &testData)
|
||||||
|
{
|
||||||
|
QImage generatedImage = QZXing::encodeData(testData.data,
|
||||||
|
QZXing::EncoderFormat_QR_CODE,
|
||||||
|
QSize(500, 500),
|
||||||
|
testData.errorCorrectionLevel);
|
||||||
|
|
||||||
|
// mutex.lock();
|
||||||
|
QZXing decoder(QZXing::DecoderFormat_QR_CODE);
|
||||||
QString decodedData = decoder.decodeImage(generatedImage);
|
QString decodedData = decoder.decodeImage(generatedImage);
|
||||||
|
bool wasDecoded = decoder.getLastDecodeOperationSucceded();
|
||||||
|
// mutex.unlock();
|
||||||
|
|
||||||
std::cout << "M[" << mode.getName() << "], E[" << errorCorrectionLevel.name() << "], L[" << i << "]: " <<
|
testData.successful = (testData.data == decodedData);
|
||||||
"decoded=" << decoder.getLastDecodeOperationSucceded() <<
|
|
||||||
", match=" << (currentCharacters == decodedData) << std::endl;
|
|
||||||
|
|
||||||
if(decoder.getLastDecodeOperationSucceded() && (currentCharacters == decodedData))
|
printLockMutex.lock();
|
||||||
{
|
std::cout << "M[" << testData.mode.getName() << "], E[" << testData.errorCorrectionLevel << "], L[" << testData.data.size() << "]: " <<
|
||||||
++sumOfSuccessfullTests;
|
"decoded=" << wasDecoded <<
|
||||||
++currentSetupSuccessfullTests;
|
", match=" << testData.successful << std::endl;
|
||||||
}
|
printLockMutex.unlock();
|
||||||
++totalExecutedTests;
|
|
||||||
++currentSetupExecutedTests;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "subtotal: M[" << mode.getName() << "], E[" << errorCorrectionLevel.name() << "]: " <<
|
|
||||||
"successfull: " << currentSetupSuccessfullTests << ", total: " << currentSetupExecutedTests << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,10 +10,28 @@
|
|||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <TestCase.h>
|
#include <TestCase.h>
|
||||||
#include <zxing/qrcode/decoder/Mode.h>
|
#include <zxing/qrcode/decoder/Mode.h>
|
||||||
|
#include <QWaitCondition>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QThreadPool>
|
||||||
|
#include <QFuture>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace tests{
|
namespace tests{
|
||||||
|
|
||||||
|
struct TestRunData {
|
||||||
|
QString data;
|
||||||
|
QZXing::EncodeErrorCorrectionLevel errorCorrectionLevel;
|
||||||
|
qrcode::Mode mode;
|
||||||
|
|
||||||
|
bool successful;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TestRunData(): data(""), errorCorrectionLevel(QZXing::EncodeErrorCorrectionLevel_L),
|
||||||
|
mode(qrcode::Mode::BYTE), successful(false) {}
|
||||||
|
};
|
||||||
|
|
||||||
class EncoderStressTest : public TestCase
|
class EncoderStressTest : public TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -21,21 +39,21 @@ public:
|
|||||||
void execute() override;
|
void execute() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int getMaxCharacterNumber(zxing::qrcode::ErrorCorrectionLevel &errorCorrectionLevel, zxing::qrcode::Mode &mode);
|
int getMaxCharacterNumber(QZXing::EncodeErrorCorrectionLevel errorCorrectionLevel, zxing::qrcode::Mode &mode);
|
||||||
char getCharacterForQrMode(zxing::qrcode::Mode &mode);
|
char getCharacterForQrMode(zxing::qrcode::Mode &mode);
|
||||||
|
|
||||||
void runTests(zxing::qrcode::Mode &mode);
|
void runTests(zxing::qrcode::Mode &mode);
|
||||||
void runTests(zxing::qrcode::ErrorCorrectionLevel &errorCorrectionLevel, zxing::qrcode::Mode &mode);
|
void runTests(QZXing::EncodeErrorCorrectionLevel errorCorrectionLevel, zxing::qrcode::Mode &mode);
|
||||||
|
|
||||||
|
static void runTest(TestRunData &testData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QZXing decoder;
|
QVector<QMap<std::string, int>> maxCharacterNumberMap_;
|
||||||
QMap<std::string, QMap<std::string, int>> maxCharacterNumberMap_;
|
size_t sumOfSuccessfullTests_;
|
||||||
|
size_t totalExecutedTests_;
|
||||||
|
|
||||||
int sumOfSuccessfullTests;
|
static QMutex mutex;
|
||||||
int totalExecutedTests;
|
static QMutex printLockMutex;
|
||||||
|
|
||||||
int currentSetupSuccessfullTests;
|
|
||||||
int currentSetupExecutedTests;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ TARGET = QZXingTests
|
|||||||
CONFIG += console
|
CONFIG += console
|
||||||
CONFIG -= app_bundle
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
QT += concurrent
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user