WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-111310-20130304164218.patch (text/plain), 18.49 KB, created by
Thiago Marcos P. Santos
on 2013-03-04 06:40:20 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Thiago Marcos P. Santos
Created:
2013-03-04 06:40:20 PST
Size:
18.49 KB
patch
obsolete
>Subversion Revision: 144163 >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 76a8cfd5fd5f34984ee3639ae68d506e00a3193f..b027a3a6bedff213b5be81645b322f1b59703dca 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,44 @@ >+2013-03-04 Thiago Marcos P. Santos <thiago.santos@intel.com> >+ >+ [WK2] Add unit tests for CoreIPC >+ https://bugs.webkit.org/show_bug.cgi?id=111310 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Added unit tests for CoreIPC and enabled them by default on the EFL port. >+ Unfortunately the process and connection Identifier creation are >+ platform dependent, so I'm adding this test just for Unix by now. >+ >+ * TestWebKitAPI/CMakeLists.txt: >+ * TestWebKitAPI/PlatformEfl.cmake: >+ * TestWebKitAPI/Tests/WebKit2/unix/CoreIPC.cpp: Added. >+ (TestWebKitAPI): >+ (TestClient): >+ (TestWebKitAPI::TestClient::TestClient): >+ (TestWebKitAPI::TestClient::connection): >+ (TestWebKitAPI::TestClient::setReceiveMessageCallback): >+ (TestWebKitAPI::TestClient::didClose): >+ (TestWebKitAPI::TestClient::didReceiveInvalidMessage): >+ (TestWebKitAPI::TestClient::didReceiveMessage): >+ (TestServer): >+ (TestWebKitAPI::TestServer::TestServer): >+ (TestWebKitAPI::TestServer::initialize): >+ (TestWebKitAPI::TestServer::loopbackMessage): >+ (TestWebKitAPI::TestServer::stringLoopbackMessage): >+ (TestWebKitAPI::TestServer::didClose): >+ (TestWebKitAPI::TestServer::didReceiveInvalidMessage): >+ (TestWebKitAPI::TestServer::didReceiveMessage): >+ (TestWebKitAPI::TestServer::didReceiveSyncMessage): >+ (CoreIPCEnvironment): >+ (TestWebKitAPI::CoreIPCEnvironment::SetUp): >+ (TestWebKitAPI::CoreIPCEnvironment::client): >+ (TestWebKitAPI::CoreIPCEnvironment::testChar): >+ (TestWebKitAPI::stringSerializationCallback): >+ (TestWebKitAPI::TEST): >+ (TestWebKitAPI::dataSerializationCallback): >+ (TestWebKitAPI::threadedStringSerializationThread): >+ (TestWebKitAPI::threadedStringSerializationShutdownCallback): >+ > 2013-02-27 Ryosuke Niwa <rniwa@webkit.org> > > Build fix after r144155. The report page is located at /api/report, not /api/test/report. >diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt >index 1d96b0d605769b4f68e8b131f3df7bd90e04661a..7c9bd110fa67f41fc0fd41238dc854823bae252b 100644 >--- a/Tools/TestWebKitAPI/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/CMakeLists.txt >@@ -122,15 +122,17 @@ set(test_webkit2_api_LIBRARIES > TestWebKitAPIBase > ${WTF_LIBRARY_NAME} > ${JavaScriptCore_LIBRARY_NAME} >+ ${WebCore_LIBRARY_NAME} > ${WebKit2_LIBRARY_NAME} > gtest > ) > > foreach (testName ${test_webkit2_api_BINARIES}) >- add_executable(test_webkit2_api_${testName} ${TESTWEBKITAPI_DIR}/Tests/WebKit2/${testName}.cpp) >- add_test(test_webkit2_api_${testName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_webkit2_api_${testName}) >- set_tests_properties(test_webkit2_api_${testName} PROPERTIES TIMEOUT 60) >- target_link_libraries(test_webkit2_api_${testName} ${test_webkit2_api_LIBRARIES}) >+ get_filename_component(testBaseName ${testName} NAME) >+ add_executable(test_webkit2_api_${testBaseName} ${TESTWEBKITAPI_DIR}/Tests/WebKit2/${testName}.cpp) >+ add_test(test_webkit2_api_${testBaseName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_webkit2_api_${testBaseName}) >+ set_tests_properties(test_webkit2_api_${testBaseName} PROPERTIES TIMEOUT 60) >+ target_link_libraries(test_webkit2_api_${testBaseName} ${test_webkit2_api_LIBRARIES}) > endforeach () > > # We don't run tests that are expected to fail. We could use the WILL_FAIL >diff --git a/Tools/TestWebKitAPI/PlatformEfl.cmake b/Tools/TestWebKitAPI/PlatformEfl.cmake >index 3bcb89b6e922817e688c430067b90a49438410a8..91876606c3db76dd926e516e9357ae9e27d5b7b2 100644 >--- a/Tools/TestWebKitAPI/PlatformEfl.cmake >+++ b/Tools/TestWebKitAPI/PlatformEfl.cmake >@@ -11,6 +11,8 @@ add_custom_target(forwarding-headersSoupForTestWebKitAPI > set(ForwardingNetworkHeadersForTestWebKitAPI_NAME forwarding-headersSoupForTestWebKitAPI) > > include_directories( >+ ${WEBKIT2_DIR}/Platform >+ ${WEBKIT2_DIR}/Platform/CoreIPC > ${WEBKIT2_DIR}/UIProcess/API/C/soup > ${WEBKIT2_DIR}/UIProcess/API/C/efl > ${WEBKIT2_DIR}/UIProcess/API/efl >@@ -88,6 +90,14 @@ set(test_webkit2_api_BINARIES > WillSendSubmitEvent > ) > >+# CoreIPC is an internal API and its symbols are not exposed by >+# default. We can only test it when building shared core. >+if (SHARED_CORE) >+ list(APPEND test_webkit2_api_BINARIES >+ unix/CoreIPC >+ ) >+endif () >+ > set(test_webkit2_api_fail_BINARIES > CanHandleRequest > DOMWindowExtensionBasic >diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/unix/CoreIPC.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/unix/CoreIPC.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..c1747cbb22ce478b3c1f39d5fcd789994ab3d800 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WebKit2/unix/CoreIPC.cpp >@@ -0,0 +1,393 @@ >+/* >+ * Copyright (C) 2013 Intel Corporation. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. 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. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "ArgumentCoders.h" >+#include "DataReference.h" >+#include "WebCoreArgumentCoders.h" >+#include <WebCore/IntPoint.h> >+#include <WebCore/IntRect.h> >+#include <WebCore/IntSize.h> >+#include <WebCore/KURL.h> >+#include <WebCore/RunLoop.h> >+#include <WebKit2/Connection.h> >+#include <WebKit2/StringReference.h> >+#include <sys/socket.h> >+#include <sys/types.h> >+#include <unistd.h> >+#include <wtf/MainThread.h> >+#include <wtf/Threading.h> >+#include <wtf/text/WTFString.h> >+ >+using namespace CoreIPC; >+using namespace WTF; >+ >+namespace TestWebKitAPI { >+ >+class TestClient : protected Connection::Client { >+public: >+ typedef void (*ReceiveMessageCallback)(MessageDecoder&); >+ >+ TestClient(Connection::Identifier identifier) >+ { >+ m_connection = Connection::createServerConnection(identifier, this, WebCore::RunLoop::main()); >+ m_connection->open(); >+ } >+ >+ Connection* connection() { return m_connection.get(); } >+ >+ void setReceiveMessageCallback(ReceiveMessageCallback callback) { m_receiveMessageCallback = callback; } >+ >+private: >+ // CoreIPC::Connection::Client interface. >+ virtual void didClose(Connection*) { CRASH(); } >+ virtual void didReceiveInvalidMessage(Connection*, StringReference, StringReference) { CRASH(); } >+ >+ // CoreIPC::MessageReceiver interface. >+ virtual void didReceiveMessage(Connection*, MessageDecoder& decoder) >+ { >+ m_receiveMessageCallback(decoder); >+ } >+ >+ ReceiveMessageCallback m_receiveMessageCallback; >+ RefPtr<Connection> m_connection; >+}; >+ >+class TestServer : protected Connection::Client { >+public: >+ TestServer(Connection::Identifier identifier) >+ { >+ m_connection = Connection::createServerConnection(identifier, this, WebCore::RunLoop::main()); >+ m_connection->open(); >+ } >+ >+ void initialize() >+ { >+ WebCore::RunLoop::run(); >+ exit(0); >+ } >+ >+private: >+ // Generic message loopback, will basically create a reply with the same >+ // contents of the input. >+ PassOwnPtr<MessageEncoder> loopbackMessage(MessageDecoder& decoder) >+ { >+ uint8_t buffer[4096]; >+ >+ size_t size; >+ for (size = 0; decoder.decode(buffer[size]); ++size) >+ EXPECT_NE(size, sizeof(buffer)); >+ >+ OwnPtr<MessageEncoder> encoder = MessageEncoder::create("IPC", "loopback", decoder.destinationID()); >+ encoder->encodeFixedLengthData(buffer, size, 1); >+ >+ return encoder.release(); >+ } >+ >+ // Optimized loopback for string contents. >+ PassOwnPtr<MessageEncoder> stringLoopbackMessage(MessageDecoder& decoder) >+ { >+ OwnPtr<MessageEncoder> encoder = MessageEncoder::create("IPC", "stringLoopback", decoder.destinationID()); >+ >+ String string; >+ while (decoder.decode(string)) >+ encoder->encode(string); >+ >+ return encoder.release(); >+ } >+ >+ // CoreIPC::Connection::Client interface. >+ virtual void didClose(Connection*) >+ { >+ WebCore::RunLoop::current()->stop(); >+ } >+ >+ // CoreIPC::Connection::Client interface. >+ virtual void didReceiveInvalidMessage(Connection*, StringReference, StringReference messageName) >+ { >+ // loopback messages will always trigger the invalid message handler >+ // because we decode it byte by byte until we find the end of the message. >+ if (messageName == StringReference("loopback")) >+ return; >+ if (messageName == StringReference("stringLoopback")) >+ return; >+ >+ CRASH(); >+ } >+ >+ // CoreIPC::MessageReceiver interface. >+ virtual void didReceiveMessage(Connection*, MessageDecoder& decoder) >+ { >+ OwnPtr<MessageEncoder> encoder; >+ >+ if (decoder.messageName() == StringReference("loopback")) >+ encoder = loopbackMessage(decoder); >+ if (decoder.messageName() == StringReference("stringLoopback")) >+ encoder = stringLoopbackMessage(decoder); >+ >+ m_connection->sendMessage(encoder.release()); >+ } >+ >+ // CoreIPC::MessageReceiver interface. >+ virtual void didReceiveSyncMessage(Connection*, MessageDecoder& decoder, OwnPtr<MessageEncoder>& encoder) >+ { >+ // For sync messages we always expect 3 strings as input and return >+ // them back. We cannot use the loopback here because the message gets >+ // invalid after that and ASSERT(). >+ String string; >+ for (unsigned i = 0; i < 3; ++i) { >+ decoder.decode(string); >+ encoder->encode(string); >+ } >+ } >+ >+ RefPtr<Connection> m_connection; >+}; >+ >+class CoreIPCEnvironment : public testing::Environment { >+public: >+ virtual void SetUp() >+ { >+ int sockets[2]; >+ ASSERT_NE(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets), -1); >+ >+ pid_t pid = fork(); >+ close(sockets[!pid]); >+ >+ WTF::initializeMainThread(); >+ WebCore::RunLoop::initializeMainRunLoop(); >+ >+ if (!pid) { >+ TestServer server(sockets[0]); >+ server.initialize(); >+ } >+ >+ m_client = adoptPtr(new TestClient(sockets[1])); >+ >+ // Fill our test string with some data. >+ int i = 0; >+ while (i < sizeof(m_testChar)) >+ i += snprintf(&m_testChar[i], sizeof(m_testChar) - i, "%d", i); >+ } >+ >+ TestClient* client() { return m_client.get(); } >+ >+ char* testChar(size_t size) >+ { >+ EXPECT_LE(size, sizeof(m_testChar)); >+ >+ return &m_testChar[sizeof(m_testChar) - size]; >+ } >+ >+private: >+ OwnPtr<TestClient> m_client; >+ char m_testChar[2048]; >+}; >+ >+CoreIPCEnvironment* const env = static_cast<TestWebKitAPI::CoreIPCEnvironment*>(::testing::AddGlobalTestEnvironment(new CoreIPCEnvironment)); >+ >+static void stringSerializationCallback(MessageDecoder& decoder) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() == WebCore::RunLoop::main()); >+ >+ String decodedString; >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(1234)); >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(123)); >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(12)); >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(1234)); >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(123)); >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(12)); >+ >+ WebCore::RunLoop::current()->stop(); >+} >+ >+TEST(WebKit2, StringSerialization) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() == WebCore::RunLoop::main()); >+ >+ env->client()->setReceiveMessageCallback(stringSerializationCallback); >+ >+ for (unsigned i = 0; i < 5000; i++) { >+ OwnPtr<MessageEncoder> encoder = MessageEncoder::create("IPC", "stringLoopback", i); >+ >+ String payloadString; >+ payloadString = env->testChar(1234); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(123); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(12); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(1234); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(123); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(12); >+ encoder->encode(payloadString); >+ >+ env->client()->connection()->sendMessage(encoder.release()); >+ >+ WebCore::RunLoop::current()->run(); >+ } >+} >+ >+static void dataSerializationCallback(MessageDecoder& decoder) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() == WebCore::RunLoop::main()); >+ >+ // TODO: Would be good to test the encoding and decoding of all >+ // the data types that can be serialized here. Right now we are >+ // just testing the most common ones. >+ uint64_t decodedUint64; >+ decoder.decode(decodedUint64); >+ EXPECT_TRUE(decodedUint64 == uint64_t(12345)); >+ decoder.decode(decodedUint64); >+ EXPECT_TRUE(decodedUint64 == uint64_t(67890)); >+ decoder.decode(decodedUint64); >+ EXPECT_TRUE(decodedUint64 == uint64_t(10101)); >+ >+ String decodedString; >+ decoder.decode(decodedString); >+ EXPECT_TRUE(decodedString == String("Another brick in the wall...")); >+ >+ WebCore::IntRect decodedIntRect; >+ decoder.decode(decodedIntRect); >+ EXPECT_TRUE(decodedIntRect == WebCore::IntRect(50, 40, 30, 20)); >+ >+ WebCore::IntSize decodedIntSize; >+ decoder.decode(decodedIntSize); >+ EXPECT_TRUE(decodedIntSize == WebCore::IntSize(12, 34)); >+ >+ WebCore::IntPoint decodedIntPoint; >+ decoder.decode(decodedIntPoint); >+ EXPECT_TRUE(decodedIntPoint == WebCore::IntPoint(42, 42)); >+ >+ WebCore::KURL decodedKURL; >+ decoder.decode(decodedKURL); >+ EXPECT_TRUE(decodedKURL == WebCore::KURL(WebCore::ParsedURLString, "http://example.com/")); >+ >+ WebCore::RunLoop::current()->stop(); >+} >+ >+TEST(WebKit2, DataSerialization) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() == WebCore::RunLoop::main()); >+ >+ env->client()->setReceiveMessageCallback(dataSerializationCallback); >+ >+ for (unsigned i = 0; i < 5000; i++) { >+ OwnPtr<MessageEncoder> encoder = MessageEncoder::create("IPC", "loopback", i); >+ >+ *encoder << uint64_t(12345); >+ *encoder << uint64_t(67890); >+ *encoder << uint64_t(10101); >+ >+ encoder->encode(String("Another brick in the wall...")); >+ encoder->encode(WebCore::IntRect(50, 40, 30, 20)); >+ encoder->encode(WebCore::IntSize(12, 34)); >+ encoder->encode(WebCore::IntPoint(42, 42)); >+ encoder->encode(WebCore::KURL(WebCore::ParsedURLString, "http://example.com/")); >+ >+ env->client()->connection()->sendMessage(encoder.release()); >+ >+ WebCore::RunLoop::current()->run(); >+ } >+} >+ >+static void threadedStringSerializationThread(void*) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() != WebCore::RunLoop::main()); >+ >+ Connection* connection = env->client()->connection(); >+ >+ for (unsigned i = 0; i < 5000; i++) { >+ uint64_t syncRequestID; >+ OwnPtr<MessageEncoder> encoder = connection->createSyncMessageEncoder("IPC", "foobar", 0, syncRequestID); >+ >+ String payloadString; >+ payloadString = env->testChar(1234); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(123); >+ encoder->encode(payloadString); >+ payloadString = env->testChar(12); >+ encoder->encode(payloadString); >+ >+ OwnPtr<MessageDecoder> decoder = connection->sendSyncMessage(syncRequestID, encoder.release(), Connection::NoTimeout); >+ >+ String decodedString; >+ decoder->decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(1234)); >+ decoder->decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(123)); >+ decoder->decode(decodedString); >+ EXPECT_TRUE(decodedString == env->testChar(12)); >+ } >+ >+ OwnPtr<MessageEncoder> encoder = MessageEncoder::create("IPC", "loopback", 0); >+ env->client()->connection()->sendMessage(encoder.release()); >+} >+ >+static void threadedStringSerializationShutdownCallback(MessageDecoder&) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() == WebCore::RunLoop::main()); >+ >+ static unsigned count; >+ >+ if (++count == 5) >+ WebCore::RunLoop::current()->stop(); >+} >+ >+TEST(WebKit2, ThreadedStringSerialization) >+{ >+ ASSERT_TRUE(WebCore::RunLoop::current() == WebCore::RunLoop::main()); >+ >+ // This test will spawn 5 threads that will send several synchronous >+ // messages. At the end of the work batch, the thread will send an asynchronous >+ // message (which is delivered back to the main thread) for signaling that >+ // the work is done. After receiving the completion message from all the >+ // threads, we stop the main loop and end the test. >+ env->client()->setReceiveMessageCallback(threadedStringSerializationShutdownCallback); >+ >+ char threadName[10]; >+ ThreadIdentifier threads[5]; >+ >+ for (int i = 0; i < sizeof(threads) / sizeof(ThreadIdentifier); ++i) { >+ sprintf(threadName, "Thread%d", i); >+ threads[i] = createThread(threadedStringSerializationThread, 0, threadName); >+ } >+ >+ WebCore::RunLoop::current()->run(); >+ >+ for (int i = 0; i < sizeof(threads) / sizeof(ThreadIdentifier); ++i) >+ waitForThreadCompletion(threads[i]); >+} >+ >+} // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 111310
: 191227