diff options
author | Dmitry Stogov <dmitry@php.net> | 2008-01-22 09:27:48 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2008-01-22 09:27:48 +0000 |
commit | 71592cec0684d376df3fc91645e98fb9679edcd5 (patch) | |
tree | 7d05ba19e5e467fcab54952c23b8069275394803 /Zend/tests | |
parent | 2be1ae5415f3087b662ac9ba6f84bb82db59c0d2 (diff) | |
download | php-git-71592cec0684d376df3fc91645e98fb9679edcd5.tar.gz |
Added garbage collector
Diffstat (limited to 'Zend/tests')
-rw-r--r-- | Zend/tests/gc_001.phpt | 12 | ||||
-rw-r--r-- | Zend/tests/gc_002.phpt | 16 | ||||
-rw-r--r-- | Zend/tests/gc_003.phpt | 16 | ||||
-rw-r--r-- | Zend/tests/gc_004.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/gc_005.phpt | 21 | ||||
-rw-r--r-- | Zend/tests/gc_006.phpt | 28 | ||||
-rw-r--r-- | Zend/tests/gc_007.phpt | 26 | ||||
-rw-r--r-- | Zend/tests/gc_008.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/gc_009.phpt | 31 | ||||
-rw-r--r-- | Zend/tests/gc_010.phpt | 25 | ||||
-rw-r--r-- | Zend/tests/gc_011.phpt | 28 | ||||
-rw-r--r-- | Zend/tests/gc_012.phpt | 17 | ||||
-rw-r--r-- | Zend/tests/gc_013.phpt | 16 | ||||
-rw-r--r-- | Zend/tests/gc_014.phpt | 18 | ||||
-rw-r--r-- | Zend/tests/gc_015.phpt | 18 | ||||
-rw-r--r-- | Zend/tests/gc_016.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/gc_017.phpt | 41 | ||||
-rw-r--r-- | Zend/tests/gc_018.phpt | 13 | ||||
-rw-r--r-- | Zend/tests/gc_019.phpt | 14 | ||||
-rw-r--r-- | Zend/tests/gc_020.phpt | 15 | ||||
-rw-r--r-- | Zend/tests/gc_021.phpt | 16 | ||||
-rw-r--r-- | Zend/tests/gc_022.phpt | 15 | ||||
-rw-r--r-- | Zend/tests/gc_023.phpt | 27 | ||||
-rw-r--r-- | Zend/tests/gc_024.phpt | 15 | ||||
-rw-r--r-- | Zend/tests/gc_025.phpt | 11 | ||||
-rw-r--r-- | Zend/tests/gc_026.phpt | 14 |
26 files changed, 525 insertions, 0 deletions
diff --git a/Zend/tests/gc_001.phpt b/Zend/tests/gc_001.phpt new file mode 100644 index 0000000000..0523c73195 --- /dev/null +++ b/Zend/tests/gc_001.phpt @@ -0,0 +1,12 @@ +--TEST-- +GC 001: gc_enable()/gc_diable()/gc_enabled() +--FILE-- +<?php +gc_disable(); +var_dump(gc_enabled()); +gc_enable(); +var_dump(gc_enabled()); +?> +--EXPECT-- +bool(false) +bool(true) diff --git a/Zend/tests/gc_002.phpt b/Zend/tests/gc_002.phpt new file mode 100644 index 0000000000..439520c46e --- /dev/null +++ b/Zend/tests/gc_002.phpt @@ -0,0 +1,16 @@ +--TEST-- +GC 002: gc_enable()/gc_diable() and ini_get() +--FILE-- +<?php +gc_disable(); +var_dump(gc_enabled()); +echo ini_get('zend.enable_gc') . "\n"; +gc_enable(); +var_dump(gc_enabled()); +echo ini_get('zend.enable_gc') . "\n"; +?> +--EXPECT-- +bool(false) +0 +bool(true) +1 diff --git a/Zend/tests/gc_003.phpt b/Zend/tests/gc_003.phpt new file mode 100644 index 0000000000..c2df57bd34 --- /dev/null +++ b/Zend/tests/gc_003.phpt @@ -0,0 +1,16 @@ +--TEST-- +GC 003: gc_enabled() and ini_set() +--FILE-- +<?php +ini_set('zend.enable_gc','0'); +var_dump(gc_enabled()); +echo ini_get('zend.enable_gc') . "\n"; +ini_set('zend.enable_gc','1'); +var_dump(gc_enabled()); +echo ini_get('zend.enable_gc') . "\n"; +?> +--EXPECT-- +bool(false) +0 +bool(true) +1 diff --git a/Zend/tests/gc_004.phpt b/Zend/tests/gc_004.phpt new file mode 100644 index 0000000000..ce6a94b79a --- /dev/null +++ b/Zend/tests/gc_004.phpt @@ -0,0 +1,24 @@ +--TEST-- +GC 004: Simple array cycle +--FILE-- +<?php +$a = array(); +$a[] =& $a; +var_dump($a); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +array(1) { + [0]=> + &array(1) { + [0]=> + &array(1) { + [0]=> + *RECURSION* + } + } +} +int(1) +ok diff --git a/Zend/tests/gc_005.phpt b/Zend/tests/gc_005.phpt new file mode 100644 index 0000000000..0660ded2f7 --- /dev/null +++ b/Zend/tests/gc_005.phpt @@ -0,0 +1,21 @@ +--TEST-- +GC 005: Simple object cycle +--FILE-- +<?php +$a = new stdClass(); +$a->a = $a; +var_dump($a); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +object(stdClass)#1 (1) { + ["a"]=> + object(stdClass)#1 (1) { + ["a"]=> + *RECURSION* + } +} +int(1) +ok diff --git a/Zend/tests/gc_006.phpt b/Zend/tests/gc_006.phpt new file mode 100644 index 0000000000..4ba0d92672 --- /dev/null +++ b/Zend/tests/gc_006.phpt @@ -0,0 +1,28 @@ +--TEST-- +GC 006: Simple array-object cycle +--FILE-- +<?php +$a = new stdClass(); +$a->a = array(); +$a->a[0] =& $a; +var_dump($a); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +object(stdClass)#1 (1) { + ["a"]=> + array(1) { + [0]=> + &object(stdClass)#1 (1) { + ["a"]=> + array(1) { + [0]=> + *RECURSION* + } + } + } +} +int(2) +ok diff --git a/Zend/tests/gc_007.phpt b/Zend/tests/gc_007.phpt new file mode 100644 index 0000000000..4baa5e666f --- /dev/null +++ b/Zend/tests/gc_007.phpt @@ -0,0 +1,26 @@ +--TEST-- +GC 007: Unreferensed array cycle +--FILE-- +<?php +$a = array(array()); +$a[0][0] =& $a[0]; +var_dump($a[0]); +var_dump(gc_collect_cycles()); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +array(1) { + [0]=> + &array(1) { + [0]=> + &array(1) { + [0]=> + *RECURSION* + } + } +} +int(0) +int(1) +ok diff --git a/Zend/tests/gc_008.phpt b/Zend/tests/gc_008.phpt new file mode 100644 index 0000000000..b62504bd27 --- /dev/null +++ b/Zend/tests/gc_008.phpt @@ -0,0 +1,24 @@ +--TEST-- +GC 008: Unreferensed object cycle +--FILE-- +<?php +$a = new stdClass(); +$a->a = new stdClass(); +$a->a->a = $a->a; +var_dump($a->a); +var_dump(gc_collect_cycles()); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +object(stdClass)#2 (1) { + ["a"]=> + object(stdClass)#2 (1) { + ["a"]=> + *RECURSION* + } +} +int(0) +int(1) +ok diff --git a/Zend/tests/gc_009.phpt b/Zend/tests/gc_009.phpt new file mode 100644 index 0000000000..02ee1ae03e --- /dev/null +++ b/Zend/tests/gc_009.phpt @@ -0,0 +1,31 @@ +--TEST-- +GC 009: Unreferensed array-object cycle +--FILE-- +<?php +$a = array(); +$a[0] = new stdClass(); +$a[0]->a = array(); +$a[0]->a[0] =& $a[0]; +var_dump($a[0]); +var_dump(gc_collect_cycles()); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +object(stdClass)#1 (1) { + ["a"]=> + array(1) { + [0]=> + &object(stdClass)#1 (1) { + ["a"]=> + array(1) { + [0]=> + *RECURSION* + } + } + } +} +int(0) +int(2) +ok diff --git a/Zend/tests/gc_010.phpt b/Zend/tests/gc_010.phpt new file mode 100644 index 0000000000..d39ef8a096 --- /dev/null +++ b/Zend/tests/gc_010.phpt @@ -0,0 +1,25 @@ +--TEST-- +GC 010: Cycle with reference to $GLOBALS +--FILE-- +<?php +$a = array(); +$a[] =& $a; +var_dump($a); +$a[] =& $GLOBALS; +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +array(1) { + [0]=> + &array(1) { + [0]=> + &array(1) { + [0]=> + *RECURSION* + } + } +} +int(1) +ok diff --git a/Zend/tests/gc_011.phpt b/Zend/tests/gc_011.phpt new file mode 100644 index 0000000000..97819be23e --- /dev/null +++ b/Zend/tests/gc_011.phpt @@ -0,0 +1,28 @@ +--TEST-- +GC 011: GC and destructors +--FILE-- +<?php +class Foo { + public $a; + function __destruct() { + echo __FUNCTION__,"\n"; + } +} +$a = new Foo(); +$a->a = $a; +var_dump($a); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +object(Foo)#1 (1) { + ["a"]=> + object(Foo)#1 (1) { + ["a"]=> + *RECURSION* + } +} +__destruct +int(1) +ok diff --git a/Zend/tests/gc_012.phpt b/Zend/tests/gc_012.phpt new file mode 100644 index 0000000000..eff76ef31c --- /dev/null +++ b/Zend/tests/gc_012.phpt @@ -0,0 +1,17 @@ +--TEST-- +GC 012: collection of many loops at once +--FILE-- +<?php +$a=array(); +for ($i=0; $i < 1000; $i++) { + $a[$i] = array(array()); + $a[$i][0] = & $a[$i]; +} +var_dump(gc_collect_cycles()); +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n"; +--EXPECT-- +int(0) +int(1000) +ok diff --git a/Zend/tests/gc_013.phpt b/Zend/tests/gc_013.phpt new file mode 100644 index 0000000000..1f75df3be2 --- /dev/null +++ b/Zend/tests/gc_013.phpt @@ -0,0 +1,16 @@ +--TEST-- +GC 013: Too many cycles in one array +--FILE-- +<?php +$a = array(); +for ($i = 0; $i < 10001; $i++) { + $a[$i] =& $a; +} +$a[] = "xxx"; +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n"; +?> +--EXPECT-- +int(2) +ok diff --git a/Zend/tests/gc_014.phpt b/Zend/tests/gc_014.phpt new file mode 100644 index 0000000000..a9d30f1592 --- /dev/null +++ b/Zend/tests/gc_014.phpt @@ -0,0 +1,18 @@ +--TEST-- +GC 014: Too many cycles in one object +--FILE-- +<?php +$a = new stdClass(); +for ($i = 0; $i < 10001; $i++) { + $b =& $a; + $a->{"a".$i} = $a; +} +unset($b); +$a->b = "xxx"; +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n"; +?> +--EXPECT-- +int(10002) +ok diff --git a/Zend/tests/gc_015.phpt b/Zend/tests/gc_015.phpt new file mode 100644 index 0000000000..76db51e7fd --- /dev/null +++ b/Zend/tests/gc_015.phpt @@ -0,0 +1,18 @@ +--TEST-- +GC 015: Object as root of cycle +--FILE-- +<?php +$a = new stdClass(); +$c =& $a; +$b = $a; +$a->a = $a; +$a->b = "xxx"; +unset($c); +unset($a); +unset($b); +var_dump(gc_collect_cycles()); +echo "ok\n"; +?> +--EXPECT-- +int(2) +ok diff --git a/Zend/tests/gc_016.phpt b/Zend/tests/gc_016.phpt new file mode 100644 index 0000000000..6d6a363070 --- /dev/null +++ b/Zend/tests/gc_016.phpt @@ -0,0 +1,24 @@ +--TEST-- +GC 016: nested GC calls +--FILE-- +<?php +class Foo { + public $a; + function __destruct() { + echo "-> "; + $a = array(); + $a[] =& $a; + unset($a); + var_dump(gc_collect_cycles()); + } +} +$a = new Foo(); +$a->a = $a; +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +-> int(1) +int(1) +ok diff --git a/Zend/tests/gc_017.phpt b/Zend/tests/gc_017.phpt new file mode 100644 index 0000000000..9df04e280f --- /dev/null +++ b/Zend/tests/gc_017.phpt @@ -0,0 +1,41 @@ +--TEST-- +GC 017: GC and destructors with unset +--FILE-- +<?php +class Node { + public $name; + public $children; + public $parent; + function __construct($name) { + $this->name = $name; + $this->children = array(); + $this->parent = null; + } + function insert($node) { + $node->parent = $this; + $this->children[] = $node; + } + function __destruct() { + var_dump($this->name); + unset($this->name); + unset($this->children); + unset($this->parent); + } +} +$a = new Node('A'); +$b = new Node('B'); +$c = new Node('C'); +$a->insert($b); +$a->insert($c); +unset($a); +unset($b); +unset($c); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECTF-- +string(1) "%s" +string(1) "%s" +string(1) "%s" +int(10) +ok diff --git a/Zend/tests/gc_018.phpt b/Zend/tests/gc_018.phpt new file mode 100644 index 0000000000..c202d8cdcf --- /dev/null +++ b/Zend/tests/gc_018.phpt @@ -0,0 +1,13 @@ +--TEST-- +GC 018: GC detach with assign +--FILE-- +<?php +$a = array(array()); +$a[0][0] =& $a[0]; +$a = 1; +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +int(1) +ok diff --git a/Zend/tests/gc_019.phpt b/Zend/tests/gc_019.phpt new file mode 100644 index 0000000000..12400d2f06 --- /dev/null +++ b/Zend/tests/gc_019.phpt @@ -0,0 +1,14 @@ +--TEST-- +GC 019: GC detach with assign by reference +--FILE-- +<?php +$a = array(array()); +$a[0][0] =& $a[0]; +$b = 1; +$a =& $b; +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +int(1) +ok diff --git a/Zend/tests/gc_020.phpt b/Zend/tests/gc_020.phpt new file mode 100644 index 0000000000..76e8aff9a9 --- /dev/null +++ b/Zend/tests/gc_020.phpt @@ -0,0 +1,15 @@ +--TEST-- +GC 020: GC detach reference with assign +--FILE-- +<?php +$a = array(); +$a[0] =& $a; +$a[1] = array(); +$a[1][0] =& $a[1]; +$a = 1; +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +int(1) +ok diff --git a/Zend/tests/gc_021.phpt b/Zend/tests/gc_021.phpt new file mode 100644 index 0000000000..4e6c750947 --- /dev/null +++ b/Zend/tests/gc_021.phpt @@ -0,0 +1,16 @@ +--TEST-- +GC 021: GC detach reference with assign by reference +--FILE-- +<?php +$a = array(); +$a[0] =& $a; +$a[1] = array(); +$a[1][0] =& $a[1]; +$b = 1; +$a =& $b; +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +int(2) +ok diff --git a/Zend/tests/gc_022.phpt b/Zend/tests/gc_022.phpt new file mode 100644 index 0000000000..0418bf9a06 --- /dev/null +++ b/Zend/tests/gc_022.phpt @@ -0,0 +1,15 @@ +--TEST-- +GC 022: GC detach reference in executor's PZVAL_UNLOCK() +--INI-- +error_reporting=0 +--FILE-- +<?php +$a = array(array()); +$a[0][0] =& $a[0]; +$s = array(1) + unserialize(serialize(&$a[0])); +var_dump(gc_collect_cycles()); +echo "ok\n" +?> +--EXPECT-- +int(1) +ok diff --git a/Zend/tests/gc_023.phpt b/Zend/tests/gc_023.phpt new file mode 100644 index 0000000000..3c0580129e --- /dev/null +++ b/Zend/tests/gc_023.phpt @@ -0,0 +1,27 @@ +--TEST-- +GC 023: Root buffer overflow (automatic collection) +--FILE-- +<?php +$a=array(); +for ($i=0; $i < 9999; $i++) { + $a[$i] = array(array()); + $a[$i][0] = & $a[$i]; +} +var_dump(gc_collect_cycles()); +unset($a); +var_dump(gc_collect_cycles()); +$a=array(); +for ($i=0; $i < 10001; $i++) { + $a[$i] = array(array()); + $a[$i][0] = & $a[$i]; +} +var_dump(gc_collect_cycles()); +unset($a); // 10000 zvals collected automatic +var_dump(gc_collect_cycles()); +echo "ok\n"; +--EXPECT-- +int(0) +int(9999) +int(0) +int(1) +ok diff --git a/Zend/tests/gc_024.phpt b/Zend/tests/gc_024.phpt new file mode 100644 index 0000000000..ee734d628c --- /dev/null +++ b/Zend/tests/gc_024.phpt @@ -0,0 +1,15 @@ +--TEST-- +GC 024: GC and objects with non-standard handlers +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php +$a = new ArrayObject(); +$a[0] = $a; +unset($a); +var_dump(gc_collect_cycles()); +echo "ok\n"; +?> +--EXPECT-- +int(1) +ok diff --git a/Zend/tests/gc_025.phpt b/Zend/tests/gc_025.phpt new file mode 100644 index 0000000000..5ae6527257 --- /dev/null +++ b/Zend/tests/gc_025.phpt @@ -0,0 +1,11 @@ +--TEST-- +GC 025: Automatic GC on request shutdown +--FILE-- +<?php +$a = array(array()); +$a[0][0] =& $a[0]; +unset($a); +echo "ok\n" +?> +--EXPECT-- +ok diff --git a/Zend/tests/gc_026.phpt b/Zend/tests/gc_026.phpt new file mode 100644 index 0000000000..330c4fa48c --- /dev/null +++ b/Zend/tests/gc_026.phpt @@ -0,0 +1,14 @@ +--TEST-- +GC 026: Automatic GC on request shutdown (GC enabled at run-time) +--INI-- +zend.enable_gc=0 +--FILE-- +<?php +gc_enable(); +$a = array(array()); +$a[0][0] =& $a[0]; +unset($a); +echo "ok\n" +?> +--EXPECT-- +ok |