Note

Please see Tutorials Setup before you proceed with this section

Buildtest Spack Integration

Note

This feature is in active development.

buildtest can use spack to build test where one can use spack to install packages followed by running any test. You must set type: spack in buildspec to use the spack schema for validating the buildspec test. Currently, we have spack.schema.json JSON schema that defines the structure of how tests are to be written in buildspec. Shown below is the schema header. The required properties are type, executor and spack.

{
  "$id": "spack.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "spack schema version",
  "description": "The spack schema is referenced using ``type: spack`` which is used for generating tests using spack package manager",
  "type": "object",
  "required": [
    "type",
    "executor",
    "spack"
  ],
  "additionalProperties": false,

Install Specs

Let’s start off with a simple example where we create a test that can spack install zlib. Shown below is a test named install_zlib. The spack keyword is a JSON object, in this test we define the root of spack using the root keyword which informs buildtest where spack is located. buildtest will automatically check the path and source the startup script. The install field is a JSON object that contains a specs property which is a list of strings types that are name of spack packages to install. Each item in the specs property will be added as a separate spack install command.

The schema is designed to mimic spack commands which will be clear with more examples.

buildspecs:
  install_specs_example:
    type: spack
    executor: generic.local.bash
    description: "Install zlib from an existing spack instance"
    tags: [spack]
    spack:
      root: $HOME/spack
      install:
        specs: ['zlib']

Let’s build this test by running the following

buildtest build -b /home/spack/buildtest/examples/spack/install_specs.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/install_specs.yml 
Buildspec Paths: ['/home/spack/buildtest/examples']
Updating buildspec cache file: /home/spack/buildtest/var/buildspecs/cache.json
╭─────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────╮                                                                                                        
│                                                                                                                         │                                                                                                        
│ User:               spack                                                                                               │                                                                                                        
│ Hostname:           0fee8530c3a4                                                                                        │                                                                                                        
│ Platform:           Linux                                                                                               │                                                                                                        
│ Current Time:       2023/07/14 18:45:34                                                                                 │                                                                                                        
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                 │                                                                                                        
│ buildtest version:  1.4                                                                                                 │                                                                                                        
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                             │                                                                                                        
│ python version:     3.8.6                                                                                               │                                                                                                        
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                        │                                                                                                        
│ Test Directory:     /home/spack/runs                                                                                    │                                                                                                        
│ Report File:        /home/spack/buildtest/var/report.json                                                               │                                                                                                        
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/install_specs.yml │                                                                                                        
│                                                                                                                         │                                                                                                        
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                        
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                  Discovered buildspecs                   
╔════════════════════════════════════════════════════════╗
║ buildspec                                              ║
╟────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/install_specs.yml ║
╚════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/install_specs.yml: VALID
Total builder objects created: 2
                                                                                         Builders by type=spack                                                                                          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                               ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                                  ┃ buildspecs                                             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ install_specs_example/40031985        │ spack │ generic.local.bash │ None     │ None  │ None  │ Install zlib from an existing spack instance │ /home/spack/buildtest/examples/spack/install_specs.yml │
├───────────────────────────────────────┼───────┼────────────────────┼──────────┼───────┼───────┼──────────────────────────────────────────────┼────────────────────────────────────────────────────────┤
│ clone_spack_and_install_zlib/7d2b08e2 │ spack │ generic.local.bash │ None     │ None  │ None  │ Clone spack and install zlib spec            │ /home/spack/buildtest/examples/spack/install_specs.yml │
└───────────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────────────────────────────────────┴────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
install_specs_example/40031985: Creating test directory: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985
install_specs_example/40031985: Creating the stage directory: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/stage
install_specs_example/40031985: Writing build script: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example_build.sh
clone_spack_and_install_zlib/7d2b08e2: Creating test directory: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2
clone_spack_and_install_zlib/7d2b08e2: Creating the stage directory: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/stage
clone_spack_and_install_zlib/7d2b08e2: Writing build script: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
clone_spack_and_install_zlib/7d2b08e2 does not have any dependencies adding test to queue
install_specs_example/40031985 does not have any dependencies adding test to queue
clone_spack_and_install_zlib/7d2b08e2: Current Working Directory : /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/stage
install_specs_example/40031985: Current Working Directory : /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/stage
install_specs_example/40031985: Running Test via command: bash --norc --noprofile -eo pipefail install_specs_example_build.sh
clone_spack_and_install_zlib/7d2b08e2: Running Test via command: bash --norc --noprofile -eo pipefail clone_spack_and_install_zlib_build.sh
install_specs_example/40031985: Test completed in 1.548599 seconds
install_specs_example/40031985: Test completed with returncode: 0
install_specs_example/40031985: Writing output file -  /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.out
install_specs_example/40031985: Writing error file - /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.err
clone_spack_and_install_zlib/7d2b08e2 failed to submit job with returncode: 3 

Cloning into 'spack'...
 Updating files:  89% (9509/10614)
 Updating files:  90% (9553/10614)
 Updating files:  91% (9659/10614)
 Updating files:  92% (9765/10614)
 Updating files:  93% (9872/10614)
 Updating files:  94% (9978/10614)
 Updating files:  95% (10084/10614)
 Updating files:  96% (10190/10614)
 Updating files:  97% (10296/10614)
 Updating files:  98% (10402/10614)
 Updating files:  99% (10508/10614)
 Updating files: 100% (10614/10614)
 Updating files: 100% (10614/10614), done.
 ==> Error: 'name'

clone_spack_and_install_zlib/7d2b08e2: Detected failure in running test, will attempt to retry test: 1 times
clone_spack_and_install_zlib/7d2b08e2: Run - 1/1
clone_spack_and_install_zlib/7d2b08e2: Running Test via command: bash --norc --noprofile -eo pipefail clone_spack_and_install_zlib_build.sh
clone_spack_and_install_zlib/7d2b08e2 failed to submit job with returncode: 3 

fatal: destination path 'spack' already exists and is not an empty directory.
 ==> Error: 'name'

clone_spack_and_install_zlib/7d2b08e2: Test completed in 44.148474 seconds
clone_spack_and_install_zlib/7d2b08e2: Test completed with returncode: 3
clone_spack_and_install_zlib/7d2b08e2: Writing output file -  /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.out
clone_spack_and_install_zlib/7d2b08e2: Writing error file - /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.err
In this iteration we are going to run the following tests: [install_specs_example/40031985, clone_spack_and_install_zlib/7d2b08e2]
                                                             Test Summary                                                             
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ builder                               ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ clone_spack_and_install_zlib/7d2b08e2 │ generic.local.bash │ FAIL   │ None None None                      │ 3          │ 44.148474 │
├───────────────────────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼───────────┤
│ install_specs_example/40031985        │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 1.548599  │
└───────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴───────────┘



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


Adding 2 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_hupirc5k.log

Let’s inspect the generated script and output file via buildtest inspect query command. We notice that buildtest will source spack setup script and install zlib which is automatically installed from the buildcache.

buildtest inspect query -o -t install_specs_example
$ buildtest inspect query -o -t install_specs_example clone_spack_and_install_zlib
─────────────────────────────────────────────────────────────────────────────────── install_specs_example/40031985-7bf5-41c1-a58e-dbf8edfbda49 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Install zlib from an existing spack instance
State: PASS
Returncode: 0
Runtime: 1.548599 sec
Starttime: 2023/07/14 18:45:34
Endtime: 2023/07/14 18:45:36
Command: bash --norc --noprofile -eo pipefail install_specs_example_build.sh
Test Script: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.sh
Build Script: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example_build.sh
Output File: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.out
Error File: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.err
Log File: /home/spack/buildtest/var/logs/buildtest_hupirc5k.log
───────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.out ─────────────────────────────────────────────────────
[+] /home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/zlib-1.2.11-smoyzzo2qhzpn6mg6rd3l2p7b23enshg                                                                                                           
                                                                                                                                                                                                                                   
────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/install_specs/install_specs_example/40031985/install_specs_example.sh ───────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack install  zlib                                                                                                                                                                                                                
──────────────────────────────────────────────────────────────────────────────── clone_spack_and_install_zlib/7d2b08e2-94ac-4487-bc1e-a7b9f72aae7f ────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Clone spack and install zlib spec
State: FAIL
Returncode: 3
Runtime: 44.148474 sec
Starttime: 2023/07/14 18:45:34
Endtime: 2023/07/14 18:46:18
Command: bash --norc --noprofile -eo pipefail clone_spack_and_install_zlib_build.sh
Test Script: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.sh
Build Script: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib_build.sh
Output File: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.out
Error File: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.err
Log File: /home/spack/buildtest/var/logs/buildtest_hupirc5k.log
────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.out ──────────────────────────────────────────────
                                                                                                                                                                                                                                   
─────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/install_specs/clone_spack_and_install_zlib/7d2b08e2/clone_spack_and_install_zlib.sh ────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
git clone https://github.com/spack/spack                                                                                                                                                                                           
source ./spack/share/spack/setup-env.sh                                                                                                                                                                                            
spack install  zlib

Spack Environment

buildtest can generate scripts to make use of spack environments which can be useful if you want to install or test specs in an isolated environment.

Currently, we can create spack environment (spack env create) via name, directory and manifest file (spack.yaml, spack.lock) and pass any options to spack env create command. Furthermore, we can activate existing spack environment via name or directory using spack env activate and pass options to the command. buildtest can remove spack environments automatically before creating spack environment or one can explicitly specify by name.

Create a Spack Environment by name

In this next example, we will create a spack environment named m4_zlib that will install m4 and zlib spec. The create field is a JSON object that maps to spack env create command which can pass some arguments in the form of key/value pairs. The name property in create section is used to create a spack environment by name. The activate property maps to spack env activate command which is used to activate a spack environment. The name property is of type: string which is name of spack environment you want to activate.

The compiler_find: true is a boolean that determines if we need to find compilers in spack via spack compiler find. This can be useful if you need to find compilers so spack can install specs with a preferred compiler otherwise spack may have issues concretizing or install specs. buildtest will run spack compiler find after sourcing spack.

Note

The compiler_find option may not be useful if your compilers are already defined in one of your configuration scopes or spack.yaml that is part of your spack environment.

The option field can pass any command line arguments to spack install command and this field is available for other properties.

buildspecs:
  install_in_spack_env:
    type: spack
    executor: generic.local.bash
    description: "Install m4 and zlib in a spack environment named m4_zlib"
    tags: [spack]
    spack:
      root: $HOME/spack
      compiler_find: true
      env:
        create:
          name: 'm4_zlib'
        specs:
          - 'm4'
          - 'zlib'
        activate:
          name: m4_zlib
        concretize: true
      install:
        option: '--keep-prefix'

If we build this test and see generated test we see that buildtest will create a spack environment m4_zlib and activate the environment, add m4 and zlib, concretize the environment and install the specs.

buildtest build -b /home/spack/buildtest/examples/spack/env_install.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/env_install.yml 
╭────────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────╮                                                                                                          
│                                                                                                                       │                                                                                                          
│ User:               spack                                                                                             │                                                                                                          
│ Hostname:           0fee8530c3a4                                                                                      │                                                                                                          
│ Platform:           Linux                                                                                             │                                                                                                          
│ Current Time:       2023/07/14 18:46:19                                                                               │                                                                                                          
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                               │                                                                                                          
│ buildtest version:  1.4                                                                                               │                                                                                                          
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                           │                                                                                                          
│ python version:     3.8.6                                                                                             │                                                                                                          
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                      │                                                                                                          
│ Test Directory:     /home/spack/runs                                                                                  │                                                                                                          
│ Report File:        /home/spack/buildtest/var/report.json                                                             │                                                                                                          
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/env_install.yml │                                                                                                          
│                                                                                                                       │                                                                                                          
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                          
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                 Discovered buildspecs                  
╔══════════════════════════════════════════════════════╗
║ buildspec                                            ║
╟──────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/env_install.yml ║
╚══════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/env_install.yml: VALID
Total builder objects created: 1
                                                                                          Builders by type=spack                                                                                           
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                       ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                                              ┃ buildspecs                                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ install_in_spack_env/0f16f091 │ spack │ generic.local.bash │ None     │ None  │ None  │ Install m4 and zlib in a spack environment named m4_zlib │ /home/spack/buildtest/examples/spack/env_install.yml │
└───────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
install_in_spack_env/0f16f091: Creating test directory: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091
install_in_spack_env/0f16f091: Creating the stage directory: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/stage
install_in_spack_env/0f16f091: Writing build script: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
install_in_spack_env/0f16f091 does not have any dependencies adding test to queue
install_in_spack_env/0f16f091: Current Working Directory : /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/stage
install_in_spack_env/0f16f091: Running Test via command: bash --norc --noprofile -eo pipefail install_in_spack_env_build.sh
install_in_spack_env/0f16f091: Test completed in 3.184986 seconds
install_in_spack_env/0f16f091: Test completed with returncode: 0
install_in_spack_env/0f16f091: Writing output file -  /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env.out
install_in_spack_env/0f16f091: Writing error file - /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env.err
In this iteration we are going to run the following tests: [install_in_spack_env/0f16f091]
                                                        Test Summary                                                         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                       ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ install_in_spack_env/0f16f091 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 3.184986 │
└───────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_91oadl48.log
buildtest inspect query -t install_in_spack_env
$ buildtest inspect query -t install_in_spack_env
──────────────────────────────────────────────────────────────────────────────────── install_in_spack_env/0f16f091-372b-44e4-8726-b1c1e39a68c3 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Install m4 and zlib in a spack environment named m4_zlib
State: PASS
Returncode: 0
Runtime: 3.184986 sec
Starttime: 2023/07/14 18:46:19
Endtime: 2023/07/14 18:46:22
Command: bash --norc --noprofile -eo pipefail install_in_spack_env_build.sh
Test Script: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env.sh
Build Script: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env_build.sh
Output File: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env.out
Error File: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env.err
Log File: /home/spack/buildtest/var/logs/buildtest_91oadl48.log
──────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/env_install/install_in_spack_env/0f16f091/install_in_spack_env.sh ─────────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack compiler find                                                                                                                                                                                                                
spack env create  m4_zlib                                                                                                                                                                                                          
spack env activate  m4_zlib                                                                                                                                                                                                        
spack add m4                                                                                                                                                                                                                       
spack add zlib                                                                                                                                                                                                                     
spack concretize -f                                                                                                                                                                                                                
spack install --keep-prefix

Creating Spack Environment in Directory

We can create spack environment from a directory using the dir property that is available as part of create and activate field. In this next example we create a spack environment in our $HOME directory and concretize m4 in the spack environment

buildspecs:
  spack_env_directory:
    type: spack
    executor: generic.local.bash
    description: "create spack environment in directory"
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        create:
          dir: $HOME/spack-envs/m4
        activate:
          dir: $HOME/spack-envs/m4
        specs:
          - 'm4'
      install:
        option: ''
    post_cmds: |
      spack find
      rm -rf $HOME/spack-envs/m4

When creating spack environment using directory, buildtest will automatically add the -d option which is required when creating spack environments. However, one can also pass this using the option field. Shown below is the build and generated script after running test.

buildtest build -b /home/spack/buildtest/examples/spack/env_create_directory.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/env_create_directory.yml 
╭────────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────────╮                                                                                                 
│                                                                                                                                │                                                                                                 
│ User:               spack                                                                                                      │                                                                                                 
│ Hostname:           0fee8530c3a4                                                                                               │                                                                                                 
│ Platform:           Linux                                                                                                      │                                                                                                 
│ Current Time:       2023/07/14 18:46:23                                                                                        │                                                                                                 
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                        │                                                                                                 
│ buildtest version:  1.4                                                                                                        │                                                                                                 
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                                    │                                                                                                 
│ python version:     3.8.6                                                                                                      │                                                                                                 
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                               │                                                                                                 
│ Test Directory:     /home/spack/runs                                                                                           │                                                                                                 
│ Report File:        /home/spack/buildtest/var/report.json                                                                      │                                                                                                 
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/env_create_directory.yml │                                                                                                 
│                                                                                                                                │                                                                                                 
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                 
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                      Discovered buildspecs                      
╔═══════════════════════════════════════════════════════════════╗
║ buildspec                                                     ║
╟───────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/env_create_directory.yml ║
╚═══════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/env_create_directory.yml: VALID
Total builder objects created: 1
                                                                                     Builders by type=spack                                                                                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                      ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                           ┃ buildspecs                                                    ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_env_directory/490db0c3 │ spack │ generic.local.bash │ None     │ None  │ None  │ create spack environment in directory │ /home/spack/buildtest/examples/spack/env_create_directory.yml │
└──────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴───────────────────────────────────────┴───────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_env_directory/490db0c3: Creating test directory: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3
spack_env_directory/490db0c3: Creating the stage directory: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/stage
spack_env_directory/490db0c3: Writing build script: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_env_directory/490db0c3 does not have any dependencies adding test to queue
spack_env_directory/490db0c3: Current Working Directory : /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/stage
spack_env_directory/490db0c3: Running Test via command: bash --norc --noprofile -eo pipefail spack_env_directory_build.sh
spack_env_directory/490db0c3: Test completed in 2.285139 seconds
spack_env_directory/490db0c3: Test completed with returncode: 0
spack_env_directory/490db0c3: Writing output file -  /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.out
spack_env_directory/490db0c3: Writing error file - /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.err
In this iteration we are going to run the following tests: [spack_env_directory/490db0c3]
                                                        Test Summary                                                        
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                      ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_env_directory/490db0c3 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 2.285139 │
└──────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_lzbl78sy.log
buildtest inspect query -o -t spack_env_directory
$ buildtest inspect query -o -t spack_env_directory
──────────────────────────────────────────────────────────────────────────────────── spack_env_directory/490db0c3-43d9-4660-8b5b-1523d2fff912 ─────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: create spack environment in directory
State: PASS
Returncode: 0
Runtime: 2.285139 sec
Starttime: 2023/07/14 18:46:23
Endtime: 2023/07/14 18:46:25
Command: bash --norc --noprofile -eo pipefail spack_env_directory_build.sh
Test Script: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.sh
Build Script: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory_build.sh
Output File: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.out
Error File: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.err
Log File: /home/spack/buildtest/var/logs/buildtest_lzbl78sy.log
─────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.out ────────────────────────────────────────────────────
==> Updating view at /home/spack/spack-envs/m4/.spack-env/view                                                                                                                                                                     
==> Created environment in /home/spack/spack-envs/m4                                                                                                                                                                               
==> You can activate this environment with:                                                                                                                                                                                        
==>   spack env activate /home/spack/spack-envs/m4                                                                                                                                                                                 
==> Adding m4 to environment /home/spack/spack-envs/m4                                                                                                                                                                             
==> Updating view at /home/spack/spack-envs/m4/.spack-env/view                                                                                                                                                                     
==> Concretized m4                                                                                                                                                                                                                 
[+]  mkc3u4x  m4@1.4.18%gcc@7.5.0+sigsegv patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 arch=linux-ubuntu18.04-x86_64                  
[+]  lbrx7ln      ^libsigsegv@2.12%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                         
==> Installing environment /home/spack/spack-envs/m4                                                                                                                                                                               
==> All of the packages are already installed                                                                                                                                                                                      
==> Updating view at /home/spack/spack-envs/m4/.spack-env/view                                                                                                                                                                     
==> In environment /home/spack/spack-envs/m4                                                                                                                                                                                       
==> Root specs                                                                                                                                                                                                                     
m4                                                                                                                                                                                                                                 
-- linux-ubuntu18.04-x86_64 / gcc@7.5.0 -------------------------                                                                                                                                                                  
libsigsegv@2.12                                                                                                                                                                                                                    
m4@1.4.18                                                                                                                                                                                                                          
                                                                                                                                                                                                                                   
───────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/env_create_directory/spack_env_directory/490db0c3/spack_env_directory.sh ─────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack env create  -d /home/spack/spack-envs/m4                                                                                                                                                                                     
spack env activate  -d /home/spack/spack-envs/m4                                                                                                                                                                                   
spack add m4                                                                                                                                                                                                                       
spack install                                                                                                                                                                                                                      
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
######## START OF POST COMMANDS ########                                                                                                                                                                                           
spack find                                                                                                                                                                                                                         
rm -rf $HOME/spack-envs/m4                                                                                                                                                                                                         
######## END OF POST COMMANDS   ########

Create Spack Environment from Manifest File (spack.yaml, spack.lock)

Spack can create environments from spack.yaml or spack.lock which can be used if you have a spack configuration that works for your system and want to write a buildspec. While creating a spack environment, you can use the manifest property to specify path to your spack.yaml or spack.lock.

Note

buildtest will not enforce that manifest names be spack.yaml or spack.lock since spack allows one to create spack environment from arbitrary name so long as it is a valid spack configuration.

Shown below is an example buildspec that generates a test from a manifest file. The manifest property is of type: string and this is only available as part of create property.

buildspecs:
  spack_env_create_from_manifest:
    type: spack
    executor: generic.local.bash
    description: "Create spack environment from spack.yaml"
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        create:
          name: 'manifest_example'
          manifest: "$BUILDTEST_ROOT/examples/spack/example/spack.yaml"
        activate:
          name: 'manifest_example'
        concretize: true

If we build this test and inspect the generated script we see spack env create command will create an environment manifest_example using the manifest file that we provided from the spack.yaml.

buildtest build -b /home/spack/buildtest/examples/spack/env_create_manifest.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/env_create_manifest.yml 
╭────────────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────────╮                                                                                                  
│                                                                                                                               │                                                                                                  
│ User:               spack                                                                                                     │                                                                                                  
│ Hostname:           0fee8530c3a4                                                                                              │                                                                                                  
│ Platform:           Linux                                                                                                     │                                                                                                  
│ Current Time:       2023/07/14 18:46:26                                                                                       │                                                                                                  
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                       │                                                                                                  
│ buildtest version:  1.4                                                                                                       │                                                                                                  
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                                   │                                                                                                  
│ python version:     3.8.6                                                                                                     │                                                                                                  
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                              │                                                                                                  
│ Test Directory:     /home/spack/runs                                                                                          │                                                                                                  
│ Report File:        /home/spack/buildtest/var/report.json                                                                     │                                                                                                  
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/env_create_manifest.yml │                                                                                                  
│                                                                                                                               │                                                                                                  
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                  
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                     Discovered buildspecs                      
╔══════════════════════════════════════════════════════════════╗
║ buildspec                                                    ║
╟──────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/env_create_manifest.yml ║
╚══════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/env_create_manifest.yml: VALID
Total builder objects created: 1
                                                                                           Builders by type=spack                                                                                            
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                                 ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                              ┃ buildspecs                                                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_env_create_from_manifest/7e04b3e5 │ spack │ generic.local.bash │ None     │ None  │ None  │ Create spack environment from spack.yaml │ /home/spack/buildtest/examples/spack/env_create_manifest.yml │
└─────────────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────────────────────────────────┴──────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_env_create_from_manifest/7e04b3e5: Creating test directory: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5
spack_env_create_from_manifest/7e04b3e5: Creating the stage directory: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/stage
spack_env_create_from_manifest/7e04b3e5: Writing build script: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_env_create_from_manifest/7e04b3e5 does not have any dependencies adding test to queue
spack_env_create_from_manifest/7e04b3e5: Current Working Directory : /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/stage
spack_env_create_from_manifest/7e04b3e5: Running Test via command: bash --norc --noprofile -eo pipefail spack_env_create_from_manifest_build.sh
spack_env_create_from_manifest/7e04b3e5: Test completed in 3.967062 seconds
spack_env_create_from_manifest/7e04b3e5: Test completed with returncode: 0
spack_env_create_from_manifest/7e04b3e5: Writing output file -  /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.out
spack_env_create_from_manifest/7e04b3e5: Writing error file - /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.err
In this iteration we are going to run the following tests: [spack_env_create_from_manifest/7e04b3e5]
                                                             Test Summary                                                              
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                                 ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_env_create_from_manifest/7e04b3e5 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 3.967062 │
└─────────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_e2ttpy9a.log
buildtest inspect query -o -t spack_env_create_from_manifest
$ buildtest inspect query -o -t spack_env_create_from_manifest
─────────────────────────────────────────────────────────────────────────────── spack_env_create_from_manifest/7e04b3e5-3626-490c-b107-a84b1fbae3e7 ───────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Create spack environment from spack.yaml
State: PASS
Returncode: 0
Runtime: 3.967062 sec
Starttime: 2023/07/14 18:46:26
Endtime: 2023/07/14 18:46:30
Command: bash --norc --noprofile -eo pipefail spack_env_create_from_manifest_build.sh
Test Script: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.sh
Build Script: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest_build.sh
Output File: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.out
Error File: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.err
Log File: /home/spack/buildtest/var/logs/buildtest_e2ttpy9a.log
───────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.out ─────────────────────────────────────────
==> Created environment 'manifest_example' in /home/spack/spack/var/spack/environments/manifest_example                                                                                                                            
==> You can activate this environment with:                                                                                                                                                                                        
==>   spack env activate manifest_example                                                                                                                                                                                          
==> Concretized m4                                                                                                                                                                                                                 
 -   mkc3u4x  m4@1.4.18%gcc@7.5.0+sigsegv patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 arch=linux-ubuntu18.04-x86_64                  
 -   lbrx7ln      ^libsigsegv@2.12%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                         
==> Concretized zlib                                                                                                                                                                                                               
 -   smoyzzo  zlib@1.2.11%gcc@7.5.0+optimize+pic+shared arch=linux-ubuntu18.04-x86_64                                                                                                                                              
==> Concretized python                                                                                                                                                                                                             
 -   szj7juk  python@3.8.6%gcc@7.5.0+bz2+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0d
 -   fvfpt26      ^bzip2@1.0.8%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64                                                                                                                                                      
 -   otkkten          ^diffutils@3.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                       
 -   jearpk4              ^libiconv@1.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                   
 -   ba7brxj      ^expat@2.2.10%gcc@7.5.0+libbsd arch=linux-ubuntu18.04-x86_64                                                                                                                                                     
 -   u6ue7vw          ^libbsd@0.10.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                       
 -   4av4gyw      ^gdbm@1.18.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                             
 -   t54jzdy          ^readline@8.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                        
 -   crhlefo              ^ncurses@6.2%gcc@7.5.0~symlinks+termlib arch=linux-ubuntu18.04-x86_64                                                                                                                                    
 -   4sh6pym                  ^pkgconf@1.7.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                               
 -   lbb45to      ^gettext@0.21%gcc@7.5.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-ubuntu18.04-x86_64                                                                                                               
 -   yn2r3wf          ^libxml2@2.9.10%gcc@7.5.0~python arch=linux-ubuntu18.04-x86_64                                                                                                                                               
 -   komekkm              ^xz@5.2.5%gcc@7.5.0~pic arch=linux-ubuntu18.04-x86_64                                                                                                                                                    
 -   smoyzzo              ^zlib@1.2.11%gcc@7.5.0+optimize+pic+shared arch=linux-ubuntu18.04-x86_64                                                                                                                                 
 -   uwe6tb5          ^tar@1.32%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                            
 -   hyhbnrm      ^libffi@3.3%gcc@7.5.0 patches=26f26c6f29a7ce9bf370ad3ab2610f99365b4bdd7b82e7c31df41a3370d685c0 arch=linux-ubuntu18.04-x86_64                                                                                     
 -   wuyj2ax      ^libuuid@1.0.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                                           
 -   es377uq      ^openssl@1.1.1h%gcc@7.5.0+systemcerts arch=linux-ubuntu18.04-x86_64                                                                                                                                              
 -   zfdvt2j          ^perl@5.32.0%gcc@7.5.0+cpanm+shared+threads arch=linux-ubuntu18.04-x86_64                                                                                                                                    
 -   4ihuiaz              ^berkeley-db@18.1.40%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64                                                                                                                                             
 -   rhv2o7b      ^sqlite@3.33.0%gcc@7.5.0+column_metadata+fts~functions~rtree arch=linux-ubuntu18.04-x86_64                                                                                                                       
                                                                                                                                                                                                                                   
────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/env_create_manifest/spack_env_create_from_manifest/7e04b3e5/spack_env_create_from_manifest.sh ───────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack env create  manifest_example /home/spack/buildtest/examples/spack/example/spack.yaml                                                                                                                                         
spack env activate  manifest_example                                                                                                                                                                                               
spack concretize -f

Deactivate Spack Environment

When you are switching between spack environments, it can be important to deactivate your current spack environment which can be used when writing test. This can be achieved using the keyword deactivate which is a boolean type.

If deactivate: true is set, then we will deactivate the spack environment by running spack env deactivate

Shown below is an example buildspec where we create a spack environment, deactivate first and then activate the environment. Buildtest will deactivate a spack environment prior to activating an environment which is specified via activate keyword.

buildspecs:
  spack_env_deactivate_first:
    type: spack
    executor: generic.local.bash
    description: "deactivate a spack environment first prior to activating it"
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        create:
          dir: $HOME/spack-envs/m4
        deactivate: true
        activate:
          dir: $HOME/spack-envs/m4
        specs:
          - 'm4'
      install:
        option: ''
    post_cmds: |
      spack find
      rm -rf $HOME/spack-envs/m4

Let’s build this by running the following

buildtest build -b /home/spack/buildtest/examples/spack/spack_env_deactivate.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/spack_env_deactivate.yml 
╭────────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────────╮                                     
│                                                                                                                                │                                     
│ User:               spack                                                                                                      │                                     
│ Hostname:           189b8c776423                                                                                               │                                     
│ Platform:           Linux                                                                                                      │                                     
│ Current Time:       2023/08/11 16:03:30                                                                                        │                                     
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                        │                                     
│ buildtest version:  1.5                                                                                                        │                                     
│ python path:        /home/spack/.pyenv/buildtest/bin/python3                                                                   │                                     
│ python version:     3.8.6                                                                                                      │                                     
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                               │                                     
│ Test Directory:     /home/spack/runs                                                                                           │                                     
│ Report File:        /home/spack/buildtest/var/report.json                                                                      │                                     
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/spack_env_deactivate.yml │                                     
│                                                                                                                                │                                     
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                     
───────────────────────────────────────────────────────────────────────  Discovering Buildspecs ───────────────────────────────────────────────────────────────────────
                      Discovered buildspecs                      
╔═══════════════════════════════════════════════════════════════╗
║ buildspec                                                     ║
╟───────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/spack_env_deactivate.yml ║
╚═══════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
───────────────────────────────────────────────────────────────────────── Parsing Buildspecs ──────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/spack_env_deactivate.yml: VALID
Total builder objects created: 1
                                                                        Builders by type=spack                                                                         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                            ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                       ┃ buildspecs                         ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_env_deactivate_first/bb6f82… │ spack │ generic.local.bash │ None     │ None  │ None  │ deactivate a spack environment    │ /home/spack/buildtest/examples/sp… │
│                                    │       │                    │          │       │       │ first prior to activating it      │                                    │
└────────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴───────────────────────────────────┴────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────── Building Test ────────────────────────────────────────────────────────────────────────────
spack_env_deactivate_first/bb6f8295: Creating test directory: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295
spack_env_deactivate_first/bb6f8295: Creating the stage directory: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/stage
spack_env_deactivate_first/bb6f8295: Writing build script: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first_build.sh
──────────────────────────────────────────────────────────────────────────── Running Tests ────────────────────────────────────────────────────────────────────────────
Spawning 2 processes for processing builders
───────────────────────────────────────────────────────────────────────────── Iteration 1 ─────────────────────────────────────────────────────────────────────────────
spack_env_deactivate_first/bb6f8295 does not have any dependencies adding test to queue
spack_env_deactivate_first/bb6f8295: Current Working Directory : /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/stage
spack_env_deactivate_first/bb6f8295: Running Test via command: bash --norc --noprofile -eo pipefail spack_env_deactivate_first_build.sh
spack_env_deactivate_first/bb6f8295: Test completed in 3.870062 seconds
spack_env_deactivate_first/bb6f8295: Test completed with returncode: 0
spack_env_deactivate_first/bb6f8295: Writing output file -  /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first.out
spack_env_deactivate_first/bb6f8295: Writing error file - /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first.err
In this iteration we are going to run the following tests: [spack_env_deactivate_first/bb6f8295]
                                                           Test Summary                                                            
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                             ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_env_deactivate_first/bb6f8295 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 3.870062 │
└─────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_s9w5kx1s.log

Let’s take a look at the generated test, take note of the spack env deactivate command and order of commands. We run spack env create, followed by spack env deactivate and finally we activate the environment using spack env activate.

buildtest inspect query --testpath spack_env_deactivate_first
$ buildtest inspect query --testpath spack_env_deactivate_first 
─────────────────────────────────────────────────── spack_env_deactivate_first/bb6f8295-ee09-4f6d-b164-5e6bf6bd4ae0 ───────────────────────────────────────────────────
Executor: generic.local.bash
Description: deactivate a spack environment first prior to activating it
State: PASS
Returncode: 0
Runtime: 3.870062 sec
Starttime: 2023/08/11 16:03:30
Endtime: 2023/08/11 16:03:34
Command: bash --norc --noprofile -eo pipefail spack_env_deactivate_first_build.sh
Test Script: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first.sh
Build Script: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first_build.sh
Output File: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first.out
Error File: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first.err
Log File: /home/spack/buildtest/var/logs/buildtest_s9w5kx1s.log
──────────────── Test File: /home/spack/runs/generic.local.bash/spack_env_deactivate/spack_env_deactivate_first/bb6f8295/spack_env_deactivate_first.sh ────────────────
#!/bin/bash                                                                                                                                                            
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                      
spack env create  -d /home/spack/spack-envs/m4                                                                                                                         
spack env deactivate                                                                                                                                                   
spack env activate  -d /home/spack/spack-envs/m4                                                                                                                       
spack add m4                                                                                                                                                           
spack install                                                                                                                                                          
                                                                                                                                                                       
                                                                                                                                                                       
######## START OF POST COMMANDS ########                                                                                                                               
spack find                                                                                                                                                             
rm -rf $HOME/spack-envs/m4                                                                                                                                             
                                                                                                                                                                       
######## END OF POST COMMANDS   ########

Removing Spack Environments

buildtest can remove spack environments which can be used if you are periodically running the same test where one is creating the same environment. buildtest can automatically remove spack environment using the property remove_environment which will remove the environment before creating it with same name. This field is part of the create field and only works if one is creating spack environments by name.

Alternately, buildtest provides the rm field which can be used for removing environment explicitly. In the rm field, the name is a required field which is the name of the spack environment to remove. The name field is of type: string Shown below are two example tests where we remove spack environment using the remove_environment and rm field.

buildspecs:
  remove_environment_automatically:
    type: spack
    executor: generic.local.bash
    description: "remove spack environment automatically before creating a new environment"
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        create:
          remove_environment: true
          name: remove_environment
        activate:
          name: remove_environment
        specs:
          - 'bzip2'
        concretize: true

  remove_environment_explicit:
    type: spack
    executor: generic.local.bash
    description: "remove spack environment explicitly using the 'rm' property"
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        rm:
          name: dummy
        create:
          name: dummy
        activate:
          name: dummy
        specs:
          - 'bzip2'
        concretize: true

Let’s build this by running the following

buildtest build -b /home/spack/buildtest/examples/spack/remove_environment_example.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/remove_environment_example.yml 
╭───────────────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────────────╮                                                                                           
│                                                                                                                                      │                                                                                           
│ User:               spack                                                                                                            │                                                                                           
│ Hostname:           0fee8530c3a4                                                                                                     │                                                                                           
│ Platform:           Linux                                                                                                            │                                                                                           
│ Current Time:       2023/07/14 18:46:31                                                                                              │                                                                                           
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                              │                                                                                           
│ buildtest version:  1.4                                                                                                              │                                                                                           
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                                          │                                                                                           
│ python version:     3.8.6                                                                                                            │                                                                                           
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                                     │                                                                                           
│ Test Directory:     /home/spack/runs                                                                                                 │                                                                                           
│ Report File:        /home/spack/buildtest/var/report.json                                                                            │                                                                                           
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/remove_environment_example.yml │                                                                                           
│                                                                                                                                      │                                                                                           
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                           
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                         Discovered buildspecs                         
╔═════════════════════════════════════════════════════════════════════╗
║ buildspec                                                           ║
╟─────────────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/remove_environment_example.yml ║
╚═════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/remove_environment_example.yml: VALID
Total builder objects created: 2
                                                                                                      Builders by type=spack                                                                                                       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                                   ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                                                  ┃ buildspecs                                                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ remove_environment_automatically/7258748c │ spack │ generic.local.bash │ None     │ None  │ None  │ remove spack environment automatically before creating a new │ /home/spack/buildtest/examples/spack/remove_environment_exa… │
│                                           │       │                    │          │       │       │ environment                                                  │                                                              │
├───────────────────────────────────────────┼───────┼────────────────────┼──────────┼───────┼───────┼──────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ remove_environment_explicit/b7f791e0      │ spack │ generic.local.bash │ None     │ None  │ None  │ remove spack environment explicitly using the 'rm' property  │ /home/spack/buildtest/examples/spack/remove_environment_exa… │
└───────────────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
remove_environment_automatically/7258748c: Creating test directory: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c
remove_environment_automatically/7258748c: Creating the stage directory: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/stage
remove_environment_automatically/7258748c: Writing build script: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically_build.sh
remove_environment_explicit/b7f791e0: Creating test directory: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0
remove_environment_explicit/b7f791e0: Creating the stage directory: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/stage
remove_environment_explicit/b7f791e0: Writing build script: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
remove_environment_explicit/b7f791e0 does not have any dependencies adding test to queue
remove_environment_automatically/7258748c does not have any dependencies adding test to queue
remove_environment_explicit/b7f791e0: Current Working Directory : /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/stage
remove_environment_automatically/7258748c: Current Working Directory : /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/stage
remove_environment_explicit/b7f791e0: Running Test via command: bash --norc --noprofile -eo pipefail remove_environment_explicit_build.sh
remove_environment_automatically/7258748c: Running Test via command: bash --norc --noprofile -eo pipefail remove_environment_automatically_build.sh
remove_environment_explicit/b7f791e0: Test completed in 2.372908 seconds
remove_environment_explicit/b7f791e0: Test completed with returncode: 0
remove_environment_explicit/b7f791e0: Writing output file -  /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit.out
remove_environment_explicit/b7f791e0: Writing error file - /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit.err
remove_environment_automatically/7258748c: Test completed in 2.384872 seconds
remove_environment_automatically/7258748c: Test completed with returncode: 0
remove_environment_automatically/7258748c: Writing output file -  /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically.out
remove_environment_automatically/7258748c: Writing error file - /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically.err
In this iteration we are going to run the following tests: [remove_environment_explicit/b7f791e0, remove_environment_automatically/7258748c]
                                                              Test Summary                                                               
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                                   ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ remove_environment_explicit/b7f791e0      │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 2.372908 │
├───────────────────────────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ remove_environment_automatically/7258748c │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 2.384872 │
└───────────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 2 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_80dhu3km.log

If we build and look at the generated te, we notice that spack will remove environments names: remove_environment, dummy.

buildtest inspect query -t remove_environment_automatically remove_environment_explicit
$ buildtest inspect query -t remove_environment_automatically remove_environment_explicit
────────────────────────────────────────────────────────────────────────────── remove_environment_automatically/7258748c-312f-4092-9773-0e48a17aed4a ──────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: remove spack environment automatically before creating a new environment
State: PASS
Returncode: 0
Runtime: 2.384872 sec
Starttime: 2023/07/14 18:46:31
Endtime: 2023/07/14 18:46:34
Command: bash --norc --noprofile -eo pipefail remove_environment_automatically_build.sh
Test Script: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically.sh
Build Script: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically_build.sh
Output File: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically.out
Error File: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically.err
Log File: /home/spack/buildtest/var/logs/buildtest_80dhu3km.log
───────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_automatically/7258748c/remove_environment_automatically.sh ─────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack env rm -y remove_environment                                                                                                                                                                                                 
spack env create  remove_environment                                                                                                                                                                                               
spack env activate  remove_environment                                                                                                                                                                                             
spack add bzip2                                                                                                                                                                                                                    
spack concretize -f                                                                                                                                                                                                                
──────────────────────────────────────────────────────────────────────────────── remove_environment_explicit/b7f791e0-e795-4ba1-9889-64e9e362e85f ─────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: remove spack environment explicitly using the 'rm' property
State: PASS
Returncode: 0
Runtime: 2.372908 sec
Starttime: 2023/07/14 18:46:31
Endtime: 2023/07/14 18:46:34
Command: bash --norc --noprofile -eo pipefail remove_environment_explicit_build.sh
Test Script: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit.sh
Build Script: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit_build.sh
Output File: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit.out
Error File: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit.err
Log File: /home/spack/buildtest/var/logs/buildtest_80dhu3km.log
────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/remove_environment_example/remove_environment_explicit/b7f791e0/remove_environment_explicit.sh ──────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack env rm -y dummy                                                                                                                                                                                                              
spack env create  dummy                                                                                                                                                                                                            
spack env activate  dummy                                                                                                                                                                                                          
spack add bzip2                                                                                                                                                                                                                    
spack concretize -f

Pre and Post Commands

The spack schema supports ability to write arbitrary shell script content using the pre_cmds and post_cmds field that are of type: string and buildtest will insert the content into the test exactly as it is defined by these two fields.

In this next example, we will test an installation of zlib by cloning spack from upstream and use pre_cmds field to specify where we will clone spack.

The pre_cmds are shell commands that are run before sourcing spack, whereas the post_cmds are run at the very end of the script. In the post_cmds, we will spack find that will be run after spack install. We remove spack root ($SPACK_ROOT) so that this test can be rerun again.

buildspecs:
  run_pre_post_commands:
    type: spack
    executor: generic.local.bash
    description: "Install zlib"
    tags: [spack]
    pre_cmds: |
      cat /etc/os-release
      gcc --version
    spack:
      root: $HOME/spack
      install:
        specs: ['zlib']
    post_cmds: |
      spack location -i gcc@6.5.0
      spack --version

If we build this test and inspect the generated script we should get the following result.

buildtest build -b /home/spack/buildtest/examples/spack/pre_post_cmds.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/pre_post_cmds.yml 
╭─────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────╮                                                                                                        
│                                                                                                                         │                                                                                                        
│ User:               spack                                                                                               │                                                                                                        
│ Hostname:           0fee8530c3a4                                                                                        │                                                                                                        
│ Platform:           Linux                                                                                               │                                                                                                        
│ Current Time:       2023/07/14 18:46:34                                                                                 │                                                                                                        
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                 │                                                                                                        
│ buildtest version:  1.4                                                                                                 │                                                                                                        
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                             │                                                                                                        
│ python version:     3.8.6                                                                                               │                                                                                                        
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                        │                                                                                                        
│ Test Directory:     /home/spack/runs                                                                                    │                                                                                                        
│ Report File:        /home/spack/buildtest/var/report.json                                                               │                                                                                                        
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/pre_post_cmds.yml │                                                                                                        
│                                                                                                                         │                                                                                                        
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                        
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                  Discovered buildspecs                   
╔════════════════════════════════════════════════════════╗
║ buildspec                                              ║
╟────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/pre_post_cmds.yml ║
╚════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/pre_post_cmds.yml: VALID
Total builder objects created: 1
                                                                      Builders by type=spack                                                                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                        ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description  ┃ buildspecs                                             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ run_pre_post_commands/63b3f722 │ spack │ generic.local.bash │ None     │ None  │ None  │ Install zlib │ /home/spack/buildtest/examples/spack/pre_post_cmds.yml │
└────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────┴────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
run_pre_post_commands/63b3f722: Creating test directory: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722
run_pre_post_commands/63b3f722: Creating the stage directory: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/stage
run_pre_post_commands/63b3f722: Writing build script: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
run_pre_post_commands/63b3f722 does not have any dependencies adding test to queue
run_pre_post_commands/63b3f722: Current Working Directory : /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/stage
run_pre_post_commands/63b3f722: Running Test via command: bash --norc --noprofile -eo pipefail run_pre_post_commands_build.sh
run_pre_post_commands/63b3f722: Test completed in 1.533831 seconds
run_pre_post_commands/63b3f722: Test completed with returncode: 0
run_pre_post_commands/63b3f722: Writing output file -  /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.out
run_pre_post_commands/63b3f722: Writing error file - /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.err
In this iteration we are going to run the following tests: [run_pre_post_commands/63b3f722]
                                                         Test Summary                                                         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                        ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ run_pre_post_commands/63b3f722 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 1.533831 │
└────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_6z4jki83.log
buildtest inspect query -o -t run_pre_post_commands
$ buildtest inspect query -o -t run_pre_post_commands
─────────────────────────────────────────────────────────────────────────────────── run_pre_post_commands/63b3f722-8c27-4fb3-bb70-64030167d3c0 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Install zlib
State: PASS
Returncode: 0
Runtime: 1.533831 sec
Starttime: 2023/07/14 18:46:34
Endtime: 2023/07/14 18:46:36
Command: bash --norc --noprofile -eo pipefail run_pre_post_commands_build.sh
Test Script: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.sh
Build Script: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands_build.sh
Output File: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.out
Error File: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.err
Log File: /home/spack/buildtest/var/logs/buildtest_6z4jki83.log
───────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.out ─────────────────────────────────────────────────────
NAME="Ubuntu"                                                                                                                                                                                                                      
VERSION="18.04.5 LTS (Bionic Beaver)"                                                                                                                                                                                              
ID=ubuntu                                                                                                                                                                                                                          
ID_LIKE=debian                                                                                                                                                                                                                     
PRETTY_NAME="Ubuntu 18.04.5 LTS"                                                                                                                                                                                                   
VERSION_ID="18.04"                                                                                                                                                                                                                 
HOME_URL="https://www.ubuntu.com/"                                                                                                                                                                                                 
SUPPORT_URL="https://help.ubuntu.com/"                                                                                                                                                                                             
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"                                                                                                                                                                                
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"                                                                                                                                                
VERSION_CODENAME=bionic                                                                                                                                                                                                            
UBUNTU_CODENAME=bionic                                                                                                                                                                                                             
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0                                                                                                                                                                                            
Copyright (C) 2017 Free Software Foundation, Inc.                                                                                                                                                                                  
This is free software; see the source for copying conditions.  There is NO                                                                                                                                                         
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                                                                                                                                        
[+] /home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/zlib-1.2.11-smoyzzo2qhzpn6mg6rd3l2p7b23enshg                                                                                                           
/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/gcc-6.5.0-ol37lodnsnyso6w7gkg5naw7m6kbltxu                                                                                                                 
0.16.3                                                                                                                                                                                                                             
                                                                                                                                                                                                                                   
────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/pre_post_cmds/run_pre_post_commands/63b3f722/run_pre_post_commands.sh ───────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
######## START OF PRE COMMANDS ########                                                                                                                                                                                            
cat /etc/os-release                                                                                                                                                                                                                
gcc --version                                                                                                                                                                                                                      
                                                                                                                                                                                                                                   
######## END OF PRE COMMANDS   ########                                                                                                                                                                                            
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack install  zlib                                                                                                                                                                                                                
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
######## START OF POST COMMANDS ########                                                                                                                                                                                           
spack location -i gcc@6.5.0                                                                                                                                                                                                        
spack --version                                                                                                                                                                                                                    
######## END OF POST COMMANDS   ########

Configuring Spack Mirrors

We can add mirrors in the spack instance or spack environment using the mirror property which is available in the spack and env section. If the mirrror property is part of the env section, the mirror will be added to spack environment. The mirror is an object that expects a Key/Value pair where the key is the name of mirror and value is location of the spack mirror.

In this next example, we will define a mirror name e4s that points to https://cache.e4s.io as the mirror location. Internally, this translates to spack mirror add e4s https://cache.e4s.io command.

buildspecs:
  add_mirror:
    type: spack
    executor: generic.local.bash
    description: Declare spack mirror
    tags: [spack]
    spack:
      root: $HOME/spack
      mirror:
        spack_tutorial_mirror: /mirror
    post_cmds: |
      spack mirror list
      spack config blame mirrors

  add_mirror_in_spack_env:
    type: spack
    executor: generic.local.bash
    description: Declare spack mirror in spack environment
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        create:
          name: spack_mirror
        activate:
          name: spack_mirror
        mirror:
          spack_tutorial_mirror: /mirror
    post_cmds: |
      spack mirror list
      spack config blame mirrors

This test can be built by running:

buildtest build -b $BUILDTEST_ROOT/examples/spack/mirror_example.yml

If we look at the generated script for both tests, we see that mirror is added for both tests. Note that one can have mirrors defined in their spack.yaml or one of the configuration scopes defined by spack.

buildtest inspect query -o -t add_mirror add_mirror_in_spack_env
$ buildtest inspect query -o  -t add_mirror add_mirror_in_spack_env
───────────────────────────────────────────────────────────────────────────────────────── add_mirror/5d67c243-2eaa-49d5-8ec9-c2c65c023bcc ─────────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Declare spack mirror
State: PASS
Returncode: 0
Runtime: 1.295348 sec
Starttime: 2023/07/14 18:46:37
Endtime: 2023/07/14 18:46:38
Command: bash --norc --noprofile -eo pipefail add_mirror_build.sh
Test Script: /home/spack/runs/generic.local.bash/mirror_example/add_mirror/5d67c243/add_mirror.sh
Build Script: /home/spack/runs/generic.local.bash/mirror_example/add_mirror/5d67c243/add_mirror_build.sh
Output File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror/5d67c243/add_mirror.out
Error File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror/5d67c243/add_mirror.err
Log File: /home/spack/buildtest/var/logs/buildtest_1jsp5fko.log
─────────────────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror/5d67c243/add_mirror.out ────────────────────────────────────────────────────────────────
spack_tutorial_mirror    file:///mirror                                                                                                                                                                                            
tutorial                 file:///mirror                                                                                                                                                                                            
spack-public             https://mirror.spack.io                                                                                                                                                                                   
---                                                  mirrors:                                                                                                                                                                      
/home/spack/.spack/mirrors.yaml:2                      spack_tutorial_mirror: file:///mirror                                                                                                                                       
/home/spack/.spack/mirrors.yaml:3                      tutorial: file:///mirror                                                                                                                                                    
/home/spack/spack/etc/spack/defaults/mirrors.yaml:2    spack-public: https://mirror.spack.io                                                                                                                                       
                                                                                                                                                                                                                                   
───────────────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror/5d67c243/add_mirror.sh ─────────────────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack mirror add spack_tutorial_mirror /mirror                                                                                                                                                                                     
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
######## START OF POST COMMANDS ########                                                                                                                                                                                           
spack mirror list                                                                                                                                                                                                                  
spack config blame mirrors                                                                                                                                                                                                         
                                                                                                                                                                                                                                   
######## END OF POST COMMANDS   ########                                                                                                                                                                                           
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
────────────────────────────────────────────────────────────────────────────────── add_mirror_in_spack_env/320eba7c-aa83-42df-a01d-29307fea40c4 ───────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Declare spack mirror in spack environment
State: PASS
Returncode: 0
Runtime: 2.10773 sec
Starttime: 2023/07/14 18:46:37
Endtime: 2023/07/14 18:46:39
Command: bash --norc --noprofile -eo pipefail add_mirror_in_spack_env_build.sh
Test Script: /home/spack/runs/generic.local.bash/mirror_example/add_mirror_in_spack_env/320eba7c/add_mirror_in_spack_env.sh
Build Script: /home/spack/runs/generic.local.bash/mirror_example/add_mirror_in_spack_env/320eba7c/add_mirror_in_spack_env_build.sh
Output File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror_in_spack_env/320eba7c/add_mirror_in_spack_env.out
Error File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror_in_spack_env/320eba7c/add_mirror_in_spack_env.err
Log File: /home/spack/buildtest/var/logs/buildtest_1jsp5fko.log
────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror_in_spack_env/320eba7c/add_mirror_in_spack_env.out ───────────────────────────────────────────────────
==> Updating view at /home/spack/spack/var/spack/environments/spack_mirror/.spack-env/view                                                                                                                                         
==> Created environment 'spack_mirror' in /home/spack/spack/var/spack/environments/spack_mirror                                                                                                                                    
==> You can activate this environment with:                                                                                                                                                                                        
==>   spack env activate spack_mirror                                                                                                                                                                                              
spack_tutorial_mirror    file:///mirror                                                                                                                                                                                            
tutorial                 file:///mirror                                                                                                                                                                                            
spack-public             https://mirror.spack.io                                                                                                                                                                                   
---                                                                  mirrors:                                                                                                                                                      
/home/spack/spack/var/spack/environments/spack_mirror/spack.yaml:10    spack_tutorial_mirror: file:///mirror                                                                                                                       
/home/spack/.spack/mirrors.yaml:3                                      tutorial: file:///mirror                                                                                                                                    
/home/spack/spack/etc/spack/defaults/mirrors.yaml:2                    spack-public: https://mirror.spack.io                                                                                                                       
                                                                                                                                                                                                                                   
──────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/mirror_example/add_mirror_in_spack_env/320eba7c/add_mirror_in_spack_env.sh ────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack env create  spack_mirror                                                                                                                                                                                                     
spack env activate  spack_mirror                                                                                                                                                                                                   
spack mirror add spack_tutorial_mirror /mirror                                                                                                                                                                                     
                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                   
######## START OF POST COMMANDS ########                                                                                                                                                                                           
spack mirror list                                                                                                                                                                                                                  
spack config blame mirrors                                                                                                                                                                                                         
######## END OF POST COMMANDS   ########

Spack Test

Note

spack test requires version 0.16.0 or higher in order to use this feature.

buildtest can run tests via spack test run that can be used for testing installed specs which comes with builtin tests by the spack framework. In order to use this feature, you need to declare the test section which is type: object in JSON and run is a required property. The run section maps to spack test run that is responsible for running tests for a list of specs that are specified using the specs property.

Upon running the tests, we can retrieve results using spack test results which is configured using the results property. The results property can query test results one of the following ways:

  1. Spec Format: spack test results -- <spec>

  2. Suitename: spack test results <suitename>

In example below, we will test m4 package by running spack test run m4 and specify the -l option (i.e spack test results -l) which will retrieve the test log.

buildspecs:
  spack_test_m4:
    type: spack
    executor: generic.local.bash
    description: "Run spack test for m4 package and report results"
    tags: [spack]
    spack:
      root: $HOME/spack
      test:
        run:
          specs: ['m4']
        results:
          option: "-l"

The spack test run –alias option is used to query results by suitename which can be used by spack test results command. buildtest will create a unique suite name for every run so you don’t have to remember the suite name when writing the buildspec.

buildtest build -b /home/spack/buildtest/examples/spack/spack_test.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/spack_test.yml 
╭───────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────╮                                                                                                           
│                                                                                                                      │                                                                                                           
│ User:               spack                                                                                            │                                                                                                           
│ Hostname:           0fee8530c3a4                                                                                     │                                                                                                           
│ Platform:           Linux                                                                                            │                                                                                                           
│ Current Time:       2023/07/14 18:46:40                                                                              │                                                                                                           
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                              │                                                                                                           
│ buildtest version:  1.4                                                                                              │                                                                                                           
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                          │                                                                                                           
│ python version:     3.8.6                                                                                            │                                                                                                           
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                     │                                                                                                           
│ Test Directory:     /home/spack/runs                                                                                 │                                                                                                           
│ Report File:        /home/spack/buildtest/var/report.json                                                            │                                                                                                           
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/spack_test.yml │                                                                                                           
│                                                                                                                      │                                                                                                           
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                           
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                 Discovered buildspecs                 
╔═════════════════════════════════════════════════════╗
║ buildspec                                           ║
╟─────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/spack_test.yml ║
╚═════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/spack_test.yml: VALID
Total builder objects created: 1
                                                                                  Builders by type=spack                                                                                   
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                                      ┃ buildspecs                                          ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_test_m4/10440e33 │ spack │ generic.local.bash │ None     │ None  │ None  │ Run spack test for m4 package and report results │ /home/spack/buildtest/examples/spack/spack_test.yml │
└────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────────────────────────────────────────┴─────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_test_m4/10440e33: Creating test directory: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33
spack_test_m4/10440e33: Creating the stage directory: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/stage
spack_test_m4/10440e33: Writing build script: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_test_m4/10440e33 does not have any dependencies adding test to queue
spack_test_m4/10440e33: Current Working Directory : /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/stage
spack_test_m4/10440e33: Running Test via command: bash --norc --noprofile -eo pipefail spack_test_m4_build.sh
spack_test_m4/10440e33: Test completed in 1.776058 seconds
spack_test_m4/10440e33: Test completed with returncode: 0
spack_test_m4/10440e33: Writing output file -  /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.out
spack_test_m4/10440e33: Writing error file - /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.err
In this iteration we are going to run the following tests: [spack_test_m4/10440e33]
                                                     Test Summary                                                     
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_test_m4/10440e33 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 1.776058 │
└────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_380_i89j.log

Take note of the generated test and the suite-name that is generated by buildtest.

buildtest inspect query -o -t spack_test_m4
$ buildtest inspect query -o -t spack_test_m4
─────────────────────────────────────────────────────────────────────────────────────── spack_test_m4/10440e33-ad42-4430-9573-c284a4a539bc ────────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Run spack test for m4 package and report results
State: PASS
Returncode: 0
Runtime: 1.776058 sec
Starttime: 2023/07/14 18:46:40
Endtime: 2023/07/14 18:46:42
Command: bash --norc --noprofile -eo pipefail spack_test_m4_build.sh
Test Script: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.sh
Build Script: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4_build.sh
Output File: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.out
Error File: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.err
Log File: /home/spack/buildtest/var/logs/buildtest_380_i89j.log
────────────────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.out ───────────────────────────────────────────────────────────────
==> Spack test 247ee4de-3d94-4142-a7d4-0e2d92f3833a                                                                                                                                                                                
==> Testing package m4-1.4.18-mkc3u4x                                                                                                                                                                                              
==> Results for test suite '247ee4de-3d94-4142-a7d4-0e2d92f3833a':                                                                                                                                                                 
==>   m4-1.4.18-mkc3u4x PASSED                                                                                                                                                                                                     
==> Testing package m4-1.4.18-mkc3u4x                                                                                                                                                                                              
==> [2023-07-14-18:46:41.834451] test: ensuring m4 version is 1.4.18                                                                                                                                                               
==> [2023-07-14-18:46:41.836393] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/m4-1.4.18-mkc3u4x2p2wie6jfhuku7g5rkovcrxps/bin/m4' '--version'                                                           
m4 (GNU M4) 1.4.18                                                                                                                                                                                                                 
Copyright (C) 2016 Free Software Foundation, Inc.                                                                                                                                                                                  
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.                                                                                                                                                     
This is free software: you are free to change and redistribute it.                                                                                                                                                                 
There is NO WARRANTY, to the extent permitted by law.                                                                                                                                                                              
Written by Rene' Seindal.                                                                                                                                                                                                          
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:41.844017] test: ensuring m4 example succeeds                                                                                                                                                                
==> [2023-07-14-18:46:41.844582] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/m4-1.4.18-mkc3u4x2p2wie6jfhuku7g5rkovcrxps/bin/m4' '/home/spack/.spack/test/im5u7c2e6xrqff67eb4cjwfmvpnlg2rd/m4-1.4.18-mk
// macro is defined                                                                                                                                                                                                                
Hello, World!                                                                                                                                                                                                                      
PASSED                                                                                                                                                                                                                             
                                                                                                                                                                                                                                   
