Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: Source/wtf/SpinLockTest.cpp

Issue 21666003: Enhancements to PartitionAlloc to support threading and arbitrary allocation sizes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review items. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/wtf/SpinLockTest.cpp
diff --git a/Source/weborigin/SecurityOriginTest.cpp b/Source/wtf/SpinLockTest.cpp
similarity index 58%
copy from Source/weborigin/SecurityOriginTest.cpp
copy to Source/wtf/SpinLockTest.cpp
index 1a000954b25fb720d967ba925a6a904ad0e02965..ac151e84945847a350bc35566f657c0bb2183378 100644
--- a/Source/weborigin/SecurityOriginTest.cpp
+++ b/Source/wtf/SpinLockTest.cpp
@@ -29,38 +29,60 @@
*/
#include "config.h"
+#include "wtf/SpinLock.h"
-#include "weborigin/KURL.h"
-#include "weborigin/SecurityOrigin.h"
-#include "wtf/testing/WTFTestHelpers.h"
-
+#include "wtf/Threading.h"
#include <gtest/gtest.h>
-using WebCore::SecurityOrigin;
-
namespace {
-const int MaxAllowedPort = 65535;
+static const size_t bufSize = 16;
-TEST(SecurityOriginTest, InvalidPortsCreateUniqueOrigins)
+static int lock = 0;
+
+static void bufFill(volatile char* buf, char fillPattern)
abarth-chromium 2013/08/05 20:40:25 bufFill -> fillBuffer? bug -> buffer? Blink's sty
{
- int ports[] = { -100, -1, MaxAllowedPort + 1, 1000000 };
+ for (int i = 0; i < bufSize; ++i)
+ buf[i] = fillPattern;
+}
+
+static void bufFiddle(volatile char* buf)
+{
+ bufFill(buf, '\0');
+ int total = 0;
+ for (int i = 0; i < bufSize; ++i)
+ total += buf[i];
+
+ EXPECT_EQ(0, total);
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ports); ++i) {
- RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", "example.com", ports[i]);
- EXPECT_TRUE(origin->isUnique()) << "Port " << ports[i] << " should have generated a unique origin.";
+ // This will mess with the other thread's calculation if we accidentally get
+ // concurrency.
+ bufFill(buf, '!');
+}
+
+static void threadMain(void* arg)
+{
+ volatile char* buf = reinterpret_cast<volatile char*>(arg);
+ for (int i = 0; i < 500000; ++i) {
+ spinLockLock(&lock);
+ bufFiddle(buf);
+ spinLockUnlock(&lock);
}
}
-TEST(SecurityOriginTest, ValidPortsCreateNonUniqueOrigins)
+TEST(WTF_SpinLock, Torture)
{
- int ports[] = { 0, 80, 443, 5000, MaxAllowedPort };
+ char sharedBuf[bufSize];
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ports); ++i) {
- RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", "example.com", ports[i]);
- EXPECT_FALSE(origin->isUnique()) << "Port " << ports[i] << " should not have generated a unique origin.";
- }
+ ThreadIdentifier thread1 = createThread(threadMain, sharedBuf, "thread1");
+ ThreadIdentifier thread2 = createThread(threadMain, sharedBuf, "thread2");
+ EXPECT_NE(0, thread1);
+ EXPECT_NE(0, thread2);
+
+ int ret = waitForThreadCompletion(thread1);
+ EXPECT_EQ(0, ret);
+ ret = waitForThreadCompletion(thread2);
+ EXPECT_EQ(0, ret);
}
} // namespace
-
« Source/wtf/SpinLock.h ('K') | « Source/wtf/SpinLock.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698