Title: [201806] trunk/Tools
Revision
201806
Author
beid...@apple.com
Date
2016-06-08 09:48:28 -0700 (Wed, 08 Jun 2016)

Log Message

Add an API test that confirms object constructor/destructor calls during creation of a CrossThreadTask.
https://bugs.webkit.org/show_bug.cgi?id=158528

Reviewed by Alex Christensen.

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/CrossThreadTask.cpp: Added.
(TestWebKitAPI::log):
(TestWebKitAPI::takeLogStr):
(TestWebKitAPI::LifetimeLogger::LifetimeLogger):
(TestWebKitAPI::LifetimeLogger::~LifetimeLogger):
(TestWebKitAPI::LifetimeLogger::isolatedCopy):
(TestWebKitAPI::testFunction):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (201805 => 201806)


--- trunk/Tools/ChangeLog	2016-06-08 13:37:04 UTC (rev 201805)
+++ trunk/Tools/ChangeLog	2016-06-08 16:48:28 UTC (rev 201806)
@@ -1,3 +1,21 @@
+2016-06-08  Brady Eidson  <beid...@apple.com>
+
+        Add an API test that confirms object constructor/destructor calls during creation of a CrossThreadTask.
+        https://bugs.webkit.org/show_bug.cgi?id=158528
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/CrossThreadTask.cpp: Added.
+        (TestWebKitAPI::log):
+        (TestWebKitAPI::takeLogStr):
+        (TestWebKitAPI::LifetimeLogger::LifetimeLogger):
+        (TestWebKitAPI::LifetimeLogger::~LifetimeLogger):
+        (TestWebKitAPI::LifetimeLogger::isolatedCopy):
+        (TestWebKitAPI::testFunction):
+        (TestWebKitAPI::TEST):
+
 2016-06-08  Konstantin Tokarev  <annu...@yandex.ru>
 
         TestWebKitAPI: Removed redunandant check PLATFORM(GTK) && !defined(BUILDING_WEBKIT2__)

Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (201805 => 201806)


--- trunk/Tools/TestWebKitAPI/CMakeLists.txt	2016-06-08 13:37:04 UTC (rev 201805)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt	2016-06-08 16:48:28 UTC (rev 201806)
@@ -42,6 +42,7 @@
     ${TESTWEBKITAPI_DIR}/TestsController.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/AtomicString.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/BloomFilter.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WTF/CrossThreadTask.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/CString.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/CheckedArithmeticOperations.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/Condition.cpp

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (201805 => 201806)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-06-08 13:37:04 UTC (rev 201805)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-06-08 16:48:28 UTC (rev 201806)
@@ -71,6 +71,7 @@
 		51714EB41CF8C78C004723C4 /* WebProcessKillIDBCleanup-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */; };
 		51714EB51CF8C78C004723C4 /* WebProcessKillIDBCleanup-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */; };
 		51714EB81CF8CA17004723C4 /* WebProcessKillIDBCleanup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */; };
+		51714EBA1D087416004723C4 /* CrossThreadTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51714EB91D087416004723C4 /* CrossThreadTask.cpp */; };
 		517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */; };
 		51B1EE8E1C80F5880064FB98 /* IndexedDBPersistence.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */; };
 		51B1EE961C80FAEF0064FB98 /* IndexedDBPersistence-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */; };
@@ -655,6 +656,7 @@
 		51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "WebProcessKillIDBCleanup-1.html"; sourceTree = "<group>"; };
 		51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "WebProcessKillIDBCleanup-2.html"; sourceTree = "<group>"; };
 		51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessKillIDBCleanup.mm; sourceTree = "<group>"; };
+		51714EB91D087416004723C4 /* CrossThreadTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossThreadTask.cpp; sourceTree = "<group>"; };
 		517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCachePruneWithinResourceLoadDelegate.mm; sourceTree = "<group>"; };
 		517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCachePruneWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
 		51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBPersistence.mm; sourceTree = "<group>"; };
@@ -1374,6 +1376,7 @@
 				0FEAE3671B7D19CB00CE17F2 /* Condition.cpp */,
 				26A2C72E15E2E73C005B1A14 /* CString.cpp */,
 				E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */,
