Skip to content

Commit 4c93f5f

Browse files
committed
Added some more unit test cases
1 parent 131eca9 commit 4c93f5f

File tree

5 files changed

+115
-33
lines changed

5 files changed

+115
-33
lines changed

vpr/src/base/partition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool Partition::contains_atom(AtomBlockId atom_id) {
3030
return contains_atom;
3131
}
3232

33-
std::vector<AtomBlockId> Partition::get_atoms() {
33+
const std::vector<AtomBlockId> Partition::get_atoms() {
3434
return atom_blocks;
3535
}
3636

vpr/src/base/partition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Partition {
3434
bool contains_atom(AtomBlockId atom_id);
3535

3636
//get the atom_blocks vector
37-
std::vector<AtomBlockId> get_atoms();
37+
const std::vector<AtomBlockId> get_atoms();
3838

3939
//set the union of regions for this partition;
4040
void set_part_regions(PartitionRegions pr);

vpr/src/base/region.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
#include "region.h"
22

33
//sentinel value for indicating that a subtile has not been specified
4-
int NO_SUBTILE = -1;
4+
constexpr int NO_SUBTILE = -1;
55

66
Region::Region() {
77
sub_tile = NO_SUBTILE;
8+
9+
//default rect for a region is (-1, -1, -1, -1)
10+
region_bounds.set_xmin(-1);
11+
region_bounds.set_ymin(-1);
12+
region_bounds.set_xmax(-1);
13+
region_bounds.set_ymax(-1);
14+
}
15+
16+
vtr::Rect<int> Region::get_region_rect(){
17+
return region_bounds;
818
}
919

1020
int Region::get_xmin() {
@@ -91,20 +101,18 @@ Region Region::regions_intersection(Region region) {
91101

92102
bool Region::locked() {
93103
bool locked = false;
94-
bool x_matches = false;
95-
bool y_matches = false;
96104

97-
if (region_bounds.xmin() == region_bounds.xmax()) {
98-
x_matches = true;
105+
if (region_bounds.xmin() != region_bounds.xmax()) {
106+
return locked;
99107
}
100108

101-
if (region_bounds.ymin() == region_bounds.ymax()) {
102-
y_matches = true;
109+
if (region_bounds.ymin() != region_bounds.ymax()) {
110+
return locked;
103111
}
104112

105-
if (x_matches && y_matches && sub_tile != NO_SUBTILE) {
106-
locked = true;
113+
if (sub_tile == NO_SUBTILE) {
114+
return locked;
107115
}
108116

109-
return locked;
117+
return locked = true;
110118
}

vpr/src/base/region.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111
*
1212
*/
1313

14-
//sentinel value for indicating that a subtile had not been specified
15-
extern int NO_SUBTILE; //don't need in header file, don't need global variable
16-
1714
class Region {
1815
public:
1916
Region();
2017

21-
//vtr::Rect get_region_rect();
18+
vtr::Rect<int> get_region_rect();
2219
int get_xmin();
2320
int get_xmax();
2421
int get_ymin();

vpr/test/test_vpr_constraints.cpp

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,40 @@
55
#include "partition_regions.h"
66
#include "region.h"
77

8+
/**
9+
* This file contains unit tests that check the functionality of all classes related to vpr constraints. These classes include
10+
* VprConstraints, Region, PartitionRegions, and Partition.
11+
*/
12+
813
TEST_CASE("RegionAccessors", "[vpr]") {
914
Region r1;
1015

1116
r1.set_region_rect(1, 2, 3, 4);
1217
r1.set_sub_tile(2);
1318

14-
REQUIRE(r1.get_xmin() == 1);
15-
REQUIRE(r1.get_ymin() == 2);
16-
REQUIRE(r1.get_xmax() == 3);
17-
REQUIRE(r1.get_ymax() == 4);
19+
vtr::Rect<int> rect;
20+
rect = r1.get_region_rect();
21+
22+
REQUIRE(rect.xmin() == 1);
23+
REQUIRE(rect.ymin() == 2);
24+
REQUIRE(rect.xmax() == 3);
25+
REQUIRE(rect.ymax() == 4);
1826
REQUIRE(r1.get_sub_tile() == 2);
27+
28+
//checking that default constructor creates an empty rectangle (-1,-1,-1,-1)
29+
Region def_region;
30+
bool is_def_empty = false;
31+
32+
vtr::Rect<int> def_rect = def_region.get_region_rect();
33+
is_def_empty = def_rect.empty();
34+
REQUIRE(is_def_empty == true);
35+
REQUIRE(def_rect.xmin() == -1);
1936
}
2037

2138
TEST_CASE("PartitionRegionsAccessors", "[vpr]") {
2239
Region r1;
2340

24-
r1.set_region_rect(0, 0, 1, 1);
41+
r1.set_region_rect(2, 3, 6, 7);
2542
r1.set_sub_tile(3);
2643

2744
PartitionRegions pr1;
@@ -30,6 +47,12 @@ TEST_CASE("PartitionRegionsAccessors", "[vpr]") {
3047

3148
std::vector<Region> pr_regions = pr1.get_partition_regions();
3249
REQUIRE(pr_regions[0].get_sub_tile() == 3);
50+
vtr::Rect<int> rect;
51+
rect = pr_regions[0].get_region_rect();
52+
REQUIRE(rect.xmin() == 2);
53+
REQUIRE(rect.ymin() == 3);
54+
REQUIRE(rect.xmax() == 6);
55+
REQUIRE(rect.ymax() == 7);
3356
}
3457

3558
TEST_CASE("PartitionAccessors", "[vpr]") {
@@ -50,10 +73,11 @@ TEST_CASE("PartitionAccessors", "[vpr]") {
5073
REQUIRE(atoms[0] == atom_1);
5174
REQUIRE(atoms[1] == atom_2);
5275
REQUIRE(part.contains_atom(atom_1) == true);
76+
REQUIRE(part.contains_atom(atom_2) == true);
5377

54-
//create region and partitionregions objects to test accessors of the Partitions class
78+
//create region and partitionregions objects to test accessors of the Partition class
5579
Region r1;
56-
r1.set_region_rect(0, 0, 1, 1);
80+
r1.set_region_rect(2, 3, 7, 8);
5781
r1.set_sub_tile(3);
5882

5983
PartitionRegions part_reg;
@@ -64,6 +88,12 @@ TEST_CASE("PartitionAccessors", "[vpr]") {
6488
std::vector<Region> regions = part_reg_2.get_partition_regions();
6589

6690
REQUIRE(regions[0].get_sub_tile() == 3);
91+
vtr::Rect<int> rect;
92+
rect = regions[0].get_region_rect();
93+
REQUIRE(rect.xmin() == 2);
94+
REQUIRE(rect.ymin() == 3);
95+
REQUIRE(rect.xmax() == 7);
96+
REQUIRE(rect.ymax() == 8);
6797
}
6898

6999
TEST_CASE("VprConstraintsAccessors", "[vpr]") {
@@ -95,20 +125,48 @@ TEST_CASE("VprConstraintsAccessors", "[vpr]") {
95125
}
96126

97127
TEST_CASE("RegionIntersect", "[vpr]") {
128+
//Test partial intersection
98129
Region region1;
99130
Region region2;
100131

101-
region1.set_region_rect(0, 0, 2, 2);
102-
region2.set_region_rect(1, 1, 2, 2);
132+
region1.set_region_rect(1,2,3,5);
133+
region2.set_region_rect(2,3,4,6);
103134

104135
Region int_reg;
105136

106137
int_reg = region1.regions_intersection(region2);
138+
vtr::Rect<int> rect = int_reg.get_region_rect();
139+
140+
REQUIRE(rect.xmin() == 2);
141+
REQUIRE(rect.ymin() == 3);
142+
REQUIRE(rect.xmax() == 3);
143+
REQUIRE(rect.ymax() == 5);
144+
145+
//Test full overlap
146+
Region region3;
147+
Region region4;
148+
149+
region3.set_region_rect(5,1,8,6);
150+
region4.set_region_rect(6,3,8,6);
151+
152+
Region int_reg_2;
153+
154+
int_reg_2 = region3.regions_intersection(region4);
155+
vtr::Rect<int> rect_2 = int_reg_2.get_region_rect();
156+
157+
REQUIRE(rect_2.xmin() == 6);
158+
REQUIRE(rect_2.ymin() == 3);
159+
REQUIRE(rect_2.xmax() == 8);
160+
REQUIRE(rect_2.ymax() == 6);
161+
162+
//Test no intersection (rect is empty)
163+
164+
Region int_reg_3;
107165

108-
REQUIRE(int_reg.get_xmin() == 1);
109-
REQUIRE(int_reg.get_ymin() == 1);
110-
REQUIRE(int_reg.get_xmax() == 2);
111-
REQUIRE(int_reg.get_ymax() == 2);
166+
int_reg_3 = region1.regions_intersection(region3);
167+
vtr::Rect<int> rect_3 = int_reg_3.get_region_rect();
168+
169+
REQUIRE(rect_3.empty() == TRUE);
112170
}
113171

114172
TEST_CASE("PartRegionIntersect", "[vpr]") {
@@ -145,15 +203,34 @@ TEST_CASE("PartRegionIntersect", "[vpr]") {
145203

146204
TEST_CASE("RegionLocked", "[vpr]") {
147205
Region r1;
148-
149-
r1.set_region_rect(0, 1, 0, 1); //xmin = xmax = 0, ymin = ymax =1
150-
r1.set_sub_tile(3); //set the region to specific x, y, subtile to lock down
151-
152206
bool is_r1_locked = false;
153207

208+
//set the region to a specific x, y, subtile location - region is locked
209+
r1.set_region_rect(2,3,2,3); //point (2,3) to point (2,3) - locking to specific x, y location
210+
r1.set_sub_tile(3); //locking down to subtile 3
211+
154212
is_r1_locked = r1.locked();
155213

156214
REQUIRE(is_r1_locked == true);
215+
216+
//do not set region to specific x, y location - region is not locked even if a subtile is specified
217+
r1.set_region_rect(2,3,5,6); //point (2,3) to point (5,6) - not locking to specific x, y location
218+
r1.set_sub_tile(3); //locking down to subtile 3
219+
220+
is_r1_locked = r1.locked();
221+
222+
REQUIRE(is_r1_locked == false);
223+
224+
//do not specify a subtile for the region - region is not locked even if it is set at specific x, y location
225+
Region r2;
226+
bool is_r2_locked = true;
227+
228+
r2.set_region_rect(2,3,2,3);
229+
230+
is_r2_locked = r2.locked();
231+
232+
REQUIRE(is_r2_locked == false);
233+
157234
}
158235

159236
TEST_CASE("PartRegionIntersect2", "[vpr]") {

0 commit comments

Comments
 (0)