GC constraint solving should be parallel
[WebKit-https.git] / Tools / TestWebKitAPI / Tests / WTF / ConcurrentPtrHashSet.cpp
1 /*
2  * Copyright (C) 2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include <wtf/ConcurrentPtrHashSet.h>
28
29 using namespace WTF;
30
31 namespace TestWebKitAPI {
32
33 namespace {
34
35 // `commands` is a string that tells this thing what to do. It has to have an even number of characters.
36 // The character pairs are commands. Commands:
37 //
38 // +x     Adds 'x' to the set (casts 'x' to a void*) and asserts that it's new.
39 // !x     Adds 'x' to the set and asserts that it was there already.
40 // =x     Asserts that 'x' is in the set
41 // -x     Asserts that 'x' is not in the set
42 void doTest(const char* commands)
43 {
44     ConcurrentPtrHashSet set;
45     for (const char* command = commands; command[0] && command[1]; command += 2) {
46         void* ptr = bitwise_cast<void*>(static_cast<uintptr_t>(command[1]));
47         switch (command[0]) {
48         case '+':
49             EXPECT_TRUE(set.add(ptr));
50             break;
51         case '!':
52             EXPECT_FALSE(set.add(ptr));
53             break;
54         case '=':
55             EXPECT_TRUE(set.contains(ptr));
56             break;
57         case '-':
58             EXPECT_FALSE(set.contains(ptr));
59             break;
60         default:
61             RELEASE_ASSERT_NOT_REACHED();
62             break;
63         }
64     }
65 }
66
67 } // anonymous namespace
68
69 TEST(WTF_ConcurrentPtrHashSet, Empty)
70 {
71     doTest("");
72 }
73
74 TEST(WTF_ConcurrentPtrHashSet, AddOneElement)
75 {
76     doTest("+x=x-y-0");
77 }
78
79 TEST(WTF_ConcurrentPtrHashSet, AddOneElementMultipleTimes)
80 {
81     doTest("+x!x!x!x!x!x!x!x!x!x!x=x-y-0");
82 }
83
84 TEST(WTF_ConcurrentPtrHashSet, AddOneElementManyTimes)
85 {
86     doTest("+x!x!x!x!x!x!x!x!x!x!x=x-y-0!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x!x");
87 }
88
89 TEST(WTF_ConcurrentPtrHashSet, AddLotsOfElements)
90 {
91     doTest("+1+2+3+4+5+6+7+8+9+0+q+w+e+r+t+y+u+i+o+p+a+s+d+f+g+h+j+k+l+z+x+c+v+b+n+m+Q+W+E+R+T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