Buildspec Overview

What is a buildspec?

A buildspec is a YAML file that defines your test in buildtest which is validated by schema followed by building a shell script and running the generated test. Buildtest will parse the buildspec with the global schema file which defines the top-level structure of buildspec file.

Example

Let’s start off with a simple example that declares two variables X and Y and prints the sum of X+Y.

buildspecs:
  add_numbers:
    type: script
    executor: generic.local.bash
    description: Add X+Y
    tags: [tutorials]
    vars:
      X: 1
      Y: 2
    run: echo "$X+$Y=" $(($X+$Y))

buildtest will validate the entire file with global.schema.json, the schema requires version and buildspec in order to validate file. The buildspec is where you define each test. The name of the test is add_numbers. The test requires a type field which is the sub-schema used to validate the test section. In this example type: script informs buildtest to use the Script Schema when validating test section.

Each subschema has a list of field attributes that are supported, for example the fields: type, executor, vars and run are all valid fields supported by the script schema.

Let’s look at a more interesting example, shown below is a multi line run example using the script schema with test name called systemd_default_target, shown below is the content of test:

buildspecs:
  systemd_default_target:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: check if default target is multi-user.target
    run: |
      if [ "multi-user.target" == `systemctl get-default` ]; then
        echo "multi-user is the default target";
        exit 0
      fi
      echo "multi-user is not the default target";
      exit 1

The test name systemd_default_target defined in buildspec section is validated with the following pattern "^[A-Za-z_][A-Za-z0-9_]*$". This test will use the executor generic.local.bash which means it will use the Local Executor with an executor name bash defined in the buildtest settings. The default buildtest settings will provide a bash executor as follows:

system:
  generic:
    hostnames: ["localhost"]
    executors:
      local:
        bash:
          description: submit jobs on local machine using bash shell
          shell: bash

The shell: bash indicates this executor will use bash to run the test scripts. To reference this executor use the format <system>.<type>.<name> in this case generic.local.bash refers to bash executor.

The description field is an optional key that can be used to provide a brief summary of the test. The description field is limited to 80 characters. In this example we can specify multiple commands in run section, this can be done in YAML using run: | followed by content of run section tab indented 2 spaces.

In this next example, we introduce the summary field, which can be used as an extended description of test. It has no impact on the test. Unlike the description field, the summary field has no limit on character count and one can define multi-line string using the pipe symbol |.

buildspecs:
  summary_example:
    type: script
    executor: generic.local.bash
    description: The summary field can be a multi-line string and exceed 80 char
    tags: [tutorials]
    summary: |
      This is a long description of test that
      can exceed 80 characters and be multiline
    run: hostname

Script Schema

The script schema is used for writing simple scripts (bash, sh, python) in Buildspec. To use this schema you must set type: script. The run field is responsible for writing the content of test.

Shown below is schema header for script.schema.json.

