mallocI.test 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # This test script checks malloc failures in various obscure operations.
  13. #
  14. # $Id: mallocI.test,v 1.3 2009/08/10 04:26:39 danielk1977 Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. source $testdir/malloc_common.tcl
  18. # Malloc failures in a view.
  19. #
  20. do_malloc_test mallocI-1 -sqlprep {
  21. CREATE TABLE t1(a,b,c,d);
  22. CREATE VIEW v1 AS SELECT a*b, c*d FROM t1 ORDER BY b-d;
  23. } -sqlbody {
  24. SELECT * FROM v1
  25. }
  26. # Malloc failure while trying to service a pragma on a TEMP database.
  27. #
  28. do_malloc_test mallocI-2 -sqlbody {
  29. PRAGMA temp.page_size
  30. }
  31. # Malloc failure while creating a table from a SELECT statement.
  32. #
  33. do_malloc_test mallocI-3 -sqlprep {
  34. CREATE TABLE t1(a,b,c);
  35. } -sqlbody {
  36. CREATE TABLE t2 AS SELECT b,c FROM t1;
  37. }
  38. # This tests that a malloc failure that occurs while passing the schema
  39. # does not result in a SHARED lock being left on the database file.
  40. #
  41. do_malloc_test mallocI-4 -tclprep {
  42. sqlite3 db2 test.db
  43. db2 eval {
  44. CREATE TABLE t1(a, b, c);
  45. CREATE TABLE t2(a, b, c);
  46. }
  47. } -sqlbody {
  48. SELECT * FROM t1
  49. } -cleanup {
  50. do_test mallocI-4.$::n.2 {
  51. # If this INSERT is possible then [db] does not hold a shared lock
  52. # on the database file.
  53. catchsql { INSERT INTO t1 VALUES(1, 2, 3) } db2
  54. } {0 {}}
  55. catch {db2 close}
  56. }
  57. catch { db2 close }
  58. finish_test