[Chromium-Android] Run DumpRenderTree as an apk (C++ and gyp part)
authorwangxianzhu@chromium.org <wangxianzhu@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2012 04:14:11 +0000 (04:14 +0000)
committerwangxianzhu@chromium.org <wangxianzhu@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 May 2012 04:14:11 +0000 (04:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86922

Source/WebKit/chromium:

Reviewed by Kent Tamura.

* All.gyp: Added DumpRenderTree_apk into dependencies for Android.

Tools:

Because we have new platformInit() in TestShellAndroid.cpp, and
we still need the timeout part in TestShellLinux.cpp, TestShellLinux.cpp
is split into TestShellPosix.cpp and TestShellX11.cpp.

Reviewed by Kent Tamura.

* DumpRenderTree/DumpRenderTree.gyp/DumpRenderTree.gyp:
* DumpRenderTree/DumpRenderTree.gypi:
* DumpRenderTree/chromium/TestShellAndroid.cpp: Added. Handles command lines to redirect stdin/stdout/stderr.
(platformInit):
* DumpRenderTree/chromium/TestShellGtk.cpp: Removed. Merged into TestShellX11.cpp
* DumpRenderTree/chromium/TestShellLinux.cpp: Removed. Split into TestShellPosix.cpp and TestShellX11.cpp.
* DumpRenderTree/chromium/TestShellPosix.cpp: Split from TestShellLinux.cpp, containing the timeout handling part, compiled when os_posix=1 (excluding mac).
(AlarmHandler):
(TestShell::waitTestFinished):
* DumpRenderTree/chromium/TestShellX11.cpp: Split from TestShellLinux.cpp, containing the fontconfig part, compiled when use_x11=1
(openStartupDialog): from TestShellGtk.cpp
(checkLayoutTestSystemDependencies): from TestShellGtk.cpp.
(setupFontconfig):
(platformInit):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118115 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/chromium/All.gyp
Source/WebKit/chromium/ChangeLog
Tools/ChangeLog
Tools/DumpRenderTree/DumpRenderTree.gyp/DumpRenderTree.gyp
Tools/DumpRenderTree/DumpRenderTree.gypi
Tools/DumpRenderTree/chromium/TestShellAndroid.cpp [new file with mode: 0644]
Tools/DumpRenderTree/chromium/TestShellPosix.cpp [moved from Tools/DumpRenderTree/chromium/TestShellGtk.cpp with 62% similarity]
Tools/DumpRenderTree/chromium/TestShellX11.cpp [moved from Tools/DumpRenderTree/chromium/TestShellLinux.cpp with 87% similarity]

index 1263c25..d28bce8 100644 (file)
                 '../../../Tools/DumpRenderTree/DumpRenderTree.gyp/DumpRenderTree.gyp:DumpRenderTree',
                 '../../../Tools/TestWebKitAPI/TestWebKitAPI.gyp/TestWebKitAPI.gyp:TestWebKitAPI',
             ],
+            'conditions': [
+                ['OS=="android"', {
+                    'dependencies': [
+                        '../../../Tools/DumpRenderTree/DumpRenderTree.gyp/DumpRenderTree.gyp:DumpRenderTree_apk',
+                    ],
+                }],
+            ],
         }
     ],
 }
index 8ff8555..cc4166b 100644 (file)
@@ -1,3 +1,12 @@
+2012-05-22  Xianzhu Wang  <wangxianzhu@chromium.org>
+
+        [Chromium-Android] Run DumpRenderTree as an apk (C++ and gyp part)
+        https://bugs.webkit.org/show_bug.cgi?id=86922
+
+        Reviewed by Kent Tamura.
+
+        * All.gyp: Added DumpRenderTree_apk into dependencies for Android.
+
 2012-05-22  Mark Pilgrim  <pilgrim@chromium.org>
 
         [Chromium] Call canAccelerate2dCanvas directly
