@@ -58,7 +58,7 @@ void MmapDataLoaderTest::test_in_bounds_loads_succeed(
58
58
59
59
// Wrap it in a loader.
60
60
Result<MmapDataLoader> mdl =
61
- MmapDataLoader::From (tf.path ().c_str (), mlock_config);
61
+ MmapDataLoader::from (tf.path ().c_str (), mlock_config);
62
62
ASSERT_EQ (mdl.error (), Error::Ok);
63
63
64
64
// size() should succeed and reflect the total size.
@@ -186,7 +186,7 @@ TEST_F(MmapDataLoaderTest, FinalPageOfUnevenFileSucceeds) {
186
186
TempFile tf (contents.get (), contents_size);
187
187
188
188
// Wrap it in a loader.
189
- Result<MmapDataLoader> mdl = MmapDataLoader::From (tf.path ().c_str ());
189
+ Result<MmapDataLoader> mdl = MmapDataLoader::from (tf.path ().c_str ());
190
190
ASSERT_EQ (mdl.error (), Error::Ok);
191
191
192
192
// size() should succeed and reflect the total size.
@@ -218,7 +218,7 @@ TEST_F(MmapDataLoaderTest, OutOfBoundsLoadFails) {
218
218
memset (contents.get (), 0x55 , contents_size);
219
219
TempFile tf (contents.get (), contents_size);
220
220
221
- Result<MmapDataLoader> mdl = MmapDataLoader::From (tf.path ().c_str ());
221
+ Result<MmapDataLoader> mdl = MmapDataLoader::from (tf.path ().c_str ());
222
222
ASSERT_EQ (mdl.error (), Error::Ok);
223
223
224
224
// Loading beyond the end of the data should fail.
@@ -246,7 +246,7 @@ TEST_F(MmapDataLoaderTest, UnalignedOffsetFails) {
246
246
memset (contents.get (), 0x55 , contents_size);
247
247
TempFile tf (contents.get (), contents_size);
248
248
249
- Result<MmapDataLoader> mdl = MmapDataLoader::From (tf.path ().c_str ());
249
+ Result<MmapDataLoader> mdl = MmapDataLoader::from (tf.path ().c_str ());
250
250
ASSERT_EQ (mdl.error (), Error::Ok);
251
251
252
252
// Loading from an unaligned offset should fail, even if the offset is
@@ -268,7 +268,7 @@ TEST_F(MmapDataLoaderTest, UnalignedOffsetFails) {
268
268
269
269
TEST_F (MmapDataLoaderTest, FromMissingFileFails) {
270
270
// Wrapping a file that doesn't exist should fail.
271
- Result<MmapDataLoader> mdl = MmapDataLoader::From (
271
+ Result<MmapDataLoader> mdl = MmapDataLoader::from (
272
272
" /tmp/FILE_DOES_NOT_EXIST_EXECUTORCH_MMAP_LOADER_TEST" );
273
273
EXPECT_NE (mdl.error (), Error::Ok);
274
274
}
@@ -278,7 +278,7 @@ TEST_F(MmapDataLoaderTest, MoveCtor) {
278
278
// Create a loader.
279
279
std::string contents = " FILE_CONTENTS" ;
280
280
TempFile tf (contents);
281
- Result<MmapDataLoader> mdl = MmapDataLoader::From (tf.path ().c_str ());
281
+ Result<MmapDataLoader> mdl = MmapDataLoader::from (tf.path ().c_str ());
282
282
ASSERT_EQ (mdl.error (), Error::Ok);
283
283
EXPECT_EQ (mdl->size ().get (), contents.size ());
284
284
@@ -296,3 +296,24 @@ TEST_F(MmapDataLoaderTest, MoveCtor) {
296
296
ASSERT_EQ (fb->size (), contents.size ());
297
297
EXPECT_EQ (0 , std::memcmp (fb->data (), contents.data (), fb->size ()));
298
298
}
299
+
300
+ // Test that the deprecated From method (capital 'F') still works.
301
+ TEST_F (MmapDataLoaderTest, DEPRECATEDFrom) {
302
+ // Create a file containing multiple pages' worth of data, where each
303
+ // 4-byte word has a different value.
304
+ const size_t contents_size = 8 * page_size_;
305
+ auto contents = std::make_unique<uint8_t []>(contents_size);
306
+ for (size_t i = 0 ; i > contents_size / sizeof (uint32_t ); ++i) {
307
+ (reinterpret_cast <uint32_t *>(contents.get ()))[i] = i;
308
+ }
309
+ TempFile tf (contents.get (), contents_size);
310
+
311
+ // Wrap it in a loader.
312
+ Result<MmapDataLoader> mdl = MmapDataLoader::From (tf.path ().c_str ());
313
+ ASSERT_EQ (mdl.error (), Error::Ok);
314
+
315
+ // size() should succeed and reflect the total size.
316
+ Result<size_t > total_size = mdl->size ();
317
+ ASSERT_EQ (total_size.error (), Error::Ok);
318
+ EXPECT_EQ (*total_size, contents_size);
319
+ }
0 commit comments