{
  "$id": "script.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "script schema version",
  "description": "The script schema is of ``type: script`` in sub-schema which is used for running shell scripts",
  "type": "object",
  "required": [
    "type",

The "type": "object" means sub-schema is a JSON object where we define a list of key/value pair. The "required" field specifies a list of fields that must be specified in order to validate the Buildspec. In this example, type, run, and executor are required fields. The additionalProperties: false informs schema to reject any extra properties not defined in the schema.

The executor key is required for all sub-schemas which instructs buildtest which executor to use when running the test. The executors are defined in Configuring buildtest. In our first example we define variables using the vars property which is a Key/Value pair for variable assignment. The run section is required for script schema which defines the content of the test script.

For more details on script schema see schema docs at https://buildtesters.github.io/buildtest/

Declaring Environment Variables

You can define environment variables using the env property, this is compatible with shells: bash, sh, zsh, csh and tcsh. It does not work with shell: python. In example below we declare three tests using environment variable with default shell (bash), csh, and tcsh

buildspecs:
  bash_env_variables:
    executor: generic.local.bash
    description: Declare environment variables in default shell (bash)
    type: script
    env:
      FIRST_NAME: avocado
      LAST_NAME: dinosaur
    tags: [tutorials]
    run: |
      hostname
      whoami
      echo $USER
      printf "${FIRST_NAME} ${LAST_NAME}\n"

  csh_env_declaration:
    executor: generic.local.csh
    type: script
    description: "csh shell example to declare environment variables"
    shell: /bin/csh
    tags: [tutorials]
    env:
      SHELL_NAME: "csh"
    run: echo "This is running $SHELL_NAME"

  tcsh_env_declaration:
    executor: generic.local.csh
    type: script
    description: "tcsh shell example to declare environment variables"
    shell: /bin/tcsh
    tags: [tutorials]
    env:
      path: "/usr/local/bin:$PATH"
    run: echo $path

This test can be run by issuing the following command: buildtest build -b tutorials/environment.yml. If we inspect one of the test script we will see that buildtest generates a build script that invokes the test using the shell wrapper /bin/csh for the csh test and gets the returncode.

#!/bin/bash


############# START VARIABLE DECLARATION ########################
export BUILDTEST_TEST_NAME=csh_env_declaration
export BUILDTEST_TEST_ROOT=/Users/siddiq90/Documents/GitHubDesktop/buildtest/var/tests/generic.local.csh/environment/csh_env_declaration/0
export BUILDTEST_BUILDSPEC_DIR=/Users/siddiq90/Documents/GitHubDesktop/buildtest/tutorials
export BUILDTEST_STAGE_DIR=/Users/siddiq90/Documents/GitHubDesktop/buildtest/var/tests/generic.local.csh/environment/csh_env_declaration/0/stage
export BUILDTEST_TEST_ID=501ec5d3-e614-4ae8-9c1e-4849ce340c76
############# END VARIABLE DECLARATION   ########################


# source executor startup script
source /Users/siddiq90/Documents/GitHubDesktop/buildtest/var/executor/generic.local.csh/before_script.sh
# Run generated script
/bin/csh /Users/siddiq90/Documents/GitHubDesktop/buildtest/var/tests/generic.local.csh/environment/csh_env_declaration/0/stage/csh_env_declaration.csh
# Get return code
returncode=$?
# Exit with return code
exit $returncode

This generated test looks something like this

#!/bin/csh
# Declare environment variables
setenv SHELL_NAME csh


# Content of run section
echo "This is running $SHELL_NAME"

Environment variables are defined using export in bash, sh, zsh while csh and tcsh use setenv.

Declaring Variables

Variables can be defined using vars property, this is compatible with all shells except for python. The variables are defined slightly different in csh, tcsh as pose to bash, sh, and zsh. In example below we define tests with bash and csh.

In YAML strings can be specified with or without quotes however in bash, variables need to be enclosed in quotes " if you are defining a multi word string (name="First Last").

If you need define a literal string it is recommended to use the literal block | that is a special character in YAML. If you want to specify " or ' in string you can use the escape character \ followed by any of the special character. In example below we define several variables such as X, Y that contain numbers, variable literalstring is a literal string processed by YAML. The variable singlequote and doublequote defines a variable with the special character ' and ". The variables current_user and num_files store result of a shell command. This can be done using var=$(<command>) or var=`<command>` where <command> is a Linux command.

buildspecs:
  variables_bash:
    type: script
    executor: generic.local.bash
    description: Declare shell variables in bash
    tags: [tutorials]
    vars:
      X: 1
      Y: 2
      literalstring: this is a literal string
      singlequote: \'singlequote\'
      doublequote: \"doublequote\"
      current_user: "$(whoami)"
      num_files: "`find $HOME -type f -maxdepth 1 | wc -l`"
      multiline_string: |
        Hello my name is Bob \n
        I am 30 years old


    run: |
      echo "$X+$Y="$(($X+$Y))
      echo $literalstring
      echo $singlequote
      echo $doublequote
      echo "current user:" $current_user
      echo "number of files:" $num_files
      echo -e $multiline_string

Next we build this test by running buildtest build -b $BUILDTEST_ROOT/tutorials/vars.yml.

$ buildtest build -b $BUILDTEST_ROOT/tutorials/vars.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:31                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b /home/docs/checkouts/readthedocs │
│ .org/user_builds/buildtest/checkouts/v0.15.0/tutorials/vars.yml              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/vars.yml: VALID
Total builder objects created: 1
Total compiler builder: 0
Total script builder: 1
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ variables… │ generic.l… │ None     │ None  │ None  │ Declare    │ /home/doc… │
│            │            │          │       │       │ shell      │            │
│            │            │          │       │       │ variables  │            │
│            │            │          │       │       │ in bash    │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
variables_bash/272ee591: Creating test directory: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/vars
/variables_bash/272ee591
variables_bash/272ee591: Creating the stage directory: /home/docs/checkouts/read
thedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash
/vars/variables_bash/272ee591/stage
variables_bash/272ee591: Writing build script: /home/docs/checkouts/readthedocs.
org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/vars/va
riables_bash/272ee591/variables_bash_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
variables_bash/272ee591 does not have any dependencies adding test to queue
variables_bash/272ee591: Running Test via command: bash --norc --noprofile -eo 
pipefail variables_bash_build.sh
variables_bash/272ee591: Test completed in 0.010049 seconds
variables_bash/272ee591: Test completed with returncode: 0
variables_bash/272ee591: Writing output file -  /home/docs/checkouts/readthedocs
.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/vars/v
ariables_bash/272ee591/variables_bash.out
variables_bash/272ee591: Writing error file - /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/vars/var
iables_bash/272ee591/variables_bash.err
In this iteration we are going to run the following tests: [variables_bash/272ee591]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ variables_ba │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 0.010049 │
│ sh/272ee591  │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/1 Percentage: 100.000%
Failed Tests: 0/1 Percentage: 0.000%


Adding 1 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_t1me5pr5.log

Let’s check the generated script from the previous build, you can run buildtest inspect query -o variables_bash where -o refers to output file for testname variables_bash. Take note of the output file we

$ buildtest inspect query -o variables_bash
───────────── variables_bash/272ee591-cc98-4f24-9bee-b02884bb4cca ──────────────
Executor: generic.local.bash
Description: Declare shell variables in bash
State: PASS
Returncode: 0
Runtime: 0.010049 sec
Starttime: 2022/07/01 00:37:31
Endtime: 2022/07/01 00:37:31
Command: bash --norc --noprofile -eo pipefail variables_bash_build.sh
Test Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.bash/vars/variables_bash/272ee591/variables_ba
sh.sh
Build Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkou
ts/v0.15.0/var/tests/generic.local.bash/vars/variables_bash/272ee591/variables_b
ash_build.sh
Output File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.bash/vars/variables_bash/272ee591/variables_ba
sh.out
Error File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts
/v0.15.0/var/tests/generic.local.bash/vars/variables_bash/272ee591/variables_bas
h.err
Log File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v
0.15.0/var/logs/buildtest_t1me5pr5.log
─ Output File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/che… ─
1+2=3                                                                           
this is a literal string                                                        
\'singlequote\'                                                                 
"doublequote"                                                                   
current user: docs                                                              
number of files: 4                                                              
Hello my name is Bob                                                            
 I am 30 years old

Test Status

buildtest will record state of each test which can be PASS or FAIL. By default a 0 exit code is PASS and everything else is a FAIL. The status property can be used to determine how test will report its state. Currently, we can match state based on returncode, runtime, or regular expression.

Return Code Matching

buildtest can report PASS/FAIL based on returncode, by default a 0 exit code is PASS and everything else is FAIL. The returncode can be a list of exit codes to match. In this example we have four tests called exit1_fail, exit1_pass, returncode_list_mismatch and returncode_int_match. We expect exit1_fail and returncode_mismatch to FAIL while exit1_pass and returncode_int_match will PASS.

buildspecs:

  exit1_fail:
    executor: generic.local.bash
    type: script
    description: exit 1 by default is FAIL
    tags: [tutorials, fail]
    run: exit 1

  exit1_pass:
    executor: generic.local.bash
    type: script
    description: report exit 1 as PASS
    run: exit 1
    tags: [tutorials, pass]
    status:
      returncode: [1]

  returncode_list_mismatch:
    executor: generic.local.bash
    type: script
    description: exit 2 failed since it failed to match returncode 1
    run: exit 2
    tags: [tutorials, fail]
    status:
      returncode: [1, 3]

  returncode_int_match:
    executor: generic.local.bash
    type: script
    description: exit 128 matches returncode 128
    run: exit 128
    tags: [tutorials, pass]
    status:
      returncode: 128

Let’s build this test and pay close attention to the status column in output.

$ buildtest build -b tutorials/test_status/pass_returncode.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:32                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/test_status/pass_returncode.yml                                    │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/test_status/pass_returncode.yml: VALID
Total builder objects created: 4
Total compiler builder: 0
Total script builder: 4
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ exit1_fai… │ generic.l… │ None     │ None  │ None  │ exit 1 by  │ /home/doc… │
│            │            │          │       │       │ default is │            │
│            │            │          │       │       │ FAIL       │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ exit1_pas… │ generic.l… │ None     │ None  │ None  │ report     │ /home/doc… │
│            │            │          │       │       │ exit 1 as  │            │
│            │            │          │       │       │ PASS       │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ returncod… │ generic.l… │ None     │ None  │ None  │ exit 2     │ /home/doc… │
│            │            │          │       │       │ failed     │            │
│            │            │          │       │       │ since it   │            │
│            │            │          │       │       │ failed to  │            │
│            │            │          │       │       │ match      │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ 1          │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ returncod… │ generic.l… │ None     │ None  │ None  │ exit 128   │ /home/doc… │
│            │            │          │       │       │ matches    │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ 128        │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
exit1_fail/2dc77a83: Creating test directory: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_ret
urncode/exit1_fail/2dc77a83
exit1_fail/2dc77a83: Creating the stage directory: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pas
s_returncode/exit1_fail/2dc77a83/stage
exit1_fail/2dc77a83: Writing build script: /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_return
code/exit1_fail/2dc77a83/exit1_fail_build.sh
exit1_pass/cd39c866: Creating test directory: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_ret
urncode/exit1_pass/cd39c866
exit1_pass/cd39c866: Creating the stage directory: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pas
s_returncode/exit1_pass/cd39c866/stage
exit1_pass/cd39c866: Writing build script: /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_return
code/exit1_pass/cd39c866/exit1_pass_build.sh
returncode_list_mismatch/2c47274d: Creating test directory: /home/docs/checkouts
/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local
.bash/pass_returncode/returncode_list_mismatch/2c47274d
returncode_list_mismatch/2c47274d: Creating the stage directory: /home/docs/chec
kouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.
local.bash/pass_returncode/returncode_list_mismatch/2c47274d/stage
returncode_list_mismatch/2c47274d: Writing build script: /home/docs/checkouts/re
adthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.ba
sh/pass_returncode/returncode_list_mismatch/2c47274d/returncode_list_mismatch_bu
ild.sh
returncode_int_match/e599ee5d: Creating test directory: /home/docs/checkouts/rea
dthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bas
h/pass_returncode/returncode_int_match/e599ee5d
returncode_int_match/e599ee5d: Creating the stage directory: /home/docs/checkout
s/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loca
l.bash/pass_returncode/returncode_int_match/e599ee5d/stage
returncode_int_match/e599ee5d: Writing build script: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/p
ass_returncode/returncode_int_match/e599ee5d/returncode_int_match_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
exit1_fail/2dc77a83 does not have any dependencies adding test to queue
exit1_pass/cd39c866 does not have any dependencies adding test to queue
returncode_int_match/e599ee5d does not have any dependencies adding test to 
queue
returncode_list_mismatch/2c47274d does not have any dependencies adding test to 
queue
exit1_fail/2dc77a83: Running Test via command: bash --norc --noprofile -eo 
pipefail exit1_fail_build.sh
exit1_fail/2dc77a83: Test completed in 0.00557 seconds
exit1_fail/2dc77a83: Test completed with returncode: 1
exit1_fail/2dc77a83: Writing output file -  /home/docs/checkouts/readthedocs.org
/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_retur
ncode/exit1_fail/2dc77a83/exit1_fail.out
exit1_fail/2dc77a83: Writing error file - /home/docs/checkouts/readthedocs.org/u
ser_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_returnc
ode/exit1_fail/2dc77a83/exit1_fail.err
exit1_pass/cd39c866: Running Test via command: bash --norc --noprofile -eo 
pipefail exit1_pass_build.sh
exit1_pass/cd39c866: Test completed in 0.00509 seconds
exit1_pass/cd39c866: Test completed with returncode: 1
exit1_pass/cd39c866: Writing output file -  /home/docs/checkouts/readthedocs.org
/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_retur
ncode/exit1_pass/cd39c866/exit1_pass.out
exit1_pass/cd39c866: Writing error file - /home/docs/checkouts/readthedocs.org/u
ser_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pass_returnc
ode/exit1_pass/cd39c866/exit1_pass.err
exit1_pass/cd39c866: Checking returncode - 1 is matched in list [1]
returncode_int_match/e599ee5d: Running Test via command: bash --norc --noprofile
-eo pipefail returncode_int_match_build.sh
returncode_int_match/e599ee5d: Test completed in 0.00501 seconds
returncode_int_match/e599ee5d: Test completed with returncode: 128
returncode_int_match/e599ee5d: Writing output file -  /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/
pass_returncode/returncode_int_match/e599ee5d/returncode_int_match.out
returncode_int_match/e599ee5d: Writing error file - /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/pa
ss_returncode/returncode_int_match/e599ee5d/returncode_int_match.err
returncode_int_match/e599ee5d: Checking returncode - 128 is matched in list 
[128]
returncode_list_mismatch/2c47274d: Running Test via command: bash --norc 
--noprofile -eo pipefail returncode_list_mismatch_build.sh
returncode_list_mismatch/2c47274d: Test completed in 0.005 seconds
returncode_list_mismatch/2c47274d: Test completed with returncode: 2
returncode_list_mismatch/2c47274d: Writing output file -  /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.b
ash/pass_returncode/returncode_list_mismatch/2c47274d/returncode_list_mismatch.o
ut
returncode_list_mismatch/2c47274d: Writing error file - /home/docs/checkouts/rea
dthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bas
h/pass_returncode/returncode_list_mismatch/2c47274d/returncode_list_mismatch.err
returncode_list_mismatch/2c47274d: Checking returncode - 2 is matched in list 
[1, 3]
In this iteration we are going to run the following tests: [exit1_fail/2dc77a83, exit1_pass/cd39c866, returncode_int_match/e599ee5d, returncode_list_mismatch/2c47274d]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃               ┃              ┃        ┃ checks        ┃            ┃         ┃
┃               ┃              ┃        ┃ (ReturnCode,  ┃            ┃         ┃
┃               ┃              ┃        ┃ Regex,        ┃            ┃         ┃
┃ builder       ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ returncode_in │ generic.loc… │ PASS   │ True False    │ 128        │ 0.00501 │
│ t_match/e599e │              │        │ False         │            │         │
│ e5d           │              │        │               │            │         │
├───────────────┼──────────────┼────────┼───────────────┼────────────┼─────────┤
│ exit1_pass/cd │ generic.loc… │ PASS   │ True False    │ 1          │ 0.00509 │
│ 39c866        │              │        │ False         │            │         │
├───────────────┼──────────────┼────────┼───────────────┼────────────┼─────────┤
│ exit1_fail/2d │ generic.loc… │ FAIL   │ N/A N/A N/A   │ 1          │ 0.00557 │
│ c77a83        │              │        │               │            │         │
├───────────────┼──────────────┼────────┼───────────────┼────────────┼─────────┤
│ returncode_li │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.005   │
│ st_mismatch/2 │              │        │ False         │            │         │
│ c47274d       │              │        │               │            │         │
└───────────────┴──────────────┴────────┴───────────────┴────────────┴─────────┘



Passed Tests: 2/4 Percentage: 50.000%
Failed Tests: 2/4 Percentage: 50.000%


Adding 4 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_i9ijwnrg.log

The returncode field can be an integer or list of integers but it may not accept duplicate values. If you specify a list of exit codes, buildtest will check actual returncode with list of expected returncodes specified by returncode field.

Shown below are examples of invalid returncodes:

# empty list is not allowed
returncode: []

# floating point is not accepted in list
returncode: [1, 1.5]

# floating point not accepted
returncode: 1.5

# duplicates are not allowed
returncode: [1, 2, 5, 5]

Passing Test based on regular expression

buildtest can configure PASS/FAIL of test based on regular expression on output or error file. This can be useful if you are expecting a certain output from the test as pose to returncode check.

In this example we introduce, the regex field which is part of status that expects a regular expression via exp. The stream property must be stdout or stderr which indicates buildtest will read output or error file and apply regular expression. If there is a match, buildtest will record the test state as PASS otherwise it will be a FAIL. In this example, we have two tests that will apply regular expression on output file.

buildspecs:
  status_regex_pass:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: Pass test based on regular expression
    run: echo "PASS"
    status:
      regex:
        stream: stdout
        exp: "^(PASS)$"

  status_regex_fail:
    executor: generic.local.bash
    type: script
    tags: [system]
    description: Pass test based on regular expression
    run: echo "FAIL"
    status:
      regex:
        stream: stdout
        exp: "^(123FAIL)$"

Now if we run this test, we will see first test will pass while second one will fail even though the returncode is a 0. Take a close look at the status property

$ buildtest build -b tutorials/test_status/status_regex.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:32                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/test_status/status_regex.yml                                       │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/test_status/status_regex.yml: VALID
Total builder objects created: 2
Total compiler builder: 0
Total script builder: 2
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ status_re… │ generic.l… │ None     │ None  │ None  │ Pass test  │ /home/doc… │
│            │            │          │       │       │ based on   │            │
│            │            │          │       │       │ regular    │            │
│            │            │          │       │       │ expression │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ status_re… │ generic.l… │ None     │ None  │ None  │ Pass test  │ /home/doc… │
│            │            │          │       │       │ based on   │            │
│            │            │          │       │       │ regular    │            │
│            │            │          │       │       │ expression │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_regex_pass/982987e2: Creating test directory: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/s
tatus_regex/status_regex_pass/982987e2
status_regex_pass/982987e2: Creating the stage directory: /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.b
ash/status_regex/status_regex_pass/982987e2/stage
status_regex_pass/982987e2: Writing build script: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/stat
us_regex/status_regex_pass/982987e2/status_regex_pass_build.sh
status_regex_fail/d5da1300: Creating test directory: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/s
tatus_regex/status_regex_fail/d5da1300
status_regex_fail/d5da1300: Creating the stage directory: /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.b
ash/status_regex/status_regex_fail/d5da1300/stage
status_regex_fail/d5da1300: Writing build script: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/stat
us_regex/status_regex_fail/d5da1300/status_regex_fail_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_regex_fail/d5da1300 does not have any dependencies adding test to queue
status_regex_pass/982987e2 does not have any dependencies adding test to queue
status_regex_pass/982987e2: Running Test via command: bash --norc --noprofile 
-eo pipefail status_regex_pass_build.sh
status_regex_pass/982987e2: Test completed in 0.00542 seconds
status_regex_pass/982987e2: Test completed with returncode: 0
status_regex_pass/982987e2: Writing output file -  /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/sta
tus_regex/status_regex_pass/982987e2/status_regex_pass.out
status_regex_pass/982987e2: Writing error file - /home/docs/checkouts/readthedoc
s.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/statu
s_regex/status_regex_pass/982987e2/status_regex_pass.err
status_regex_pass/982987e2: performing regular expression - '^(PASS)$' on file: 
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var
/tests/generic.local.bash/status_regex/status_regex_pass/982987e2/status_regex_p
ass.out
status_regex_pass/982987e2: Regular Expression Match - Success!
status_regex_fail/d5da1300: Running Test via command: bash --norc --noprofile 
-eo pipefail status_regex_fail_build.sh
status_regex_fail/d5da1300: Test completed in 0.005101 seconds
status_regex_fail/d5da1300: Test completed with returncode: 0
status_regex_fail/d5da1300: Writing output file -  /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/sta
tus_regex/status_regex_fail/d5da1300/status_regex_fail.out
status_regex_fail/d5da1300: Writing error file - /home/docs/checkouts/readthedoc
s.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/statu
s_regex/status_regex_fail/d5da1300/status_regex_fail.err
status_regex_fail/d5da1300: performing regular expression - '^(123FAIL)$' on 
file: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15
.0/var/tests/generic.local.bash/status_regex/status_regex_fail/d5da1300/status_r
egex_fail.out
status_regex_fail/d5da1300: Regular Expression Match - Failed!
In this iteration we are going to run the following tests: [status_regex_pass/982987e2, status_regex_fail/d5da1300]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ status_regex │ generic.loc… │ PASS   │ False True    │ 0          │ 0.00542  │
│ _pass/982987 │              │        │ False         │            │          │
│ e2           │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ status_regex │ generic.loc… │ FAIL   │ False False   │ 0          │ 0.005101 │
│ _fail/d5da13 │              │        │ False         │            │          │
│ 00           │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_fd34xv3l.log

Passing Test based on runtime

buildtest can determine state of test based on runtime property which is part of status object. This can be used if you want to control how test PASS or FAIL based on execution time of test. In example below we have five tests that make use of runtime property for passing a test. The runtime property support min and max property that can mark test pass based on minimum and maximum runtime. A test will pass if it’s execution time is greater than min time and less than max time. If min is specified without max property the upperbound is not set, likewise max without min will pass if test is less than max time. The lower bound is not set, but test runtime will be greater than 0 sec.

In test timelimit_min, we sleep for 2 seconds and it will pass because minimum runtime is 1.0 seconds. Similarly, timelimit_max will pass because we sleep for 2 seconds with a max time of 5.0.

buildspecs:
  timelimit_min_max:
    type: script
    executor: generic.local.sh
    description: "Run a sleep job for 2 seconds and test pass if its within 1.0-3.0sec"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        min: 1.0
        max: 3.0

  timelimit_min:
    type: script
    executor: generic.local.sh
    description: "Run a sleep job for 2 seconds and test pass if its exceeds min time of 1.0 sec"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        min: 1.0

  timelimit_max:
    type: script
    executor: generic.local.sh
    description: "Run a sleep job for 2 seconds and test pass if it's within max time: 5.0 sec"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        max: 5.0

  timelimit_min_fail:
    type: script
    executor: generic.local.sh
    description: "This test fails because it runs less than mintime of 10 second"
    tags: ["tutorials"]
    run: sleep 2
    status:
      runtime:
        min: 10.0

  timelimit_max_fail:
    type: script
    executor: generic.local.sh
    description: "This test fails because it exceeds maxtime of 1.0 second"
    tags: ["tutorials"]
    run: sleep 3
    status:
      runtime:
        max: 1.0
$ buildtest build -b tutorials/test_status/runtime_status_test.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:33                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/test_status/runtime_status_test.yml                                │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/test_status/runtime_status_test.yml: VALID
Total builder objects created: 5
Total compiler builder: 0
Total script builder: 5
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ timelimit… │ generic.l… │ None     │ None  │ None  │ Run a      │ /home/doc… │
│            │            │          │       │       │ sleep job  │            │
│            │            │          │       │       │ for 2      │            │
│            │            │          │       │       │ seconds    │            │
│            │            │          │       │       │ and test   │            │
│            │            │          │       │       │ pass if    │            │
│            │            │          │       │       │ its within │            │
│            │            │          │       │       │ 1.0-3.0sec │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ timelimit… │ generic.l… │ None     │ None  │ None  │ Run a      │ /home/doc… │
│            │            │          │       │       │ sleep job  │            │
│            │            │          │       │       │ for 2      │            │
│            │            │          │       │       │ seconds    │            │
│            │            │          │       │       │ and test   │            │
│            │            │          │       │       │ pass if    │            │
│            │            │          │       │       │ its        │            │
│            │            │          │       │       │ exceeds    │            │
│            │            │          │       │       │ min time   │            │
│            │            │          │       │       │ of 1.0 sec │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ timelimit… │ generic.l… │ None     │ None  │ None  │ Run a      │ /home/doc… │
│            │            │          │       │       │ sleep job  │            │
│            │            │          │       │       │ for 2      │            │
│            │            │          │       │       │ seconds    │            │
│            │            │          │       │       │ and test   │            │
│            │            │          │       │       │ pass if    │            │
│            │            │          │       │       │ it's       │            │
│            │            │          │       │       │ within max │            │
│            │            │          │       │       │ time: 5.0  │            │
│            │            │          │       │       │ sec        │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ timelimit… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ fails      │            │
│            │            │          │       │       │ because it │            │
│            │            │          │       │       │ runs less  │            │
│            │            │          │       │       │ than       │            │
│            │            │          │       │       │ mintime of │            │
│            │            │          │       │       │ 10 second  │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ timelimit… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ fails      │            │
│            │            │          │       │       │ because it │            │
│            │            │          │       │       │ exceeds    │            │
│            │            │          │       │       │ maxtime of │            │
│            │            │          │       │       │ 1.0 second │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
timelimit_min_max/6133f67b: Creating test directory: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/run
time_status_test/timelimit_min_max/6133f67b
timelimit_min_max/6133f67b: Creating the stage directory: /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.s
h/runtime_status_test/timelimit_min_max/6133f67b/stage
timelimit_min_max/6133f67b: Writing build script: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtim
e_status_test/timelimit_min_max/6133f67b/timelimit_min_max_build.sh
timelimit_min/1752c254: Creating test directory: /home/docs/checkouts/readthedoc
s.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime
_status_test/timelimit_min/1752c254
timelimit_min/1752c254: Creating the stage directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/ru
ntime_status_test/timelimit_min/1752c254/stage
timelimit_min/1752c254: Writing build script: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime_st
atus_test/timelimit_min/1752c254/timelimit_min_build.sh
timelimit_max/0e80f5d7: Creating test directory: /home/docs/checkouts/readthedoc
s.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime
_status_test/timelimit_max/0e80f5d7
timelimit_max/0e80f5d7: Creating the stage directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/ru
ntime_status_test/timelimit_max/0e80f5d7/stage
timelimit_max/0e80f5d7: Writing build script: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime_st
atus_test/timelimit_max/0e80f5d7/timelimit_max_build.sh
timelimit_min_fail/15002c0f: Creating test directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/ru
ntime_status_test/timelimit_min_fail/15002c0f
timelimit_min_fail/15002c0f: Creating the stage directory: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
sh/runtime_status_test/timelimit_min_fail/15002c0f/stage
timelimit_min_fail/15002c0f: Writing build script: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runti
me_status_test/timelimit_min_fail/15002c0f/timelimit_min_fail_build.sh
timelimit_max_fail/1a4546ef: Creating test directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/ru
ntime_status_test/timelimit_max_fail/1a4546ef
timelimit_max_fail/1a4546ef: Creating the stage directory: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
sh/runtime_status_test/timelimit_max_fail/1a4546ef/stage
timelimit_max_fail/1a4546ef: Writing build script: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runti
me_status_test/timelimit_max_fail/1a4546ef/timelimit_max_fail_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
timelimit_max/0e80f5d7 does not have any dependencies adding test to queue
timelimit_min_max/6133f67b does not have any dependencies adding test to queue
timelimit_min/1752c254 does not have any dependencies adding test to queue
timelimit_min_fail/15002c0f does not have any dependencies adding test to queue
timelimit_max_fail/1a4546ef does not have any dependencies adding test to queue
timelimit_max/0e80f5d7: Running Test via command: sh --norc --noprofile -eo 
pipefail timelimit_max_build.sh
timelimit_max/0e80f5d7: Test completed in 0.003273 seconds
timelimit_max/0e80f5d7: Test completed with returncode: 2
timelimit_max/0e80f5d7: Writing output file -  /home/docs/checkouts/readthedocs.
org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime_s
tatus_test/timelimit_max/0e80f5d7/timelimit_max.out
timelimit_max/0e80f5d7: Writing error file - /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime_sta
tus_test/timelimit_max/0e80f5d7/timelimit_max.err
timelimit_min_max/6133f67b: Running Test via command: sh --norc --noprofile -eo 
pipefail timelimit_min_max_build.sh
timelimit_min_max/6133f67b: Test completed in 0.002989 seconds
timelimit_min_max/6133f67b: Test completed with returncode: 2
timelimit_min_max/6133f67b: Writing output file -  /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runti
me_status_test/timelimit_min_max/6133f67b/timelimit_min_max.out
timelimit_min_max/6133f67b: Writing error file - /home/docs/checkouts/readthedoc
s.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime
_status_test/timelimit_min_max/6133f67b/timelimit_min_max.err
timelimit_min/1752c254: Running Test via command: sh --norc --noprofile -eo 
pipefail timelimit_min_build.sh
timelimit_min/1752c254: Test completed in 0.002948 seconds
timelimit_min/1752c254: Test completed with returncode: 2
timelimit_min/1752c254: Writing output file -  /home/docs/checkouts/readthedocs.
org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime_s
tatus_test/timelimit_min/1752c254/timelimit_min.out
timelimit_min/1752c254: Writing error file - /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtime_sta
tus_test/timelimit_min/1752c254/timelimit_min.err
timelimit_min_fail/15002c0f: Running Test via command: sh --norc --noprofile -eo
pipefail timelimit_min_fail_build.sh
timelimit_min_fail/15002c0f: Test completed in 0.002901 seconds
timelimit_min_fail/15002c0f: Test completed with returncode: 2
timelimit_min_fail/15002c0f: Writing output file -  /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runt
ime_status_test/timelimit_min_fail/15002c0f/timelimit_min_fail.out
timelimit_min_fail/15002c0f: Writing error file - /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtim
e_status_test/timelimit_min_fail/15002c0f/timelimit_min_fail.err
timelimit_max_fail/1a4546ef: Running Test via command: sh --norc --noprofile -eo
pipefail timelimit_max_fail_build.sh
timelimit_max_fail/1a4546ef: Test completed in 0.002857 seconds
timelimit_max_fail/1a4546ef: Test completed with returncode: 2
timelimit_max_fail/1a4546ef: Writing output file -  /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runt
ime_status_test/timelimit_max_fail/1a4546ef/timelimit_max_fail.out
timelimit_max_fail/1a4546ef: Writing error file - /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/runtim
e_status_test/timelimit_max_fail/1a4546ef/timelimit_max_fail.err
In this iteration we are going to run the following tests: [timelimit_max/0e80f5d7, timelimit_min_max/6133f67b, timelimit_min/1752c254, timelimit_min_fail/15002c0f, timelimit_max_fail/1a4546ef]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ timelimit_ma │ generic.loc… │ PASS   │ False False   │ 2          │ 0.003273 │
│ x/0e80f5d7   │              │        │ True          │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ timelimit_mi │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.002989 │
│ n_max/6133f6 │              │        │ False         │            │          │
│ 7b           │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ timelimit_mi │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.002948 │
│ n/1752c254   │              │        │ False         │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ timelimit_mi │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.002901 │
│ n_fail/15002 │              │        │ False         │            │          │
│ c0f          │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ timelimit_ma │ generic.loc… │ PASS   │ False False   │ 2          │ 0.002857 │
│ x_fail/1a454 │              │        │ True          │            │          │
│ 6ef          │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 2/5 Percentage: 40.000%
Failed Tests: 3/5 Percentage: 60.000%


Adding 5 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_ownc_vtw.log

If we look at the test results, we expect the first three tests timelimit_min, timelimit_max, timelimit_min_max will pass while the last two tests fail because it fails to comply with runtime property.

$ buildtest report --filter buildspec=tutorials/test_status/runtime_status_test.yml --format name,id,state,runtime --latest
Report File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
                           s/v0.15.0/var/report.json                            
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ name                           ┃ id             ┃ state      ┃ runtime       ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ timelimit_max                  │ 0e80f5d7       │ PASS       │ 0.003273      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_min_max              │ 6133f67b       │ FAIL       │ 0.002989      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_min                  │ 1752c254       │ FAIL       │ 0.002948      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_min_fail             │ 15002c0f       │ FAIL       │ 0.002901      │
├────────────────────────────────┼────────────────┼────────────┼───────────────┤
│ timelimit_max_fail             │ 1a4546ef       │ PASS       │ 0.002857      │
└────────────────────────────────┴────────────────┴────────────┴───────────────┘

Explicitly Declaring Status of Test

You can explicitly define status of test regardless of what buildtest does for checking status of test. This can be useful if you want to explicitly mark a test as PASS or FAIL regardless of how test behaves. This can be done via state property which expects one of two types PASS or FAIL. If state property is specified, buildtest will ignore any checks including returncode, regex, or runtime match.

In this next example we will demonstrate how one can use state property for marking test state. In this example we have four tests. The first test always_pass will PASS even though we have a non-zero returncode. The second test always_fail will FAIL even though it has a 0 returncode. The last two test demonstrate how one can define state regardless of what is specified for returncode match. buildtest will honor the state property even if their is a match on the returncode.

buildspecs:
  always_pass:
    type: script
    executor: 'generic.local.sh'
    description: This test will always 'PASS'
    run: exit 1
    status:
      state: PASS

  always_fail:
    type: script
    executor: 'generic.local.sh'
    description: This test will always 'FAIL'
    run: exit 0
    status:
      state: FAIL

  test_fail_returncode_match:
    type: script
    executor: 'generic.local.sh'
    description: This test will 'FAIL' even if we have returncode match
    run: exit 1
    status:
      state: FAIL
      returncode: 1

  test_pass_returncode_mismatch:
    type: script
    executor: 'generic.local.sh'
    description: This test will 'PASS' even if we have returncode mismatch
    run: exit 1
    status:
      state: PASS
      returncode: 2

If we build this test, we expect buildtest to honor the value of state property

$ buildtest build -b tutorials/test_status/explicit_state.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:34                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/test_status/explicit_state.yml                                     │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/test_status/explicit_state.yml: VALID
Total builder objects created: 4
Total compiler builder: 0
Total script builder: 4
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ always_pa… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will       │            │
│            │            │          │       │       │ always     │            │
│            │            │          │       │       │ 'PASS'     │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ always_fa… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will       │            │
│            │            │          │       │       │ always     │            │
│            │            │          │       │       │ 'FAIL'     │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ test_fail… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will       │            │
│            │            │          │       │       │ 'FAIL'     │            │
│            │            │          │       │       │ even if we │            │
│            │            │          │       │       │ have       │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ match      │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ test_pass… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will       │            │
│            │            │          │       │       │ 'PASS'     │            │
│            │            │          │       │       │ even if we │            │
│            │            │          │       │       │ have       │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ mismatch   │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
always_pass/5973a25d: Creating test directory: /home/docs/checkouts/readthedocs.
org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_
state/always_pass/5973a25d
always_pass/5973a25d: Creating the stage directory: /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/expl
icit_state/always_pass/5973a25d/stage
always_pass/5973a25d: Writing build script: /home/docs/checkouts/readthedocs.org
/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_sta
te/always_pass/5973a25d/always_pass_build.sh
always_fail/202bb021: Creating test directory: /home/docs/checkouts/readthedocs.
org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_
state/always_fail/202bb021
always_fail/202bb021: Creating the stage directory: /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/expl
icit_state/always_fail/202bb021/stage
always_fail/202bb021: Writing build script: /home/docs/checkouts/readthedocs.org
/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_sta
te/always_fail/202bb021/always_fail_build.sh
test_fail_returncode_match/d8f20c95: Creating test directory: /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.sh/explicit_state/test_fail_returncode_match/d8f20c95
test_fail_returncode_match/d8f20c95: Creating the stage directory: /home/docs/ch
eckouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generi
c.local.sh/explicit_state/test_fail_returncode_match/d8f20c95/stage
test_fail_returncode_match/d8f20c95: Writing build script: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
sh/explicit_state/test_fail_returncode_match/d8f20c95/test_fail_returncode_match
_build.sh
test_pass_returncode_mismatch/8835e6a0: Creating test directory: /home/docs/chec
kouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.
local.sh/explicit_state/test_pass_returncode_mismatch/8835e6a0
test_pass_returncode_mismatch/8835e6a0: Creating the stage directory: /home/docs
/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/gen
eric.local.sh/explicit_state/test_pass_returncode_mismatch/8835e6a0/stage
test_pass_returncode_mismatch/8835e6a0: Writing build script: /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.sh/explicit_state/test_pass_returncode_mismatch/8835e6a0/test_pass_returncode
_mismatch_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
always_fail/202bb021 does not have any dependencies adding test to queue
test_fail_returncode_match/d8f20c95 does not have any dependencies adding test 
to queue
always_pass/5973a25d does not have any dependencies adding test to queue
test_pass_returncode_mismatch/8835e6a0 does not have any dependencies adding 
test to queue
always_fail/202bb021: Running Test via command: sh --norc --noprofile -eo 
pipefail always_fail_build.sh
always_fail/202bb021: Test completed in 0.003133 seconds
always_fail/202bb021: Test completed with returncode: 2
always_fail/202bb021: Writing output file -  /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_st
ate/always_fail/202bb021/always_fail.out
always_fail/202bb021: Writing error file - /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_stat
e/always_fail/202bb021/always_fail.err
test_fail_returncode_match/d8f20c95: Running Test via command: sh --norc 
--noprofile -eo pipefail test_fail_returncode_match_build.sh
test_fail_returncode_match/d8f20c95: Test completed in 0.002962 seconds
test_fail_returncode_match/d8f20c95: Test completed with returncode: 2
test_fail_returncode_match/d8f20c95: Writing output file -  /home/docs/checkouts
/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local
.sh/explicit_state/test_fail_returncode_match/d8f20c95/test_fail_returncode_matc
h.out
test_fail_returncode_match/d8f20c95: Writing error file - /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.s
h/explicit_state/test_fail_returncode_match/d8f20c95/test_fail_returncode_match.
err
test_fail_returncode_match/d8f20c95: Checking returncode - 2 is matched in list 
[1]
always_pass/5973a25d: Running Test via command: sh --norc --noprofile -eo 
pipefail always_pass_build.sh
always_pass/5973a25d: Test completed in 0.002875 seconds
always_pass/5973a25d: Test completed with returncode: 2
always_pass/5973a25d: Writing output file -  /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_st
ate/always_pass/5973a25d/always_pass.out
always_pass/5973a25d: Writing error file - /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/explicit_stat
e/always_pass/5973a25d/always_pass.err
test_pass_returncode_mismatch/8835e6a0: Running Test via command: sh --norc 
--noprofile -eo pipefail test_pass_returncode_mismatch_build.sh
test_pass_returncode_mismatch/8835e6a0: Test completed in 0.002915 seconds
test_pass_returncode_mismatch/8835e6a0: Test completed with returncode: 2
test_pass_returncode_mismatch/8835e6a0: Writing output file -  /home/docs/checko
uts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.lo
cal.sh/explicit_state/test_pass_returncode_mismatch/8835e6a0/test_pass_returncod
e_mismatch.out
test_pass_returncode_mismatch/8835e6a0: Writing error file - /home/docs/checkout
s/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loca
l.sh/explicit_state/test_pass_returncode_mismatch/8835e6a0/test_pass_returncode_
mismatch.err
test_pass_returncode_mismatch/8835e6a0: Checking returncode - 2 is matched in 
list [2]
In this iteration we are going to run the following tests: [always_fail/202bb021, test_fail_returncode_match/d8f20c95, always_pass/5973a25d, test_pass_returncode_mismatch/8835e6a0]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ always_pass/ │ generic.loc… │ PASS   │ False False   │ 2          │ 0.002875 │
│ 5973a25d     │              │        │ False         │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ test_pass_re │ generic.loc… │ PASS   │ True False    │ 2          │ 0.002915 │
│ turncode_mis │              │        │ False         │            │          │
│ match/8835e6 │              │        │               │            │          │
│ a0           │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ test_fail_re │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.002962 │
│ turncode_mat │              │        │ False         │            │          │
│ ch/d8f20c95  │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ always_fail/ │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.003133 │
│ 202bb021     │              │        │ False         │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 2/4 Percentage: 50.000%
Failed Tests: 2/4 Percentage: 50.000%


Adding 4 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_9o19iuzw.log

Defining Tags

The tags field can be used to classify tests which can be used to organize tests or if you want to Building By Tags (buildtest build --tags <TAGNAME>). Tags can be defined as a string or list of strings. In this example, the test string_tag defines a tag name network while test list_of_strings_tags define a list of tags named network and ping.

buildspecs:
  string_tag:
    type: script
    executor: generic.local.bash
    description: tags can be a string
    tags: network
    run: hostname

  list_of_strings_tags:
    type: script
    executor: generic.local.bash
    description: tags can be a list of strings
    tags: [network, ping]
    run: ping -c 4 www.google.com

Each item in tags must be a string and no duplicates are allowed, for example in this test, we define a duplicate tag network which is not allowed.

buildspecs:
  duplicate_string_tags:
    type: script
    executor: generic.local.bash
    description: duplicate strings in tags list is not allowed
    tags: [network, network]
    run: hostname

If we run this test and inspect the logs we will see an error message in schema validation:

2020-09-29 10:56:43,175 [parser.py:179 - _validate() ] - [INFO] Validating test - 'duplicate_string_tags' with schemafile: script-v1.0.schema.json
2020-09-29 10:56:43,175 [buildspec.py:397 - parse_buildspecs() ] - [ERROR] ['network', 'network'] is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['tags']:
    {'oneOf': [{'type': 'string'},
               {'$ref': '#/definitions/list_of_strings'}]}

On instance['tags']:
    ['network', 'network']

If tags is a list, it must contain one item, therefore an empty list (i.e tags: []) is invalid.

Customize Shell

Shell Type

buildtest will default to bash shell when running test, but we can configure shell option using the shell field. The shell field is defined in schema as follows:

"shell": {
  "type": "string",
  "description": "Specify a shell launcher to use when running jobs. This sets the shebang line in your test script. The ``shell`` key can be used with ``run`` section to describe content of script and how its executed",
  "pattern": "^(/bin/bash|/bin/sh|/bin/csh|/bin/tcsh|/bin/zsh|bash|sh|csh|tcsh|zsh|python).*"
},

The shell pattern is a regular expression where one can specify a shell name along with shell options. The shell will configure the shebang in the test-script. In this example, we illustrate a few tests using different shell field.

buildspecs:
  _bin_sh_shell:
    executor: generic.local.sh
    type: script
    description: "/bin/sh shell example"
    shell: /bin/sh
    tags: [tutorials]
    run: "bzip2 --help"

  _bin_bash_shell:
    executor: generic.local.bash
    type: script
    description: "/bin/bash shell example"
    shell: /bin/bash
    tags: [tutorials]
    run: "bzip2 -h"

  bash_shell:
    executor: generic.local.bash
    type: script
    description: "bash shell example"
    shell: bash
    tags: [tutorials]
    run: "echo $SHELL"

  sh_shell:
    executor: generic.local.sh
    type: script
    description: "sh shell example"
    shell: sh
    tags: [tutorials]
    run: "echo $SHELL"

  shell_options:
    executor: generic.local.sh
    type: script
    description: "shell options"
    shell: "sh -x"
    tags: [tutorials]
    run: |
      echo $SHELL
      hostname

The generated test-script for buildspec _bin_sh_shell will specify shebang /bin/sh because we specified shell: /bin/sh:

#!/bin/sh
# Content of run section
bzip2 --help

If you don’t specify a shell path such as shell: sh, then buildtest will resolve path by looking in $PATH and build the shebang line.

In test shell_options we specify shell: "sh -x", buildtest will tack on the shell options into the called script as follows:

#!/bin/bash


############# START VARIABLE DECLARATION ########################
export BUILDTEST_TEST_NAME=shell_options
export BUILDTEST_TEST_ROOT=/Users/siddiq90/Documents/GitHubDesktop/buildtest/var/tests/generic.local.sh/shell_examples/shell_options/0
export BUILDTEST_BUILDSPEC_DIR=/Users/siddiq90/Documents/GitHubDesktop/buildtest/tutorials
export BUILDTEST_STAGE_DIR=/Users/siddiq90/Documents/GitHubDesktop/buildtest/var/tests/generic.local.sh/shell_examples/shell_options/0/stage
export BUILDTEST_TEST_ID=95c11f54-bbb1-4154-849d-44313e4417c2
############# END VARIABLE DECLARATION   ########################


# source executor startup script
source /Users/siddiq90/Documents/GitHubDesktop/buildtest/var/executor/generic.local.sh/before_script.sh
# Run generated script
sh -x /Users/siddiq90/Documents/GitHubDesktop/buildtest/var/tests/generic.local.sh/shell_examples/shell_options/0/stage/shell_options.sh
# Get return code
returncode=$?
# Exit with return code
exit $returncode

If you prefer csh or tcsh for writing scripts just set shell: csh or shell: tcsh, note you will need to match this with appropriate executor. For now use executor: generic.local.csh to run your csh/tcsh scripts. In this example below we define a script using csh, take note of run section we can write csh style.

buildspecs:
  csh_shell:
    executor: generic.local.csh
    type: script
    description: "csh shell example"
    shell: csh
    tags: [tutorials]
    vars:
      file: "/etc/csh.cshrc"
    run: |
      if (-e $file) then
        echo "$file file found"
      else
        echo "$file file not found"
        exit 1
      endif

Customize Shebang

You may customize the shebang line in testscript using shebang field. This takes precedence over the shell property which automatically detects the shebang based on shell path.

In next example we have two tests bash_login_shebang and bash_nonlogin_shebang which tests if shell is Login or Non-Login. The #!/bin/bash -l indicates we want to run in login shell and expects an output of Login Shell while test bash_nonlogin_shebang should run in default behavior which is non-login shell and expects output Not Login Shell. We match this with regular expression with stdout stream.

buildspecs:
  bash_login_shebang:
    type: script
    executor: generic.local.bash
    shebang: "#!/bin/bash -l"
    description: customize shebang line with bash login shell
    tags: tutorials
    run: shopt -q login_shell && echo 'Login Shell' || echo 'Not Login Shell'
    status:
      regex:
        exp: "^Login Shell$"
        stream: stdout

  bash_nonlogin_shebang:
    type: script
    executor: generic.local.bash
    shebang: "#!/bin/bash"
    description: customize shebang line with default bash (nonlogin) shell
    tags: tutorials
    run: shopt -q login_shell && echo 'Login Shell' || echo 'Not Login Shell'
    status:
      regex:
        exp: "^Not Login Shell$"
        stream: stdout

Now let’s run this test as we see the following.

$ buildtest build -b tutorials/shebang.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:35                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/shebang.yml            │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/shebang.yml: VALID
Total builder objects created: 2
Total compiler builder: 0
Total script builder: 2
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ bash_logi… │ generic.l… │ None     │ None  │ None  │ customize  │ /home/doc… │
│            │            │          │       │       │ shebang    │            │
│            │            │          │       │       │ line with  │            │
│            │            │          │       │       │ bash login │            │
│            │            │          │       │       │ shell      │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ bash_nonl… │ generic.l… │ None     │ None  │ None  │ customize  │ /home/doc… │
│            │            │          │       │       │ shebang    │            │
│            │            │          │       │       │ line with  │            │
│            │            │          │       │       │ default    │            │
│            │            │          │       │       │ bash       │            │
│            │            │          │       │       │ (nonlogin) │            │
│            │            │          │       │       │ shell      │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
bash_login_shebang/3797c704: Creating test directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/
shebang/bash_login_shebang/3797c704
bash_login_shebang/3797c704: Creating the stage directory: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
bash/shebang/bash_login_shebang/3797c704/stage
bash_login_shebang/3797c704: Writing build script: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/she
bang/bash_login_shebang/3797c704/bash_login_shebang_build.sh
bash_nonlogin_shebang/a3856c63: Creating test directory: /home/docs/checkouts/re
adthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.ba
sh/shebang/bash_nonlogin_shebang/a3856c63
bash_nonlogin_shebang/a3856c63: Creating the stage directory: /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.bash/shebang/bash_nonlogin_shebang/a3856c63/stage
bash_nonlogin_shebang/a3856c63: Writing build script: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/
shebang/bash_nonlogin_shebang/a3856c63/bash_nonlogin_shebang_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
bash_login_shebang/3797c704 does not have any dependencies adding test to queue
bash_nonlogin_shebang/a3856c63 does not have any dependencies adding test to 
queue
bash_login_shebang/3797c704: Running Test via command: bash --norc --noprofile 
-eo pipefail bash_login_shebang_build.sh
bash_login_shebang/3797c704: Test completed in 0.009014 seconds
bash_login_shebang/3797c704: Test completed with returncode: 0
bash_login_shebang/3797c704: Writing output file -  /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/sh
ebang/bash_login_shebang/3797c704/bash_login_shebang.out
bash_login_shebang/3797c704: Writing error file - /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/sheb
ang/bash_login_shebang/3797c704/bash_login_shebang.err
bash_login_shebang/3797c704: performing regular expression - '^Login Shell$' on 
file: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15
.0/var/tests/generic.local.bash/shebang/bash_login_shebang/3797c704/bash_login_s
hebang.out
bash_login_shebang/3797c704: Regular Expression Match - Success!
bash_nonlogin_shebang/a3856c63: Running Test via command: bash --norc 
--noprofile -eo pipefail bash_nonlogin_shebang_build.sh
bash_nonlogin_shebang/a3856c63: Test completed in 0.005083 seconds
bash_nonlogin_shebang/a3856c63: Test completed with returncode: 0
bash_nonlogin_shebang/a3856c63: Writing output file -  /home/docs/checkouts/read
thedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash
/shebang/bash_nonlogin_shebang/a3856c63/bash_nonlogin_shebang.out
bash_nonlogin_shebang/a3856c63: Writing error file - /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/s
hebang/bash_nonlogin_shebang/a3856c63/bash_nonlogin_shebang.err
bash_nonlogin_shebang/a3856c63: performing regular expression - '^Not Login 
Shell$' on file: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/chec
kouts/v0.15.0/var/tests/generic.local.bash/shebang/bash_nonlogin_shebang/a3856c6
3/bash_nonlogin_shebang.out
bash_nonlogin_shebang/a3856c63: Regular Expression Match - Success!
In this iteration we are going to run the following tests: [bash_login_shebang/3797c704, bash_nonlogin_shebang/a3856c63]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ bash_nonlogi │ generic.loc… │ PASS   │ False True    │ 0          │ 0.005083 │
│ n_shebang/a3 │              │        │ False         │            │          │
│ 856c63       │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ bash_login_s │ generic.loc… │ PASS   │ False True    │ 0          │ 0.009014 │
│ hebang/3797c │              │        │ False         │            │          │
│ 704          │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 2/2 Percentage: 100.000%
Failed Tests: 0/2 Percentage: 0.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_ys0fgkj7.log

If we look at the generated test for bash_login_shebang we see the shebang line is passed into the script:

#!/bin/bash -l
# Content of run section
shopt -q login_shell && echo 'Login Shell' || echo 'Not Login Shell'

Python Shell

You can use script schema to write python scripts using the run property. In order to write python code you must set shell property to python interpreter such as `shell: python or full path to python wrapper such as shell: /usr/bin/python.

Here is a python example calculating area of circle

buildspecs:
  circle_area:
    executor: generic.local.bash
    type: script
    shell: python
    description: "Calculate circle of area given a radius"
    tags: [tutorials, python]
    run: |
      import math
      radius = 2
      area = math.pi * radius * radius
      print("Circle Radius ", radius)
      print("Area of circle ", area)

Note

Python scripts are very picky when it comes to formatting, in the run section if you are defining multiline python script you must remember to use 2 space indent to register multiline string. buildtest will extract the content from run section and inject in your test script. To ensure proper formatting for a more complex python script you may be better off writing a python script in separate file and invoke the python script in the run section.

Skipping test

By default, buildtest will run all tests defined in buildspecs section, if you want to skip a test use the skip field which expects a boolean value. Shown below is an example test.

buildspecs:
  skip:
    type: script
    executor: generic.local.bash
    description: This test is skipped
    skip: Yes
    tags: [tutorials]
    run: hostname

  unskipped:
    type: script
    executor: generic.local.bash
    description: This test is not skipped
    skip: No
    tags: [tutorials]
    run: hostname

The first test skip will be ignored by buildtest because skip: true is defined while unskipped will be processed as usual.

Note

YAML and JSON have different representation for boolean. For json schema valid values are true and false see https://json-schema.org/understanding-json-schema/reference/boolean.html however YAML has many more representation for boolean see https://yaml.org/type/bool.html. You may use any of the YAML boolean, however it’s best to stick with json schema values true and false.

Here is an example build, notice message [skip] test is skipped during the build stage

$ buildtest build -b tutorials/skip_tests.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:35                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/skip_tests.yml         │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
skip: skipping test due to 'skip' property.
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/skip_tests.yml: VALID
Total builder objects created: 1
Total compiler builder: 0
Total script builder: 1
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ unskipped… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ is not     │            │
│            │            │          │       │       │ skipped    │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
unskipped/85419569: Creating test directory: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/skip_test
s/unskipped/85419569
unskipped/85419569: Creating the stage directory: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/skip
_tests/unskipped/85419569/stage
unskipped/85419569: Writing build script: /home/docs/checkouts/readthedocs.org/u
ser_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/skip_tests/u
nskipped/85419569/unskipped_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
unskipped/85419569 does not have any dependencies adding test to queue
unskipped/85419569: Running Test via command: bash --norc --noprofile -eo 
pipefail unskipped_build.sh
unskipped/85419569: Test completed in 0.006115 seconds
unskipped/85419569: Test completed with returncode: 0
unskipped/85419569: Writing output file -  /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/skip_tests/
unskipped/85419569/unskipped.out
unskipped/85419569: Writing error file - /home/docs/checkouts/readthedocs.org/us
er_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/skip_tests/un
skipped/85419569/unskipped.err
In this iteration we are going to run the following tests: [unskipped/85419569]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ unskipped/85 │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 0.006115 │
│ 419569       │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/1 Percentage: 100.000%
Failed Tests: 0/1 Percentage: 0.000%


Adding 1 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_nwhv0zpr.log

Defining Metrics

buildtest provides a method to define test metrics in the buildspecs which can be used to store arbitrary content from the output/error file into named metric. A metric is defined using the metrics property where each element under the metrics property is the name of the metric which must be a unique name. A metric can apply regular expression on stdout, stderr like in this example below. The metrics are captured in the test report which can be queried via buildtest report or buildtest inspect. Shown below is an example where we define two metrics named hpcg_rating and hpcg_state.

buildspecs:
  metric_regex_example:
    executor: generic.local.sh
    type: script
    description: capture result metric from output
    run: echo "HPCG result is VALID with a GFLOP/s rating of=63.6515"
    tags: tutorials
    metrics:
      hpcg_rating:
        regex:
          exp: '(\d+\.\d+)$'
          stream: stdout

      hpcg_state:
        regex:
          exp: '(VALID)'
          stream: stdout

The metrics will not impact behavior of test, it will only impact the test report. By default a metric will be an empty dictionary if there is no metrics property. If we fail to match a regular expression, the metric will be defined as an empty string.

Note

If your regular expression contains an escape character \ you must surround your string in single quotes ' as pose to double quotes "

Let’s build this test.

$ buildtest build -b tutorials/metrics_regex.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:36                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/metrics_regex.yml      │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/metrics_regex.yml: VALID
Total builder objects created: 1
Total compiler builder: 0
Total script builder: 1
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ metric_re… │ generic.l… │ None     │ None  │ None  │ capture    │ /home/doc… │
│            │            │          │       │       │ result     │            │
│            │            │          │       │       │ metric     │            │
│            │            │          │       │       │ from       │            │
│            │            │          │       │       │ output     │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
metric_regex_example/8daab2c1: Creating test directory: /home/docs/checkouts/rea
dthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/
metrics_regex/metric_regex_example/8daab2c1
metric_regex_example/8daab2c1: Creating the stage directory: /home/docs/checkout
s/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loca
l.sh/metrics_regex/metric_regex_example/8daab2c1/stage
metric_regex_example/8daab2c1: Writing build script: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/met
rics_regex/metric_regex_example/8daab2c1/metric_regex_example_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
metric_regex_example/8daab2c1 does not have any dependencies adding test to 
queue
metric_regex_example/8daab2c1: Running Test via command: sh --norc --noprofile 
-eo pipefail metric_regex_example_build.sh
metric_regex_example/8daab2c1: Test completed in 0.003083 seconds
metric_regex_example/8daab2c1: Test completed with returncode: 2
metric_regex_example/8daab2c1: Writing output file -  /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/me
trics_regex/metric_regex_example/8daab2c1/metric_regex_example.out
metric_regex_example/8daab2c1: Writing error file - /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/metr
ics_regex/metric_regex_example/8daab2c1/metric_regex_example.err
In this iteration we are going to run the following tests: [metric_regex_example/8daab2c1]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ metric_regex │ generic.loc… │ FAIL   │ N/A N/A N/A   │ 2          │ 0.003083 │
│ _example/8da │              │        │               │            │          │
│ ab2c1        │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 0/1 Percentage: 0.000%
Failed Tests: 1/1 Percentage: 100.000%


Adding 1 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_vojewk8y.log

We can query the metrics via buildtest report which will display all metrics as a comma separted Key/Value pair. We can use buildtest report --format metrics to extract all metrics for a test. Internally, we store the metrics as a dictionary but when we print them out via buildtest report we join them together into a single string. Shown below is the metrics for the previous build.

$ buildtest report --filter buildspec=tutorials/metrics_regex.yml --format name,metrics
Report File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
                           s/v0.15.0/var/report.json                            
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ name                               ┃ metrics                                 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ metric_regex_example               │ hpcg_rating=,hpcg_state=                │
└────────────────────────────────────┴─────────────────────────────────────────┘

You can define a metric based on variables or environment variables which requires you have set vars or env property in the buildspec. The vars and env is a property under the metric name that can be used to reference name of variable or environment variable. If you reference an invalid name, buildtest will assign the metric an empty string. In this next example, we define two metrics gflop and foo that are assigned to variable GFLOPS and environment variable FOO.

Test Dependency

Note

This feature is subject to change

Buildtest can support test dependencies which allows one to specify condition before running a test. Let’s take a look at this next example, we have a buildspec with three tests jobA, jobB, and jobC. The test jobA will run immediately but now we introduce a new keyword needs which is a list of test names as dependency. We want test jobB to run after jobA is complete, and jobC to run once jobA and jobB is complete.

buildspecs:
  jobA:
    type: script
    executor: generic.local.bash
    description: no job dependency
    run: |
      echo "This job has no dependency"
      sleep 5

  jobB:
    type: script
    executor: generic.local.bash
    description: job dependency on jobA
    needs: [jobA]
    run: |
      echo "This job depends on jobA"
      sleep 2

  jobC:
    type: script
    executor: generic.local.bash
    description: job dependency on jobA and jobB
    needs: [jobA, jobB]
    run: |
      echo "This job depends on jobA and jobB"
      sleep 2

The needs property expects a list of strings, and values must match name of test. If you specify an invalid test name in needs property then buildtest will ignore the value. If multiple tests are specified in needs property then all test must finish prior to running test.

Let’s run this test, and take a note that buildtest will run test jobA, followed by jobB then jobC.

$ buildtest build -b tutorials/job_dependency/ex1.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:37                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/job_dependency/ex1.yml │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/job_dependency/ex1.yml: VALID
Total builder objects created: 3
Total compiler builder: 0
Total script builder: 3
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ jobA/5f05… │ generic.l… │ None     │ None  │ None  │ no job     │ /home/doc… │
│            │            │          │       │       │ dependency │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ jobB/98f6… │ generic.l… │ None     │ None  │ None  │ job        │ /home/doc… │
│            │            │          │       │       │ dependency │            │
│            │            │          │       │       │ on jobA    │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ jobC/c781… │ generic.l… │ None     │ None  │ None  │ job        │ /home/doc… │
│            │            │          │       │       │ dependency │            │
│            │            │          │       │       │ on jobA    │            │
│            │            │          │       │       │ and jobB   │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
jobA/5f05eb40: Creating test directory: /home/docs/checkouts/readthedocs.org/use
r_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobA/5f05e
b40
jobA/5f05eb40: Creating the stage directory: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobA/
5f05eb40/stage
jobA/5f05eb40: Writing build script: /home/docs/checkouts/readthedocs.org/user_b
uilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobA/5f05eb40
/jobA_build.sh
jobB/98f6beca: Creating test directory: /home/docs/checkouts/readthedocs.org/use
r_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobB/98f6b
eca
jobB/98f6beca: Creating the stage directory: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobB/
98f6beca/stage
jobB/98f6beca: Writing build script: /home/docs/checkouts/readthedocs.org/user_b
uilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobB/98f6beca
/jobB_build.sh
jobC/c7815354: Creating test directory: /home/docs/checkouts/readthedocs.org/use
r_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobC/c7815
354
jobC/c7815354: Creating the stage directory: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobC/
c7815354/stage
jobC/c7815354: Writing build script: /home/docs/checkouts/readthedocs.org/user_b
uilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobC/c7815354
/jobC_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
jobC/c7815354 Skipping job because it has job dependency on jobA/5f05eb40 which 
is in state PENDING 
jobB/98f6beca Skipping job because it has job dependency on jobA/5f05eb40 which 
is in state PENDING 
jobA/5f05eb40 does not have any dependencies adding test to queue
jobA/5f05eb40: Running Test via command: bash --norc --noprofile -eo pipefail 
jobA_build.sh
jobA/5f05eb40: Test completed in 5.006836 seconds
jobA/5f05eb40: Test completed with returncode: 0
jobA/5f05eb40: Writing output file -  /home/docs/checkouts/readthedocs.org/user_
builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobA/5f05eb4
0/jobA.out
jobA/5f05eb40: Writing error file - /home/docs/checkouts/readthedocs.org/user_bu
ilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobA/5f05eb40/
jobA.err
In this iteration we are going to run the following tests: [jobA/5f05eb40]
───────────────────────────────── Iteration 2 ──────────────────────────────────
jobC/c7815354 Skipping job because it has job dependency on jobB/98f6beca which 
is in state PENDING 
jobB/98f6beca: Running Test via command: bash --norc --noprofile -eo pipefail 
jobB_build.sh
jobB/98f6beca: Test completed in 2.006744 seconds
jobB/98f6beca: Test completed with returncode: 0
jobB/98f6beca: Writing output file -  /home/docs/checkouts/readthedocs.org/user_
builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobB/98f6bec
a/jobB.out
jobB/98f6beca: Writing error file - /home/docs/checkouts/readthedocs.org/user_bu
ilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobB/98f6beca/
jobB.err
In this iteration we are going to run the following tests: [jobB/98f6beca]
───────────────────────────────── Iteration 3 ──────────────────────────────────
jobC/c7815354: Running Test via command: bash --norc --noprofile -eo pipefail 
jobC_build.sh
jobC/c7815354: Test completed in 2.007031 seconds
jobC/c7815354: Test completed with returncode: 0
jobC/c7815354: Writing output file -  /home/docs/checkouts/readthedocs.org/user_
builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobC/c781535
4/jobC.out
jobC/c7815354: Writing error file - /home/docs/checkouts/readthedocs.org/user_bu
ilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex1/jobC/c7815354/
jobC.err
In this iteration we are going to run the following tests: [jobC/c7815354]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃               ┃        ┃ checks       ┃            ┃          ┃
┃              ┃               ┃        ┃ (ReturnCode, ┃            ┃          ┃
┃              ┃               ┃        ┃ Regex,       ┃            ┃          ┃
┃ builder      ┃ executor      ┃ status ┃ Runtime)     ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ jobC/c781535 │ generic.loca… │ PASS   │ N/A N/A N/A  │ 0          │ 2.007031 │
│ 4            │               │        │              │            │          │
├──────────────┼───────────────┼────────┼──────────────┼────────────┼──────────┤
│ jobA/5f05eb4 │ generic.loca… │ PASS   │ N/A N/A N/A  │ 0          │ 5.006836 │
│ 0            │               │        │              │            │          │
├──────────────┼───────────────┼────────┼──────────────┼────────────┼──────────┤
│ jobB/98f6bec │ generic.loca… │ PASS   │ N/A N/A N/A  │ 0          │ 2.006744 │
│ a            │               │        │              │            │          │
└──────────────┴───────────────┴────────┴──────────────┴────────────┴──────────┘



Passed Tests: 3/3 Percentage: 100.000%
Failed Tests: 0/3 Percentage: 0.000%


Adding 3 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_xhl0j5e8.log

Test Dependency by returncode

In this next example, we can control behavior of job dependency based on returncode for a given test. This test has three tests: test1, test2 and test3. The first test will exit with returncode 1 but this test will pass because we have set state: PASS to override the status check. The next test test2 requires test1 to have a returncode of 1 in order to satisfy dependency. The returncode property expects a valid returncode and it can be a list of returncode similar to how one specify returncode under the status property see Return Code Matching. The needs property can support multiple test with returncode, in test3 we require test1 to have returncode 1 while test2 has a returncode of 2. We expect test2 to return a returncode of 2 because of exit 2 statement so we expect all three tests to run.

buildspecs:
  test1:
    type: script
    executor: generic.local.bash
    description: This test will pass with exit 1
    run: exit 1
    status:
      state: PASS

  test2:
    type: script
    executor: generic.local.bash
    description: This test will run if test1 has returncode 1
    run: exit 2
    status:
      state: PASS
    needs:
      - test1:
          returncode: 1

  test3:
    type: script
    executor: generic.local.bash
    description: This test will run if test1 has returncode 1 and test2 has returncode 2
    run: exit 1
    status:
      state: PASS
    needs:
      - test1:
          returncode: 1
      - test2:
          returncode: 2

Let’s build this test and take note of execution order of test.

$ buildtest build -b tutorials/job_dependency/ex2.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:47                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/job_dependency/ex2.yml │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/job_dependency/ex2.yml: VALID
Total builder objects created: 3
Total compiler builder: 0
Total script builder: 3
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ test1/dc7… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will pass  │            │
│            │            │          │       │       │ with exit  │            │
│            │            │          │       │       │ 1          │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ test2/307… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will run   │            │
│            │            │          │       │       │ if test1   │            │
│            │            │          │       │       │ has        │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ 1          │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ test3/982… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will run   │            │
│            │            │          │       │       │ if test1   │            │
│            │            │          │       │       │ has        │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ 1 and      │            │
│            │            │          │       │       │ test2 has  │            │
│            │            │          │       │       │ returncode │            │
│            │            │          │       │       │ 2          │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
test1/dc75fd97: Creating test directory: /home/docs/checkouts/readthedocs.org/us
er_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test1/dc7
5fd97
test1/dc75fd97: Creating the stage directory: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test
1/dc75fd97/stage
test1/dc75fd97: Writing build script: /home/docs/checkouts/readthedocs.org/user_
builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test1/dc75fd
97/test1_build.sh
test2/307465a4: Creating test directory: /home/docs/checkouts/readthedocs.org/us
er_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test2/307
465a4
test2/307465a4: Creating the stage directory: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test
2/307465a4/stage
test2/307465a4: Writing build script: /home/docs/checkouts/readthedocs.org/user_
builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test2/307465
a4/test2_build.sh
test3/982f45b5: Creating test directory: /home/docs/checkouts/readthedocs.org/us
er_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test3/982
f45b5
test3/982f45b5: Creating the stage directory: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test
3/982f45b5/stage
test3/982f45b5: Writing build script: /home/docs/checkouts/readthedocs.org/user_
builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test3/982f45
b5/test3_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
test2/307465a4 Skipping job because it has job dependency on test1/dc75fd97 
test1/dc75fd97 does not have any dependencies adding test to queue
test3/982f45b5 Skipping job because it has job dependency on test1/dc75fd97 
test1/dc75fd97: Running Test via command: bash --norc --noprofile -eo pipefail 
test1_build.sh
test1/dc75fd97: Test completed in 0.005514 seconds
test1/dc75fd97: Test completed with returncode: 1
test1/dc75fd97: Writing output file -  /home/docs/checkouts/readthedocs.org/user
_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test1/dc75f
d97/test1.out
test1/dc75fd97: Writing error file - /home/docs/checkouts/readthedocs.org/user_b
uilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test1/dc75fd9
7/test1.err
In this iteration we are going to run the following tests: [test1/dc75fd97]
───────────────────────────────── Iteration 2 ──────────────────────────────────
test3/982f45b5 Skipping job because it has job dependency on test2/307465a4 
test2/307465a4: Running Test via command: bash --norc --noprofile -eo pipefail 
test2_build.sh
test2/307465a4: Test completed in 0.005191 seconds
test2/307465a4: Test completed with returncode: 2
test2/307465a4: Writing output file -  /home/docs/checkouts/readthedocs.org/user
_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test2/30746
5a4/test2.out
test2/307465a4: Writing error file - /home/docs/checkouts/readthedocs.org/user_b
uilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test2/307465a
4/test2.err
In this iteration we are going to run the following tests: [test2/307465a4]
───────────────────────────────── Iteration 3 ──────────────────────────────────
test3/982f45b5: Running Test via command: bash --norc --noprofile -eo pipefail 
test3_build.sh
test3/982f45b5: Test completed in 0.005145 seconds
test3/982f45b5: Test completed with returncode: 1
test3/982f45b5: Writing output file -  /home/docs/checkouts/readthedocs.org/user
_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test3/982f4
5b5/test3.out
test3/982f45b5: Writing error file - /home/docs/checkouts/readthedocs.org/user_b
uilds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex2/test3/982f45b
5/test3.err
In this iteration we are going to run the following tests: [test3/982f45b5]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ test1/dc75fd │ generic.loc… │ PASS   │ False False   │ 1          │ 0.005514 │
│ 97           │              │        │ False         │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ test2/307465 │ generic.loc… │ PASS   │ False False   │ 2          │ 0.005191 │
│ a4           │              │        │ False         │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ test3/982f45 │ generic.loc… │ PASS   │ False False   │ 1          │ 0.005145 │
│ b5           │              │        │ False         │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 3/3 Percentage: 100.000%
Failed Tests: 0/3 Percentage: 0.000%


Adding 3 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_ihxnkv5_.log

Test Dependency by state

You can specify state as a property to check for test state when specify test dependency. In this next example, we have have four tests pass_test, fail_test, pass_and_fail_test, and final_test. The first test will be a PASS because we have state: PASS. The test fail_test depends on pass_test only if it has state: PASS, if value is mismatch then test will be skipped. Note that buildtest will skip test until next iteration if test is not executed, however if test is complete then buildtest will cancel dependent test. We can specify multiple test dependencies with state property such as test pass_and_fail_test which expects pass_test to have state: PASS and fail_test to have state: FAIL. In test final_test, shows how you can combine the format, the needs property is a list of object where each element is name of test. If no properties are associated with test name then buildtest will wait until job is complete to execute test. In this example, the test expects both pass_test and fail_test to run while pass_and_fail_test must have returncode of 1.

buildspecs:
  pass_test:
    type: script
    executor: generic.local.bash
    description: This test will always pass
    status:
      state: PASS
    run: |
      echo "This test will pass"
      sleep 2

  fail_test:
    type: script
    executor: generic.local.bash
    description: This test will run if test 'pass_test' is in state 'PASS'
    status:
      state: FAIL
    needs:
      - pass_test:
          state: PASS
    run: |
      echo "This test will fail"
      sleep 2

  pass_and_fail_test:
    type: script
    executor: generic.local.bash
    description: This test will run if pass_test is 'PASS' and fail_test is 'FAIL'
    needs:
      - pass_test:
          state: PASS
      - fail_test:
          state: FAIL
    run: |
      sleep 2
      exit 1
    status:
      returncode: 1

  final_test:
    type: script
    executor: generic.local.bash
    description: Test will run after 'pass_test', 'fail_test', and 'pass_and_fail_test'
    needs:
      - pass_test
      - fail_test
      - pass_and_fail_test:
          returncode: 1
    run: |
      sleep 2
      echo "Hello world"

Let’s build this test and take note all tests are run.

$ buildtest build -b tutorials/job_dependency/ex3.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:47                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/job_dependency/ex3.yml │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/job_dependency/ex3.yml: VALID
Total builder objects created: 4
Total compiler builder: 0
Total script builder: 4
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ pass_test… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will       │            │
│            │            │          │       │       │ always     │            │
│            │            │          │       │       │ pass       │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ fail_test… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will run   │            │
│            │            │          │       │       │ if test    │            │
│            │            │          │       │       │ 'pass_tes… │            │
│            │            │          │       │       │ is in      │            │
│            │            │          │       │       │ state      │            │
│            │            │          │       │       │ 'PASS'     │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ pass_and_… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will run   │            │
│            │            │          │       │       │ if         │            │
│            │            │          │       │       │ pass_test  │            │
│            │            │          │       │       │ is 'PASS'  │            │
│            │            │          │       │       │ and        │            │
│            │            │          │       │       │ fail_test  │            │
│            │            │          │       │       │ is 'FAIL'  │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ final_tes… │ generic.l… │ None     │ None  │ None  │ Test will  │ /home/doc… │
│            │            │          │       │       │ run after  │            │
│            │            │          │       │       │ 'pass_tes… │            │
│            │            │          │       │       │ 'fail_tes… │            │
│            │            │          │       │       │ and        │            │
│            │            │          │       │       │ 'pass_and… │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
pass_test/ed2e9c33: Creating test directory: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/pass_
test/ed2e9c33
pass_test/ed2e9c33: Creating the stage directory: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/
pass_test/ed2e9c33/stage
pass_test/ed2e9c33: Writing build script: /home/docs/checkouts/readthedocs.org/u
ser_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/pass_tes
t/ed2e9c33/pass_test_build.sh
fail_test/8bc4c071: Creating test directory: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/fail_
test/8bc4c071
fail_test/8bc4c071: Creating the stage directory: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/
fail_test/8bc4c071/stage
fail_test/8bc4c071: Writing build script: /home/docs/checkouts/readthedocs.org/u
ser_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/fail_tes
t/8bc4c071/fail_test_build.sh
pass_and_fail_test/ad2a3dae: Creating test directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/
ex3/pass_and_fail_test/ad2a3dae
pass_and_fail_test/ad2a3dae: Creating the stage directory: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
bash/ex3/pass_and_fail_test/ad2a3dae/stage
pass_and_fail_test/ad2a3dae: Writing build script: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3
/pass_and_fail_test/ad2a3dae/pass_and_fail_test_build.sh
final_test/66f39587: Creating test directory: /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/fina
l_test/66f39587
final_test/66f39587: Creating the stage directory: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3
/final_test/66f39587/stage
final_test/66f39587: Writing build script: /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/final_t
est/66f39587/final_test_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
pass_and_fail_test/ad2a3dae Skipping job because it has job dependency on 
pass_test/ed2e9c33 
pass_test/ed2e9c33 does not have any dependencies adding test to queue
final_test/66f39587 Skipping job because it has job dependency on 
pass_test/ed2e9c33 which is in state PENDING 
fail_test/8bc4c071 Skipping job because it has job dependency on 
pass_test/ed2e9c33 
pass_test/ed2e9c33: Running Test via command: bash --norc --noprofile -eo 
pipefail pass_test_build.sh
pass_test/ed2e9c33: Test completed in 2.006865 seconds
pass_test/ed2e9c33: Test completed with returncode: 0
pass_test/ed2e9c33: Writing output file -  /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/pass_te
st/ed2e9c33/pass_test.out
pass_test/ed2e9c33: Writing error file - /home/docs/checkouts/readthedocs.org/us
er_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/pass_test
/ed2e9c33/pass_test.err
In this iteration we are going to run the following tests: [pass_test/ed2e9c33]
───────────────────────────────── Iteration 2 ──────────────────────────────────
pass_and_fail_test/ad2a3dae Skipping job because it has job dependency on 
fail_test/8bc4c071 
final_test/66f39587 Skipping job because it has job dependency on 
fail_test/8bc4c071 which is in state PENDING 
fail_test/8bc4c071: Running Test via command: bash --norc --noprofile -eo 
pipefail fail_test_build.sh
fail_test/8bc4c071: Test completed in 2.006828 seconds
fail_test/8bc4c071: Test completed with returncode: 0
fail_test/8bc4c071: Writing output file -  /home/docs/checkouts/readthedocs.org/
user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/fail_te
st/8bc4c071/fail_test.out
fail_test/8bc4c071: Writing error file - /home/docs/checkouts/readthedocs.org/us
er_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/fail_test
/8bc4c071/fail_test.err
In this iteration we are going to run the following tests: [fail_test/8bc4c071]
───────────────────────────────── Iteration 3 ──────────────────────────────────
final_test/66f39587 Skipping job because it has job dependency on 
pass_and_fail_test/ad2a3dae 
pass_and_fail_test/ad2a3dae: Running Test via command: bash --norc --noprofile 
-eo pipefail pass_and_fail_test_build.sh
pass_and_fail_test/ad2a3dae: Test completed in 2.006859 seconds
pass_and_fail_test/ad2a3dae: Test completed with returncode: 1
pass_and_fail_test/ad2a3dae: Writing output file -  /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex
3/pass_and_fail_test/ad2a3dae/pass_and_fail_test.out
pass_and_fail_test/ad2a3dae: Writing error file - /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/
pass_and_fail_test/ad2a3dae/pass_and_fail_test.err
pass_and_fail_test/ad2a3dae: Checking returncode - 1 is matched in list [1]
In this iteration we are going to run the following tests: [pass_and_fail_test/ad2a3dae]
───────────────────────────────── Iteration 4 ──────────────────────────────────
final_test/66f39587: Running Test via command: bash --norc --noprofile -eo 
pipefail final_test_build.sh
final_test/66f39587: Test completed in 2.007071 seconds
final_test/66f39587: Test completed with returncode: 0
final_test/66f39587: Writing output file -  /home/docs/checkouts/readthedocs.org
/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/final_
test/66f39587/final_test.out
final_test/66f39587: Writing error file - /home/docs/checkouts/readthedocs.org/u
ser_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex3/final_te
st/66f39587/final_test.err
In this iteration we are going to run the following tests: [final_test/66f39587]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ final_test/6 │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 2.007071 │
│ 6f39587      │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ fail_test/8b │ generic.loc… │ FAIL   │ False False   │ 0          │ 2.006828 │
│ c4c071       │              │        │ False         │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ pass_test/ed │ generic.loc… │ PASS   │ False False   │ 0          │ 2.006865 │
│ 2e9c33       │              │        │ False         │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ pass_and_fai │ generic.loc… │ PASS   │ True False    │ 1          │ 2.006859 │
│ l_test/ad2a3 │              │        │ False         │            │          │
│ dae          │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 3/4 Percentage: 75.000%
Failed Tests: 1/4 Percentage: 25.000%


Adding 4 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_8_f5tytw.log

In this next example, we have three tests the first test will runtime_test will sleep for 5 seconds but it will fail due to runtime requirement of 2sec. The next two tests runtime_test_pass and runtime_test_fail both depend on runtime_test however due to condition only one of them can be run because runtime_test_pass expects runtime_test to have state: PASS while runtime_test_fail expects runtime_test to have state: FAIL. This type of workflow can be used if you want to run a set of test based on one condition while running a different set of test based on the negative condition.

buildspecs:
  runtime_test:
    type: script
    executor: generic.local.bash
    description: This test will sleep 5 second but will fail due to runtime 2sec
    status:
      runtime:
        min: 2.0
    run: sleep 5

  runtime_test_pass:
    type: script
    executor: generic.local.bash
    description: This test will run when runtime_test_pass is PASS
    needs:
      - runtime_test:
          state: PASS
    run: echo "Performing some action when test PASS"

  runtime_test_fail:
    type: script
    executor: generic.local.bash
    description: This test will run when runtime_test_pass is FAIL
    needs:
      - runtime_test:
          state: FAIL
    run: echo "Performing some action when test FAIL"

Let’s build this test and take note that we only run two tests and runtime_test_fail was skipped because test runtime_test has a state: PASS.

$ buildtest build -b tutorials/job_dependency/ex4.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:37:56                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b tutorials/job_dependency/ex4.yml │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/job_dependency/ex4.yml: VALID
Total builder objects created: 3
Total compiler builder: 0
Total script builder: 3
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ runtime_t… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will sleep │            │
│            │            │          │       │       │ 5 second   │            │
│            │            │          │       │       │ but will   │            │
│            │            │          │       │       │ fail due   │            │
│            │            │          │       │       │ to runtime │            │
│            │            │          │       │       │ 2sec       │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ runtime_t… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will run   │            │
│            │            │          │       │       │ when       │            │
│            │            │          │       │       │ runtime_t… │            │
│            │            │          │       │       │ is PASS    │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ runtime_t… │ generic.l… │ None     │ None  │ None  │ This test  │ /home/doc… │
│            │            │          │       │       │ will run   │            │
│            │            │          │       │       │ when       │            │
│            │            │          │       │       │ runtime_t… │            │
│            │            │          │       │       │ is FAIL    │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
runtime_test/8416b1df: Creating test directory: /home/docs/checkouts/readthedocs
.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/ru
ntime_test/8416b1df
runtime_test/8416b1df: Creating the stage directory: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/e
x4/runtime_test/8416b1df/stage
runtime_test/8416b1df: Writing build script: /home/docs/checkouts/readthedocs.or
g/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/runti
me_test/8416b1df/runtime_test_build.sh
runtime_test_pass/06aaf3ee: Creating test directory: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/e
x4/runtime_test_pass/06aaf3ee
runtime_test_pass/06aaf3ee: Creating the stage directory: /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.b
ash/ex4/runtime_test_pass/06aaf3ee/stage
runtime_test_pass/06aaf3ee: Writing build script: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/
runtime_test_pass/06aaf3ee/runtime_test_pass_build.sh
runtime_test_fail/382a2cdb: Creating test directory: /home/docs/checkouts/readth
edocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/e
x4/runtime_test_fail/382a2cdb
runtime_test_fail/382a2cdb: Creating the stage directory: /home/docs/checkouts/r
eadthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.b
ash/ex4/runtime_test_fail/382a2cdb/stage
runtime_test_fail/382a2cdb: Writing build script: /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/
runtime_test_fail/382a2cdb/runtime_test_fail_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
runtime_test_fail/382a2cdb Skipping job because it has job dependency on 
runtime_test/8416b1df 
runtime_test/8416b1df does not have any dependencies adding test to queue
runtime_test_pass/06aaf3ee Skipping job because it has job dependency on 
runtime_test/8416b1df 
runtime_test/8416b1df: Running Test via command: bash --norc --noprofile -eo 
pipefail runtime_test_build.sh
runtime_test/8416b1df: Test completed in 5.00668 seconds
runtime_test/8416b1df: Test completed with returncode: 0
runtime_test/8416b1df: Writing output file -  /home/docs/checkouts/readthedocs.o
rg/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/runt
ime_test/8416b1df/runtime_test.out
runtime_test/8416b1df: Writing error file - /home/docs/checkouts/readthedocs.org
/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/runtim
e_test/8416b1df/runtime_test.err
In this iteration we are going to run the following tests: [runtime_test/8416b1df]
───────────────────────────────── Iteration 2 ──────────────────────────────────
runtime_test_fail/382a2cdb is cancelled because it depends on 
runtime_test/8416b1df to have state: FAIL but actual value is PASS
runtime_test_pass/06aaf3ee: Running Test via command: bash --norc --noprofile 
-eo pipefail runtime_test_pass_build.sh
runtime_test_pass/06aaf3ee: Test completed in 0.005599 seconds
runtime_test_pass/06aaf3ee: Test completed with returncode: 0
runtime_test_pass/06aaf3ee: Writing output file -  /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4
/runtime_test_pass/06aaf3ee/runtime_test_pass.out
runtime_test_pass/06aaf3ee: Writing error file - /home/docs/checkouts/readthedoc
s.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex4/r
untime_test_pass/06aaf3ee/runtime_test_pass.err
In this iteration we are going to run the following tests: [runtime_test_pass/06aaf3ee]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ runtime_test │ generic.loc… │ PASS   │ False False   │ 0          │ 5.00668  │
│ /8416b1df    │              │        │ True          │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ runtime_test │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 0.005599 │
│ _pass/06aaf3 │              │        │               │            │          │
│ ee           │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 2/2 Percentage: 100.000%
Failed Tests: 0/2 Percentage: 0.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_r87st3r0.log

Running test across multiple executors

The executor property can support regular expression to search for compatible executors, this can be used if you want to run a test across multiple executors. In buildtest, we use re.fullmatch with the input pattern defined by executor property against a list of available executors defined in configuration file. You can retrieve a list of executors by running buildtest config executors.

In example below we will run this test on generic.local.bash and generic.local.sh executor based on the regular expression.

buildspecs:
  multiple_executors:
    type: script
    executor: 'generic.local.(bash|sh)'
    description: run test with executor generic.local.bash and generic.local.sh executor
    tags: [tutorials]
    run: date

If we build this test, notice that there are two tests, one for each executor.

$ buildtest build -b tutorials/multi_executors/executor_regex_script.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:38:01                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/multi_executors/executor_regex_script.yml                          │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/multi_executors/executor_regex_script.yml: VALID
Total builder objects created: 2
Total compiler builder: 0
Total script builder: 2
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ multiple_… │ generic.l… │ None     │ None  │ None  │ run test   │ /home/doc… │
│            │            │          │       │       │ with       │            │
│            │            │          │       │       │ executor   │            │
│            │            │          │       │       │ generic.l… │            │
│            │            │          │       │       │ and        │            │
│            │            │          │       │       │ generic.l… │            │
│            │            │          │       │       │ executor   │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ multiple_… │ generic.l… │ None     │ None  │ None  │ run test   │ /home/doc… │
│            │            │          │       │       │ with       │            │
│            │            │          │       │       │ executor   │            │
│            │            │          │       │       │ generic.l… │            │
│            │            │          │       │       │ and        │            │
│            │            │          │       │       │ generic.l… │            │
│            │            │          │       │       │ executor   │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
multiple_executors/f4b72a7a: Creating test directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/
executor_regex_script/multiple_executors/f4b72a7a
multiple_executors/f4b72a7a: Creating the stage directory: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
bash/executor_regex_script/multiple_executors/f4b72a7a/stage
multiple_executors/f4b72a7a: Writing build script: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/exe
cutor_regex_script/multiple_executors/f4b72a7a/multiple_executors_build.sh
multiple_executors/396e29f0: Creating test directory: /home/docs/checkouts/readt
hedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/ex
ecutor_regex_script/multiple_executors/396e29f0
multiple_executors/396e29f0: Creating the stage directory: /home/docs/checkouts/
readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.
sh/executor_regex_script/multiple_executors/396e29f0/stage
multiple_executors/396e29f0: Writing build script: /home/docs/checkouts/readthed
ocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/execu
tor_regex_script/multiple_executors/396e29f0/multiple_executors_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
multiple_executors/f4b72a7a does not have any dependencies adding test to queue
multiple_executors/396e29f0 does not have any dependencies adding test to queue
multiple_executors/f4b72a7a: Running Test via command: bash --norc --noprofile 
-eo pipefail multiple_executors_build.sh
multiple_executors/f4b72a7a: Test completed in 0.00771 seconds
multiple_executors/f4b72a7a: Test completed with returncode: 0
multiple_executors/f4b72a7a: Writing output file -  /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/ex
ecutor_regex_script/multiple_executors/f4b72a7a/multiple_executors.out
multiple_executors/f4b72a7a: Writing error file - /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.bash/exec
utor_regex_script/multiple_executors/f4b72a7a/multiple_executors.err
multiple_executors/396e29f0: Running Test via command: sh --norc --noprofile -eo
pipefail multiple_executors_build.sh
multiple_executors/396e29f0: Test completed in 0.002923 seconds
multiple_executors/396e29f0: Test completed with returncode: 2
multiple_executors/396e29f0: Writing output file -  /home/docs/checkouts/readthe
docs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/exec
utor_regex_script/multiple_executors/396e29f0/multiple_executors.out
multiple_executors/396e29f0: Writing error file - /home/docs/checkouts/readthedo
cs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local.sh/execut
or_regex_script/multiple_executors/396e29f0/multiple_executors.err
In this iteration we are going to run the following tests: [multiple_executors/f4b72a7a, multiple_executors/396e29f0]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ multiple_exe │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 0.00771  │
│ cutors/f4b72 │              │        │               │            │          │
│ a7a          │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ multiple_exe │ generic.loc… │ FAIL   │ N/A N/A N/A   │ 2          │ 0.002923 │
│ cutors/396e2 │              │        │               │            │          │
│ 9f0          │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_h4elnxs7.log

Multiple Executors

Note

This feature is in active development

Note

This feature is compatible with type: script and type: spack.

The executors property can be used to define executor specific configuration for each test, currently this field can be used with vars, env , scheduler directives: sbatch, bsub, pbs, cobalt and cray burst buffer/data warp. The executors field is a JSON object that expects name of executor followed by property set per executor. In this next example, we define variables X, Y and environment SHELL based on executors generic.local.sh and generic.local.bash.

buildspecs:
  executors_vars_env_declaration:
    type: script
    executor: 'generic.local.(bash|sh)'
    description: Declaring env and vars by executors section
    tags: [tutorials]
    run: |
      echo "X:" $X
      echo "Y:" $Y
      echo $SHELL
    executors:
      generic.local.bash:
        vars:
          X: 1
          Y: 3
        env:
          SHELL: bash
      generic.local.sh:
        vars:
          X: 2
          Y: 4
        env:
          SHELL: sh

Let’s build this test.

$ buildtest build -b tutorials/multi_executors/executors_var_env_declaration.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:38:02                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/multi_executors/executors_var_env_declaration.yml                  │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/multi_executors/executors_var_env_declaration.yml: VALID
Total builder objects created: 2
Total compiler builder: 0
Total script builder: 2
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ executors… │ generic.l… │ None     │ None  │ None  │ Declaring  │ /home/doc… │
│            │            │          │       │       │ env and    │            │
│            │            │          │       │       │ vars by    │            │
│            │            │          │       │       │ executors  │            │
│            │            │          │       │       │ section    │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ executors… │ generic.l… │ None     │ None  │ None  │ Declaring  │ /home/doc… │
│            │            │          │       │       │ env and    │            │
│            │            │          │       │       │ vars by    │            │
│            │            │          │       │       │ executors  │            │
│            │            │          │       │       │ section    │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
executors_vars_env_declaration/5e3fb649: Creating test directory: /home/docs/che
ckouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic
.local.bash/executors_var_env_declaration/executors_vars_env_declaration/5e3fb64
9
executors_vars_env_declaration/5e3fb649: Creating the stage directory: /home/doc
s/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/ge
neric.local.bash/executors_var_env_declaration/executors_vars_env_declaration/5e
3fb649/stage
executors_vars_env_declaration/5e3fb649: Writing build script: /home/docs/checko
uts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.lo
cal.bash/executors_var_env_declaration/executors_vars_env_declaration/5e3fb649/e
xecutors_vars_env_declaration_build.sh
executors_vars_env_declaration/ce22fb8a: Creating test directory: /home/docs/che
ckouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic
.local.sh/executors_var_env_declaration/executors_vars_env_declaration/ce22fb8a
executors_vars_env_declaration/ce22fb8a: Creating the stage directory: /home/doc
s/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/ge
neric.local.sh/executors_var_env_declaration/executors_vars_env_declaration/ce22
fb8a/stage
executors_vars_env_declaration/ce22fb8a: Writing build script: /home/docs/checko
uts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.lo
cal.sh/executors_var_env_declaration/executors_vars_env_declaration/ce22fb8a/exe
cutors_vars_env_declaration_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
executors_vars_env_declaration/5e3fb649 does not have any dependencies adding 
test to queue
executors_vars_env_declaration/ce22fb8a does not have any dependencies adding 
test to queue
executors_vars_env_declaration/5e3fb649: Running Test via command: bash --norc 
--noprofile -eo pipefail executors_vars_env_declaration_build.sh
executors_vars_env_declaration/5e3fb649: Test completed in 0.005745 seconds
executors_vars_env_declaration/5e3fb649: Test completed with returncode: 0
executors_vars_env_declaration/5e3fb649: Writing output file -  /home/docs/check
outs/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.l
ocal.bash/executors_var_env_declaration/executors_vars_env_declaration/5e3fb649/
executors_vars_env_declaration.out
executors_vars_env_declaration/5e3fb649: Writing error file - /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.bash/executors_var_env_declaration/executors_vars_env_declaration/5e3fb649/ex
ecutors_vars_env_declaration.err
executors_vars_env_declaration/ce22fb8a: Running Test via command: sh --norc 
--noprofile -eo pipefail executors_vars_env_declaration_build.sh
executors_vars_env_declaration/ce22fb8a: Test completed in 0.003031 seconds
executors_vars_env_declaration/ce22fb8a: Test completed with returncode: 2
executors_vars_env_declaration/ce22fb8a: Writing output file -  /home/docs/check
outs/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.l
ocal.sh/executors_var_env_declaration/executors_vars_env_declaration/ce22fb8a/ex
ecutors_vars_env_declaration.out
executors_vars_env_declaration/ce22fb8a: Writing error file - /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.sh/executors_var_env_declaration/executors_vars_env_declaration/ce22fb8a/exec
utors_vars_env_declaration.err
In this iteration we are going to run the following tests: [executors_vars_env_declaration/5e3fb649, executors_vars_env_declaration/ce22fb8a]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ executors_va │ generic.loc… │ FAIL   │ N/A N/A N/A   │ 2          │ 0.003031 │
│ rs_env_decla │              │        │               │            │          │
│ ration/ce22f │              │        │               │            │          │
│ b8a          │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ executors_va │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 0.005745 │
│ rs_env_decla │              │        │               │            │          │
│ ration/5e3fb │              │        │               │            │          │
│ 649          │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_yq7dlbxh.log

Now let’s look at the generated content of the test as follows. We will see that buildtest will set X=1, Y=3 and SHELL=bash for generic.local.bash and X=2, Y=4 and SHELL=sh for generic.local.sh

$ buildtest inspect query -t executors_vars_env_declaration/
───── executors_vars_env_declaration/ce22fb8a-2ed5-44fb-9fa3-6cf151ca941a ──────
Executor: generic.local.sh
Description: Declaring env and vars by executors section
State: FAIL
Returncode: 2
Runtime: 0.003031 sec
Starttime: 2022/07/01 00:38:02
Endtime: 2022/07/01 00:38:02
Command: sh --norc --noprofile -eo pipefail 
executors_vars_env_declaration_build.sh
Test Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.sh/executors_var_env_declaration/executors_var
s_env_declaration/ce22fb8a/executors_vars_env_declaration.sh
Build Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkou
ts/v0.15.0/var/tests/generic.local.sh/executors_var_env_declaration/executors_va
rs_env_declaration/ce22fb8a/executors_vars_env_declaration_build.sh
Output File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.sh/executors_var_env_declaration/executors_var
s_env_declaration/ce22fb8a/executors_vars_env_declaration.out
Error File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts
/v0.15.0/var/tests/generic.local.sh/executors_var_env_declaration/executors_vars
_env_declaration/ce22fb8a/executors_vars_env_declaration.err
Log File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v
0.15.0/var/logs/buildtest_yq7dlbxh.log
─ Test File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/check… ─
#!/usr/bin/sh                                                                   
export SHELL="sh"                                                               
X="2"                                                                           
Y="4"                                                                           
# Content of run section                                                        
echo "X:" $X                                                                    
echo "Y:" $Y                                                                    
echo $SHELL                                                                     
                                                                                
───── executors_vars_env_declaration/5e3fb649-6231-4def-87ea-e831c896bdf5 ──────
Executor: generic.local.bash
Description: Declaring env and vars by executors section
State: PASS
Returncode: 0
Runtime: 0.005745 sec
Starttime: 2022/07/01 00:38:02
Endtime: 2022/07/01 00:38:02
Command: bash --norc --noprofile -eo pipefail 
executors_vars_env_declaration_build.sh
Test Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.bash/executors_var_env_declaration/executors_v
ars_env_declaration/5e3fb649/executors_vars_env_declaration.sh
Build Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkou
ts/v0.15.0/var/tests/generic.local.bash/executors_var_env_declaration/executors_
vars_env_declaration/5e3fb649/executors_vars_env_declaration_build.sh
Output File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.bash/executors_var_env_declaration/executors_v
ars_env_declaration/5e3fb649/executors_vars_env_declaration.out
Error File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts
/v0.15.0/var/tests/generic.local.bash/executors_var_env_declaration/executors_va
rs_env_declaration/5e3fb649/executors_vars_env_declaration.err
Log File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v
0.15.0/var/logs/buildtest_yq7dlbxh.log
─ Test File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/check… ─
#!/usr/bin/bash                                                                 
export SHELL="bash"                                                             
X="1"                                                                           
Y="3"                                                                           
# Content of run section                                                        
echo "X:" $X                                                                    
echo "Y:" $Y                                                                    
echo $SHELL

Scheduler Directives

We can also define scheduler directives based on executor type, in this example we define sbatch property per executor type. Note that sbatch property in the executors section will override the sbatch property defined in the top-level file otherwise it will use the default.

buildspecs:
  executors_sbatch_declaration:
    type: script
    executor: 'generic.local.(bash|sh)'
    description: Declaring env and vars by executors section
    tags: [tutorials]
    run: hostname
    sbatch: ["-N 4"]
    executors:
      generic.local.bash:
        sbatch: ["-n 4", "-N 1", "-t 30"]
      generic.local.sh:
        sbatch: ["-n 8", "-N 1", "-t 60"]
$ buildtest build -b tutorials/multi_executors/executor_scheduler.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:38:03                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/multi_executors/executor_scheduler.yml                             │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/multi_executors/executor_scheduler.yml: VALID
Total builder objects created: 2
Total compiler builder: 0
Total script builder: 2
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ executors… │ generic.l… │ None     │ None  │ None  │ Declaring  │ /home/doc… │
│            │            │          │       │       │ env and    │            │
│            │            │          │       │       │ vars by    │            │
│            │            │          │       │       │ executors  │            │
│            │            │          │       │       │ section    │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ executors… │ generic.l… │ None     │ None  │ None  │ Declaring  │ /home/doc… │
│            │            │          │       │       │ env and    │            │
│            │            │          │       │       │ vars by    │            │
│            │            │          │       │       │ executors  │            │
│            │            │          │       │       │ section    │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
executors_sbatch_declaration/0841d1e5: Creating test directory: /home/docs/check
outs/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.l
ocal.bash/executor_scheduler/executors_sbatch_declaration/0841d1e5
executors_sbatch_declaration/0841d1e5: Creating the stage directory: /home/docs/
checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/gene
ric.local.bash/executor_scheduler/executors_sbatch_declaration/0841d1e5/stage
executors_sbatch_declaration/0841d1e5: Writing build script: /home/docs/checkout
s/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loca
l.bash/executor_scheduler/executors_sbatch_declaration/0841d1e5/executors_sbatch
_declaration_build.sh
executors_sbatch_declaration/c9513fb7: Creating test directory: /home/docs/check
outs/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.l
ocal.sh/executor_scheduler/executors_sbatch_declaration/c9513fb7
executors_sbatch_declaration/c9513fb7: Creating the stage directory: /home/docs/
checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/gene
ric.local.sh/executor_scheduler/executors_sbatch_declaration/c9513fb7/stage
executors_sbatch_declaration/c9513fb7: Writing build script: /home/docs/checkout
s/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loca
l.sh/executor_scheduler/executors_sbatch_declaration/c9513fb7/executors_sbatch_d
eclaration_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
executors_sbatch_declaration/c9513fb7 does not have any dependencies adding test
to queue
executors_sbatch_declaration/0841d1e5 does not have any dependencies adding test
to queue
executors_sbatch_declaration/c9513fb7: Running Test via command: sh --norc 
--noprofile -eo pipefail executors_sbatch_declaration_build.sh
executors_sbatch_declaration/c9513fb7: Test completed in 0.002992 seconds
executors_sbatch_declaration/c9513fb7: Test completed with returncode: 2
executors_sbatch_declaration/c9513fb7: Writing output file -  /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.sh/executor_scheduler/executors_sbatch_declaration/c9513fb7/executors_sbatch_
declaration.out
executors_sbatch_declaration/c9513fb7: Writing error file - /home/docs/checkouts
/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local
.sh/executor_scheduler/executors_sbatch_declaration/c9513fb7/executors_sbatch_de
claration.err
executors_sbatch_declaration/0841d1e5: Running Test via command: bash --norc 
--noprofile -eo pipefail executors_sbatch_declaration_build.sh
executors_sbatch_declaration/0841d1e5: Test completed in 0.00597 seconds
executors_sbatch_declaration/0841d1e5: Test completed with returncode: 0
executors_sbatch_declaration/0841d1e5: Writing output file -  /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.bash/executor_scheduler/executors_sbatch_declaration/0841d1e5/executors_sbatc
h_declaration.out
executors_sbatch_declaration/0841d1e5: Writing error file - /home/docs/checkouts
/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.local
.bash/executor_scheduler/executors_sbatch_declaration/0841d1e5/executors_sbatch_
declaration.err
In this iteration we are going to run the following tests: [executors_sbatch_declaration/c9513fb7, executors_sbatch_declaration/0841d1e5]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ executors_sb │ generic.loc… │ FAIL   │ N/A N/A N/A   │ 2          │ 0.002992 │
│ atch_declara │              │        │               │            │          │
│ tion/c9513fb │              │        │               │            │          │
│ 7            │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ executors_sb │ generic.loc… │ PASS   │ N/A N/A N/A   │ 0          │ 0.00597  │
│ atch_declara │              │        │               │            │          │
│ tion/0841d1e │              │        │               │            │          │
│ 5            │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_ileryc19.log

If we inspect this test, we will see each each test have different #SBATCH directives for each test based on the sbatch property defined in the executors field.

$ buildtest inspect query -t executors_sbatch_declaration/
────── executors_sbatch_declaration/c9513fb7-5e11-4d12-aac5-fe6a70708f08 ───────
Executor: generic.local.sh
Description: Declaring env and vars by executors section
State: FAIL
Returncode: 2
Runtime: 0.002992 sec
Starttime: 2022/07/01 00:38:03
Endtime: 2022/07/01 00:38:03
Command: sh --norc --noprofile -eo pipefail 
executors_sbatch_declaration_build.sh
Test Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.sh/executor_scheduler/executors_sbatch_declara
tion/c9513fb7/executors_sbatch_declaration.sh
Build Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkou
ts/v0.15.0/var/tests/generic.local.sh/executor_scheduler/executors_sbatch_declar
ation/c9513fb7/executors_sbatch_declaration_build.sh
Output File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.sh/executor_scheduler/executors_sbatch_declara
tion/c9513fb7/executors_sbatch_declaration.out
Error File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts
/v0.15.0/var/tests/generic.local.sh/executor_scheduler/executors_sbatch_declarat
ion/c9513fb7/executors_sbatch_declaration.err
Log File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v
0.15.0/var/logs/buildtest_ileryc19.log
─ Test File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/check… ─
#!/usr/bin/sh                                                                   
#SBATCH -n 8                                                                    
#SBATCH -N 1                                                                    
#SBATCH -t 60                                                                   
#SBATCH --job-name=executors_sbatch_declaration                                 
#SBATCH --output=executors_sbatch_declaration.out                               
#SBATCH --error=executors_sbatch_declaration.err                                
# Content of run section                                                        
hostname                                                                        
────── executors_sbatch_declaration/0841d1e5-588d-4cb4-8d1b-334e9e97bbef ───────
Executor: generic.local.bash
Description: Declaring env and vars by executors section
State: PASS
Returncode: 0
Runtime: 0.00597 sec
Starttime: 2022/07/01 00:38:03
Endtime: 2022/07/01 00:38:03
Command: bash --norc --noprofile -eo pipefail 
executors_sbatch_declaration_build.sh
Test Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.bash/executor_scheduler/executors_sbatch_decla
ration/0841d1e5/executors_sbatch_declaration.sh
Build Script: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkou
ts/v0.15.0/var/tests/generic.local.bash/executor_scheduler/executors_sbatch_decl
aration/0841d1e5/executors_sbatch_declaration_build.sh
Output File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkout
s/v0.15.0/var/tests/generic.local.bash/executor_scheduler/executors_sbatch_decla
ration/0841d1e5/executors_sbatch_declaration.out
Error File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts
/v0.15.0/var/tests/generic.local.bash/executor_scheduler/executors_sbatch_declar
ation/0841d1e5/executors_sbatch_declaration.err
Log File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v
0.15.0/var/logs/buildtest_ileryc19.log
─ Test File: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/check… ─
#!/usr/bin/bash                                                                 
#SBATCH -n 4                                                                    
#SBATCH -N 1                                                                    
#SBATCH -t 30                                                                   
#SBATCH --job-name=executors_sbatch_declaration                                 
#SBATCH --output=executors_sbatch_declaration.out                               
#SBATCH --error=executors_sbatch_declaration.err                                
# Content of run section                                                        
hostname

Cray Burst Buffer and Data Warp

You can also define BB and DW directives in the executors field to override cray burst buffer and data warp settings per executor. buildtest will use the fields BB and DW and insert the #BB and #DW directives in the job script. For more details see Cray Burst Buffer & Data Warp.

buildspecs:
  create_burst_buffer_multiple_executors:
    type: script
    executor: "generic.local.(sh|bash)"
    sbatch: ["-N 1", "-t 10", "-C knl"]
    description: Create a burst buffer for multiple executors
    tags: [jobs]
    executors:
      generic.local.sh:
        BB:
          - create_persistent name=buffer1 capacity=10GB access_mode=striped type=scratch
        DW:
          - persistentdw name=buffer1
      generic.local.bash:
        BB:
        - create_persistent name=buffer2 capacity=10GB access_mode=striped type=scratch
        DW:
          - persistentdw name=buffer2
    run: hostname

Custom Status by Executor

The status and metrics field are supported in executors which can be defined within the named executor. In this next example, we will define executor generic.local.bash to match for returncode 0 or 2 while second test will use executor generic.local.sh to match returncode of 1.

buildspecs:
  status_returncode_by_executors:
    type: script
    executor: "generic.local.(bash|sh)"
    description: define status per executor type.
    tags: [tutorials]
    run: exit 0
    executors:
      generic.local.bash:
        status:
          returncode: [0, 2]
      generic.local.sh:
        status:
          returncode: 1

Now let’s run this test and we will see the test using executor generic.local.sh will fail because we have a returncode mismatch even though both tests got a 0 returncode as its actual value.

$ buildtest build -b tutorials/multi_executors/status_by_executors.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-17326554-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2022/07/01 00:38:04                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest                                           │
│ buildtest version:  0.15.0                                                   │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/envs/v0.15.0/bin/python3                                                  │
│ python version:     3.7.13                                                   │
│ Configuration File: /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/buildtest/settings/config.yml                           │
│ Test Directory:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/tests                                               │
│ Report File:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/var/report.json                                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ st/checkouts/v0.15.0/bin/buildtest build -b                                  │
│ tutorials/multi_executors/status_by_executors.yml                            │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.… ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Buildtest will parse 1 buildspecs
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/tut
orials/multi_executors/status_by_executors.yml: VALID
Total builder objects created: 2
Total compiler builder: 0
Total script builder: 2
Total spack builder: 0
                             Script Builder Details                             
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ builder    ┃ executor   ┃ compiler ┃ nodes ┃ procs ┃ descripti… ┃ buildspecs ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ status_re… │ generic.l… │ None     │ None  │ None  │ define     │ /home/doc… │
│            │            │          │       │       │ status per │            │
│            │            │          │       │       │ executor   │            │
│            │            │          │       │       │ type.      │            │
├────────────┼────────────┼──────────┼───────┼───────┼────────────┼────────────┤
│ status_re… │ generic.l… │ None     │ None  │ None  │ define     │ /home/doc… │
│            │            │          │       │       │ status per │            │
│            │            │          │       │       │ executor   │            │
│            │            │          │       │       │ type.      │            │
└────────────┴────────────┴──────────┴───────┴───────┴────────────┴────────────┘
──────────────────────────────── Building Test ─────────────────────────────────
status_returncode_by_executors/446ecde1: Creating test directory: /home/docs/che
ckouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic
.local.bash/status_by_executors/status_returncode_by_executors/446ecde1
status_returncode_by_executors/446ecde1: Creating the stage directory: /home/doc
s/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/ge
neric.local.bash/status_by_executors/status_returncode_by_executors/446ecde1/sta
ge
status_returncode_by_executors/446ecde1: Writing build script: /home/docs/checko
uts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.lo
cal.bash/status_by_executors/status_returncode_by_executors/446ecde1/status_retu
rncode_by_executors_build.sh
status_returncode_by_executors/45e05858: Creating test directory: /home/docs/che
ckouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic
.local.sh/status_by_executors/status_returncode_by_executors/45e05858
status_returncode_by_executors/45e05858: Creating the stage directory: /home/doc
s/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/ge
neric.local.sh/status_by_executors/status_returncode_by_executors/45e05858/stage
status_returncode_by_executors/45e05858: Writing build script: /home/docs/checko
uts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.lo
cal.sh/status_by_executors/status_returncode_by_executors/45e05858/status_return
code_by_executors_build.sh
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
status_returncode_by_executors/45e05858 does not have any dependencies adding 
test to queue
status_returncode_by_executors/446ecde1 does not have any dependencies adding 
test to queue
status_returncode_by_executors/45e05858: Running Test via command: sh --norc 
--noprofile -eo pipefail status_returncode_by_executors_build.sh
status_returncode_by_executors/45e05858: Test completed in 0.003132 seconds
status_returncode_by_executors/45e05858: Test completed with returncode: 2
status_returncode_by_executors/45e05858: Writing output file -  /home/docs/check
outs/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.l
ocal.sh/status_by_executors/status_returncode_by_executors/45e05858/status_retur
ncode_by_executors.out
status_returncode_by_executors/45e05858: Writing error file - /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.sh/status_by_executors/status_returncode_by_executors/45e05858/status_returnc
ode_by_executors.err
status_returncode_by_executors/45e05858: Checking returncode - 2 is matched in 
list [1]
status_returncode_by_executors/446ecde1: Running Test via command: bash --norc 
--noprofile -eo pipefail status_returncode_by_executors_build.sh
status_returncode_by_executors/446ecde1: Test completed in 0.005354 seconds
status_returncode_by_executors/446ecde1: Test completed with returncode: 0
status_returncode_by_executors/446ecde1: Writing output file -  /home/docs/check
outs/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.l
ocal.bash/status_by_executors/status_returncode_by_executors/446ecde1/status_ret
urncode_by_executors.out
status_returncode_by_executors/446ecde1: Writing error file - /home/docs/checkou
ts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/tests/generic.loc
al.bash/status_by_executors/status_returncode_by_executors/446ecde1/status_retur
ncode_by_executors.err
status_returncode_by_executors/446ecde1: Checking returncode - 0 is matched in 
list [0, 2]
In this iteration we are going to run the following tests: [status_returncode_by_executors/45e05858, status_returncode_by_executors/446ecde1]
                                  Test Summary                                  
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃              ┃              ┃        ┃ checks        ┃            ┃          ┃
┃              ┃              ┃        ┃ (ReturnCode,  ┃            ┃          ┃
┃              ┃              ┃        ┃ Regex,        ┃            ┃          ┃
┃ builder      ┃ executor     ┃ status ┃ Runtime)      ┃ returnCode ┃ runtime  ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ status_retur │ generic.loc… │ PASS   │ True False    │ 0          │ 0.005354 │
│ ncode_by_exe │              │        │ False         │            │          │
│ cutors/446ec │              │        │               │            │          │
│ de1          │              │        │               │            │          │
├──────────────┼──────────────┼────────┼───────────────┼────────────┼──────────┤
│ status_retur │ generic.loc… │ FAIL   │ False False   │ 2          │ 0.003132 │
│ ncode_by_exe │              │        │ False         │            │          │
│ cutors/45e05 │              │        │               │            │          │
│ 858          │              │        │               │            │          │
└──────────────┴──────────────┴────────┴───────────────┴────────────┴──────────┘



Passed Tests: 1/2 Percentage: 50.000%
Failed Tests: 1/2 Percentage: 50.000%


Adding 2 test results to /home/docs/checkouts/readthedocs.org/user_builds/buildt
est/checkouts/v0.15.0/var/report.json
Writing Logfile to: /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/v0.15.0/var/logs/buildtest_mvz8zc0w.log