index 8568cea..8cbe927 100644 (file)
@@ -1,3 +1,29 @@
+2012-05-22  Xianzhu Wang  <wangxianzhu@chromium.org>
+
+        [Chromium-Android] Run DumpRenderTree as an apk (C++ and gyp part)
+        https://bugs.webkit.org/show_bug.cgi?id=86922
+
+        Because we have new platformInit() in TestShellAndroid.cpp, and
+        we still need the timeout part in TestShellLinux.cpp, TestShellLinux.cpp
+        is split into TestShellPosix.cpp and TestShellX11.cpp.
+
+        Reviewed by Kent Tamura.
+
+        * DumpRenderTree/DumpRenderTree.gyp/DumpRenderTree.gyp:
+        * DumpRenderTree/DumpRenderTree.gypi:
+        * DumpRenderTree/chromium/TestShellAndroid.cpp: Added. Handles command lines to redirect stdin/stdout/stderr.
+        (platformInit):
+        * DumpRenderTree/chromium/TestShellGtk.cpp: Removed. Merged into TestShellX11.cpp
+        * DumpRenderTree/chromium/TestShellLinux.cpp: Removed. Split into TestShellPosix.cpp and TestShellX11.cpp.
+        * DumpRenderTree/chromium/TestShellPosix.cpp: Split from TestShellLinux.cpp, containing the timeout handling part, compiled when os_posix=1 (excluding mac).
+        (AlarmHandler):
+        (TestShell::waitTestFinished):
+        * DumpRenderTree/chromium/TestShellX11.cpp: Split from TestShellLinux.cpp, containing the fontconfig part, compiled when use_x11=1
+        (openStartupDialog): from TestShellGtk.cpp
+        (checkLayoutTestSystemDependencies): from TestShellGtk.cpp.
+        (setupFontconfig):
+        (platformInit):
+
 2012-05-22  Kangil Han  <kangil.han@samsung.com>
 
         [EFL][DRT] Implement touch event
index 9c57a81..92e6b10 100644 (file)
             'type': 'executable',
             'mac_bundle': 1,
             'dependencies': [
+                'ImageDiff',
+                'copy_TestNetscapePlugIn',
                 '<(source_dir)/WebKit/chromium/WebKit.gyp:inspector_resources',
                 '<(source_dir)/WebKit/chromium/WebKit.gyp:webkit',
                 '<(source_dir)/WTF/WTF.gyp/WTF.gyp:wtf',
                 '<(chromium_src_dir)/build/temp_gyp/googleurl.gyp:googleurl',
                 '<(chromium_src_dir)/third_party/icu/icu.gyp:icuuc',
+                '<(chromium_src_dir)/third_party/mesa/mesa.gyp:osmesa',
                 '<(chromium_src_dir)/v8/tools/gyp/v8.gyp:v8',
                 '<(chromium_src_dir)/base/base.gyp:test_support_base',
                 '<(chromium_src_dir)/webkit/support/webkit_support.gyp:blob',
                         '<(chromium_src_dir)/third_party/angle/src/build_angle.gyp:libEGL',
                         '<(chromium_src_dir)/third_party/angle/src/build_angle.gyp:libGLESv2',
                     ],
-
                     'resource_include_dirs': ['<(SHARED_INTERMEDIATE_DIR)/webkit'],
                     'sources': [
                         '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.rc',
                         ['exclude', 'Mac\\.cpp$'],
                     ],
                 }],