──────────────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/spack_test/spack_test_m4/10440e33/spack_test_m4.sh ────────────────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack test run --alias 247ee4de-3d94-4142-a7d4-0e2d92f3833a m4                                                                                                                                                                     
spack test results -l 247ee4de-3d94-4142-a7d4-0e2d92f3833a

We can search for test results using the spec format instead of suite name. In the results property we can use specs field to specify a list of spec names to run. In spack, you can retrieve the results using spack test results -- <spec>, note that double dash -- is in front of spec name. We can pass options to spack test results using the option property which is available for results and run property. Currently, spack will write test results in $HOME/.spack/tests and we can use spack test remove to clear all test results. This can be done in buildspec using the remove_tests field which is a boolean. If this is set to True buildtest will run spack test remove -y to remove all test suites before running the tests.

In this next example, we will create a spack environment to install libxml2 and libsigsegv and test the package and report log after running test.

buildspecs:
  spack_test_results_specs_format:
    type: spack
    executor: generic.local.bash
    description: "Run spack test results with spec format"
    tags: [spack]
    spack:
      root: $HOME/spack
      env:
        create:
          name: spack_test_example
        activate:
          name: spack_test_example
      install:
        specs: ['libxml2', 'libsigsegv']
      test:
        remove_tests: true
        run:
          specs: ['libxml2', 'libsigsegv']
        results:
          option: '-l'
          specs: ['libxml2', 'libsigsegv']

