summaryrefslogtreecommitdiff
path: root/Zend/tests
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2008-01-22 09:29:29 +0000
committerDmitry Stogov <dmitry@php.net>2008-01-22 09:29:29 +0000
commit6847c1815034e87752c1efb9f6632fc424263fa9 (patch)
treebf62fa0d9063974efb2bc8bd4da0a948b79b2b78 /Zend/tests
parentf51bf6118c2bb8fad9e290e721074ccdc929c3c3 (diff)
downloadphp-git-6847c1815034e87752c1efb9f6632fc424263fa9.tar.gz
Added garbage collector
Diffstat (limited to 'Zend/tests')
-rw-r--r--Zend/tests/gc_001.phpt12
-rw-r--r--Zend/tests/gc_002.phpt16
-rw-r--r--Zend/tests/gc_003.phpt16
-rw-r--r--Zend/tests/gc_004.phpt24
-rw-r--r--Zend/tests/gc_005.phpt31
-rw-r--r--Zend/tests/gc_006.phpt44
-rw-r--r--Zend/tests/gc_007.phpt26
-rw-r--r--Zend/tests/gc_008.phpt35
-rw-r--r--Zend/tests/gc_009.phpt48
-rw-r--r--Zend/tests/gc_010.phpt25
-rw-r--r--Zend/tests/gc_011.phpt39
-rw-r--r--Zend/tests/gc_012.phpt17
-rw-r--r--Zend/tests/gc_013.phpt16
-rw-r--r--Zend/tests/gc_014.phpt18
-rw-r--r--Zend/tests/gc_015.phpt18
-rw-r--r--Zend/tests/gc_016.phpt24
-rw-r--r--Zend/tests/gc_017.phpt47
-rw-r--r--Zend/tests/gc_018.phpt13
-rw-r--r--Zend/tests/gc_019.phpt14
-rw-r--r--Zend/tests/gc_020.phpt15
-rw-r--r--Zend/tests/gc_021.phpt16
-rw-r--r--Zend/tests/gc_022.phpt15
-rw-r--r--Zend/tests/gc_023.phpt27
-rw-r--r--Zend/tests/gc_024.phpt16
-rw-r--r--Zend/tests/gc_025.phpt11
-rw-r--r--Zend/tests/gc_026.phpt14
26 files changed, 597 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..4e0f02d413
--- /dev/null
+++ b/Zend/tests/gc_005.phpt
@@ -0,0 +1,31 @@
+--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
+--UEXPECT--
+object(stdClass)#1 (1) {
+ [u"a"]=>
+ object(stdClass)#1 (1) {
+ [u"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..50c68e3909
--- /dev/null
+++ b/Zend/tests/gc_006.phpt
@@ -0,0 +1,44 @@
+--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
+--UEXPECT--
+object(stdClass)#1 (1) {
+ [u"a"]=>
+ array(1) {
+ [0]=>
+ &object(stdClass)#1 (1) {
+ [u"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..efe132aa85
--- /dev/null
+++ b/Zend/tests/gc_008.phpt
@@ -0,0 +1,35 @@
+--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
+--UEXPECT--
+object(stdClass)#2 (1) {
+ [u"a"]=>
+ object(stdClass)#2 (1) {
+ [u"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..3b7ed066fc
--- /dev/null
+++ b/Zend/tests/gc_009.phpt
@@ -0,0 +1,48 @@
+--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
+--UEXPECT--
+object(stdClass)#1 (1) {
+ [u"a"]=>
+ array(1) {
+ [0]=>
+ &object(stdClass)#1 (1) {
+ [u"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..ab6ee41fce
--- /dev/null
+++ b/Zend/tests/gc_011.phpt
@@ -0,0 +1,39 @@
+--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
+--UEXPECT--
+object(Foo)#1 (1) {
+ [u"a"]=>
+ object(Foo)#1 (1) {
+ [u"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..a0af41294b
--- /dev/null
+++ b/Zend/tests/gc_017.phpt
@@ -0,0 +1,47 @@
+--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
+--UEXPECTF--
+unicode(1) "%s"
+unicode(1) "%s"
+unicode(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..ee3e5625f3
--- /dev/null
+++ b/Zend/tests/gc_024.phpt
@@ -0,0 +1,16 @@
+--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;
+//var_dump($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