<< Documentation Home
Module Writing

Phoronix Test Suite Modules

Writing a module for the Phoronix Test Suite allows new functionality to be added without having to extensively learn how pts-core functions. The module framework for the Phoronix Test Suite allows modules to be written either as a PHP object. Example PTS modules could include a module to shutdown the screensaver when the Phoronix Test Suite starts up and re-enabling it when the test is over, using sendmail to forward the results to an e-mail address when testing is completed, or writing the current test status to a LCDproc-enabled VFD display.

Modules are stored in pts-core/modules/. Loading a module is done by either setting the PTS_MODULES environmental variable with the name of the module (excluding the .php file extension) or by associating a module with a separate environmental variable. The default list of modules to be loaded is stored in ~/.phoronix-test-suite/user-config.xml.

Note: To run through all of the function calls for a module without needing to run a test, run phoronix-test-suite test-module MODULE_NAME. Additionally, running phoronix-test-suite debug-module MODULE_NAME will yield additional debugging details while executing the same process.

Module

To see all of the functions supported for modules written in PHP, look at pts-core/modules/dummy_module.php and additionally the other .php modules that ship with the Phoronix Test Suite. Additionally, there are several functions written specifically for Phoronix Test Suite modules that make it easier to save files, read files, and provided multi-threading support for modules. The pts_timed_function() makes it possible (and very easy) to thread functions within a module so that at a set interval the defined functions will be called. For example, this support is used heavily within the system_monitor module to poll sensors every X seconds even while there are tests running. These functions can be found within pts-core/objects/pts_module.php.

Below is a sample module that times how long it takes to run the Phoronix Test Suite. It would be saved as pts-core/modules/time_me.php.

<?php
class time_me extends pts_module_interface
{
    const module_name = "Time Me!";
    const module_version = "1.0.0";
    const module_description = "This is a module that times how long the Phoronix Test Suite runs.";
    const module_author = "Phoronix Media";

    static $start_time = NULL;
    static $end_time = NULL;

    public static function __startup()
    {
        self::$start_time = time();
    }
    public static function __shutdown()
    {
        self::$end_time = time();

        $time_elapsed = self::$end_time - self::$start_time;

        echo "\nThe Phoronix Test Suite Ran For " . $time_elapsed . " Seconds.\n";
    }
}
?>

Then by running PTS_MODULES=time_me phoronix-test-suite benchmark video-extensions, at the end of the test it would print a string similar to: "The Phoronix Test Suite Ran For 52 Seconds."

Phoronix-Test-Suite.com
Copyright © 2008 by Phoronix Media.