We can build this test by running the following

buildtest build -b /home/spack/buildtest/examples/spack/spack_test_specs.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/spack_test_specs.yml 
╭──────────────────────────────────────────────────── buildtest summary ─────────────────────────────────────────────────────╮                                                                                                     
│                                                                                                                            │                                                                                                     
│ User:               spack                                                                                                  │                                                                                                     
│ Hostname:           0fee8530c3a4                                                                                           │                                                                                                     
│ Platform:           Linux                                                                                                  │                                                                                                     
│ Current Time:       2023/07/14 18:46:43                                                                                    │                                                                                                     
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                    │                                                                                                     
│ buildtest version:  1.4                                                                                                    │                                                                                                     
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                                │                                                                                                     
│ python version:     3.8.6                                                                                                  │                                                                                                     
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                           │                                                                                                     
│ Test Directory:     /home/spack/runs                                                                                       │                                                                                                     
│ Report File:        /home/spack/buildtest/var/report.json                                                                  │                                                                                                     
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/spack_test_specs.yml │                                                                                                     
│                                                                                                                            │                                                                                                     
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                     
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                    Discovered buildspecs                    
╔═══════════════════════════════════════════════════════════╗
║ buildspec                                                 ║
╟───────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/spack_test_specs.yml ║
╚═══════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/spack_test_specs.yml: VALID
Total builder objects created: 1
                                                                                          Builders by type=spack                                                                                          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                                  ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                             ┃ buildspecs                                                ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_test_results_specs_format/14270fab │ spack │ generic.local.bash │ None     │ None  │ None  │ Run spack test results with spec format │ /home/spack/buildtest/examples/spack/spack_test_specs.yml │