+                ['os_posix!=1 or OS=="mac"', {
+                    'sources/': [
+                        ['exclude', 'Posix\\.cpp$'],
+                    ],
+                }],
                 ['use_x11 == 1', {
                     'dependencies': [
                         '<(chromium_src_dir)/build/linux/system.gyp:fontconfig',
                     ],
                 },{ # use_x11 != 1
                     'sources/': [
-                        ['exclude', 'Linux\\.cpp$']
+                        ['exclude', 'X11\\.cpp$'],
                     ]
                 }],
                 ['toolkit_uses_gtk == 1', {
                     'include_dirs': [
                         '<(source_dir)/WebKit/chromium/public/gtk',
                     ],
-                },{ # toolkit_uses_gtk != 1
-                    'sources/': [
-                        ['exclude', 'Gtk\\.cpp$']
-                    ]
                 }],
                 ['OS=="android"', {
+                    'type': 'shared_library',
                     'dependencies': [
                         'ImageDiff#host',
+                        '<(chromium_src_dir)/base/base.gyp:test_support_base',
+                        '<(chromium_src_dir)/tools/android/forwarder/forwarder.gyp:forwarder',
+                        '<(chromium_src_dir)/testing/android/native_test.gyp:native_test_native_code',
                     ],
-                    'sources/': [
-                        ['include', 'chromium/TestShellLinux\\.cpp$'],
-                    ],
-                },{ # OS!="android"
-                    'sources/': [
-                        ['exclude', '(Android)\\.cpp$']
-                    ],
-                    'dependencies': [
+                    'dependencies!': [
                         'ImageDiff',
                         'copy_TestNetscapePlugIn',
                         '<(chromium_src_dir)/third_party/mesa/mesa.gyp:osmesa',
                     ],
+                    'copies': [{
+                        'destination': '<(PRODUCT_DIR)',
+                        'files': [
+                            '<(ahem_path)',
+                            '<(INTERMEDIATE_DIR)/repack/DumpRenderTree.pak',
+                        ]
+                    }],
+                }, { # OS!="android"
+                    'sources/': [
+                        ['exclude', 'Android\\.cpp$'],
+                    ],
                 }],
                 ['inside_chromium_build==1 and component=="shared_library"', {
                     'sources': [
                 'cflags_cc': ['-Wno-c++0x-compat'],
             },
         }],
+        ['OS=="android"', {
+            # Wrap libDumpRenderTree.so into an android apk for execution.
+            # See <(chromium_src_dir)/base/base.gyp for TODO(jrg)s about this strategy.
+            'targets': [{
+                'target_name': 'DumpRenderTree_apk',
+                'type': 'none',
+                'dependencies': [
+                    'DumpRenderTree',
+                ],
+                'actions': [{
+                    # Generate apk files (including source and antfile) from
+                    # a template, and builds them.
+                    'action_name': 'generate_and_build',
+                    'inputs': [
+                        '<(chromium_src_dir)/testing/android/generate_native_test.py',
+                        '<(PRODUCT_DIR)/lib.target/libDumpRenderTree.so',
+                        # FIXME: Build the jar for native tests with SDK.
+                        # For now we are using Android.mk to build the apk.
+                    ],
+                    'outputs': [
+                        '<(PRODUCT_DIR)/DumpRenderTree_apk/ChromeNativeTests-debug.apk',
+                    ],
+                    'action': [
+                        '<(chromium_src_dir)/testing/android/generate_native_test.py',
+                        '--native_library',
+                        '<(PRODUCT_DIR)/lib.target/libDumpRenderTree.so',
+                        # FIXME: Build the jar for native tests with SDK.
+                        # '--jar',
+                        # 'foo/bar.jar',
+                        '--output',
+                        '<(PRODUCT_DIR)/DumpRenderTree_apk',
+                        '--ant-args',
+                        '-DPRODUCT_DIR=<(PRODUCT_DIR)',
+                        '--ant-compile'
+                    ],
+                }],
+            }],
+        }],
     ], # conditions
 }
index 0bbeded..e5ed536 100644 (file)
             'chromium/TestNavigationController.h',
             'chromium/TestShell.cpp',
             'chromium/TestShell.h',
-            'chromium/TestShellLinux.cpp',
-            'chromium/TestShellGtk.cpp',
+            'chromium/TestShellAndroid.cpp',
             'chromium/TestShellMac.mm',
+            'chromium/TestShellPosix.cpp',
             'chromium/TestShellStub.cpp',
             'chromium/TestShellWin.cpp',
