aboutsummaryrefslogtreecommitdiff
path: root/tests/sqlite
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-11 16:16:10 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-11 16:16:10 -0700
commit7143eab384be3f42ae75f7595d6f047a68f0f481 (patch)
treefc9539b72b0f8248f3964ddf695f408c3dba9641 /tests/sqlite
parent4a29c4fa7de4be1d598a37d6907c3e084f362d7c (diff)
improve sqlite test
Diffstat (limited to 'tests/sqlite')
-rw-r--r--tests/sqlite/benchmark.c38
-rw-r--r--tests/sqlite/benchmark.txt10
-rw-r--r--tests/sqlite/sqlite3.c15
3 files changed, 60 insertions, 3 deletions
diff --git a/tests/sqlite/benchmark.c b/tests/sqlite/benchmark.c
index de8a9a82..5618d388 100644
--- a/tests/sqlite/benchmark.c
+++ b/tests/sqlite/benchmark.c
@@ -11,6 +11,38 @@ static int callback(void *NotUsed, int argc, char **argv, char **azColName){
return 0;
}
+int test(){
+ sqlite3 *db;
+ char *zErrMsg = 0;
+ int rc;
+ int i;
+ const char *commands[] = {
+ "CREATE TABLE t2(a INTEGER, b INTEGER, c VARCHAR(100));",
+ "INSERT INTO t2 VALUES(1,13153,'thirteen thousand one hundred fifty three');",
+ "INSERT INTO t2 VALUES(1,987,'some other number');",
+ "SELECT count(*) FROM t2;",
+ "SELECT a, b, c FROM t2;",
+ NULL
+ };
+
+ rc = sqlite3_open(":memory:", &db);
+ if( rc ){
+ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+ sqlite3_close(db);
+ exit(1);
+ }
+ for (i = 0; commands[i]; i++) {
+ rc = sqlite3_exec(db, commands[i], callback, 0, &zErrMsg);
+ if( rc!=SQLITE_OK ){
+ fprintf(stderr, "SQL error on %d: %s\n", i, zErrMsg);
+ sqlite3_free(zErrMsg);
+ exit(1);
+ }
+ }
+ sqlite3_close(db);
+ return 0;
+}
+
int main(){
sqlite3 *db;
char *zErrMsg = 0;
@@ -41,6 +73,7 @@ int main(){
}
t = clock();
+ TIME("'startup'");
RUN("CREATE TABLE t1(a INTEGER, b INTEGER, c VARCHAR(100));");
TIME("create table");
@@ -48,7 +81,7 @@ int main(){
RUN("BEGIN;");
// 25000 INSERTs in a transaction
- for (i = 0; i < 5000; i++) {
+ for (i = 0; i < 5; i++) {
RUN("INSERT INTO t1 VALUES(1,12345,'one 1 one 1 one 1');");
RUN("INSERT INTO t1 VALUES(2,23422,'two two two two');");
RUN("INSERT INTO t1 VALUES(3,31233,'three three 33333333333 three');");
@@ -77,6 +110,7 @@ int main(){
TIME("selects with indexes");
sqlite3_close(db);
- return 0;
+
+ return test();
}
diff --git a/tests/sqlite/benchmark.txt b/tests/sqlite/benchmark.txt
new file mode 100644
index 00000000..472221df
--- /dev/null
+++ b/tests/sqlite/benchmark.txt
@@ -0,0 +1,10 @@
+count(*) = 2
+
+a = 1
+b = 13153
+c = thirteen thousand one hundred fifty three
+
+a = 1
+b = 987
+c = some other number
+
diff --git a/tests/sqlite/sqlite3.c b/tests/sqlite/sqlite3.c
index 2c426c21..2d6633ea 100644
--- a/tests/sqlite/sqlite3.c
+++ b/tests/sqlite/sqlite3.c
@@ -29799,7 +29799,7 @@ static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){
** tests repeatable.
*/
memset(zBuf, 0, nBuf);
-#if !defined(SQLITE_TEST)
+#if 0 // XXX EMSCRIPTEN keep it all 0 for simplicity !defined(SQLITE_TEST)
{
int pid, fd;
fd = robust_open("/dev/urandom", O_RDONLY, 0);
@@ -38132,6 +38132,9 @@ static int writeJournalHdr(Pager *pPager){
u32 nHeader = (u32)pPager->pageSize;/* Size of buffer pointed to by zHeader */
u32 nWrite; /* Bytes of header sector written */
int ii; /* Loop counter */
+#ifdef EMSCRIPTEN
+ u8 temp[4];
+#endif
assert( isOpen(pPager->jfd) ); /* Journal file must be open. */
@@ -38182,7 +38185,12 @@ static int writeJournalHdr(Pager *pPager){
}
/* The random check-hash initialiser */
+#ifdef EMSCRIPTEN
+ sqlite3_randomness(sizeof(pPager->cksumInit), temp);
+ pPager->cksumInit = temp[0] + (((u32)temp[1]) << 8) + (((u32)temp[2]) << 16) + (((u32)temp[3]) << 24);
+#else
sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
+#endif
put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
/* The initial database size */
put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
@@ -53030,7 +53038,12 @@ static void insertCell(
endPtr = &data[ins];
assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
while( ptr>endPtr ){
+#ifdef EMSCRIPTEN
+ ptr[0] = ptr[-2];
+ ptr[1] = ptr[-1];
+#else
*(u16*)ptr = *(u16*)&ptr[-2];
+#endif
ptr -= 2;
}
put2byte(&data[ins], idx);