└──────────────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴─────────────────────────────────────────┴───────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_test_results_specs_format/14270fab: Creating test directory: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab
spack_test_results_specs_format/14270fab: Creating the stage directory: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/stage
spack_test_results_specs_format/14270fab: Writing build script: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_test_results_specs_format/14270fab does not have any dependencies adding test to queue
spack_test_results_specs_format/14270fab: Current Working Directory : /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/stage
spack_test_results_specs_format/14270fab: Running Test via command: bash --norc --noprofile -eo pipefail spack_test_results_specs_format_build.sh
spack_test_results_specs_format/14270fab: Test completed in 5.893645 seconds
spack_test_results_specs_format/14270fab: Test completed with returncode: 0
spack_test_results_specs_format/14270fab: Writing output file -  /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.out
spack_test_results_specs_format/14270fab: Writing error file - /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.err
In this iteration we are going to run the following tests: [spack_test_results_specs_format/14270fab]
                                                              Test Summary                                                              
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                                  ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_test_results_specs_format/14270fab │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 5.893645 │
└──────────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_zyoqo248.log

Now let’s check the generated test and output file, we see buildtest will install libxml2 and libsigsegv in spack environment followed by removing all testsuites using spack test remove -y and run the test. Note that we can query results in spec format (spack test results --l --libxml2) where spack will try to match a result file that matches the corresponding spec.

