Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: sql/sqlite_features_unittest.cc

Issue 2083543003: Updates SQL code now that mmap is supported on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sql/connection_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/memory_mapped_file.h" 12 #include "base/files/memory_mapped_file.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "sql/connection.h" 14 #include "sql/connection.h"
15 #include "sql/statement.h" 15 #include "sql/statement.h"
16 #include "sql/test/sql_test_base.h" 16 #include "sql/test/sql_test_base.h"
17 #include "sql/test/test_helpers.h" 17 #include "sql/test/test_helpers.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/sqlite/sqlite3.h" 19 #include "third_party/sqlite/sqlite3.h"
20 20
21 #if defined(OS_IOS)
22 #include "base/ios/ios_util.h"
23 #endif
24
21 // Test that certain features are/are-not enabled in our SQLite. 25 // Test that certain features are/are-not enabled in our SQLite.
22 26
23 namespace { 27 namespace {
24 28
25 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, 29 void CaptureErrorCallback(int* error_pointer, std::string* sql_text,
26 int error, sql::Statement* stmt) { 30 int error, sql::Statement* stmt) {
27 *error_pointer = error; 31 *error_pointer = error;
28 const char* text = stmt ? stmt->GetSQLStatement() : NULL; 32 const char* text = stmt ? stmt->GetSQLStatement() : NULL;
29 *sql_text = text ? text : "no statement available"; 33 *sql_text = text ? text : "no statement available";
30 } 34 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // Deleting the parent should cascade, i.e., delete the children as well. 148 // Deleting the parent should cascade, i.e., delete the children as well.
145 ASSERT_TRUE(db().Execute("DELETE FROM parents")); 149 ASSERT_TRUE(db().Execute("DELETE FROM parents"));
146 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows)); 150 EXPECT_TRUE(sql::test::CountTableRows(&db(), "children", &rows));
147 EXPECT_EQ(0u, rows); 151 EXPECT_EQ(0u, rows);
148 } 152 }
149 153
150 #if defined(MOJO_APPTEST_IMPL) || defined(OS_IOS) 154 #if defined(MOJO_APPTEST_IMPL) || defined(OS_IOS)
151 // If the platform cannot support SQLite mmap'ed I/O, make sure SQLite isn't 155 // If the platform cannot support SQLite mmap'ed I/O, make sure SQLite isn't
152 // offering to support it. 156 // offering to support it.
153 TEST_F(SQLiteFeaturesTest, NoMmap) { 157 TEST_F(SQLiteFeaturesTest, NoMmap) {
158 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
159 if (base::ios::IsRunningOnIOS10OrLater()) {
160 // iOS 10 added mmap support for sqlite.
161 return;
162 }
163 #endif
164
154 // For recent versions of SQLite, SQLITE_MAX_MMAP_SIZE=0 can be used to 165 // For recent versions of SQLite, SQLITE_MAX_MMAP_SIZE=0 can be used to
155 // disable mmap support. Alternately, sqlite3_config() could be used. In 166 // disable mmap support. Alternately, sqlite3_config() could be used. In
156 // that case, the pragma will run successfully, but the size will always be 0. 167 // that case, the pragma will run successfully, but the size will always be 0.
157 // 168 //
158 // The SQLite embedded in older iOS releases predates the addition of mmap 169 // The SQLite embedded in older iOS releases predates the addition of mmap
159 // support. In that case the pragma will run without error, but no results 170 // support. In that case the pragma will run without error, but no results
160 // are returned when querying the value. 171 // are returned when querying the value.
161 // 172 //
162 // MojoVFS implements a no-op for xFileControl(). PRAGMA mmap_size is 173 // MojoVFS implements a no-op for xFileControl(). PRAGMA mmap_size is
163 // implemented in terms of SQLITE_FCNTL_MMAP_SIZE. In that case, the pragma 174 // implemented in terms of SQLITE_FCNTL_MMAP_SIZE. In that case, the pragma
164 // will succeed but with no effect. 175 // will succeed but with no effect.
165 ignore_result(db().Execute("PRAGMA mmap_size = 1048576")); 176 ignore_result(db().Execute("PRAGMA mmap_size = 1048576"));
166 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size")); 177 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size"));
167 ASSERT_TRUE(!s.Step() || !s.ColumnInt64(0)); 178 ASSERT_TRUE(!s.Step() || !s.ColumnInt64(0));
168 } 179 }
169 #else 180 #endif
181
182 #if !defined(MOJO_APPTEST_IMPL)
170 // Verify that OS file writes are reflected in the memory mapping of a 183 // Verify that OS file writes are reflected in the memory mapping of a
171 // memory-mapped file. Normally SQLite writes to memory-mapped files using 184 // memory-mapped file. Normally SQLite writes to memory-mapped files using
172 // memcpy(), which should stay consistent. Our SQLite is slightly patched to 185 // memcpy(), which should stay consistent. Our SQLite is slightly patched to
173 // mmap read only, then write using OS file writes. If the memory-mapped 186 // mmap read only, then write using OS file writes. If the memory-mapped
174 // version doesn't reflect the OS file writes, SQLite's memory-mapped I/O should 187 // version doesn't reflect the OS file writes, SQLite's memory-mapped I/O should
175 // be disabled on this platform using SQLITE_MAX_MMAP_SIZE=0. 188 // be disabled on this platform using SQLITE_MAX_MMAP_SIZE=0.
176 TEST_F(SQLiteFeaturesTest, Mmap) { 189 TEST_F(SQLiteFeaturesTest, Mmap) {
190 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
191 if (!base::ios::IsRunningOnIOS10OrLater()) {
192 // iOS9's sqlite does not support mmap, so this test must be skipped.
193 return;
194 }
195 #endif
196
177 // Try to turn on mmap'ed I/O. 197 // Try to turn on mmap'ed I/O.
178 ignore_result(db().Execute("PRAGMA mmap_size = 1048576")); 198 ignore_result(db().Execute("PRAGMA mmap_size = 1048576"));
179 { 199 {
180 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size")); 200 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size"));
181 201
182 #if !defined(USE_SYSTEM_SQLITE) 202 #if !defined(USE_SYSTEM_SQLITE)
183 // With Chromium's version of SQLite, the setting should always be non-zero. 203 // With Chromium's version of SQLite, the setting should always be non-zero.
184 ASSERT_TRUE(s.Step()); 204 ASSERT_TRUE(s.Step());
185 ASSERT_GT(s.ColumnInt64(0), 0); 205 ASSERT_GT(s.ColumnInt64(0), 0);
186 #else 206 #else
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 ASSERT_TRUE(f.IsValid()); 264 ASSERT_TRUE(f.IsValid());
245 buf[0] = '4'; 265 buf[0] = '4';
246 ASSERT_EQ(f.Write(kOffset, buf, 1), 1); 266 ASSERT_EQ(f.Write(kOffset, buf, 1), 1);
247 } 267 }
248 ASSERT_EQ('4', m.data()[kOffset]); 268 ASSERT_EQ('4', m.data()[kOffset]);
249 } 269 }
250 } 270 }
251 #endif 271 #endif
252 272
253 } // namespace 273 } // namespace
OLDNEW
« no previous file with comments | « sql/connection_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698