1
0

lookaside.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # 2008 August 01
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # Tests for the lookaside memory allocator.
  13. #
  14. # $Id: lookaside.test,v 1.10 2009/04/09 01:23:49 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. ifcapable !lookaside {
  18. finish_test
  19. return
  20. }
  21. # The tests in this file configure the lookaside allocator after a
  22. # connection is opened. This will not work if there is any "presql"
  23. # configured (SQL run within the [sqlite3] wrapper in tester.tcl).
  24. if {[info exists ::G(perm:presql)]} {
  25. finish_test
  26. return
  27. }
  28. catch {db close}
  29. sqlite3_shutdown
  30. sqlite3_config_pagecache 0 0
  31. sqlite3_config_scratch 0 0
  32. sqlite3_initialize
  33. autoinstall_test_functions
  34. sqlite3 db test.db
  35. # Make sure sqlite3_db_config() and sqlite3_db_status are working.
  36. #
  37. do_test lookaside-1.1 {
  38. catch {sqlite3_config_error db}
  39. } {0}
  40. do_test lookaside-1.2 {
  41. sqlite3_db_config_lookaside db 1 18 18
  42. } {0}
  43. do_test lookaside-1.3.1 {
  44. sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
  45. } {0 0 0}
  46. do_test lookaside-1.3.2 {
  47. sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
  48. } {0 0 0}
  49. do_test lookaside-1.3.3 {
  50. sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
  51. } {0 0 0}
  52. do_test lookaside-1.3.4 {
  53. sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
  54. } {0 0 0}
  55. do_test lookaside-1.4 {
  56. db eval {CREATE TABLE t1(w,x,y,z);}
  57. foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  58. set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2]
  59. set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2]
  60. set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2]
  61. expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0}
  62. } {0}
  63. do_test lookaside-1.5 {
  64. foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
  65. expr {$x==0 && $y<$z && $z==18}
  66. } {0}
  67. do_test lookaside-1.6 {
  68. foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  69. expr {$x==0 && $y==$z && $y<18}
  70. } {1}
  71. do_test lookaside-1.7 {
  72. db cache flush
  73. foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  74. expr {$x==0 && $y==0 && $z<18}
  75. } {1}
  76. do_test lookaside-1.8 {
  77. db cache flush
  78. foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
  79. expr {$x==0 && $y==0 && $z<18}
  80. } {1}
  81. do_test lookaside-1.9 {
  82. db cache flush
  83. sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
  84. } {0 0 0}
  85. do_test lookaside-2.1 {
  86. sqlite3_db_config_lookaside db 0 100 1000
  87. } {0}
  88. do_test lookaside-2.2 {
  89. db eval {CREATE TABLE t2(x);}
  90. foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  91. expr {$x==0 && $y<$z && $z>10 && $z<100}
  92. } {1}
  93. do_test lookaside-2.3 {
  94. sqlite3_db_config_lookaside db 0 50 50
  95. } {5} ;# SQLITE_BUSY
  96. do_test lookaside-2.4 {
  97. db cache flush
  98. sqlite3_db_config_lookaside db 0 50 50
  99. } {0} ;# SQLITE_OK
  100. do_test lookaside-2.5 {
  101. sqlite3_db_config_lookaside db 0 -1 50
  102. } {0} ;# SQLITE_OK
  103. do_test lookaside-2.6 {
  104. sqlite3_db_config_lookaside db 0 50 -1
  105. } {0} ;# SQLITE_OK
  106. # sqlite3_db_status() with an invalid verb returns an error.
  107. #
  108. do_test lookaside-3.1 {
  109. sqlite3_db_status db 99999 0
  110. } {1 0 0}
  111. # Test that an invalid verb on sqlite3_config() is detected and
  112. # reported as an error.
  113. #
  114. do_test lookaside-4.1 {
  115. db close
  116. sqlite3_shutdown
  117. catch sqlite3_config_error
  118. } {0}
  119. sqlite3_initialize
  120. autoinstall_test_functions
  121. finish_test