buildtest inspect query -o -t spack_test_results_specs_format
$ buildtest inspect query -o -t spack_test_results_specs_format
────────────────────────────────────────────────────────────────────────────── spack_test_results_specs_format/14270fab-4e5f-4e84-ad46-64ac869eeb80 ───────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Run spack test results with spec format
State: PASS
Returncode: 0
Runtime: 5.893645 sec
Starttime: 2023/07/14 18:46:43
Endtime: 2023/07/14 18:46:49
Command: bash --norc --noprofile -eo pipefail spack_test_results_specs_format_build.sh
Test Script: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.sh
Build Script: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format_build.sh
Output File: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.out
Error File: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.err
Log File: /home/spack/buildtest/var/logs/buildtest_zyoqo248.log
───────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.out ──────────────────────────────────────────
==> Updating view at /home/spack/spack/var/spack/environments/spack_test_example/.spack-env/view                                                                                                                                   
==> Created environment 'spack_test_example' in /home/spack/spack/var/spack/environments/spack_test_example                                                                                                                        
==> You can activate this environment with:                                                                                                                                                                                        
==>   spack env activate spack_test_example                                                                                                                                                                                        
==> All of the packages are already installed                                                                                                                                                                                      
==> All of the packages are already installed                                                                                                                                                                                      
==> Spack test 5a60603e-c10f-4381-bfc6-379902ea2cd2                                                                                                                                                                                
==> Testing package libxml2-2.9.10-yn2r3wf                                                                                                                                                                                         
==> Testing package libsigsegv-2.12-lbrx7ln                                                                                                                                                                                        
==> Results for test suite '5a60603e-c10f-4381-bfc6-379902ea2cd2', spec matching 'libxml2':                                                                                                                                        
==>   libxml2-2.9.10-yn2r3wf PASSED                                                                                                                                                                                                
==> Testing package libxml2-2.9.10-yn2r3wf                                                                                                                                                                                         
==> [2023-07-14-18:46:47.352925] test: Performing simple import test                                                                                                                                                               
==> [2023-07-14-18:46:47.354613] test: xml2-config: expect command status in [0]                                                                                                                                                   
==> [2023-07-14-18:46:47.354959] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libxml2-2.9.10-yn2r3wfhiilelyulh5toteicdtxjhw7d/bin/xml2-config' '--version'                                             
2.9.10                                                                                                                                                                                                                             
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:47.359961] test: xmllint: expect command status in [0]                                                                                                                                                       
==> [2023-07-14-18:46:47.360286] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libxml2-2.9.10-yn2r3wfhiilelyulh5toteicdtxjhw7d/bin/xmllint' '--auto' '-o' 'test.xml'                                    
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:47.372936] test: xmllint: expect command status in [3]                                                                                                                                                       
==> [2023-07-14-18:46:47.373315] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libxml2-2.9.10-yn2r3wfhiilelyulh5toteicdtxjhw7d/bin/xmllint' '--postvalid' 'test.xml'                                    
<?xml version="1.0"?>                                                                                                                                                                                                              
<info>abc</info>                                                                                                                                                                                                                   
validity error : no DTD found!                                                                                                                                                                                                     
Document test.xml does not validate                                                                                                                                                                                                
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:47.378796] test: xmllint: expect command status in [3]                                                                                                                                                       
==> [2023-07-14-18:46:47.379154] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libxml2-2.9.10-yn2r3wfhiilelyulh5toteicdtxjhw7d/bin/xmllint' '--dtdvalid' '/home/spack/.spack/test/xuxznm5pb453azff2waecm
<?xml version="1.0"?>                                                                                                                                                                                                              
<info>abc</info>                                                                                                                                                                                                                   
test.xml:2: element info: validity error : Element info content does not follow the DTD, expecting (data), got (CDATA)                                                                                                             
Document test.xml does not validate against /home/spack/.spack/test/xuxznm5pb453azff2waecmx6euyq5cq2/libxml2-2.9.10-yn2r3wf/data/libxml2/info.dtd                                                                                  
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:47.384176] test: xmllint: expect command status in [0]                                                                                                                                                       
==> [2023-07-14-18:46:47.384573] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libxml2-2.9.10-yn2r3wfhiilelyulh5toteicdtxjhw7d/bin/xmllint' '--dtdvalid' '/home/spack/.spack/test/xuxznm5pb453azff2waecm
<?xml version="1.0"?>                                                                                                                                                                                                              
<info>                                                                                                                                                                                                                             
<data>abc</data>                                                                                                                                                                                                                   
</info>                                                                                                                                                                                                                            
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:47.389354] test: xmlcatalog: expect command status in [0]                                                                                                                                                    
==> [2023-07-14-18:46:47.389757] '/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libxml2-2.9.10-yn2r3wfhiilelyulh5toteicdtxjhw7d/bin/xmlcatalog' '--create'                                               
<?xml version="1.0"?>                                                                                                                                                                                                              
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">                                                                             
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"/>                                                                                                                                                                     
PASSED                                                                                                                                                                                                                             
==> Results for test suite '5a60603e-c10f-4381-bfc6-379902ea2cd2', spec matching 'libsigsegv':                                                                                                                                     
==>   libsigsegv-2.12-lbrx7ln PASSED                                                                                                                                                                                               
==> Testing package libsigsegv-2.12-lbrx7ln                                                                                                                                                                                        
==> [2023-07-14-18:46:47.782506] test: checking ability to link to the library                                                                                                                                                     
==> [2023-07-14-18:46:47.783205] '/home/spack/spack/lib/spack/env/cc' '-I/home/spack/spack-workspace/software/linux-ubuntu18.04-x86_64/gcc-7.5.0/libsigsegv-2.12-lbrx7lnfz46ukewxbhxnucmx76g23c6q/include' '/home/spack/.spack/test
PASSED                                                                                                                                                                                                                             
==> [2023-07-14-18:46:47.969736] test: checking ability to use the library                                                                                                                                                         
==> [2023-07-14-18:46:47.970154] './smoke_test'                                                                                                                                                                                    
Caught sigsegv #1                                                                                                                                                                                                                  
Hello World!                                                                                                                                                                                                                       
PASSED                                                                                                                                                                                                                             
                                                                                                                                                                                                                                   
