Tools/ChangeLog

 12011-03-17 Qi Zhang <qi.2.zhang@nokia.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 [Qt] Add a command line option to capture stdout and stderr for DumpRenderTree
 6 https://bugs.webkit.org/show_bug.cgi?id=56323
 7
 8 Using freopen to redirect STDOUT and STDERR when DumpRenderTree command line provide
 9 "--stdout" or "--stderr" option.
 10
 11 * DumpRenderTree/qt/DumpRenderTreeQt.cpp:
 12 (WebCore::DumpRenderTree::~DumpRenderTree):
 13 (WebCore::DumpRenderTree::processArgsLine):
 14 (WebCore::DumpRenderTree::loadNextTestInStandAloneMode):
 15 * DumpRenderTree/qt/DumpRenderTreeQt.h:
 16 (WebCore::DumpRenderTree::setRedirectOutputFileName):
 17 (WebCore::DumpRenderTree::setRedirectErrorFileName):
 18 * DumpRenderTree/qt/main.cpp:
 19 (isOption):
 20 (takeOptionValue):
 21 (printUsage):
 22 (main):
 23
1242011-03-17 Mikhail Naganov <mnaganov@chromium.org>
225
326 Reviewed by Yury Semikhatsky.
81375

Tools/DumpRenderTree/qt/DumpRenderTreeQt.cpp

@@DumpRenderTree::DumpRenderTree()
499499
500500DumpRenderTree::~DumpRenderTree()
501501{
 502 if (!m_redirectOutputFileName.isEmpty())
 503 fclose(stdout);
 504 if (!m_redirectErrorFileName.isEmpty())
 505 fclose(stderr);
502506 delete m_mainView;
503507 delete m_stdin;
504508 DumpRenderTreeSupportQt::removeMockDeviceOrientation();

@@void DumpRenderTree::processArgsLine(con
677681 setStandAloneMode(true);
678682
679683 for (int i = 1; i < args.size(); ++i)
680  if (!args.at(i).startsWith('-'))
681  m_standAloneModeTestList.append(args[i]);
 684 m_standAloneModeTestList.append(args[i]);
682685
683686 QFileInfo firstEntry(m_standAloneModeTestList.first());
684687 if (firstEntry.isDir()) {

@@void DumpRenderTree::processArgsLine(con
690693 for (int i = 0; i < m_standAloneModeTestList.size(); ++i)
691694 m_standAloneModeTestList[i] = folderEntry.absoluteFilePath(m_standAloneModeTestList[i]);
692695 }
693 
694  processLine(m_standAloneModeTestList.first());
695  m_standAloneModeTestList.removeFirst();
696 
697696 connect(this, SIGNAL(ready()), this, SLOT(loadNextTestInStandAloneMode()));
 697
 698 if (!m_standAloneModeTestList.isEmpty()) {
 699 QString first = m_standAloneModeTestList.takeFirst();
 700 processLine(first);
 701 }
698702}
699703
700704void DumpRenderTree::loadNextTestInStandAloneMode()

@@void DumpRenderTree::loadNextTestInStand
703707 emit quit();
704708 return;
705709 }
706 
707  processLine(m_standAloneModeTestList.first());
708  m_standAloneModeTestList.removeFirst();
 710 if (!m_standAloneModeTestList.isEmpty()) {
 711 QString first = m_standAloneModeTestList.takeFirst();
 712 processLine(first);
 713 }
709714}
710715
711716void DumpRenderTree::processLine(const QString &input)
81044

Tools/DumpRenderTree/qt/DumpRenderTreeQt.h

@@public:
105105 static void initializeFonts();
106106#endif
107107 void processArgsLine(const QStringList&);
 108 void setRedirectOutputFileName(const QString& s) { m_redirectOutputFileName = s; }
 109 void setRedirectErrorFileName(const QString& s) { m_redirectErrorFileName = s; }
108110
109111public Q_SLOTS:
110112 void initJSObjects();

