@@ -28,26 +28,26 @@ using facebook::cachelib::detail::getPageSize;
28
28
using facebook::cachelib::detail::getPageSizeInSMap;
29
29
using facebook::cachelib::detail::isPageAlignedSize;
30
30
31
- void ShmTest::testCreateAttach (bool posix ) {
31
+ void ShmTest::testCreateAttach () {
32
32
const unsigned char magicVal = ' d' ;
33
33
{
34
34
// create with 0 size should round up to page size
35
- ShmSegment s (ShmNew, segmentName, 0 , posix );
35
+ ShmSegment s (ShmNew, segmentName, 0 , opts );
36
36
ASSERT_EQ (getPageSize (), s.getSize ());
37
37
s.markForRemoval ();
38
38
}
39
39
40
40
{
41
41
// create with unaligned size
42
42
ASSERT_TRUE (isPageAlignedSize (shmSize));
43
- ShmSegment s (ShmNew, segmentName, shmSize + 500 , posix );
43
+ ShmSegment s (ShmNew, segmentName, shmSize + 500 , opts );
44
44
ASSERT_EQ (shmSize + getPageSize (), s.getSize ());
45
45
s.markForRemoval ();
46
46
}
47
47
auto addr = getNewUnmappedAddr ();
48
48
49
49
{
50
- ShmSegment s (ShmNew, segmentName, shmSize, posix );
50
+ ShmSegment s (ShmNew, segmentName, shmSize, opts );
51
51
ASSERT_EQ (s.getSize (), shmSize);
52
52
ASSERT_FALSE (s.isMapped ());
53
53
ASSERT_TRUE (s.mapAddress (addr));
@@ -57,14 +57,14 @@ void ShmTest::testCreateAttach(bool posix) {
57
57
ASSERT_TRUE (s.isMapped ());
58
58
checkMemory (addr, s.getSize (), 0 );
59
59
writeToMemory (addr, s.getSize (), magicVal);
60
- ASSERT_THROW (ShmSegment (ShmNew, segmentName, shmSize, posix ),
60
+ ASSERT_THROW (ShmSegment (ShmNew, segmentName, shmSize, opts ),
61
61
std::system_error);
62
62
const auto m = s.getCurrentMapping ();
63
63
ASSERT_EQ (m.size , shmSize);
64
64
}
65
65
66
66
ASSERT_NO_THROW ({
67
- ShmSegment s2 (ShmAttach, segmentName, posix );
67
+ ShmSegment s2 (ShmAttach, segmentName, opts );
68
68
ASSERT_EQ (s2.getSize (), shmSize);
69
69
ASSERT_TRUE (s2.mapAddress (addr));
70
70
checkMemory (addr, s2.getSize (), magicVal);
@@ -73,15 +73,17 @@ void ShmTest::testCreateAttach(bool posix) {
73
73
});
74
74
}
75
75
76
- TEST_F (ShmTestPosix, CreateAttach) { testCreateAttach (true ); }
76
+ TEST_F (ShmTestPosix, CreateAttach) { testCreateAttach (); }
77
77
78
- TEST_F (ShmTestSysV, CreateAttach) { testCreateAttach (false ); }
78
+ TEST_F (ShmTestSysV, CreateAttach) { testCreateAttach (); }
79
79
80
- void ShmTest::testMapping (bool posix) {
80
+ TEST_F (ShmTestFile, CreateAttach) { testCreateAttach (); }
81
+
82
+ void ShmTest::testMapping () {
81
83
const unsigned char magicVal = ' z' ;
82
84
auto addr = getNewUnmappedAddr ();
83
85
{ // create a segment
84
- ShmSegment s (ShmNew, segmentName, shmSize, posix );
86
+ ShmSegment s (ShmNew, segmentName, shmSize, opts );
85
87
ASSERT_TRUE (s.mapAddress (addr));
86
88
ASSERT_TRUE (s.isMapped ());
87
89
// creating another mapping should fail
@@ -95,7 +97,7 @@ void ShmTest::testMapping(bool posix) {
95
97
96
98
// map with nullptr
97
99
{
98
- ShmSegment s (ShmAttach, segmentName, posix );
100
+ ShmSegment s (ShmAttach, segmentName, opts );
99
101
ASSERT_TRUE (s.mapAddress (nullptr ));
100
102
ASSERT_TRUE (s.isMapped ());
101
103
const auto m = s.getCurrentMapping ();
@@ -107,7 +109,7 @@ void ShmTest::testMapping(bool posix) {
107
109
}
108
110
109
111
{
110
- ShmSegment s (ShmAttach, segmentName, posix );
112
+ ShmSegment s (ShmAttach, segmentName, opts );
111
113
// can map again.
112
114
ASSERT_TRUE (s.mapAddress (addr));
113
115
ASSERT_TRUE (s.isMapped ());
@@ -148,13 +150,15 @@ void ShmTest::testMapping(bool posix) {
148
150
}
149
151
}
150
152
151
- TEST_F (ShmTestPosix, Mapping) { testMapping (true ); }
153
+ TEST_F (ShmTestPosix, Mapping) { testMapping (); }
154
+
155
+ TEST_F (ShmTestSysV, Mapping) { testMapping (); }
152
156
153
- TEST_F (ShmTestSysV , Mapping) { testMapping (false ); }
157
+ TEST_F (ShmTestFile , Mapping) { testMapping (); }
154
158
155
- void ShmTest::testMappingAlignment (bool posix ) {
159
+ void ShmTest::testMappingAlignment () {
156
160
{ // create a segment
157
- ShmSegment s (ShmNew, segmentName, shmSize, posix );
161
+ ShmSegment s (ShmNew, segmentName, shmSize, opts );
158
162
159
163
// 0 alignment is wrong.
160
164
ASSERT_FALSE (s.mapAddress (nullptr , 0 ));
@@ -171,11 +175,13 @@ void ShmTest::testMappingAlignment(bool posix) {
171
175
}
172
176
}
173
177
174
- TEST_F (ShmTestPosix, MappingAlignment) { testMappingAlignment (true ); }
178
+ TEST_F (ShmTestPosix, MappingAlignment) { testMappingAlignment (); }
179
+
180
+ TEST_F (ShmTestSysV, MappingAlignment) { testMappingAlignment (); }
175
181
176
- TEST_F (ShmTestSysV , MappingAlignment) { testMappingAlignment (false ); }
182
+ TEST_F (ShmTestFile , MappingAlignment) { testMappingAlignment (); }
177
183
178
- void ShmTest::testLifetime (bool posix ) {
184
+ void ShmTest::testLifetime () {
179
185
const size_t safeSize = getRandomSize ();
180
186
const char magicVal = ' x' ;
181
187
ASSERT_NO_THROW ({
@@ -184,7 +190,7 @@ void ShmTest::testLifetime(bool posix) {
184
190
// from address space. this should not actually delete the segment and
185
191
// we should be able to map it back as long as the object is within the
186
192
// scope.
187
- ShmSegment s (ShmNew, segmentName, safeSize, posix );
193
+ ShmSegment s (ShmNew, segmentName, safeSize, opts );
188
194
s.mapAddress (nullptr );
189
195
auto m = s.getCurrentMapping ();
190
196
writeToMemory (m.addr , m.size , magicVal);
@@ -200,14 +206,14 @@ void ShmTest::testLifetime(bool posix) {
200
206
// should be able to create a new segment with same segmentName after the
201
207
// previous scope exit destroys the segment.
202
208
const size_t newSize = getRandomSize ();
203
- ShmSegment s (ShmNew, segmentName, newSize, posix );
209
+ ShmSegment s (ShmNew, segmentName, newSize, opts );
204
210
s.mapAddress (nullptr );
205
211
auto m = s.getCurrentMapping ();
206
212
checkMemory (m.addr , m.size , 0 );
207
213
writeToMemory (m.addr , m.size , magicVal);
208
214
}
209
215
// attaching should have the same behavior.
210
- ShmSegment s (ShmAttach, segmentName, posix );
216
+ ShmSegment s (ShmAttach, segmentName, opts );
211
217
s.mapAddress (nullptr );
212
218
s.markForRemoval ();
213
219
ASSERT_TRUE (s.isMarkedForRemoval ());
@@ -218,5 +224,6 @@ void ShmTest::testLifetime(bool posix) {
218
224
});
219
225
}
220
226
221
- TEST_F (ShmTestPosix, Lifetime) { testLifetime (true ); }
222
- TEST_F (ShmTestSysV, Lifetime) { testLifetime (false ); }
227
+ TEST_F (ShmTestPosix, Lifetime) { testLifetime (); }
228
+ TEST_F (ShmTestSysV, Lifetime) { testLifetime (); }
229
+ TEST_F (ShmTestFile, Lifetime) { testLifetime (); }
0 commit comments