From 6847c1815034e87752c1efb9f6632fc424263fa9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 22 Jan 2008 09:29:29 +0000 Subject: Added garbage collector --- Zend/tests/gc_001.phpt | 12 ++++++++++++ Zend/tests/gc_002.phpt | 16 ++++++++++++++++ Zend/tests/gc_003.phpt | 16 ++++++++++++++++ Zend/tests/gc_004.phpt | 24 ++++++++++++++++++++++++ Zend/tests/gc_005.phpt | 31 +++++++++++++++++++++++++++++++ Zend/tests/gc_006.phpt | 44 ++++++++++++++++++++++++++++++++++++++++++++ Zend/tests/gc_007.phpt | 26 ++++++++++++++++++++++++++ Zend/tests/gc_008.phpt | 35 +++++++++++++++++++++++++++++++++++ Zend/tests/gc_009.phpt | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Zend/tests/gc_010.phpt | 25 +++++++++++++++++++++++++ Zend/tests/gc_011.phpt | 39 +++++++++++++++++++++++++++++++++++++++ Zend/tests/gc_012.phpt | 17 +++++++++++++++++ Zend/tests/gc_013.phpt | 16 ++++++++++++++++ Zend/tests/gc_014.phpt | 18 ++++++++++++++++++ Zend/tests/gc_015.phpt | 18 ++++++++++++++++++ Zend/tests/gc_016.phpt | 24 ++++++++++++++++++++++++ Zend/tests/gc_017.phpt | 47 +++++++++++++++++++++++++++++++++++++++++++++++ Zend/tests/gc_018.phpt | 13 +++++++++++++ Zend/tests/gc_019.phpt | 14 ++++++++++++++ Zend/tests/gc_020.phpt | 15 +++++++++++++++ Zend/tests/gc_021.phpt | 16 ++++++++++++++++ Zend/tests/gc_022.phpt | 15 +++++++++++++++ Zend/tests/gc_023.phpt | 27 +++++++++++++++++++++++++++ Zend/tests/gc_024.phpt | 16 ++++++++++++++++ Zend/tests/gc_025.phpt | 11 +++++++++++ Zend/tests/gc_026.phpt | 14 ++++++++++++++ 26 files changed, 597 insertions(+) create mode 100644 Zend/tests/gc_001.phpt create mode 100644 Zend/tests/gc_002.phpt create mode 100644 Zend/tests/gc_003.phpt create mode 100644 Zend/tests/gc_004.phpt create mode 100644 Zend/tests/gc_005.phpt create mode 100644 Zend/tests/gc_006.phpt create mode 100644 Zend/tests/gc_007.phpt create mode 100644 Zend/tests/gc_008.phpt create mode 100644 Zend/tests/gc_009.phpt create mode 100644 Zend/tests/gc_010.phpt create mode 100644 Zend/tests/gc_011.phpt create mode 100644 Zend/tests/gc_012.phpt create mode 100644 Zend/tests/gc_013.phpt create mode 100644 Zend/tests/gc_014.phpt create mode 100644 Zend/tests/gc_015.phpt create mode 100644 Zend/tests/gc_016.phpt create mode 100644 Zend/tests/gc_017.phpt create mode 100644 Zend/tests/gc_018.phpt create mode 100644 Zend/tests/gc_019.phpt create mode 100644 Zend/tests/gc_020.phpt create mode 100644 Zend/tests/gc_021.phpt create mode 100644 Zend/tests/gc_022.phpt create mode 100644 Zend/tests/gc_023.phpt create mode 100644 Zend/tests/gc_024.phpt create mode 100644 Zend/tests/gc_025.phpt create mode 100644 Zend/tests/gc_026.phpt (limited to 'Zend/tests') 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-- + +--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-- + +--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-- + +--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-- + +--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-- +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-- +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-- + +--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-- +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-- +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-- + +--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-- +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-- + +--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-- +{"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-- +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-- + "; + $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-- +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-- + +--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-- + +--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-- + +--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-- + +--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-- + +--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-- + +--FILE-- + +--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-- + +--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-- + +--EXPECT-- +ok -- cgit v1.2.1