─────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/spack_test_specs/spack_test_results_specs_format/14270fab/spack_test_results_specs_format.sh ───────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack env create  spack_test_example                                                                                                                                                                                               
spack env activate  spack_test_example                                                                                                                                                                                             
spack install  libxml2                                                                                                                                                                                                             
spack install  libsigsegv                                                                                                                                                                                                          
spack test remove -y                                                                                                                                                                                                               
spack test run --alias 5a60603e-c10f-4381-bfc6-379902ea2cd2 libxml2 libsigsegv                                                                                                                                                     
spack test results -l -- libxml2                                                                                                                                                                                                   
spack test results -l -- libsigsegv

Specifying Scheduler Directives

The spack schema supports all of the scheduler scheduler directives such as sbatch, bsub, pbs, cobalt, and batch property in the buildspec.

The directives are applied at top of script. Shown below is a toy example that will define directives using sbatch property. Note, this test won’t submit job to scheduler since we are not using the a slurm executor.

buildspecs:
  spack_sbatch_example:
    type: spack
    executor: generic.local.bash
    description: "sbatch directives can be defined in spack schema"
    tags: [spack]
    sbatch: ["-N 1", "-n 8", "-t 30"]
    spack:
      root: $HOME/spack
      install:
        specs: ['zlib@1.2.11%clang', 'zlib@1.2.8%clang']

