diff options
-rw-r--r-- | tests/runner.py | 23 | ||||
-rw-r--r-- | tests/sqlite/benchmark.c | 38 | ||||
-rw-r--r-- | tests/sqlite/benchmark.txt | 10 | ||||
-rw-r--r-- | tests/sqlite/sqlite3.c | 15 |
4 files changed, 69 insertions, 17 deletions
diff --git a/tests/runner.py b/tests/runner.py index aeb93429..90ce7d42 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -3087,9 +3087,11 @@ if 'benchmark' not in str(sys.argv): #build_ll_hook=self.do_autodebug) def test_sqlite(self): - global QUANTUM_SIZE, OPTIMIZE, RELOOP - if QUANTUM_SIZE == 1 or OPTIMIZE or RELOOP: return self.skip('TODO FIXME') + global QUANTUM_SIZE, OPTIMIZE, RELOOP, USE_TYPED_ARRAYS + if QUANTUM_SIZE == 1 or USE_TYPED_ARRAYS == 2: return self.skip('TODO FIXME') + RELOOP = 0 # too slow + #global AUTO_OPTIMIZE; AUTO_OPTIMIZE = 1 global CORRECT_SIGNS; CORRECT_SIGNS = 1 global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1 global CORRECT_ROUNDINGS; CORRECT_ROUNDINGS = 1 @@ -3114,21 +3116,14 @@ if 'benchmark' not in str(sys.argv): #define SQLITE_DISABLE_LFS #define LONGDOUBLE_TYPE double #define SQLITE_INT64_TYPE int + #define SQLITE_THREADSAFE 0 ''' + open(path_from_root('tests', 'sqlite', 'sqlite3.c'), 'r').read() + - open(path_from_root('tests', 'sqlite', 'test.c'), 'r').read(), - #open(path_from_root('tests', 'sqlite', 'benchmark.c'), 'r').read(), - '''count(*) = 2 - -a = 1 -b = 13153 -c = thirteen thousand one hundred fifty three - -a = 1 -b = 987 -c = some other number''', + open(path_from_root('tests', 'sqlite', 'benchmark.c'), 'r').read(), + open(path_from_root('tests', 'sqlite', 'benchmark.txt'), 'r').read(), includes=[path_from_root('tests', 'sqlite')], force_c=True, - post_build=post)# ,build_ll_hook=self.do_autodebug) + extra_emscripten_args=['-m'], + post_build=post)#,build_ll_hook=self.do_autodebug) def test_zlib(self): global CORRECT_SIGNS; CORRECT_SIGNS = 1 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); |