BuilderBase class is an abstract class that defines common functions for any types of builders. Each type schema (script, compiler) is implemented as separate Builder.

ScriptBuilder class implements ‘type: script’ CompilerBuilder class implements ‘type: compiler’

Module Contents



The BuilderBase is an abstract class that implements common functions for

class buildtest.buildsystem.base.BuilderBase(name, recipe, buildspec, executor, buildexecutor, testdir)

Bases: abc.ABC

The BuilderBase is an abstract class that implements common functions for any kind of builder.


Return repr(self).


Return str(self).


This method is the setup operation to get ready to build test which includes getting unique build id, setting up metadata object to store test details such as where test will be located and directory of test. This section cannot be reached without a valid, loaded recipe.


This method conducts a regular expression check using with regular expression defined in Buildspec. User must specify an output stream (stdout, stderr) to select when performing regex. In buildtest, this would read the .out or .err file based on stream and run the regular expression to see if there is a match. This method will return a boolean True indicates there is a match otherwise False if regex object not defined or doesn’t find a match.


builder (BuilderBase (subclass)) – instance of BuilderBase class


A boolean return True/False based on if is successful or not

Return type



This method will return a boolean (True/False) based on runtime specified in buildspec and check with test runtime. User can specify both min and max, or just specify min or max.


Return a list of lines inserted in testscript that define buildtest specific variables that can be referenced when writing tests. The buildtest variables all start with BUILDTEST_*


This method will return a shell command used to invoke the script that is used for tests that use local executors


Generate a unique build id using uuid.uuid4().

_get_burst_buffer(self, burstbuffer)

Get Burst Buffer directives (#BB) lines specified by BB property


burstbuffer (dict, required) – Burst Buffer configuration specified by BB property


list of burst buffer directives

Return type


_get_data_warp(self, datawarp)

Get Cray Data Warp directives (#DW) lines specified by DW property.


datawarp (dict, required) – Data Warp configuration specified by DW property


list of data warp directives

Return type


_get_environment(self, env)

Retrieve a list of environment variables defined in buildspec and return them as list with the shell equivalent command


list of environment variable lines to add to test script.

Return type


_get_scheduler_directives(self, bsub=None, sbatch=None, cobalt=None, pbs=None, batch=None)

Get Scheduler Directives for LSF, Slurm, PBS or Cobalt if we are processing test with one of the executor types. This method will return a list of string containing scheduler directives generally found at top of script. If test is local executor we return an empty list

  • bsub – bsub property from buildspec

  • sbatch – sbatch property from buildspec

  • cobalt – cobalt property from buildspec

  • pbs – pbs property from buildspec

  • batch – batch property from buildspec

_get_variables(self, variables)

Retrieve a list of variables defined in buildspec and return them as list with the shell equivalent command.


list of variables variable lines to add to test script.

Return type



Check status check of returncode field if specified in status property.

_set_execute_perm(self, fname)

Set permission to 755 for a given file. The filepath must be an absolute path to file


This method sets self.metadata that contains metadata for each builder object.


This method will write the build script used for running the test


This method is responsible for invoking generate_script that formulates content of testscript which is implemented in each subclass. Next we write content to file and apply 755 permission on script so it has executable permission.


This method will update the metrics field stored in self.metadata['metrics']. The metrics property can be defined in the buildspdec to assign value to a metrics name based on regular expression, environment or variable assignment.


This method is responsible for invoking setup, creating test directory and writing test. This method is called from an instance object of this class that does


This method is responsible for detecting state of test (PASS/FAIL) based on returncode or regular expression.


This method is invoked to indicate that builder job is complete after polling job.


Copy output and error file into test root directory since stage directory will be removed.


This method is called upon termination of job, we get current time using and calculate runtime of job


Return error content

abstract generate_script(self)

Build the testscript content implemented in each subclass


Return the test extension, which depends on the shell used. Based on the value of shell key we return the shell extension.

shell: bash –> sh (default)


returns test extension based on shell type

Return type



This method indicates that builder job is not complete after polling job either job was cancelled by scheduler or job failed to run.


Return output content


Run the test and record the starttime and start timer. We also return the instance object of type BuildTestCommand which is used by Executors for processing output and error


Command used to run the build script. buildtest will change into the stage directory (self.stage_dir) before running the test.


Calculate runtime of job by calculating delta between endtime and starttime. The unit of measure is seconds.


Keep internal time for start of test. We start timer by calling Timer class


This method will record the starttime when job starts execution by using


Stop timer of test and calculate duration.