buildtest will generate the shell script with the job directives and set the name, output and error files based on name of test. If we build this test, and inspect the generated test we see that #SBATCH directives are written based on the sbatch field.

buildtest build -b /home/spack/buildtest/examples/spack/spack_sbatch.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/spack_sbatch.yml 
╭────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────╮                                                                                                         
│                                                                                                                        │                                                                                                         
│ User:               spack                                                                                              │                                                                                                         
│ Hostname:           0fee8530c3a4                                                                                       │                                                                                                         
│ Platform:           Linux                                                                                              │                                                                                                         
│ Current Time:       2023/07/14 18:46:50                                                                                │                                                                                                         
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                │                                                                                                         
│ buildtest version:  1.4                                                                                                │                                                                                                         
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                            │                                                                                                         
│ python version:     3.8.6                                                                                              │                                                                                                         
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                       │                                                                                                         
│ Test Directory:     /home/spack/runs                                                                                   │                                                                                                         
│ Report File:        /home/spack/buildtest/var/report.json                                                              │                                                                                                         
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/spack_sbatch.yml │                                                                                                         
│                                                                                                                        │                                                                                                         
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                         
─────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ─────────────────────────────────────────────────────────────────────────────────────────────────────
                  Discovered buildspecs                  
╔═══════════════════════════════════════════════════════╗
║ buildspec                                             ║
╟───────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/spack_sbatch.yml ║
╚═══════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
─────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/spack_sbatch.yml: VALID
Total builder objects created: 1
                                                                                       Builders by type=spack                                                                                       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                       ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                                      ┃ buildspecs                                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_sbatch_example/f86aa2f5 │ spack │ generic.local.bash │ None     │ None  │ None  │ sbatch directives can be defined in spack schema │ /home/spack/buildtest/examples/spack/spack_sbatch.yml │
└───────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴──────────────────────────────────────────────────┴───────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ──────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_sbatch_example/f86aa2f5: Creating test directory: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5
spack_sbatch_example/f86aa2f5: Creating the stage directory: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/stage
spack_sbatch_example/f86aa2f5: Writing build script: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example_build.sh
────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
─────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ───────────────────────────────────────────────────────────────────────────────────────────────────────────
spack_sbatch_example/f86aa2f5 does not have any dependencies adding test to queue
spack_sbatch_example/f86aa2f5: Current Working Directory : /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/stage
spack_sbatch_example/f86aa2f5: Running Test via command: bash --norc --noprofile -eo pipefail spack_sbatch_example_build.sh
spack_sbatch_example/f86aa2f5: Test completed in 3.825424 seconds
spack_sbatch_example/f86aa2f5: Test completed with returncode: 0
spack_sbatch_example/f86aa2f5: Writing output file -  /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example.out
spack_sbatch_example/f86aa2f5: Writing error file - /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example.err
In this iteration we are going to run the following tests: [spack_sbatch_example/f86aa2f5]
                                                        Test Summary                                                         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                       ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_sbatch_example/f86aa2f5 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 3.825424 │
└───────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_zp2e3f2p.log
buildtest inspect query -t spack_sbatch_example
$ buildtest inspect query -t spack_sbatch_example
──────────────────────────────────────────────────────────────────────────────────── spack_sbatch_example/f86aa2f5-b3fa-40e9-94d1-d7b1faf58c25 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: sbatch directives can be defined in spack schema
State: PASS
Returncode: 0
Runtime: 3.825424 sec
Starttime: 2023/07/14 18:46:50
Endtime: 2023/07/14 18:46:54
Command: bash --norc --noprofile -eo pipefail spack_sbatch_example_build.sh
Test Script: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example.sh
Build Script: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example_build.sh
Output File: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example.out
Error File: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example.err
Log File: /home/spack/buildtest/var/logs/buildtest_zp2e3f2p.log
──────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/spack_sbatch/spack_sbatch_example/f86aa2f5/spack_sbatch_example.sh ────────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                        
#SBATCH -N 1                                                                                                                                                                                                                       
#SBATCH -n 8                                                                                                                                                                                                                       
#SBATCH -t 30                                                                                                                                                                                                                      
#SBATCH --job-name=spack_sbatch_example                                                                                                                                                                                            
#SBATCH --output=spack_sbatch_example.out                                                                                                                                                                                          
#SBATCH --error=spack_sbatch_example.err                                                                                                                                                                                           
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                                                                                  
spack install  zlib@1.2.11%clang                                                                                                                                                                                                   
spack install  zlib@1.2.8%clang

You can define multiple executors in your buildspec with spack schema via executors. This can be useful if you need to specify different scheduler directives based on executor type since your executor will map to a queue.

Shown below is an example buildspec that will specify sbatch directives for generic.local.sh and generic.local.bash

buildspecs:
  spack_sbatch_multi_executors:
    type: spack
    executor: "generic.local.(sh|bash)"
    description: "sbatch directives can be defined in spack schema"
    tags: [spack]
    executors:
      generic.local.sh:
        sbatch: ["-N 1", "-t 30"]
      generic.local.bash:
        sbatch: ["-N 8", "-t 15"]
    spack:
      root: $HOME/spack
      test:
        run:
          specs: ['libsigsegv']
        results:
          specs: ['libsigsegv']
          option: "-l"

Cloning Spack

buildtest will automatically clone spack if root is not specified in the buildspec, which will be performed in the test directory where the test is executed. In example below have two tests, first one will clone spack automatically and second test will clone explicitly in /tmp where we specify root property.

buildspecs:
  clone_spack_automatically:
    type: spack
    executor: generic.local.bash
    description: "Clone spack automatically"
    tags: [ spack ]
    spack:
      env:
        create:
          name: 'spack-develop'
    post_cmds: |
      spack env list
      which spack

  clone_spack_and_specify_root:
    type: spack
    executor: generic.local.bash
    description: Clone spack explicitly and specify root
    tags: [ spack ]
    pre_cmds: git clone -b e4s-23.05 https://github.com/spack/spack.git /tmp/spack-demo
    spack:
      root: /tmp/spack-demo
      env:
        create:
          name: 'e4s'
    post_cmds: |
      spack env list
      which spack

Let’s build the following test

buildtest build -b /home/spack/buildtest/examples/spack/spack_clone.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/clone_spack.yml 
╭────────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────╮                                                                                                               
│                                                                                                                       │                                                                                                               
│ User:               spack                                                                                             │                                                                                                               
│ Hostname:           6f06e7949c52                                                                                      │                                                                                                               
│ Platform:           Linux                                                                                             │                                                                                                               
│ Current Time:       2023/07/21 13:32:57                                                                               │                                                                                                               
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                               │                                                                                                               
│ buildtest version:  1.4                                                                                               │                                                                                                               
│ python path:        /home/spack/pyenv/buildtest/bin/python3                                                           │                                                                                                               
│ python version:     3.8.6                                                                                             │                                                                                                               
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                      │                                                                                                               
│ Test Directory:     /home/spack/runs                                                                                  │                                                                                                               
│ Report File:        /home/spack/buildtest/var/report.json                                                             │                                                                                                               
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/clone_spack.yml │                                                                                                               
│                                                                                                                       │                                                                                                               
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                                                               
───────────────────────────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ────────────────────────────────────────────────────────────────────────────────────────────────────────
                 Discovered buildspecs                  
