1
- #include " gtest/gtest.h"
1
+ // ===--- PartitionUtilsTest.cpp -------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ // ===----------------------------------------------------------------------===//
2
12
3
13
#include " swift/SILOptimizer/Utils/PartitionUtils.h"
4
14
15
+ #include " gtest/gtest.h"
16
+
5
17
using namespace swift ;
6
18
7
19
// this test tests that if a series of merges is split between two partitions
@@ -109,7 +121,9 @@ TEST(PartitionUtilsTest, TestAssign) {
109
121
p3.apply (PartitionOp::AssignFresh (Element (2 )));
110
122
p3.apply (PartitionOp::AssignFresh (Element (3 )));
111
123
112
- // expected: p1: ((Element(0)) (Element(1)) (Element(2)) (Element(3))), p2: ((Element(0)) (Element(1)) (Element(2)) (Element(3))), p3: ((Element(0)) (Element(1)) (Element(2)) (Element(3)))
124
+ // expected: p1: ((Element(0)) (Element(1)) (Element(2)) (Element(3))), p2:
125
+ // ((Element(0)) (Element(1)) (Element(2)) (Element(3))), p3: ((Element(0))
126
+ // (Element(1)) (Element(2)) (Element(3)))
113
127
114
128
EXPECT_TRUE (Partition::equals (p1, p2));
115
129
EXPECT_TRUE (Partition::equals (p2, p3));
@@ -119,7 +133,8 @@ TEST(PartitionUtilsTest, TestAssign) {
119
133
p2.apply (PartitionOp::Assign (Element (1 ), Element (0 )));
120
134
p3.apply (PartitionOp::Assign (Element (2 ), Element (1 )));
121
135
122
- // expected: p1: ((0 1) (Element(2)) (Element(3))), p2: ((0 1) (Element(2)) (Element(3))), p3: ((Element(0)) (1 2) (Element(3)))
136
+ // expected: p1: ((0 1) (Element(2)) (Element(3))), p2: ((0 1) (Element(2))
137
+ // (Element(3))), p3: ((Element(0)) (1 2) (Element(3)))
123
138
124
139
EXPECT_TRUE (Partition::equals (p1, p2));
125
140
EXPECT_FALSE (Partition::equals (p2, p3));
@@ -129,7 +144,8 @@ TEST(PartitionUtilsTest, TestAssign) {
129
144
p2.apply (PartitionOp::Assign (Element (2 ), Element (1 )));
130
145
p3.apply (PartitionOp::Assign (Element (0 ), Element (2 )));
131
146
132
- // expected: p1: ((0 1 2) (Element(3))), p2: ((0 1 2) (Element(3))), p3: ((0 1 2) (Element(3)))
147
+ // expected: p1: ((0 1 2) (Element(3))), p2: ((0 1 2) (Element(3))), p3: ((0 1
148
+ // 2) (Element(3)))
133
149
134
150
EXPECT_TRUE (Partition::equals (p1, p2));
135
151
EXPECT_TRUE (Partition::equals (p2, p3));
@@ -139,7 +155,7 @@ TEST(PartitionUtilsTest, TestAssign) {
139
155
p2.apply (PartitionOp::Assign (Element (1 ), Element (3 )));
140
156
p3.apply (PartitionOp::Assign (Element (2 ), Element (3 )));
141
157
142
- // expected: p1: ((1 2) (0 3)), p2: ((0 2) (1 3)), p3: ((0 1) (2 3))
158
+ // expected: p1: ((1 2) (0 3)), p2: ((0 2) (1 3)), p3: ((0 1) (2 3))
143
159
144
160
EXPECT_FALSE (Partition::equals (p1, p2));
145
161
EXPECT_FALSE (Partition::equals (p2, p3));
@@ -149,7 +165,8 @@ TEST(PartitionUtilsTest, TestAssign) {
149
165
p2.apply (PartitionOp::Assign (Element (2 ), Element (1 )));
150
166
p3.apply (PartitionOp::Assign (Element (0 ), Element (2 )));
151
167
152
- // expected: p1: ((Element(2)) (0 1 3)), p2: ((Element(0)) (1 2 3)), p3: ((Element(1)) (0 2 3))
168
+ // expected: p1: ((Element(2)) (0 1 3)), p2: ((Element(0)) (1 2 3)), p3:
169
+ // ((Element(1)) (0 2 3))
153
170
154
171
EXPECT_FALSE (Partition::equals (p1, p2));
155
172
EXPECT_FALSE (Partition::equals (p2, p3));
@@ -159,7 +176,7 @@ TEST(PartitionUtilsTest, TestAssign) {
159
176
p2.apply (PartitionOp::Assign (Element (0 ), Element (3 )));
160
177
p3.apply (PartitionOp::Assign (Element (1 ), Element (3 )));
161
178
162
- // expected: p1: ((0 1 2 3)), p2: ((0 1 2 3)), p3: ((0 1 2 3))
179
+ // expected: p1: ((0 1 2 3)), p2: ((0 1 2 3)), p3: ((0 1 2 3))
163
180
164
181
EXPECT_TRUE (Partition::equals (p1, p2));
165
182
EXPECT_TRUE (Partition::equals (p2, p3));
@@ -192,23 +209,21 @@ TEST(PartitionUtilsTest, TestConsumeAndRequire) {
192
209
p.apply (PartitionOp::Assign (Element (7 ), Element (6 )));
193
210
p.apply (PartitionOp::Assign (Element (9 ), Element (8 )));
194
211
195
- // expected: p: ((0 1 2) (3 4 5) (6 7) (8 9) (Element(10)) (Element(11)))
212
+ // expected: p: ((0 1 2) (3 4 5) (6 7) (8 9) (Element(10)) (Element(11)))
196
213
197
214
p.apply (PartitionOp::Transfer (Element (2 )));
198
215
p.apply (PartitionOp::Transfer (Element (7 )));
199
216
p.apply (PartitionOp::Transfer (Element (10 )));
200
217
201
218
// expected: p: ({0 1 2 6 7 10} (3 4 5) (8 9) (Element(11)))
202
219
203
- auto never_called = [](const PartitionOp &, unsigned ) {
204
- EXPECT_TRUE (false );
205
- };
220
+ auto never_called = [](const PartitionOp &, unsigned ) { EXPECT_TRUE (false ); };
206
221
207
222
int times_called = 0 ;
208
223
int expected_times_called = 0 ;
209
224
auto increment_times_called = [&](const PartitionOp &, unsigned ) {
210
- times_called++;
211
- };
225
+ times_called++;
226
+ };
212
227
auto get_increment_times_called = [&]() {
213
228
expected_times_called++;
214
229
return increment_times_called;
@@ -238,12 +253,10 @@ TEST(PartitionUtilsTest, TestCopyConstructor) {
238
253
Partition p2 = p1;
239
254
p1.apply (PartitionOp::Transfer (Element (0 )));
240
255
bool failure = false ;
241
- p1.apply (PartitionOp::Require (Element (0 )), [&](const PartitionOp &, unsigned ) {
242
- failure = true ;
243
- });
256
+ p1.apply (PartitionOp::Require (Element (0 )),
257
+ [&](const PartitionOp &, unsigned ) { failure = true ; });
244
258
EXPECT_TRUE (failure);
245
259
246
- p2.apply (PartitionOp::Require (Element (0 )), [](const PartitionOp &, unsigned ) {
247
- EXPECT_TRUE (false );
248
- });
260
+ p2.apply (PartitionOp::Require (Element (0 )),
261
+ [](const PartitionOp &, unsigned ) { EXPECT_TRUE (false ); });
249
262
}
0 commit comments