Using and writing Ghostscript testing scripts

Table of contents

This document describes how to use the scripts located in the toolbin/tests directory, and conventions for writing new testing scripts.

For other information, see the Ghostscript overview and the documentation related to maintaining Ghostscript.

General overview

The test scripts discussed here are written in Python, a language whose implementation is freely available from The scripts require Python version 2.1 or later.

Running tests

On Unix and Linux systems, test scripts written in Python can be executed directly simply by typing their name into the shell, e.g.,


On other systems, it may be necessary to invoke Python explicitly, e.g.,

python toolbin/tests/

The test scripts will print information about any failures that occur.

Individual tests

The individual test scripts are named toolbin/tests/ (if they do not run Ghostscript) or toolbin/tests/ (if they do run Ghostscript). Any script with such a name can be run individually, and is also normally run as part of regression testing (described in the next section).

We don't list the individual test scripts here, because any such documentation would inevitably be out of date most of the time. Each of these scripts contains documentation about what it tests: we suggest you read the documentation in the scripts.

Regression testing

We run a nightly regression test to discover any obvious problems caused by code checked in the previous day. Here is a list of the scripts and supporting files that make up the regression test.

Top-level scripts

This script creates an initial test database. It uses gsconf.baselinegs to create raster data from the test files and computes their MD5 sums and stores them in the gsconf.testdatadb database.
A debugging script that will print the contents of the database defined by gsconf.testdatadb.
A helper script to make two versions of a particular file for visual diffing or manual analysis. When a test fails nightly regression, this is generally the first investigative step.
Same as above, except for pdfwrite regressions.
this script provides the difference between two sets of regression results. if end date is omitted, the current date will be used.
This script is invoked to update the MD5 sum in the test database when a nightly regression is really a progression. Generally after noticing that the output from make_two_versions is acceptable or better, this script is run to log the changes to the database.
Same as above, except for pdfwrite baselines.
In cases where a baseline has been accidentally updated, this script will revert the database entry to the MD5 sum computed with gsconf.baselinegs.
This script runs the full gamut of regression tests using files from gsconf.comparedir. It differentiates files by extension and controls what tests get run and with what options.
This is the control script (usually invoked by cron) that controls the nightly test run. It's responsible for checking the latest code out of CVS, building a new Ghostscript to compare with and launching the test suite via run_regression.
Same as above, except for pdfwrite baselines.

Support files

A fuzzy comparison tool appropriate for tests where exact binary matches aren't appropriate.
This is the master configuration for the scripts above. It controls where files are found, where Ghostscript executables are and the location of the test database. Most test configuration will be in this file.
This provides classes for running tests that actually execute Ghostcript.
What parameters tests get run with by default are stored in this file. Between this configuration information and the information in all configurable testing parameters should be covered.
Helper functions that compute, compare and store MD5 sums.

Writing new tests

Some of Ghostscript's test scripts follow a set of conventions that allow them to be run either stand-alone or as part of a suite; in particular, they can be run as part of the nightly regression test suite. In this section, we provide pointers to documentation on how to write new tests that follow these conventions, since that will make them the most useful.

The test scripts are based on Python's unittest module. We suggest that if you are not familiar with this module, you read the documentation, which is available at

Ghostscript specializes the unittest module by defining subclasses, which all individual tests use in place of those in unittest. These subclasses are defined in toolbin/tests/

Since code documentation separate from the code itself is always out of date, we have decided to maintain the primary documentation for writing new tests in rather than here in a separate document. Please read that file for more information.

Copyright © 2002 artofcode LLC. All rights reserved.

This file is part of AFPL Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing AFPL Ghostscript.

Ghostscript version 8.00, 21 November 2002