╔══════════════════════════════════════════════════════╗
║ buildspec                                            ║
╟──────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/clone_spack.yml ║
╚══════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ──────────────────────────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/clone_spack.yml: VALID
Total builder objects created: 2
                                                                                      Builders by type=spack                                                                                      
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                               ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                             ┃ buildspecs                                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ clone_spack_automatically/32829f81    │ spack │ generic.local.bash │ None     │ None  │ None  │ Clone spack automatically               │ /home/spack/buildtest/examples/spack/clone_spack.yml │
├───────────────────────────────────────┼───────┼────────────────────┼──────────┼───────┼───────┼─────────────────────────────────────────┼──────────────────────────────────────────────────────┤
│ clone_spack_and_specify_root/7c8764bd │ spack │ generic.local.bash │ None     │ None  │ None  │ Clone spack explicitly and specify root │ /home/spack/buildtest/examples/spack/clone_spack.yml │
└───────────────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴─────────────────────────────────────────┴──────────────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────────────────────────── Building Test ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
clone_spack_automatically/32829f81: Creating test directory: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81
clone_spack_automatically/32829f81: Creating the stage directory: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/stage
clone_spack_automatically/32829f81: Writing build script: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically_build.sh
clone_spack_and_specify_root/7c8764bd: Creating test directory: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd
clone_spack_and_specify_root/7c8764bd: Creating the stage directory: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/stage
clone_spack_and_specify_root/7c8764bd: Writing build script: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root_build.sh
──────────────────────────────────────────────────────────────────────────────────────────────────────────── Running Tests ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
Spawning 4 processes for processing builders
───────────────────────────────────────────────────────────────────────────────────────────────────────────── Iteration 1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
clone_spack_and_specify_root/7c8764bd does not have any dependencies adding test to queue
clone_spack_automatically/32829f81 does not have any dependencies adding test to queue
clone_spack_and_specify_root/7c8764bd: Current Working Directory : /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/stage
clone_spack_automatically/32829f81: Current Working Directory : /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/stage
clone_spack_and_specify_root/7c8764bd: Running Test via command: bash --norc --noprofile -eo pipefail clone_spack_and_specify_root_build.sh
clone_spack_automatically/32829f81: Running Test via command: bash --norc --noprofile -eo pipefail clone_spack_automatically_build.sh
clone_spack_and_specify_root/7c8764bd: Test completed in 3.636492 seconds
clone_spack_and_specify_root/7c8764bd: Test completed with returncode: 0
clone_spack_and_specify_root/7c8764bd: Writing output file -  /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.out
clone_spack_and_specify_root/7c8764bd: Writing error file - /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.err
clone_spack_automatically/32829f81: Test completed in 32.998718 seconds
clone_spack_automatically/32829f81: Test completed with returncode: 0
clone_spack_automatically/32829f81: Writing output file -  /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.out
clone_spack_automatically/32829f81: Writing error file - /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.err
In this iteration we are going to run the following tests: [clone_spack_and_specify_root/7c8764bd, clone_spack_automatically/32829f81]
                                                             Test Summary                                                             
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ builder                               ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ clone_spack_automatically/32829f81    │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 32.998718 │
├───────────────────────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼───────────┤
│ clone_spack_and_specify_root/7c8764bd │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 3.636492  │
└───────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴───────────┘



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


Adding 2 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_vfshvbrm.log

Let’s check the generated output, take note in the output the full path to where spack binary is present in each test. You must clone spack in pre_cmds in second test in order for buildtest to find the spack binary since you need to specify this the root property in-order for buildtest to install spack in the environment.

buildtest inspect query -t clone_spack_automatically clone_spack_and_specify_root
$ buildtest inspect query -o -t clone_spack_automatically clone_spack_and_specify_root
──────────────────────────────────────────────────────────────────────────────────── clone_spack_automatically/32829f81-0acc-4d11-bb99-e77bb01e37c7 ────────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Clone spack automatically
State: PASS
Returncode: 0
Runtime: 32.998718 sec
Starttime: 2023/07/21 13:32:57
Endtime: 2023/07/21 13:33:30
Command: bash --norc --noprofile -eo pipefail clone_spack_automatically_build.sh
Test Script: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.sh
Build Script: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically_build.sh
Output File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.out
Error File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.err
Log File: /home/spack/buildtest/var/logs/buildtest_vfshvbrm.log
──────────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.out ─────────────────────────────────────────────────────
==> Created environment 'spack-develop' in /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/stage/spack/var/spack/environments/spack-develop                                                          
==> You can activate this environment with:                                                                                                                                                                                             
==>   spack env activate spack-develop                                                                                                                                                                                                  
    spack-develop                                                                                                                                                                                                                       
/home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/stage/spack/bin/spack                                                                                                                                
                                                                                                                                                                                                                                        
────────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_automatically/32829f81/clone_spack_automatically.sh ──────────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                             
git clone https://github.com/spack/spack                                                                                                                                                                                                
source ./spack/share/spack/setup-env.sh                                                                                                                                                                                                 
spack env create  spack-develop                                                                                                                                                                                                         
                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                        
######## START OF POST COMMANDS ########                                                                                                                                                                                                
spack env list                                                                                                                                                                                                                          
which spack                                                                                                                                                                                                                             
                                                                                                                                                                                                                                        
######## END OF POST COMMANDS   ########                                                                                                                                                                                                
                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                        
────────────────────────────────────────────────────────────────────────────────── clone_spack_and_specify_root/7c8764bd-ec84-4e24-87c0-8732e1b34193 ───────────────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Clone spack explicitly and specify root
State: PASS
Returncode: 0
Runtime: 3.636492 sec
Starttime: 2023/07/21 13:32:57
Endtime: 2023/07/21 13:33:01
Command: bash --norc --noprofile -eo pipefail clone_spack_and_specify_root_build.sh
Test Script: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.sh
Build Script: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root_build.sh
Output File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.out
Error File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.err
Log File: /home/spack/buildtest/var/logs/buildtest_vfshvbrm.log
───────────────────────────────────────────────── Output File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.out ──────────────────────────────────────────────────
    e4s                                                                                                                                                                                                                                 
/tmp/spack-demo/bin/spack                                                                                                                                                                                                               
                                                                                                                                                                                                                                        
─────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/clone_spack/clone_spack_and_specify_root/7c8764bd/clone_spack_and_specify_root.sh ───────────────────────────────────────────────────
#!/bin/bash                                                                                                                                                                                                                             
                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                        
######## START OF PRE COMMANDS ########                                                                                                                                                                                                 
git clone -b e4s-23.05 https://github.com/spack/spack.git /tmp/spack-demo                                                                                                                                                               
######## END OF PRE COMMANDS   ########                                                                                                                                                                                                 
                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                        
source /tmp/spack-demo/share/spack/setup-env.sh                                                                                                                                                                                         
spack env create  e4s                                                                                                                                                                                                                   
                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                        
######## START OF POST COMMANDS ########                                                                                                                                                                                                
spack env list                                                                                                                                                                                                                          
which spack                                                                                                                                                                                                                             
######## END OF POST COMMANDS   ########

Loading Specs

We can load specs into our user environment via spack load which can be used for running tests or simply loading the package once it is installed. In this next example, we will test m4 package, where we load the package first prior to testing it. The load refers to spack load and options refers to command options passed to spack load command with a list of specs to load defined by specs property.

In this test, the command would translate to spack load --only package m4

buildspecs:
  spack_load_example:
    type: spack
    executor: generic.local.bash
    description: "Run spack load for m4 package and run tests"
    tags: [spack]
    spack:
      root: $HOME/spack
      load:
        options: '--only package'
        specs: [m4]
      test:
        run:
          specs: ['m4']
        results:
          option: "-l"

Let’s build this by running the following

buildtest build -b /home/spack/buildtest/examples/spack/spack_load.yml
$ buildtest build -b /home/spack/buildtest/examples/spack/spack_load.yml 
╭───────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────╮                                                    
│                                                                                                                      │                                                    
│ User:               spack                                                                                            │                                                    
│ Hostname:           b6f30f1b3d3f                                                                                     │                                                    
│ Platform:           Linux                                                                                            │                                                    
│ Current Time:       2023/08/08 18:10:42                                                                              │                                                    
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                              │                                                    
│ buildtest version:  1.5                                                                                              │                                                    
│ python path:        /home/spack/.pyenv/buildtest/bin/python3                                                         │                                                    
│ python version:     3.8.6                                                                                            │                                                    
│ Configuration File: /home/spack/buildtest/buildtest/settings/spack_container.yml                                     │                                                    
│ Test Directory:     /home/spack/runs                                                                                 │                                                    
│ Report File:        /home/spack/buildtest/var/report.json                                                            │                                                    
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/spack/spack_load.yml │                                                    
│                                                                                                                      │                                                    
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                    
─────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────
                 Discovered buildspecs                 
╔═════════════════════════════════════════════════════╗
║ buildspec                                           ║
╟─────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/spack/spack_load.yml ║
╚═════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
──────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/spack/spack_load.yml: VALID
Total builder objects created: 1
                                                                           Builders by type=spack                                                                           
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ builder                     ┃ type  ┃ executor           ┃ compiler ┃ nodes ┃ procs ┃ description                             ┃ buildspecs                               ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ spack_load_example/60d45649 │ spack │ generic.local.bash │ None     │ None  │ None  │ Run spack load for m4 package and run   │ /home/spack/buildtest/examples/spack/sp… │
│                             │       │                    │          │       │       │ tests                                   │                                          │
└─────────────────────────────┴───────┴────────────────────┴──────────┴───────┴───────┴─────────────────────────────────────────┴──────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────
spack_load_example/60d45649: Creating test directory: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649
spack_load_example/60d45649: Creating the stage directory: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/stage
spack_load_example/60d45649: Writing build script: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example_build.sh
────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────
Spawning 2 processes for processing builders
─────────────────────────────────────────────────────────────────────────────── Iteration 1 ────────────────────────────────────────────────────────────────────────────────
spack_load_example/60d45649 does not have any dependencies adding test to queue
spack_load_example/60d45649: Current Working Directory : /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/stage
spack_load_example/60d45649: Running Test via command: bash --norc --noprofile -eo pipefail spack_load_example_build.sh
spack_load_example/60d45649: Test completed in 2.911326 seconds
spack_load_example/60d45649: Test completed with returncode: 0
spack_load_example/60d45649: Writing output file -  /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example.out
spack_load_example/60d45649: Writing error file - /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example.err
In this iteration we are going to run the following tests: [spack_load_example/60d45649]
                                                       Test Summary                                                        
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ builder                     ┃ executor           ┃ status ┃ checks (ReturnCode, Regex, Runtime) ┃ returncode ┃ runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ spack_load_example/60d45649 │ generic.local.bash │ PASS   │ None None None                      │ 0          │ 2.911326 │
└─────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


Adding 1 test results to /home/spack/buildtest/var/report.json
Writing Logfile to: /home/spack/buildtest/var/logs/buildtest_hhrqf19o.log

Let’s take a look at the generated test, take note of the spack load command .. dropdown:: buildtest inspect query -t spack_load_example

$ buildtest inspect query -t spack_load_example
───────────────────────────────────────────────────────── spack_load_example/60d45649-5ee2-4efd-978b-58b7bafbc10d ──────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Run spack load for m4 package and run tests
State: PASS
Returncode: 0
Runtime: 2.911326 sec
Starttime: 2023/08/08 18:10:42
Endtime: 2023/08/08 18:10:45
Command: bash --norc --noprofile -eo pipefail spack_load_example_build.sh
Test Script: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example.sh
Build Script: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example_build.sh
Output File: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example.out
Error File: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example.err
Log File: /home/spack/buildtest/var/logs/buildtest_hhrqf19o.log
─────────────────────────────── Test File: /home/spack/runs/generic.local.bash/spack_load/spack_load_example/60d45649/spack_load_example.sh ────────────────────────────────
#!/bin/bash                                                                                                                                                                 
source /home/spack/spack/share/spack/setup-env.sh                                                                                                                           
spack load  m4                                                                                                                                                              
spack test run --alias 47fcdc7a-1994-4013-98c2-eba6d48e7103 m4                                                                                                              
spack test results -l 47fcdc7a-1994-4013-98c2-eba6d48e7103