-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add info_dump.phpt test that tests meminfo_info_dump function
- add info_dump_memory-leak.phpt test that tests meminfo_info_dump function memory leak
- Loading branch information
Dmitry Gopkalo
committed
Sep 24, 2016
1 parent
684368a
commit 4f8d854
Showing
3 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" | ||
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [ | ||
]> | ||
<book id="listing"> | ||
<title>My lists</title> | ||
<chapter id="books"> | ||
<title>My books</title> | ||
<para> | ||
<informaltable> | ||
<tgroup cols="4"> | ||
<thead> | ||
<row> | ||
<entry>Title</entry> | ||
<entry>Author</entry> | ||
<entry>Language</entry> | ||
<entry>ISBN</entry> | ||
</row> | ||
</thead> | ||
<tbody> | ||
<row> | ||
<entry>The Grapes of Wrath</entry> | ||
<entry>John Steinbeck</entry> | ||
<entry>en</entry> | ||
<entry>0140186409</entry> | ||
</row> | ||
<row> | ||
<entry>The Pearl</entry> | ||
<entry>John Steinbeck</entry> | ||
<entry>en</entry> | ||
<entry>014017737X</entry> | ||
</row> | ||
<row> | ||
<entry>Samarcande</entry> | ||
<entry>Amine Maalouf</entry> | ||
<entry>fr</entry> | ||
<entry>2253051209</entry> | ||
</row> | ||
<!-- TODO: I have a lot of remaining books to add.. --> | ||
</tbody> | ||
</tgroup> | ||
</informaltable> | ||
</para> | ||
</chapter> | ||
</book> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--TEST-- | ||
meminfo_objects_list with some objects | ||
--FILE-- | ||
<?php | ||
$docTest = new DOMDocument(); | ||
$docTest->load(__DIR__.'/fixture/book.xml'); | ||
|
||
$rFilePointer = fopen('php://memory', 'rw'); | ||
|
||
$arrayTest = [ | ||
'itemBool' => true, | ||
'itemInteger' => 23, | ||
'itemDoubles' => 1.2e3, | ||
'itemNull' => null, | ||
'itemString' => 'hello', | ||
'itemObject' => $docTest, | ||
'itemArray' => (array) $docTest, | ||
'itemResource' => $rFilePointer, | ||
]; | ||
|
||
meminfo_info_dump($rFilePointer); | ||
|
||
rewind($rFilePointer); | ||
$jsonO = json_decode(stream_get_contents($rFilePointer), true); | ||
fclose($rFilePointer); | ||
if (is_array($jsonO)) { | ||
$items = $jsonO['items']; | ||
printf( | ||
"meminfo_info_dump JSON decode ok\nz_val_count:%d\n", | ||
count($items) | ||
); | ||
uasort($items, function ($itemA, $itemB) { | ||
return $itemA['type'] > $itemB['type'] | ||
|| ($itemA['type'] == $itemB['type'] && $itemA['size'] > $itemB['size']); | ||
}); | ||
|
||
foreach($items as $item){ | ||
printf( | ||
"item type:%s size:%d\n", | ||
$item['type'], | ||
$item['size'] | ||
); | ||
} | ||
} else { | ||
echo 'meminfo_info_dump JSON decode fail'; | ||
} | ||
?> | ||
--EXPECT-- | ||
meminfo_info_dump JSON decode ok | ||
z_val_count:62 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:array size:96 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:boolean size:24 | ||
item type:double size:24 | ||
item type:double size:24 | ||
item type:integer size:24 | ||
item type:integer size:24 | ||
item type:integer size:24 | ||
item type:integer size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:null size:24 | ||
item type:object size:56 | ||
item type:resource size:24 | ||
item type:string size:24 | ||
item type:string size:24 | ||
item type:string size:25 | ||
item type:string size:25 | ||
item type:string size:25 | ||
item type:string size:25 | ||
item type:string size:27 | ||
item type:string size:27 | ||
item type:string size:27 | ||
item type:string size:29 | ||
item type:string size:29 | ||
item type:string size:29 | ||
item type:string size:29 | ||
item type:string size:33 | ||
item type:string size:37 | ||
item type:string size:46 | ||
item type:string size:64 | ||
item type:string size:64 | ||
item type:string size:64 | ||
item type:string size:84 | ||
item type:string size:84 | ||
item type:string size:84 | ||
item type:string size:84 | ||
item type:string size:84 | ||
item type:string size:87 | ||
item type:string size:87 | ||
item type:string size:1054 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
meminfo_objects_list with some objects | ||
--FILE-- | ||
<?php | ||
$docTest = new DOMDocument(); | ||
$docTest->load(__DIR__.'/fixture/book.xml'); | ||
|
||
$rFilePointer = fopen('/dev/null', 'rw'); | ||
|
||
$arrayTest = [ | ||
'itemBool' => true, | ||
'itemInteger' => 23, | ||
'itemDoubles' => 1.2e3, | ||
'itemNull' => null, | ||
'itemString' => 'hello', | ||
'itemObject' => $docTest, | ||
'itemArray' => (array) $docTest, | ||
'itemResource' => $rFilePointer, | ||
]; | ||
$attemptCount = 1000; | ||
gc_collect_cycles(); | ||
$startM = memory_get_usage(true); | ||
while ($attemptCount-- > 0) { | ||
meminfo_info_dump($rFilePointer); | ||
} | ||
fclose($rFilePointer); | ||
gc_collect_cycles(); | ||
$endM = memory_get_usage(true); | ||
if ($endM / $startM < 2) { | ||
echo 'Memory leak test was successful'; | ||
} else { | ||
echo "Memory leak test was failed\n"; | ||
printf("Memory leak:%s bytes",$endM - $startM); | ||
} | ||
?> | ||
--EXPECT-- | ||
Memory leak test was successful |