qt4/tests/CMakeLists.txt | 1 qt4/tests/Makefile.am | 9 + qt4/tests/stress-threads-qt4.cpp | 298 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 1 deletion(-)
New commits: commit 287afe2290d64ca63cdb75fef8f3fbdc20997970 Author: Adam Reichold <[email protected]> Date: Sun Jun 2 23:29:00 2013 +0200 Add a thread stresser in qt4 diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt index 4d30fe6..69e9c49 100644 --- a/qt4/tests/CMakeLists.txt +++ b/qt4/tests/CMakeLists.txt @@ -43,6 +43,7 @@ qt4_add_simpletest(poppler-fonts poppler-fonts.cpp) qt4_add_simpletest(poppler_attachments poppler-attachments.cpp) qt4_add_simpletest(stress-poppler-qt4 stress-poppler-qt4.cpp) qt4_add_simpletest(stress-poppler-dir stress-poppler-dir.cpp) +qt4_add_simpletest(stress-threads-qt4 stress-threads-qt4.cpp) qt4_add_simpletest(poppler-texts poppler-texts.cpp) qt4_add_qtest(check_attachments check_attachments.cpp) diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am index e018f36..cc4853e 100644 --- a/qt4/tests/Makefile.am +++ b/qt4/tests/Makefile.am @@ -19,7 +19,8 @@ SUFFIXES: .moc noinst_PROGRAMS = test-poppler-qt4 stress-poppler-qt4 \ poppler-fonts test-password-qt4 stress-poppler-dir \ - poppler-attachments poppler-texts poppler-forms + poppler-attachments poppler-texts poppler-forms \ + stress-threads-qt4 test_poppler_qt4_SOURCES = \ @@ -65,6 +66,12 @@ stress_poppler_dir_SOURCES = \ stress_poppler_dir_LDADD = $(LDADDS) +stress-threads-qt4_SOURCES = \ + stress-threads-qt4.cpp + +stress-threads-qt4_LDADD = $(LDADDS) + + clean-generic: rm -f *.moc diff --git a/qt4/tests/stress-threads-qt4.cpp b/qt4/tests/stress-threads-qt4.cpp new file mode 100644 index 0000000..7e72728 --- /dev/null +++ b/qt4/tests/stress-threads-qt4.cpp @@ -0,0 +1,298 @@ + +#include <unistd.h> + +#include <poppler-qt4.h> +#include <poppler-form.h> + +#include <QtCore/QDebug> +#include <QtCore/QMutex> +#include <QtCore/QThread> +#include <QtGui/QImage> + +class SillyThread : public QThread +{ +public: + SillyThread(Poppler::Document* document, QObject* parent = 0); + + void run(); + +private: + Poppler::Document* m_document; + QVector< Poppler::Page* > m_pages; + +}; + +class CrazyThread : public QThread +{ +public: + CrazyThread(Poppler::Document* document, QMutex* annotationMutex, QObject* parent = 0); + + void run(); + +private: + Poppler::Document* m_document; + QMutex* m_annotationMutex; + +}; + +static Poppler::Page* loadPage(Poppler::Document* document, int index) +{ + Poppler::Page* page = document->page(index); + + if(page == 0) + { + qDebug() << "!Document::page"; + + exit(EXIT_FAILURE); + } + + return page; +} + +static Poppler::Page* loadRandomPage(Poppler::Document* document) +{ + return loadPage(document, qrand() % document->numPages()); +} + +SillyThread::SillyThread(Poppler::Document* document, QObject* parent) : QThread(parent), + m_document(document), + m_pages() +{ + m_pages.reserve(m_document->numPages()); + + for(int index = 0; index < m_document->numPages(); ++index) + { + m_pages.append(loadPage(m_document, index)); + } +} + + +void SillyThread::run() +{ + forever + { + foreach(Poppler::Page* page, m_pages) + { + QImage image = page->renderToImage(); + + if(image.isNull()) + { + qDebug() << "!Page::renderToImage"; + + ::exit(EXIT_FAILURE); + } + } + } +} + +CrazyThread::CrazyThread(Poppler::Document* document, QMutex* annotationMutex, QObject* parent) : QThread(parent), + m_document(document), + m_annotationMutex(annotationMutex) +{ +} + +void CrazyThread::run() +{ + typedef QScopedPointer< Poppler::Page > PagePointer; + + qsrand(static_cast< uint >(currentThreadId())); + + forever + { + if(qrand() % 2 == 0) + { + qDebug() << "search..."; + + PagePointer page(loadRandomPage(m_document)); + + page->search("c", Poppler::Page::CaseInsensitive); + page->search("r", Poppler::Page::CaseSensitive); + page->search("a", Poppler::Page::CaseInsensitive); + page->search("z", Poppler::Page::CaseSensitive); + page->search("y", Poppler::Page::CaseInsensitive); + } + + if(qrand() % 2 == 0) + { + qDebug() << "links..."; + + PagePointer page(loadRandomPage(m_document)); + + QList< Poppler::Link* > links = page->links(); + + qDeleteAll(links); + } + + if(qrand() % 2 == 0) + { + qDebug() << "form fields..."; + + PagePointer page(loadRandomPage(m_document)); + + QList< Poppler::FormField* > formFields = page->formFields(); + + qDeleteAll(formFields); + } + + if(qrand() % 2 == 0) + { + qDebug() << "thumbnail..."; + + PagePointer page(loadRandomPage(m_document)); + + page->thumbnail(); + } + + if(qrand() % 2 == 0) + { + qDebug() << "text..."; + + PagePointer page(loadRandomPage(m_document)); + + page->text(QRectF(QPointF(), page->pageSizeF())); + } + + if(qrand() % 2 == 0) + { + QMutexLocker mutexLocker(m_annotationMutex); + + qDebug() << "add annotation..."; + + PagePointer page(loadRandomPage(m_document)); + + Poppler::Annotation* annotation = 0; + + switch(qrand() % 3) + { + default: + case 0: + annotation = new Poppler::TextAnnotation(qrand() % 2 == 0 ? Poppler::TextAnnotation::Linked : Poppler::TextAnnotation::InPlace); + break; + case 1: + annotation = new Poppler::HighlightAnnotation(); + break; + case 2: + annotation = new Poppler::InkAnnotation(); + break; + } + + annotation->setBoundary(QRectF(0.0, 0.0, 0.5, 0.5)); + annotation->setContents("crazy"); + + page->addAnnotation(annotation); + + delete annotation; + } + + if(qrand() % 2 == 0) + { + QMutexLocker mutexLocker(m_annotationMutex); + + for(int index = 0; index < m_document->numPages(); ++index) + { + PagePointer page(loadPage(m_document, index)); + + QList< Poppler::Annotation* > annotations = page->annotations(); + + if(!annotations.isEmpty()) + { + qDebug() << "modify annotation..."; + + annotations.at(qrand() % annotations.size())->setBoundary(QRectF(0.5, 0.5, 0.25, 0.25)); + annotations.at(qrand() % annotations.size())->setAuthor("foo"); + annotations.at(qrand() % annotations.size())->setContents("bar"); + annotations.at(qrand() % annotations.size())->setCreationDate(QDateTime::currentDateTime()); + annotations.at(qrand() % annotations.size())->setModificationDate(QDateTime::currentDateTime()); + } + + qDeleteAll(annotations); + + if(!annotations.isEmpty()) + { + break; + } + } + } + + if(qrand() % 2 == 0) + { + QMutexLocker mutexLocker(m_annotationMutex); + + for(int index = 0; index < m_document->numPages(); ++index) + { + PagePointer page(loadPage(m_document, index)); + + QList< Poppler::Annotation* > annotations = page->annotations(); + + if(!annotations.isEmpty()) + { + qDebug() << "remove annotation..."; + + page->removeAnnotation(annotations.takeAt(qrand() % annotations.size())); + } + + qDeleteAll(annotations); + + if(!annotations.isEmpty()) + { + break; + } + } + } + + if(qrand() % 2 == 0) + { + qDebug() << "fonts..."; + + m_document->fonts(); + } + } +} + +int main(int argc, char** argv) +{ + if(argc < 3) + { + qDebug() << "usage: stress-threads-qt duration sillyCount crazyCount file(s)"; + + return EXIT_FAILURE; + } + + const int duration = atoi(argv[1]); + const int sillyCount = atoi(argv[2]); + const int crazyCount = atoi(argv[3]); + + for(int argi = 4; argi < argc; ++argi) + { + const QString file = QFile::decodeName(argv[argi]); + Poppler::Document* document = Poppler::Document::load(file); + + if(document == 0) + { + qDebug() << "Could not load" << file; + continue; + } + + if(document->isLocked()) + { + qDebug() << file << "is locked"; + continue; + } + + for(int i = 0; i < sillyCount; ++i) + { + (new SillyThread(document))->start(); + } + + QMutex* annotationMutex = new QMutex(); + + for(int i = 0; i < crazyCount; ++i) + { + (new CrazyThread(document, annotationMutex))->start(); + } + } + + sleep(duration); + + return EXIT_SUCCESS; +} _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