+				51714EB91D087416004723C4 /* CrossThreadTask.cpp */,
 				7AA021BA1AB09EA70052953F /* DateMath.cpp */,
 				E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */,
 				7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */,
@@ -2055,6 +2058,7 @@
 				1AAD19F71C7CE20300831E47 /* Coding.mm in Sources */,
 				1A9FB6CE1CA34BE500966124 /* EarlyKVOCrash.mm in Sources */,
 				9B0786A31C58830F00D159E3 /* InjectedBundleMakeAllShadowRootsOpen.cpp in Sources */,
+				51714EBA1D087416004723C4 /* CrossThreadTask.cpp in Sources */,
 				1A4F81CC1BDFFD37004E672E /* RemoteObjectRegistry.mm in Sources */,
 				51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */,
 				7A38D7E61C752D5F004F157D /* HashCountedSet.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/CrossThreadTask.cpp (0 => 201806)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/CrossThreadTask.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/CrossThreadTask.cpp	2016-06-08 16:48:28 UTC (rev 201806)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2016 Apple 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:
+ * 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 <string>
+#include <wtf/CrossThreadTask.h>
+
+namespace TestWebKitAPI {
+
+inline std::ostringstream& log()
+{
+    static std::ostringstream log;
+    return log;
+}
+
+inline std::string takeLogStr()
+{
+    std::string string = log().str();
+    log().str("");
+    return string;
+}
+
+struct LifetimeLogger {
+    LifetimeLogger()
+    {
+        log() << "default_constructor(" << &name << "-" << copyGeneration << "-" << moveGeneration << ") ";
+    }
+
+    LifetimeLogger(const char* inputName)
+        : name(*inputName)
+    {
+        log() << "name_constructor(" << &name << "-" << copyGeneration << "-" << moveGeneration << ") ";
+    }
+
+    LifetimeLogger(const LifetimeLogger& other)
+        : name(other.name)
+        , copyGeneration(other.copyGeneration + 1)
+        , moveGeneration(other.moveGeneration)
+    {
+        log() << "copy_constructor(" << &name << "-" << copyGeneration << "-" << moveGeneration << ") ";
+    }
+
+    LifetimeLogger(LifetimeLogger&& other)
+        : name(other.name)
+        , copyGeneration(other.copyGeneration)
+        , moveGeneration(other.moveGeneration + 1)
+    {
+        log() << "move_constructor(" << &name << "-" << copyGeneration << "-" << moveGeneration << ") ";
+    }
+
+    ~LifetimeLogger()
+    {
+        log() << "destructor(" << &name << "-" << copyGeneration << "-" << moveGeneration << ") ";
+    }
+
+    LifetimeLogger isolatedCopy() const
+    {
+        log() << "isolatedCopy() ";
+        return LifetimeLogger(*this);
+    }
+
+    const char& name { *"<default>" };
+    int copyGeneration { 0 };
+    int moveGeneration { 0 };
+};
+
+void testFunction(const LifetimeLogger&, const LifetimeLogger&, const LifetimeLogger&)
+{
+    log() << "testFunction called" << " ";
+}
+
+TEST(WTF_CrossThreadTask, Basic)
+{
+    {
+        LifetimeLogger logger1;
+        LifetimeLogger logger2(logger1);
+        LifetimeLogger logger3("logger");
+
+        auto task = createCrossThreadTask(testFunction, logger1, logger2, logger3);
+        task.performTask();
+    }
+    ASSERT_STREQ("default_constructor(<default>-0-0) copy_constructor(<default>-1-0) name_constructor(logger-0-0) isolatedCopy() copy_constructor(<default>-1-0) isolatedCopy() copy_constructor(<default>-2-0) isolatedCopy() copy_constructor(logger-1-0) copy_constructor(<default>-2-0) copy_constructor(<default>-3-0) copy_constructor(logger-2-0) copy_constructor(<default>-3-0) copy_constructor(<default>-4-0) copy_constructor(logger-3-0) destructor(logger-2-0) destructor(<default>-3-0) destructor(<default>-2-0) destructor(logger-1-0) destructor(<default>-2-0) destructor(<default>-1-0) testFunction called destructor(logger-3-0) destructor(<default>-4-0) destructor(<default>-3-0) destructor(logger-0-0) destructor(<default>-1-0) destructor(<default>-0-0) ", takeLogStr().c_str());
+}
+    
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to