Skip to content

Commit

Permalink
Alter test to not use unreasonable values, and to give easier to unde…
Browse files Browse the repository at this point in the history
…rstand error messages on failure.
  • Loading branch information
Danack committed Jul 7, 2024
1 parent a66f84a commit ef495c0
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions tests/014-setresourcelimit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,65 @@ require_once(dirname(__FILE__) . '/skipif.inc');
<?php



$k = 1024;
$m = $k * $k;
$g = $k * $m;
$t = $k * $g;

// These tests are flaky as the values ImageMagick will accept
// are limited by the policy.xml of the system.
// Also, it appears that some versions of ImageMagick will
// reject overly large values. e.g. setting RESOURCETYPE_WIDTH
// to a billion fails. Which is not totally unreasonable.

$tests = array(
Imagick::RESOURCETYPE_AREA => 100000000,

// Set maximum amount of disk space in bytes permitted for use by the pixel cache. When this limit is exceeded, the pixel cache is not be created and an error message is returned.
Imagick::RESOURCETYPE_DISK => 100,



//Set maximum number of open pixel cache files. When this limit is exceeded, any subsequent pixels cached to disk are closed and reopened on demand. This behavior permits a large number of images to be accessed simultaneously on disk, but with a speed penalty due to repeated open/close calls.
Imagick::RESOURCETYPE_FILE => 100,

// Set maximum amount of memory map in bytes to allocate for the pixel cache. When this limit is exceeded, the image pixels are cached to disk
Imagick::RESOURCETYPE_MAP => 10 * $g,
Imagick::RESOURCETYPE_MAP => 123 * $m,

// Set maximum amount of memory in bytes to allocate for the pixel cache from the heap. When this limit is exceeded, the image pixels are cached to memory-mapped disk
Imagick::RESOURCETYPE_MEMORY => 10 * $g,
Imagick::RESOURCETYPE_MEMORY => 234 * $m,
);

if (defined('Imagick::RESOURCETYPE_TIME')) {
$tests[Imagick::RESOURCETYPE_TIME] = 30;
$tests[Imagick::RESOURCETYPE_TIME] = 30;
}

if (defined('Imagick::RESOURCETYPE_THROTTLE')) {
$tests[Imagick::RESOURCETYPE_THROTTLE] = 1;
$tests[Imagick::RESOURCETYPE_THROTTLE] = 1;
}
if (defined('Imagick::RESOURCETYPE_THREAD')) {
$tests[Imagick::RESOURCETYPE_THREAD] = 1;
$tests[Imagick::RESOURCETYPE_THREAD] = 1;
}
if (defined('Imagick::RESOURCETYPE_WIDTH')) {
$tests[Imagick::RESOURCETYPE_WIDTH] = $g;
$tests[Imagick::RESOURCETYPE_WIDTH] = 15 * $k;
}
if (defined('Imagick::RESOURCETYPE_HEIGHT')) {
$tests[Imagick::RESOURCETYPE_HEIGHT] = $g;
$tests[Imagick::RESOURCETYPE_HEIGHT] = 15 * $k;
}

$reflection_class = new ReflectionClass(Imagick::class);
$constants = $reflection_class->getConstants();
$resource_constants = [];
foreach ($constants as $name => $value) {
if (strpos($name, "RESOURCETYPE") === 0) {
$resource_constants[$value] = $name;
}
}


foreach ($tests as $resourceType => $value) {
Imagick::setResourceLimit($resourceType, $value);
$actualValue = Imagick::getResourceLimit($resourceType);

if ($actualValue != $value) {
echo "Error testing $resourceType, value returned $actualValue is not $value \n";
$resourceTypeString = $resource_constants[$resourceType];
echo "Error testing $resourceTypeString, value returned $actualValue is not $value \n";
}
}

Expand Down

0 comments on commit ef495c0

Please sign in to comment.