1
0

fuzz_malloc.test 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #
  2. # 2007 May 10
  3. #
  4. # The author disclaims copyright to this source code. In place of
  5. # a legal notice, here is a blessing:
  6. #
  7. # May you do good and not evil.
  8. # May you find forgiveness for yourself and forgive others.
  9. # May you share freely, never taking more than you give.
  10. #
  11. #***********************************************************************
  12. #
  13. # This file tests malloc failures in concert with fuzzy SQL generation.
  14. #
  15. # $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. ifcapable !memdebug {
  19. finish_test
  20. return
  21. }
  22. source $testdir/malloc_common.tcl
  23. source $testdir/fuzz_common.tcl
  24. if {[info exists G(isquick)]} {
  25. set ::REPEATS 20
  26. } elseif {[info exists G(issoak)]} {
  27. set ::REPEATS 100
  28. } else {
  29. set ::REPEATS 40
  30. }
  31. #
  32. # Usage: do_fuzzy_malloc_test <testname> ?<options>?
  33. #
  34. # -template
  35. # -sqlprep
  36. # -repeats
  37. #
  38. proc do_fuzzy_malloc_test {testname args} {
  39. set ::fuzzyopts(-repeats) $::REPEATS
  40. set ::fuzzyopts(-sqlprep) {}
  41. array set ::fuzzyopts $args
  42. sqlite3_memdebug_fail -1
  43. db close
  44. delete_file test.db test.db-journal
  45. sqlite3 db test.db
  46. set ::prep $::fuzzyopts(-sqlprep)
  47. execsql $::prep
  48. set jj 0
  49. for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
  50. expr srand($jj)
  51. incr jj
  52. set ::sql [subst $::fuzzyopts(-template)]
  53. # puts fuzyy-sql=\[$::sql\]; flush stdout
  54. foreach {rc res} [catchsql "$::sql"] {}
  55. if {$rc==0} {
  56. do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
  57. } else {
  58. incr ii -1
  59. }
  60. }
  61. }
  62. #----------------------------------------------------------------
  63. # Test malloc failure during parsing (and execution) of a fuzzily
  64. # generated expressions.
  65. #
  66. do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
  67. do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
  68. set ::SQLPREP {
  69. BEGIN;
  70. CREATE TABLE abc(a, b, c);
  71. CREATE TABLE def(a, b, c);
  72. CREATE TABLE ghi(a, b, c);
  73. INSERT INTO abc VALUES(1.5, 3, 'a short string');
  74. INSERT INTO def VALUES(NULL, X'ABCDEF',
  75. 'a longer string. Long enough that it doesn''t fit in Mem.zShort');
  76. INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
  77. COMMIT;
  78. }
  79. set ::TableList [list abc def ghi]
  80. set ::ColumnList [list a b c]
  81. do_fuzzy_malloc_test fuzzy_malloc-3 \
  82. -template {[Select]} \
  83. -sqlprep $::SQLPREP
  84. finish_test