Chromium Code Reviews| 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 |
| - |