OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/memory_mapped_file.h" | 7 #include "base/files/memory_mapped_file.h" |
8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 samples = tester.GetHistogramSamplesSinceCreation(kAutoCommitTime); | 1299 samples = tester.GetHistogramSamplesSinceCreation(kAutoCommitTime); |
1300 EXPECT_EQ(0, samples->sum()); | 1300 EXPECT_EQ(0, samples->sum()); |
1301 } | 1301 } |
1302 | 1302 |
1303 // Make sure that OS file writes to a mmap'ed file are reflected in the memory | 1303 // Make sure that OS file writes to a mmap'ed file are reflected in the memory |
1304 // mapping of a memory-mapped file. Normally SQLite writes to memory-mapped | 1304 // mapping of a memory-mapped file. Normally SQLite writes to memory-mapped |
1305 // files using memcpy(), which should stay consistent. Our SQLite is slightly | 1305 // files using memcpy(), which should stay consistent. Our SQLite is slightly |
1306 // patched to mmap read only, then write using OS file writes. If the | 1306 // patched to mmap read only, then write using OS file writes. If the |
1307 // memory-mapped version doesn't reflect the OS file writes, SQLite's | 1307 // memory-mapped version doesn't reflect the OS file writes, SQLite's |
1308 // memory-mapped I/O should be disabled on this platform. | 1308 // memory-mapped I/O should be disabled on this platform. |
1309 #if !defined(MOJO_APPTEST_IMPL) | |
1309 TEST_F(SQLConnectionTest, MmapTest) { | 1310 TEST_F(SQLConnectionTest, MmapTest) { |
1310 // Skip the test for platforms which don't enable memory-mapped I/O in SQLite, | 1311 // Skip the test for platforms which don't enable memory-mapped I/O in SQLite, |
1311 // or which don't even support the pragma. The former seems to apply to iOS, | 1312 // or which don't even support the pragma. The former seems to apply to iOS, |
1312 // the latter to older iOS. | 1313 // the latter to older iOS. |
1313 // TODO(shess): Disable test on iOS? Disable on USE_SYSTEM_SQLITE? | 1314 // TODO(shess): Disable test on iOS? Disable on USE_SYSTEM_SQLITE? |
1314 { | 1315 { |
1315 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size")); | 1316 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size")); |
1316 if (!s.Step() || !s.ColumnInt64(0)) | 1317 if (!s.Step() || !s.ColumnInt64(0)) |
1317 return; | 1318 return; |
1318 } | 1319 } |
1319 | 1320 |
1320 // The test re-uses the database file to make sure it's representative of a | 1321 // The test re-uses the database file to make sure it's representative of a |
1321 // SQLite file, but will be storing incompatible data. | 1322 // SQLite file, but will be storing incompatible data. |
1322 db().Close(); | 1323 db().Close(); |
1323 | 1324 |
1324 const uint32 kFlags = | 1325 const uint32 kFlags = |
1325 base::File::FLAG_OPEN|base::File::FLAG_READ|base::File::FLAG_WRITE; | 1326 base::File::FLAG_OPEN|base::File::FLAG_READ|base::File::FLAG_WRITE; |
1326 char buf[4096]; | 1327 char buf[4096]; |
1327 | 1328 |
1328 // Create a file with a block of '0', a block of '1', and a block of '2'. | 1329 // Create a file with a block of '0', a block of '1', and a block of '2'. |
1329 { | 1330 { |
1330 base::File f(db_path(), kFlags); | 1331 base::File f(db_path(), kFlags); |
1331 ASSERT_TRUE(f.IsValid()); | 1332 ASSERT_TRUE(f.IsValid()); |
Scott Hess - ex-Googler
2015/09/23 21:32:30
Things start breaking here under Mojo. Which seem
| |
1332 memset(buf, '0', sizeof(buf)); | 1333 memset(buf, '0', sizeof(buf)); |
1333 ASSERT_EQ(f.Write(0*sizeof(buf), buf, sizeof(buf)), (int)sizeof(buf)); | 1334 ASSERT_EQ(f.Write(0*sizeof(buf), buf, sizeof(buf)), (int)sizeof(buf)); |
1334 | 1335 |
1335 memset(buf, '1', sizeof(buf)); | 1336 memset(buf, '1', sizeof(buf)); |
1336 ASSERT_EQ(f.Write(1*sizeof(buf), buf, sizeof(buf)), (int)sizeof(buf)); | 1337 ASSERT_EQ(f.Write(1*sizeof(buf), buf, sizeof(buf)), (int)sizeof(buf)); |
1337 | 1338 |
1338 memset(buf, '2', sizeof(buf)); | 1339 memset(buf, '2', sizeof(buf)); |
1339 ASSERT_EQ(f.Write(2*sizeof(buf), buf, sizeof(buf)), (int)sizeof(buf)); | 1340 ASSERT_EQ(f.Write(2*sizeof(buf), buf, sizeof(buf)), (int)sizeof(buf)); |
1340 } | 1341 } |
1341 | 1342 |
(...skipping 26 matching lines...) Expand all Loading... | |
1368 ASSERT_NE('4', m.data()[kOffset]); | 1369 ASSERT_NE('4', m.data()[kOffset]); |
1369 { | 1370 { |
1370 base::File f(db_path(), kFlags); | 1371 base::File f(db_path(), kFlags); |
1371 ASSERT_TRUE(f.IsValid()); | 1372 ASSERT_TRUE(f.IsValid()); |
1372 buf[0] = '4'; | 1373 buf[0] = '4'; |
1373 ASSERT_EQ(f.Write(kOffset, buf, 1), 1); | 1374 ASSERT_EQ(f.Write(kOffset, buf, 1), 1); |
1374 } | 1375 } |
1375 ASSERT_EQ('4', m.data()[kOffset]); | 1376 ASSERT_EQ('4', m.data()[kOffset]); |
1376 } | 1377 } |
1377 } | 1378 } |
1379 #endif | |
1378 | 1380 |
1379 } // namespace | 1381 } // namespace |
OLD | NEW |