Skip to content

Commit c474f6c

Browse files
committed
[region-isolation] Move unittests from SIL to SILOptimizer.
This is the correct thing to do since the header is in SILOptimizer. That being said the reason why I am doing this is that I want to add a command line flag to PartitionUtils.h to allow for more verbose debug output and the flag's definition will be in the SILOptimizer library. So this is just a little cleanup that follows from that.
1 parent d598da5 commit c474f6c

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

unittests/SIL/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
add_swift_unittest(SwiftSILTests
2-
PartitionUtilsTest.cpp
32
SILBitfieldTest.cpp
43
)
54

unittests/SILOptimizer/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_swift_unittest(SwiftSILOptimizerTests
2+
PartitionUtilsTest.cpp
3+
)
4+
5+
target_link_libraries(SwiftSILOptimizerTests
6+
PRIVATE
7+
swiftSILOptimizer
8+
)

unittests/SIL/PartitionUtilsTest.cpp renamed to unittests/SILOptimizer/PartitionUtilsTest.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
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+
//===----------------------------------------------------------------------===//
212

313
#include "swift/SILOptimizer/Utils/PartitionUtils.h"
414

15+
#include "gtest/gtest.h"
16+
517
using namespace swift;
618

719
// this test tests that if a series of merges is split between two partitions
@@ -109,7 +121,9 @@ TEST(PartitionUtilsTest, TestAssign) {
109121
p3.apply(PartitionOp::AssignFresh(Element(2)));
110122
p3.apply(PartitionOp::AssignFresh(Element(3)));
111123

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)))
113127

114128
EXPECT_TRUE(Partition::equals(p1, p2));
115129
EXPECT_TRUE(Partition::equals(p2, p3));
@@ -119,7 +133,8 @@ TEST(PartitionUtilsTest, TestAssign) {
119133
p2.apply(PartitionOp::Assign(Element(1), Element(0)));
120134
p3.apply(PartitionOp::Assign(Element(2), Element(1)));
121135

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)))
123138

124139
EXPECT_TRUE(Partition::equals(p1, p2));
125140
EXPECT_FALSE(Partition::equals(p2, p3));
@@ -129,7 +144,8 @@ TEST(PartitionUtilsTest, TestAssign) {
129144
p2.apply(PartitionOp::Assign(Element(2), Element(1)));
130145
p3.apply(PartitionOp::Assign(Element(0), Element(2)));
131146

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)))
133149

134150
EXPECT_TRUE(Partition::equals(p1, p2));
135151
EXPECT_TRUE(Partition::equals(p2, p3));
@@ -139,7 +155,7 @@ TEST(PartitionUtilsTest, TestAssign) {
139155
p2.apply(PartitionOp::Assign(Element(1), Element(3)));
140156
p3.apply(PartitionOp::Assign(Element(2), Element(3)));
141157

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))
143159

144160
EXPECT_FALSE(Partition::equals(p1, p2));
145161
EXPECT_FALSE(Partition::equals(p2, p3));
@@ -149,7 +165,8 @@ TEST(PartitionUtilsTest, TestAssign) {
149165
p2.apply(PartitionOp::Assign(Element(2), Element(1)));
150166
p3.apply(PartitionOp::Assign(Element(0), Element(2)));
151167

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))
153170

154171
EXPECT_FALSE(Partition::equals(p1, p2));
155172
EXPECT_FALSE(Partition::equals(p2, p3));
@@ -159,7 +176,7 @@ TEST(PartitionUtilsTest, TestAssign) {
159176
p2.apply(PartitionOp::Assign(Element(0), Element(3)));
160177
p3.apply(PartitionOp::Assign(Element(1), Element(3)));
161178

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))
163180

164181
EXPECT_TRUE(Partition::equals(p1, p2));
165182
EXPECT_TRUE(Partition::equals(p2, p3));
@@ -192,23 +209,21 @@ TEST(PartitionUtilsTest, TestConsumeAndRequire) {
192209
p.apply(PartitionOp::Assign(Element(7), Element(6)));
193210
p.apply(PartitionOp::Assign(Element(9), Element(8)));
194211

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)))
196213

197214
p.apply(PartitionOp::Transfer(Element(2)));
198215
p.apply(PartitionOp::Transfer(Element(7)));
199216
p.apply(PartitionOp::Transfer(Element(10)));
200217

201218
// expected: p: ({0 1 2 6 7 10} (3 4 5) (8 9) (Element(11)))
202219

203-
auto never_called = [](const PartitionOp &, unsigned) {
204-
EXPECT_TRUE(false);
205-
};
220+
auto never_called = [](const PartitionOp &, unsigned) { EXPECT_TRUE(false); };
206221

207222
int times_called = 0;
208223
int expected_times_called = 0;
209224
auto increment_times_called = [&](const PartitionOp &, unsigned) {
210-
times_called++;
211-
};
225+
times_called++;
226+
};
212227
auto get_increment_times_called = [&]() {
213228
expected_times_called++;
214229
return increment_times_called;
@@ -238,12 +253,10 @@ TEST(PartitionUtilsTest, TestCopyConstructor) {
238253
Partition p2 = p1;
239254
p1.apply(PartitionOp::Transfer(Element(0)));
240255
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; });
244258
EXPECT_TRUE(failure);
245259

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); });
249262
}

0 commit comments

Comments
 (0)