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

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 comments. 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
« no previous file with comments | « Source/wtf/SpinLock.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/SpinLockTest.cpp
diff --git a/Source/weborigin/SecurityOriginTest.cpp b/Source/wtf/SpinLockTest.cpp
similarity index 57%
copy from Source/weborigin/SecurityOriginTest.cpp
copy to Source/wtf/SpinLockTest.cpp
index 1a000954b25fb720d967ba925a6a904ad0e02965..733901aa2a1593f6492de7712b3b1d7058898705 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 bufferSize = 16;
-TEST(SecurityOriginTest, InvalidPortsCreateUniqueOrigins)
+static int lock = 0;
+
+static void fillBuffer(volatile char* buffer, char fillPattern)
{
- int ports[] = { -100, -1, MaxAllowedPort + 1, 1000000 };
+ for (int i = 0; i < bufferSize; ++i)
+ buffer[i] = fillPattern;
+}
+
+static void changeAndCheckBuffer(volatile char* buffer)
+{
+ fillBuffer(buffer, '\0');
+ int total = 0;
+ for (int i = 0; i < bufferSize; ++i)
+ total += buffer[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.
+ fillBuffer(buffer, '!');
+}
+
+static void threadMain(void* arg)
+{
+ volatile char* buffer = reinterpret_cast<volatile char*>(arg);
+ for (int i = 0; i < 500000; ++i) {
+ spinLockLock(&lock);
+ changeAndCheckBuffer(buffer);
+ spinLockUnlock(&lock);
}
}
-TEST(SecurityOriginTest, ValidPortsCreateNonUniqueOrigins)
+TEST(WTF_SpinLock, Torture)
{
- int ports[] = { 0, 80, 443, 5000, MaxAllowedPort };
+ char sharedBuffer[bufferSize];
- 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, sharedBuffer, "thread1");
+ ThreadIdentifier thread2 = createThread(threadMain, sharedBuffer, "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
-
« no previous file with comments | « Source/wtf/SpinLock.h ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698