+            'chromium/TestShellX11.cpp',
             'chromium/TestWebPlugin.cpp',
             'chromium/TestWebPlugin.h',
             'chromium/TextInputController.cpp',
diff --git a/Tools/DumpRenderTree/chromium/TestShellAndroid.cpp b/Tools/DumpRenderTree/chromium/TestShellAndroid.cpp
new file mode 100644 (file)
index 0000000..e77d80d
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TestShell.h"
+
+#include <android/log.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <wtf/Assertions.h>
+
+namespace {
+
+const char optionInFIFO[] = "--in-fifo=";
+const char optionOutFIFO[] = "--out-fifo=";
+const char optionErrFile[] = "--err-file=";
+
+void androidLogError(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
+
+void androidLogError(const char* format, ...)
+{
+    va_list args;
+    va_start(args, format);
+    __android_log_vprint(ANDROID_LOG_ERROR, "DumpRenderTree", format, args);
+    va_end(args);
+}
+
+void removeArg(int index, int* argc, char*** argv)
+{
+    for (int i = index; i < *argc; ++i)
+        (*argv)[i] = (*argv)[i + 1];
+    --*argc;
+}
+
+void createFIFO(const char* fifoPath)
+{
+    unlink(fifoPath);
+    if (mkfifo(fifoPath, 0600)) {
+        androidLogError("Failed to create fifo %s: %s\n", fifoPath, strerror(errno));
+        exit(EXIT_FAILURE);
+    }
+}
+
+void createFile(const char* filePath)
+{
+    unlink(filePath);
+    int fd = creat(filePath, 0600);
+    if (fd < 0) {
+        androidLogError("Failed to create file %s: %s\n", filePath, strerror(errno));
+        exit(EXIT_FAILURE);
+    }
+    close(fd);
+}
+
+void redirectToFile(FILE* stream, const char* path, const char* mode)
+{
+    if (!freopen(path, mode, stream)) {
+        androidLogError("Failed to redirect stream to file: %s: %s\n", path, strerror(errno));
+        exit(EXIT_FAILURE);
+    }
+}
+
+} // namespace
+
+void platformInit(int* argc, char*** argv)
+{
+    const char* inFIFO = 0;
+    const char* outFIFO = 0;
+    const char* errFile = 0;
+    for (int i = 1; i < *argc; ) {
+        const char* argument = (*argv)[i];
+        if (strstr(argument, optionInFIFO) == argument) {
+            inFIFO = argument + WTF_ARRAY_LENGTH(optionInFIFO) - 1;
+            createFIFO(inFIFO);
+            removeArg(i, argc, argv);
+        } else if (strstr(argument, optionOutFIFO) == argument) {
+            outFIFO = argument + WTF_ARRAY_LENGTH(optionOutFIFO) - 1;
+            createFIFO(outFIFO);
+            removeArg(i, argc, argv);
+        } else if (strstr(argument, optionErrFile) == argument) {
+            errFile = argument + WTF_ARRAY_LENGTH(optionErrFile) - 1;
+            createFile(errFile);
+            removeArg(i, argc, argv);
+        } else
+            ++i;
+    }
+
+    // The order of createFIFO() and redirectToFIFO() is important to avoid deadlock.
+    if (outFIFO)
+        redirectToFile(stdout, outFIFO, "w");
+    if (inFIFO)
+        redirectToFile(stdin, inFIFO, "r");
+    if (errFile)
+        redirectToFile(stderr, errFile, "w");
+    else {
+        // Redirect stderr to stdout.
+        dup2(1, 2);
+    }
+}
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
 #include "TestShell.h"
 
 #include "webkit/support/webkit_support.h"
-#include <fontconfig/fontconfig.h>
-#include <gtk/gtk.h>
-#include <signal.h>
 
+#include <signal.h>
+#include <unistd.h>
 
-void openStartupDialog()
+static void AlarmHandler(int)
 {
-    GtkWidget* dialog = gtk_message_dialog_new(
-        0, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Attach to me?");
-    gtk_window_set_title(GTK_WINDOW(dialog), "DumpRenderTree");
-    gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop.
-    gtk_widget_destroy(dialog);
+    // If the alarm alarmed, kill the process since we have a really bad hang.
+    puts("\n#TEST_TIMED_OUT\n");
+    puts("#EOF\n");
+    fflush(stdout);
+    exit(0);
 }
 
-bool checkLayoutTestSystemDependencies()
+void TestShell::waitTestFinished()
 {
-    return true;
+    ASSERT(!m_testIsPending);
+    m_testIsPending = true;
+
+    // Install an alarm signal handler that will kill us if we time out.
+    struct sigaction alarmAction;
+    alarmAction.sa_handler = AlarmHandler;
+    sigemptyset(&alarmAction.sa_mask);
+    alarmAction.sa_flags = 0;
+
+    struct sigaction oldAction;
+    sigaction(SIGALRM, &alarmAction, &oldAction);
+    alarm(layoutTestTimeoutForWatchDog() / 1000);
+
+    // TestFinished() will post a quit message to break this loop when the page
+    // finishes loading.
+    while (m_testIsPending)
+        webkit_support::RunMessageLoop();
+
+    // Remove the alarm.
+    alarm(0);
+    sigaction(SIGALRM, &oldAction, 0);
 }
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
 #include "config.h"
 #include "TestShell.h"
 
-#include "SkTypeface.h"
-#include "WebView.h"
-#include "webkit/support/webkit_support.h"
-
-#if !OS(ANDROID)
 #include <fontconfig/fontconfig.h>
-#endif
 
 #if USE(GTK)
 #include <gtk/gtk.h>
-#endif
-#include <signal.h>
-#include <unistd.h>
 
-static void AlarmHandler(int)
+void openStartupDialog()
 {
-    // If the alarm alarmed, kill the process since we have a really bad hang.
-    puts("\n#TEST_TIMED_OUT\n");
-    puts("#EOF\n");
-    fflush(stdout);
-    exit(0);
+    GtkWidget* dialog = gtk_message_dialog_new(
+        0, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Attach to me?");
+    gtk_window_set_title(GTK_WINDOW(dialog), "DumpRenderTree");
+    gtk_dialog_run(GTK_DIALOG(dialog)); // Runs a nested message loop.
+    gtk_widget_destroy(dialog);
 }
 
-void TestShell::waitTestFinished()
+bool checkLayoutTestSystemDependencies()
 {
-    ASSERT(!m_testIsPending);
-    m_testIsPending = true;
-
-    // Install an alarm signal handler that will kill us if we time out.
-    struct sigaction alarmAction;
-    alarmAction.sa_handler = AlarmHandler;
-    sigemptyset(&alarmAction.sa_mask);
-    alarmAction.sa_flags = 0;
-
-    struct sigaction oldAction;
-    sigaction(SIGALRM, &alarmAction, &oldAction);
-    alarm(layoutTestTimeoutForWatchDog() / 1000);
-
-    // TestFinished() will post a quit message to break this loop when the page
-    // finishes loading.
-    while (m_testIsPending)
-        webkit_support::RunMessageLoop();
-
-    // Remove the alarm.
-    alarm(0);
-    sigaction(SIGALRM, &oldAction, 0);
+    return true;
 }
+#endif // USE(GTK)
 
-#if !OS(ANDROID)
 static bool checkAndLoadFontFile(FcConfig* fontcfg, const char* path1, const char* path2)
 {
     const char* font = path1;
@@ -206,7 +177,6 @@ static void setupFontconfig()
         exit(1);
     }
 }
-#endif // !OS(ANDROID)
 
 void platformInit(int* argc, char*** argv)
 {
@@ -216,8 +186,5 @@ void platformInit(int* argc, char*** argv)
     gtk_init(argc, argv);
 #endif
 
-#if !OS(ANDROID)
     setupFontconfig();
-#endif
 }
-