@@private:
160162 bool m_standAloneMode;
161163 bool m_graphicsBased;
162164 QString m_persistentStoragePath;
 165 QString m_redirectOutputFileName;
 166 QString m_redirectErrorFileName;
163167};
164168
165169class NetworkAccessManager : public QNetworkAccessManager {
81044

Tools/DumpRenderTree/qt/main.cpp

@@void messageHandler(QtMsgType type, cons
6767 // do nothing
6868}
6969
 70// We only support -v or --pixel-tests or --stdout or --stderr or -, all the others will be
 71// pass as test case name (even -abc.html is a valid test case name)
 72bool isOption(const QString& str)
 73{
 74 return str == QString("-v") || str == QString("--pixel-tests")
 75 || str == QString("--stdout") || str == QString("--stderr")
 76 || str == QString("-");
 77}
 78
 79// Get the option value and remove the option and value from arguments list
 80QString takeOptionValue(QStringList& arguments, int index)
 81{
 82 QString result;
 83
 84 if (index + 1 < arguments.count() && !isOption(arguments.at(index + 1)))
 85 result = arguments.takeAt(index + 1);
 86 arguments.removeAt(index);
 87
 88 return result;
 89}
 90
 91void printUsage()
 92{
 93 fprintf(stderr, "Usage: DumpRenderTree [-v|--pixel-tests] [-o output_filename] [-e error_filename] filename [filename2..n]\n");
 94 fprintf(stderr, "Or folder containing test files: DumpRenderTree [-v|--pixel-tests] dirpath\n");
 95 fflush(stderr);
 96}
 97
7098QString get_backtrace() {
7199 QString s;
72100

@@int main(int argc, char* argv[])
143171
144172 QStringList args = app.arguments();
145173 if (args.count() < 2) {
146  qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename [filename2..n]";
147  qDebug() << "Or folder containing test files: DumpRenderTree [-v|--pixel-tests] dirpath";
 174 printUsage();
148175 exit(0);
149176 }
150177
151178 // Suppress debug output from Qt if not started with -v
152  if (!args.contains(QLatin1String("-v")))
 179 int index = args.indexOf(QLatin1String("-v"));
 180 if (index == -1)
153181 qInstallMsgHandler(messageHandler);
 182 else
 183 args.removeAt(index);
154184
155185 WebCore::DumpRenderTree dumper;
156186
157  if (args.contains(QLatin1String("--pixel-tests")))
 187 index = args.indexOf(QLatin1String("--pixel-tests"));
 188 if (index != -1) {
158189 dumper.setDumpPixels(true);
 190 args.removeAt(index);
 191 }
159192
 193 index = args.indexOf(QLatin1String("--stdout"));
 194 if (index != -1) {
 195 QString fileName = takeOptionValue(args, index);
 196 dumper.setRedirectOutputFileName(fileName);
 197 if (fileName.isEmpty() || !freopen(qPrintable(fileName), "w", stdout)) {
 198 fprintf(stderr, "Redirect STDOUT failed.");
 199 exit(0);
 200 }
 201 }
 202 index = args.indexOf(QLatin1String("--stderr"));
 203 if (index != -1) {
 204 QString fileName = takeOptionValue(args, index);
 205 dumper.setRedirectErrorFileName(fileName);
 206 if (!freopen(qPrintable(fileName), "w", stderr)) {
 207 fprintf(stderr, "Redirect STDERR failed.");
 208 exit(0);
 209 }
 210 }
160211 QWebDatabase::removeAllDatabases();
161212
162213 if (args.contains(QLatin1String("-"))) {
163214 QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
164215 QTimer::singleShot(0, &dumper, SLOT(readLine()));
165  } else
 216 } else {
 217 // Go into standalone mode
 218 // Standalone mode need at least one test case
 219 if (args.count() < 2) {
 220 printUsage();
 221 exit(0);
 222 }
166223 dumper.processArgsLine(args);
167224
 225 }
168226 return app.exec();
169227
170228#ifdef Q_WS_X11
81044