Note

Please see Tutorials Setup before you proceed with this section

Compiler Schema

The compiler schema is used for compilation of programs, currently we support single source file compilation. In order to use the compiler schema you must set type: compiler in your test. For more details see compiler schema docs

We assume the reader has basic understanding of Global Schema validation. Shown below is the schema header definition for compiler-v1.0.schema.json:

{
  "$id": "compiler-v1.0.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "compiler schema version 1.0",
  "description": "The compiler schema is of ``type: compiler`` in sub-schema which is used for compiling and running programs",
  "type": "object",
  "required": [
    "type",
    "source",
    "compilers",
    "executor"
  ],

The required fields for compiler schema are type, compilers, source and executor.

First Example - Hello World

We will start out with compilation a Hello World program in Fortran using the GNU compiler. In this example we have a test called hello_f. The type: compiler is set to signify this test will be validated with compiler-v1.0.schema.json.

The source property is used to specify the source code to compile, this can be a relative path to buildspec file or an absolute path. In this example the source file src/hello.f90 is relative path to where buildspec file is located. The compilers section declares compiler configuration, the name property is required that is used to search compiler names from our buildtest configuration via regular expression. In this example we use the builtin_gcc compiler as regular expression which is the system gcc compiler provided by buildtest. The default section specifies default compiler configuration applicable to a specific compiler group like gcc. Within each compiler group we can specify options like cflags, fflags, cxxflags, ldflags to customize compilation line.

version: "1.0"
buildspecs:
  hello_f:
    type: compiler
    description: "Hello World Fortran Compilation"
    executor: generic.local.bash
    tags: [tutorials, compile]
    source: "src/hello.f90"
    compilers:
      name: ["^(builtin_gcc)$"]
      default:
        gcc:
          fflags: -Wall

Shown below is an example build for this test.

$ buildtest build -b /home/spack/buildtest/examples/compilers/gnu_hello_fortran.yml 
╭─────────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────────╮                                                          
│                                                                                                                                 │                                                          
│ User:               spack                                                                                                       │                                                          
│ Hostname:           2d93bd00cb98                                                                                                │                                                          
│ Platform:           Linux                                                                                                       │                                                          
│ Current Time:       2022/01/14 15:19:43                                                                                         │                                                          
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                         │                                                          
│ buildtest version:  0.12.0                                                                                                      │                                                          
│ 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                                                                                            │                                                          
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/compilers/gnu_hello_fortran.yml │                                                          
│                                                                                                                                 │                                                          
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                          
──────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────────────
Discovered Buildspecs:  1
Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
                      Discovered buildspecs                       
╔════════════════════════════════════════════════════════════════╗
║ Buildspecs                                                     ║
╟────────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/compilers/gnu_hello_fortran.yml ║
╚════════════════════════════════════════════════════════════════╝
──────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ─────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/compilers/gnu_hello_fortran.yml: VALID
Total builder objects created: 1
Total compiler builder: 1
Total script builder: 0
Total spack builder: 0
                                                                 Compiler Builder Details                                                                 
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder          ┃ Executor           ┃ Compiler    ┃ description                     ┃ buildspecs                                                     ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ hello_f/43c099a2 │ generic.local.bash │ builtin_gcc │ Hello World Fortran Compilation │ /home/spack/buildtest/examples/compilers/gnu_hello_fortran.yml │
└──────────────────┴────────────────────┴─────────────┴─────────────────────────────────┴────────────────────────────────────────────────────────────────┘
─────────────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────────────
hello_f/43c099a2: Creating test directory: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2
hello_f/43c099a2: Creating the stage directory: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/stage
hello_f/43c099a2: Writing build script: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/hello_f_build.sh
─────────────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────────────
______________________________
Launching test: hello_f/43c099a2
hello_f/43c099a2: Running Test via command: bash --norc --noprofile -eo pipefail
hello_f_build.sh
hello_f/43c099a2: Test completed with returncode: 0
hello_f/43c099a2: Test completed in 0.08557 seconds
hello_f/43c099a2: Writing output file -  /home/spack/runs/generic.local.bash/gnu
_hello_fortran/hello_f/43c099a2/hello_f.out
hello_f/43c099a2: Writing error file - /home/spack/runs/generic.local.bash/gnu_h
ello_fortran/hello_f/43c099a2/hello_f.err
                                                 Test Summary                                                  
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Builder          ┃ executor           ┃ status ┃ Checks (ReturnCode, Regex, Runtime) ┃ ReturnCode ┃ Runtime ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ hello_f/43c099a2 │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.08557 │
└──────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴─────────┘



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_6nyv90up.log

The generated test for test name hello_f is the following:

$ buildtest inspect query -t hello_f 
─────────────────────────────────────────────────────────────────────── hello_f/43c099a2-cee6-41e7-9906-488ae77a19b3 ────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Hello World Fortran Compilation
State: PASS
Returncode: 0
Runtime: 0.08557 sec
Starttime: 2022/01/14 15:19:43
Endtime: 2022/01/14 15:19:43
Command: bash --norc --noprofile -eo pipefail hello_f_build.sh
Test Script: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/hello_f.sh
Build Script: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/hello_f_build.sh
Output File: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/hello_f.out
Error File: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/hello_f.err
Log File: /home/spack/buildtest/var/logs/buildtest_6nyv90up.log
─────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/gnu_hello_fortran/hello_f/43c099a2/hello_f.sh ────────────────────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello.f90.exe                                                                                                                                                                     
   6 # Compilation Line                                                                                                                                                                      
   7 /usr/bin/gfortran -Wall -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello.f90                                                                                                
   8                                                                                                                                                                                         
   9                                                                                                                                                                                         
  10 # Run executable                                                                                                                                                                        
  11 ./$_EXEC                                                                                                                                                                                
  12                                                                                                                                                                                         
  13

How does compiler search work?

Compilers are defined in your configuration file that is used by buildtest to search compilers via name property when building test. In configuring compilers you will learn how one can define compiler, each compiler instance will have a unique name and be under one of the compiler groups like gcc, intel, cray, pgi, cuda, clang, etc…

You can see the compiler declaration from our configuration file by running buildtest config compilers -y which will display compiler settings in YAML format. Note that for each compiler instance one can define name of compiler and path to cc, fc, cxx wrapper. In addition one can specify module property to map compiler instance to modulefile. If module property is defined you can specify list of modules to load via load property and buildtest will automatically load these modules when using the compiler.

$ buildtest config compilers -y 
gcc:
  builtin_gcc:
    cc: /usr/bin/gcc
    cxx: /usr/bin/g++
    fc: /usr/bin/gfortran
  gcc_6.5.0:
    cc: gcc
    cxx: g++
    fc: gfortran
    module:
      load:
      - gcc/6.5.0-gcc-7.5.0
  gcc_8.3.0:
    cc: gcc
    cxx: g++
    fc: gfortran
    module:
      load:
      - gcc/8.3.0-gcc-7.5.0

How does buildtest detect programming language?

buildtest will detect the file extension of source file to detect programming language and generate the appropriate C, C++, or Fortran compilation line based on language detected. In this example, buildtest detects a .f90 file extension and determines this is a Fortran program.

Shown below is the file extension table buildtest uses for determining the programming language.

File Extension Language Mapping

Language

File Extension

C

.c

C++

.cc .cxx .cpp .c++

Fortran

.f90 .F90 .f95 .f .F .FOR .for .FTN .ftn

Compiler Selection

buildtest selects compiler based on name property which is a list of regular expression applied for available compilers defined in buildtest configuration. In this next example, we will compile an OpenACC code that will compute vector addition. We specify all gcc compilers are used for building this test via the name property. The -fopenacc compiler flag enables GNU compilers to compile OpenACC code, we can set this via fflags property. We can specify linker flags via ldflags during compilation, this code requires we specify -lm flag to link with math library.

version: "1.0"
buildspecs:
  vecadd_gnu:
    type: compiler
    description: Vector Addition example with GNU compiler
    tags: [tutorials, compile]
    executor: generic.local.bash
    source: src/vecAdd.c
    compilers:
      name: ["^(gcc)"]
      default:
        gcc:
          cflags: -fopenacc
          ldflags: -lm

We expect buildtest to select gcc_6.5.0 and gcc_8.3.0 compiler instance based on the regular expression. We can see there are two tests one for each compiler.

$ buildtest build -b /home/spack/buildtest/examples/compilers/vecadd.yml 
╭───────────────────────────────────────────────── buildtest summary ──────────────────────────────────────────────────╮                                                                     
│                                                                                                                      │                                                                     
│ User:               spack                                                                                            │                                                                     
│ Hostname:           2d93bd00cb98                                                                                     │                                                                     
│ Platform:           Linux                                                                                            │                                                                     
│ Current Time:       2022/01/14 15:19:47                                                                              │                                                                     
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                              │                                                                     
│ buildtest version:  0.12.0                                                                                           │                                                                     
│ 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                                                                                 │                                                                     
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/compilers/vecadd.yml │                                                                     
│                                                                                                                      │                                                                     
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                     
──────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────────────
Discovered Buildspecs:  1
Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
                 Discovered buildspecs                 
╔═════════════════════════════════════════════════════╗
║ Buildspecs                                          ║
╟─────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/compilers/vecadd.yml ║
╚═════════════════════════════════════════════════════╝
──────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ─────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/compilers/vecadd.yml: VALID
Total builder objects created: 2
Total compiler builder: 2
Total script builder: 0
Total spack builder: 0
                                                                 Compiler Builder Details                                                                 
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder             ┃ Executor           ┃ Compiler  ┃ description                               ┃ buildspecs                                          ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ vecadd_gnu/e9142f9a │ generic.local.bash │ gcc_6.5.0 │ Vector Addition example with GNU compiler │ /home/spack/buildtest/examples/compilers/vecadd.yml │
├─────────────────────┼────────────────────┼───────────┼───────────────────────────────────────────┼─────────────────────────────────────────────────────┤
│ vecadd_gnu/71246158 │ generic.local.bash │ gcc_8.3.0 │ Vector Addition example with GNU compiler │ /home/spack/buildtest/examples/compilers/vecadd.yml │
└─────────────────────┴────────────────────┴───────────┴───────────────────────────────────────────┴─────────────────────────────────────────────────────┘
─────────────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────────────
vecadd_gnu/e9142f9a: Creating test directory: /home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/e9142f9a
vecadd_gnu/e9142f9a: Creating the stage directory: /home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/e9142f9a/stage
vecadd_gnu/e9142f9a: Writing build script: /home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/e9142f9a/vecadd_gnu_build.sh
vecadd_gnu/71246158: Creating test directory: /home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/71246158
vecadd_gnu/71246158: Creating the stage directory: /home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/71246158/stage
vecadd_gnu/71246158: Writing build script: /home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/71246158/vecadd_gnu_build.sh
─────────────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────────────
______________________________
Launching test: vecadd_gnu/e9142f9a
______________________________
Launching test: vecadd_gnu/71246158
vecadd_gnu/e9142f9a: Running Test via command: bash --norc --noprofile -eo 
pipefail vecadd_gnu_build.sh
vecadd_gnu/71246158: Running Test via command: bash --norc --noprofile -eo 
pipefail vecadd_gnu_build.sh
vecadd_gnu/71246158: Test completed with returncode: 0
vecadd_gnu/71246158: Test completed in 0.132217 seconds
vecadd_gnu/71246158: Writing output file -  
/home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/71246158/vecadd_gnu.out
vecadd_gnu/71246158: Writing error file - 
/home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/71246158/vecadd_gnu.err
vecadd_gnu/e9142f9a: Test completed with returncode: 0
vecadd_gnu/e9142f9a: Test completed in 0.200467 seconds
vecadd_gnu/e9142f9a: Writing output file -  
/home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/e9142f9a/vecadd_gnu.out
vecadd_gnu/e9142f9a: Writing error file - 
/home/spack/runs/generic.local.bash/vecadd/vecadd_gnu/e9142f9a/vecadd_gnu.err
                                                   Test Summary                                                    
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Builder             ┃ executor           ┃ status ┃ Checks (ReturnCode, Regex, Runtime) ┃ ReturnCode ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ vecadd_gnu/71246158 │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.132217 │
├─────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ vecadd_gnu/e9142f9a │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.200467 │
└─────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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_qof2wcaa.log

Customize Compiler Option

We can specify custom compiler options per compiler instance using the config property. In this next example, we have a Hello World C example that will specify different cflags based on compiler name. We can specify default compiler setting via default property. In this example the default is -O1. The config section can be used to specify custom compiler options for each compiler name.

version: "1.0"
buildspecs:
  hello_c:
    type: compiler
    description: "Hello World C Compilation"
    executor: generic.local.bash
    tags: [tutorials, compile]
    source: "src/hello.c"
    compilers:
      name: ["^(builtin_gcc|gcc)"]
      default:
        gcc:
          cflags: -O1
      config:
        gcc_6.5.0:
          cflags: -O2
        gcc_8.3.0:
          cflags: -O3

Let’s build this test, we will see there is one builder instance for each compiler.

$ buildtest build -b /home/spack/buildtest/examples/compilers/gnu_hello_c.yml 
╭──────────────────────────────────────────────────── buildtest summary ────────────────────────────────────────────────────╮                                                                
│                                                                                                                           │                                                                
│ User:               spack                                                                                                 │                                                                
│ Hostname:           2d93bd00cb98                                                                                          │                                                                
│ Platform:           Linux                                                                                                 │                                                                
│ Current Time:       2022/01/14 15:19:49                                                                                   │                                                                
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                   │                                                                
│ buildtest version:  0.12.0                                                                                                │                                                                
│ 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                                                                                      │                                                                
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/compilers/gnu_hello_c.yml │                                                                
│                                                                                                                           │                                                                
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                
──────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────────────
Discovered Buildspecs:  1
Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
                   Discovered buildspecs                    
╔══════════════════════════════════════════════════════════╗
║ Buildspecs                                               ║
╟──────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/compilers/gnu_hello_c.yml ║
╚══════════════════════════════════════════════════════════╝
──────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ─────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/compilers/gnu_hello_c.yml: VALID
Total builder objects created: 3
Total compiler builder: 3
Total script builder: 0
Total spack builder: 0
                                                           Compiler Builder Details                                                           
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder          ┃ Executor           ┃ Compiler    ┃ description               ┃ buildspecs                                               ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ hello_c/3076d5ac │ generic.local.bash │ builtin_gcc │ Hello World C Compilation │ /home/spack/buildtest/examples/compilers/gnu_hello_c.yml │
├──────────────────┼────────────────────┼─────────────┼───────────────────────────┼──────────────────────────────────────────────────────────┤
│ hello_c/656a758f │ generic.local.bash │ gcc_6.5.0   │ Hello World C Compilation │ /home/spack/buildtest/examples/compilers/gnu_hello_c.yml │
├──────────────────┼────────────────────┼─────────────┼───────────────────────────┼──────────────────────────────────────────────────────────┤
│ hello_c/b1724443 │ generic.local.bash │ gcc_8.3.0   │ Hello World C Compilation │ /home/spack/buildtest/examples/compilers/gnu_hello_c.yml │
└──────────────────┴────────────────────┴─────────────┴───────────────────────────┴──────────────────────────────────────────────────────────┘
─────────────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────────────
hello_c/3076d5ac: Creating test directory: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac
hello_c/3076d5ac: Creating the stage directory: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/stage
hello_c/3076d5ac: Writing build script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c_build.sh
hello_c/656a758f: Creating test directory: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f
hello_c/656a758f: Creating the stage directory: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/stage
hello_c/656a758f: Writing build script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c_build.sh
hello_c/b1724443: Creating test directory: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443
hello_c/b1724443: Creating the stage directory: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/stage
hello_c/b1724443: Writing build script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c_build.sh
─────────────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────────────
______________________________
Launching test: hello_c/3076d5ac
______________________________
Launching test: hello_c/656a758f
______________________________
Launching test: hello_c/b1724443
hello_c/3076d5ac: Running Test via command: bash --norc --noprofile -eo pipefail
hello_c_build.sh
hello_c/656a758f: Running Test via command: bash --norc --noprofile -eo pipefail
hello_c_build.sh
hello_c/656a758f: Test completed with returncode: 0
hello_c/656a758f: Test completed in 0.091859 seconds
hello_c/656a758f: Writing output file -  
/home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c.out
hello_c/3076d5ac: Test completed with returncode: 0
hello_c/656a758f: Writing error file - 
/home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c.err
hello_c/3076d5ac: Test completed in 0.104387 seconds
hello_c/b1724443: Running Test via command: bash --norc --noprofile -eo pipefail
hello_c_build.sh
hello_c/3076d5ac: Writing output file -  
/home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c.out
hello_c/3076d5ac: Writing error file - 
/home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c.err
hello_c/b1724443: Test completed with returncode: 0
hello_c/b1724443: Test completed in 0.117283 seconds
hello_c/b1724443: Writing output file -  
/home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c.out
hello_c/b1724443: Writing error file - 
/home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c.err
                                                  Test Summary                                                  
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Builder          ┃ executor           ┃ status ┃ Checks (ReturnCode, Regex, Runtime) ┃ ReturnCode ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ hello_c/656a758f │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.091859 │
├──────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ hello_c/3076d5ac │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.104387 │
├──────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ hello_c/b1724443 │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.117283 │
└──────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


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

If we inspect the following test, we see each test has its own compiler flags. The default cflag is -O1 while gcc_6.5.0 will use -O2 and gcc_8.3.0 will use -O3.

$ buildtest inspect query -t hello_c/ 
─────────────────────────────────────────────────────────────────────── hello_c/3076d5ac-2695-4071-b01e-fd7ed83e2743 ────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Hello World C Compilation
State: PASS
Returncode: 0
Runtime: 0.104387 sec
Starttime: 2022/01/14 15:19:49
Endtime: 2022/01/14 15:19:50
Command: bash --norc --noprofile -eo pipefail hello_c_build.sh
Test Script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c.sh
Build Script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c_build.sh
Output File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c.out
Error File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c.err
Log File: /home/spack/buildtest/var/logs/buildtest_1i9u3ct1.log
────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/3076d5ac/hello_c.sh ───────────────────────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello.c.exe                                                                                                                                                                       
   6 # Compilation Line                                                                                                                                                                      
   7 /usr/bin/gcc -O1 -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello.c                                                                                                         
   8                                                                                                                                                                                         
   9                                                                                                                                                                                         
  10 # Run executable                                                                                                                                                                        
  11 ./$_EXEC                                                                                                                                                                                
  12                                                                                                                                                                                         
  13                                                                                                                                                                                         
─────────────────────────────────────────────────────────────────────── hello_c/b1724443-2a3b-4e2c-bfca-7587c7b27701 ────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Hello World C Compilation
State: PASS
Returncode: 0
Runtime: 0.117283 sec
Starttime: 2022/01/14 15:19:50
Endtime: 2022/01/14 15:19:50
Command: bash --norc --noprofile -eo pipefail hello_c_build.sh
Test Script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c.sh
Build Script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c_build.sh
Output File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c.out
Error File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c.err
Log File: /home/spack/buildtest/var/logs/buildtest_1i9u3ct1.log
────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/b1724443/hello_c.sh ───────────────────────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello.c.exe                                                                                                                                                                       
   6 # Loading modules                                                                                                                                                                       
   7 module load gcc/8.3.0-gcc-7.5.0                                                                                                                                                         
   8 # Compilation Line                                                                                                                                                                      
   9 gcc -O3 -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello.c                                                                                                                  
  10                                                                                                                                                                                         
  11                                                                                                                                                                                         
  12 # Run executable                                                                                                                                                                        
  13 ./$_EXEC                                                                                                                                                                                
  14                                                                                                                                                                                         
  15                                                                                                                                                                                         
─────────────────────────────────────────────────────────────────────── hello_c/656a758f-3ac2-4dc4-b4c3-8886f1ab436a ────────────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Hello World C Compilation
State: PASS
Returncode: 0
Runtime: 0.091859 sec
Starttime: 2022/01/14 15:19:49
Endtime: 2022/01/14 15:19:50
Command: bash --norc --noprofile -eo pipefail hello_c_build.sh
Test Script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c.sh
Build Script: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c_build.sh
Output File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c.out
Error File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c.err
Log File: /home/spack/buildtest/var/logs/buildtest_1i9u3ct1.log
────────────────────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/gnu_hello_c/hello_c/656a758f/hello_c.sh ───────────────────────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello.c.exe                                                                                                                                                                       
   6 # Loading modules                                                                                                                                                                       
   7 module load gcc/6.5.0-gcc-7.5.0                                                                                                                                                         
   8 # Compilation Line                                                                                                                                                                      
   9 gcc -O2 -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello.c                                                                                                                  
  10                                                                                                                                                                                         
  11                                                                                                                                                                                         
  12 # Run executable                                                                                                                                                                        
  13 ./$_EXEC                                                                                                                                                                                
  14                                                                                                                                                                                         
  15

Excluding Compilers

The exclude property allows one to exclude compilers upon discovery which is a list of compiler names that will be removed prior to building test. buildtest will exclude any compilers if they were found based on regular expression via name property. In this next example, we will exclude gcc_6.5.0 compiler from building

version: "1.0"
buildspecs:
  vecadd_gnu_exclude:
    type: compiler
    description: Vector Addition example with GNU compilers but exclude gcc_6.5.0
    tags: [tutorials, compile]
    executor: generic.local.bash
    source: src/vecAdd.c
    compilers:
      name: ["^(gcc)"]
      exclude: [gcc_6.5.0]
      default:
        gcc:
          cflags: -fopenacc
          ldflags: -lm

Now if we run this test, we will notice that there is only one build for this test even though buildtest discovered both gcc_6.5.0 and gcc_8.3.0 compilers.

$ buildtest build -b /home/spack/buildtest/examples/compilers/compiler_exclude.yml 
╭────────────────────────────────────────────────────── buildtest summary ───────────────────────────────────────────────────────╮                                                           
│                                                                                                                                │                                                           
│ User:               spack                                                                                                      │                                                           
│ Hostname:           2d93bd00cb98                                                                                               │                                                           
│ Platform:           Linux                                                                                                      │                                                           
│ Current Time:       2022/01/14 15:19:52                                                                                        │                                                           
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                        │                                                           
│ buildtest version:  0.12.0                                                                                                     │                                                           
│ 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                                                                                           │                                                           
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/compilers/compiler_exclude.yml │                                                           
│                                                                                                                                │                                                           
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                           
──────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────────────
Discovered Buildspecs:  1
Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
                      Discovered buildspecs                      
╔═══════════════════════════════════════════════════════════════╗
║ Buildspecs                                                    ║
╟───────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/compilers/compiler_exclude.yml ║
╚═══════════════════════════════════════════════════════════════╝
──────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ─────────────────────────────────────────────────────────────────────────────────────
Excluding compiler: gcc_6.5.0 from test generation
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/compilers/compiler_exclude.yml: VALID
Total builder objects created: 1
Total compiler builder: 1
Total script builder: 0
Total spack builder: 0
                                                                                  Compiler Builder Details                                                                                   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                     ┃ Executor           ┃ Compiler  ┃ description                                                 ┃ buildspecs                                                   ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ vecadd_gnu_exclude/35b3d402 │ generic.local.bash │ gcc_8.3.0 │ Vector Addition example with GNU compilers but exclude      │ /home/spack/buildtest/examples/compilers/compiler_exclude.ym │
│                             │                    │           │ gcc_6.5.0                                                   │ l                                                            │
└─────────────────────────────┴────────────────────┴───────────┴─────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────┘
─────────────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────────────
vecadd_gnu_exclude/35b3d402: Creating test directory: /home/spack/runs/generic.local.bash/compiler_exclude/vecadd_gnu_exclude/35b3d402
vecadd_gnu_exclude/35b3d402: Creating the stage directory: /home/spack/runs/generic.local.bash/compiler_exclude/vecadd_gnu_exclude/35b3d402/stage
vecadd_gnu_exclude/35b3d402: Writing build script: /home/spack/runs/generic.local.bash/compiler_exclude/vecadd_gnu_exclude/35b3d402/vecadd_gnu_exclude_build.sh
─────────────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────────────
______________________________
Launching test: vecadd_gnu_exclude/35b3d402
vecadd_gnu_exclude/35b3d402: Running Test via command: bash --norc --noprofile 
-eo pipefail vecadd_gnu_exclude_build.sh
vecadd_gnu_exclude/35b3d402: Test completed with returncode: 0
vecadd_gnu_exclude/35b3d402: Test completed in 0.089494 seconds
vecadd_gnu_exclude/35b3d402: Writing output file -  /home/spack/runs/generic.loc
al.bash/compiler_exclude/vecadd_gnu_exclude/35b3d402/vecadd_gnu_exclude.out
vecadd_gnu_exclude/35b3d402: Writing error file - /home/spack/runs/generic.local
.bash/compiler_exclude/vecadd_gnu_exclude/35b3d402/vecadd_gnu_exclude.err
                                                       Test Summary                                                        
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Builder                     ┃ executor           ┃ status ┃ Checks (ReturnCode, Regex, Runtime) ┃ ReturnCode ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ vecadd_gnu_exclude/35b3d402 │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.089494 │
└─────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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_69ekd9qy.log

Setting environment variables

We can define environment variables using env property which is a list of key/value pair where key is environment name and value is a string assigned to the environment. The env property can be used in default or config section within a compiler instance. In this next example we have an OpenMP Hello World example which defines environment variable OMP_NUM_THREADS that controls number of OpenMP threads to use when running program. In this example we will set OMP_NUM_THREADS=2

version: "1.0"
buildspecs:
  openmp_hello_c_example:
    type: compiler
    description: OpenMP Hello World C example
    executor: generic.local.bash
    tags: [tutorials, compile]
    source: "src/hello_omp.c"
    compilers:
      name: ["^(builtin_gcc)"]
      default:
        gcc:
          cflags: -fopenmp
          env:
            OMP_NUM_THREADS: 2

Now let’s build this test.

$ buildtest build -b /home/spack/buildtest/examples/compilers/openmp_hello.yml 
╭──────────────────────────────────────────────────── buildtest summary ─────────────────────────────────────────────────────╮                                                               
│                                                                                                                            │                                                               
│ User:               spack                                                                                                  │                                                               
│ Hostname:           2d93bd00cb98                                                                                           │                                                               
│ Platform:           Linux                                                                                                  │                                                               
│ Current Time:       2022/01/14 15:19:53                                                                                    │                                                               
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                    │                                                               
│ buildtest version:  0.12.0                                                                                                 │                                                               
│ 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                                                                                       │                                                               
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/compilers/openmp_hello.yml │                                                               
│                                                                                                                            │                                                               
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                               
──────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────────────
Discovered Buildspecs:  1
Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
                    Discovered buildspecs                    
╔═══════════════════════════════════════════════════════════╗
║ Buildspecs                                                ║
╟───────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/compilers/openmp_hello.yml ║
╚═══════════════════════════════════════════════════════════╝
──────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ─────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/compilers/openmp_hello.yml: VALID
Total builder objects created: 1
Total compiler builder: 1
Total script builder: 0
Total spack builder: 0
                                                                    Compiler Builder Details                                                                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                         ┃ Executor           ┃ Compiler    ┃ description                  ┃ buildspecs                                                ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ openmp_hello_c_example/d1ac8dfe │ generic.local.bash │ builtin_gcc │ OpenMP Hello World C example │ /home/spack/buildtest/examples/compilers/openmp_hello.yml │
└─────────────────────────────────┴────────────────────┴─────────────┴──────────────────────────────┴───────────────────────────────────────────────────────────┘
─────────────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────────────
openmp_hello_c_example/d1ac8dfe: Creating test directory: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe
openmp_hello_c_example/d1ac8dfe: Creating the stage directory: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/stage
openmp_hello_c_example/d1ac8dfe: Writing build script: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example_build.sh
─────────────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────────────
______________________________
Launching test: openmp_hello_c_example/d1ac8dfe
openmp_hello_c_example/d1ac8dfe: Running Test via command: bash --norc 
--noprofile -eo pipefail openmp_hello_c_example_build.sh
openmp_hello_c_example/d1ac8dfe: Test completed with returncode: 0
openmp_hello_c_example/d1ac8dfe: Test completed in 0.066246 seconds
openmp_hello_c_example/d1ac8dfe: Writing output file -  /home/spack/runs/generic
.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example.
out
openmp_hello_c_example/d1ac8dfe: Writing error file - /home/spack/runs/generic.l
ocal.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example.er
r
                                                         Test Summary                                                          
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Builder                         ┃ executor           ┃ status ┃ Checks (ReturnCode, Regex, Runtime) ┃ ReturnCode ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ openmp_hello_c_example/d1ac8dfe │ generic.local.bash │ PASS   │ N/A N/A N/A                         │ 0          │ 0.066246 │
└─────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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_3oilsl6g.log

We can see the generated test using buildtest inspect query given the name of test. Take a close look at the export OMP_NUM_THREADS in the generated test.

$ buildtest inspect query -t openmp_hello_c_example 
──────────────────────────────────────────────────────────────── openmp_hello_c_example/d1ac8dfe-47b3-4b14-ac84-b0ea7cf5ae5f ────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: OpenMP Hello World C example
State: PASS
Returncode: 0
Runtime: 0.066246 sec
Starttime: 2022/01/14 15:19:53
Endtime: 2022/01/14 15:19:53
Command: bash --norc --noprofile -eo pipefail openmp_hello_c_example_build.sh
Test Script: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example.sh
Build Script: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example_build.sh
Output File: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example.out
Error File: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example.err
Log File: /home/spack/buildtest/var/logs/buildtest_3oilsl6g.log
─────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/openmp_hello/openmp_hello_c_example/d1ac8dfe/openmp_hello_c_example.sh ───────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello_omp.c.exe                                                                                                                                                                   
   6 # Declare environment variables                                                                                                                                                         
   7 export OMP_NUM_THREADS=2                                                                                                                                                                
   8                                                                                                                                                                                         
   9                                                                                                                                                                                         
  10 # Compilation Line                                                                                                                                                                      
  11 /usr/bin/gcc -fopenmp -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello_omp.c                                                                                                
  12                                                                                                                                                                                         
  13                                                                                                                                                                                         
  14 # Run executable                                                                                                                                                                        
  15 ./$_EXEC                                                                                                                                                                                
  16                                                                                                                                                                                         
  17

We can define environment variables per compiler instance. buildtest will automatically override any key in defaults with one matched under config for the compiler name. In this next example, we will define OMP_NUM_THREADS to 4 for gcc_8.3.0 while the default is 2 for all gcc compilers.

version: "1.0"
buildspecs:
  override_environmentvars:
    type: compiler
    description: override default environment variables
    executor: generic.local.bash
    tags: [tutorials, compile]
    source: "src/hello_omp.c"
    compilers:
      name: ["^(builtin_gcc|gcc_8.3.0)"]
      default:
        gcc:
          cflags: -fopenmp
          env:
            OMP_NUM_THREADS: 2
      config:
        gcc_8.3.0:
          env:
            OMP_NUM_THREADS: 4

We can build this test by running:

buildtest build -b $BUILDTEST_ROOT/examples/compilers/envvar_override.yml

Next, let’s see the generated test by running buildtest inspect query -d all -t override_environmentvars. The -d all will display all test records for override_environmentvars. Take a note that we have export OMP_NUM_THREADS=4 for gcc_8.3.0 test and export OMP_NUM_THREADS=2 for system gcc.

$ buildtest inspect query -t override_environmentvars/ 
─────────────────────────────────────────────────────────────── override_environmentvars/040814b8-df41-4a25-8ec5-2d6af5a506f3 ───────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: override default environment variables
State: PASS
Returncode: 0
Runtime: 0.125883 sec
Starttime: 2022/01/14 15:19:56
Endtime: 2022/01/14 15:19:56
Command: bash --norc --noprofile -eo pipefail override_environmentvars_build.sh
Test Script: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/040814b8/override_environmentvars.sh
Build Script: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/040814b8/override_environmentvars_build.sh
Output File: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/040814b8/override_environmentvars.out
Error File: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/040814b8/override_environmentvars.err
Log File: /home/spack/buildtest/var/logs/buildtest_4edzfvng.log
─────────────────────────────── Test File: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/040814b8/override_environmentvars.sh ────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello_omp.c.exe                                                                                                                                                                   
   6 # Declare environment variables                                                                                                                                                         
   7 export OMP_NUM_THREADS=2                                                                                                                                                                
   8                                                                                                                                                                                         
   9                                                                                                                                                                                         
  10 # Compilation Line                                                                                                                                                                      
  11 /usr/bin/gcc -fopenmp -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello_omp.c                                                                                                
  12                                                                                                                                                                                         
  13                                                                                                                                                                                         
  14 # Run executable                                                                                                                                                                        
  15 ./$_EXEC                                                                                                                                                                                
  16                                                                                                                                                                                         
  17                                                                                                                                                                                         
─────────────────────────────────────────────────────────────── override_environmentvars/71b66eb2-69de-41ea-a8f0-3b55780db847 ───────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: override default environment variables
State: PASS
Returncode: 0
Runtime: 0.197309 sec
Starttime: 2022/01/14 15:19:56
Endtime: 2022/01/14 15:19:56
Command: bash --norc --noprofile -eo pipefail override_environmentvars_build.sh
Test Script: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/71b66eb2/override_environmentvars.sh
Build Script: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/71b66eb2/override_environmentvars_build.sh
Output File: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/71b66eb2/override_environmentvars.out
Error File: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/71b66eb2/override_environmentvars.err
Log File: /home/spack/buildtest/var/logs/buildtest_4edzfvng.log
─────────────────────────────── Test File: /home/spack/runs/generic.local.bash/envvar_override/override_environmentvars/71b66eb2/override_environmentvars.sh ────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello_omp.c.exe                                                                                                                                                                   
   6 # Declare environment variables                                                                                                                                                         
   7 export OMP_NUM_THREADS=4                                                                                                                                                                
   8                                                                                                                                                                                         
   9                                                                                                                                                                                         
  10 # Loading modules                                                                                                                                                                       
  11 module load gcc/8.3.0-gcc-7.5.0                                                                                                                                                         
  12 # Compilation Line                                                                                                                                                                      
  13 gcc -fopenmp -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello_omp.c                                                                                                         
  14                                                                                                                                                                                         
  15                                                                                                                                                                                         
  16 # Run executable                                                                                                                                                                        
  17 ./$_EXEC                                                                                                                                                                                
  18                                                                                                                                                                                         
  19

Tweak how test are passed

The status property is used to determine how buildtest will determine status of test (PASS/FAIL). By default, an exitcode 0 is a PASS and anything else is FAIL.

Sometimes, it may be useful check output of test to determine using regular expression. This can be done via regex property. In this example, we define two tests, the first one defines status property in the default gcc group. This means all compilers that belong to gcc group will be matched based on returncode.

In second test we override the status property for a given compiler instance under the config section. The test is expected to produce output of final result: 1.000000 but we will specify a different value in order to show this test will fail.

version: "1.0"
buildspecs:
  default_status_returncode:
    type: compiler
    description: status check based on returncode
    tags: [tutorials, compile]
    executor: generic.local.bash
    source: src/vecAdd.c
    compilers:
      name: ["^(gcc)"]
      default:
        gcc:
          cflags: -fopenacc
          ldflags: -lm
          status:
            returncode: 0

  override_status_regex:
    type: compiler
    description: override 'status' property in compiler gcc_8.3.0 instance
    tags: [tutorials, compile]
    executor: generic.local.bash
    source: src/vecAdd.c
    compilers:
      name: ["^(gcc)"]
      default:
        gcc:
          cflags: -fopenacc
          ldflags: -lm
          status:
            returncode: 1
      config:
        gcc_8.3.0:
          status:
            regex:
              stream: stdout
              exp: "^final result: 0.99$"

If we build this test, we should expect the first test example should pass based on returncode 0. If the returncode doesn’t match buildtest will report failure. For the second test example, we have have specified test will pass if we get a returncode 1 based on default property however for gcc_8.3.0 compiler test we have defined a status property to check based on regular expression. We will expect both tests to fail since we will have a mismatch on returncode and regular expression

$ buildtest build -b /home/spack/buildtest/examples/compilers/compiler_status_regex.yml 
╭───────────────────────────────────────────────────────── buildtest summary ─────────────────────────────────────────────────────────╮                                                      
│                                                                                                                                     │                                                      
│ User:               spack                                                                                                           │                                                      
│ Hostname:           2d93bd00cb98                                                                                                    │                                                      
│ Platform:           Linux                                                                                                           │                                                      
│ Current Time:       2022/01/14 15:19:58                                                                                             │                                                      
│ buildtest path:     /home/spack/buildtest/bin/buildtest                                                                             │                                                      
│ buildtest version:  0.12.0                                                                                                          │                                                      
│ 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                                                                                                │                                                      
│ Command:            /home/spack/buildtest/bin/buildtest build -b /home/spack/buildtest/examples/compilers/compiler_status_regex.yml │                                                      
│                                                                                                                                     │                                                      
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                      
──────────────────────────────────────────────────────────────────────────────────  Discovering Buildspecs ──────────────────────────────────────────────────────────────────────────────────
Discovered Buildspecs:  1
Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
                        Discovered buildspecs                         
╔════════════════════════════════════════════════════════════════════╗
║ Buildspecs                                                         ║
╟────────────────────────────────────────────────────────────────────╢
║ /home/spack/buildtest/examples/compilers/compiler_status_regex.yml ║
╚════════════════════════════════════════════════════════════════════╝
──────────────────────────────────────────────────────────────────────────────────── Parsing Buildspecs ─────────────────────────────────────────────────────────────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/spack/buildtest/examples/compilers/compiler_status_regex.yml: VALID
Total builder objects created: 4
Total compiler builder: 4
Total script builder: 0
Total spack builder: 0
                                                                                  Compiler Builder Details                                                                                   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                            ┃ Executor           ┃ Compiler  ┃ description                                              ┃ buildspecs                                               ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ default_status_returncode/9b80dfae │ generic.local.bash │ gcc_6.5.0 │ status check based on returncode                         │ /home/spack/buildtest/examples/compilers/compiler_status │
│                                    │                    │           │                                                          │ _regex.yml                                               │
├────────────────────────────────────┼────────────────────┼───────────┼──────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│ default_status_returncode/6892280f │ generic.local.bash │ gcc_8.3.0 │ status check based on returncode                         │ /home/spack/buildtest/examples/compilers/compiler_status │
│                                    │                    │           │                                                          │ _regex.yml                                               │
├────────────────────────────────────┼────────────────────┼───────────┼──────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│ override_status_regex/f7c2f371     │ generic.local.bash │ gcc_6.5.0 │ override 'status' property in compiler gcc_8.3.0         │ /home/spack/buildtest/examples/compilers/compiler_status │
│                                    │                    │           │ instance                                                 │ _regex.yml                                               │
├────────────────────────────────────┼────────────────────┼───────────┼──────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│ override_status_regex/48595f45     │ generic.local.bash │ gcc_8.3.0 │ override 'status' property in compiler gcc_8.3.0         │ /home/spack/buildtest/examples/compilers/compiler_status │
│                                    │                    │           │ instance                                                 │ _regex.yml                                               │
└────────────────────────────────────┴────────────────────┴───────────┴──────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────┘
─────────────────────────────────────────────────────────────────────────────────────── Building Test ───────────────────────────────────────────────────────────────────────────────────────
default_status_returncode/9b80dfae: Creating test directory: /home/spack/runs/generic.local.bash/compiler_status_regex/default_status_returncode/9b80dfae
default_status_returncode/9b80dfae: Creating the stage directory: /home/spack/runs/generic.local.bash/compiler_status_regex/default_status_returncode/9b80dfae/stage
default_status_returncode/9b80dfae: Writing build script: /home/spack/runs/generic.local.bash/compiler_status_regex/default_status_returncode/9b80dfae/default_status_returncode_build.sh
default_status_returncode/6892280f: Creating test directory: /home/spack/runs/generic.local.bash/compiler_status_regex/default_status_returncode/6892280f
default_status_returncode/6892280f: Creating the stage directory: /home/spack/runs/generic.local.bash/compiler_status_regex/default_status_returncode/6892280f/stage
default_status_returncode/6892280f: Writing build script: /home/spack/runs/generic.local.bash/compiler_status_regex/default_status_returncode/6892280f/default_status_returncode_build.sh
override_status_regex/f7c2f371: Creating test directory: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371
override_status_regex/f7c2f371: Creating the stage directory: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/stage
override_status_regex/f7c2f371: Writing build script: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_regex_build.sh
override_status_regex/48595f45: Creating test directory: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45
override_status_regex/48595f45: Creating the stage directory: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/stage
override_status_regex/48595f45: Writing build script: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_regex_build.sh
─────────────────────────────────────────────────────────────────────────────────────── Running Tests ───────────────────────────────────────────────────────────────────────────────────────
______________________________
Launching test: default_status_returncode/9b80dfae
______________________________
Launching test: default_status_returncode/6892280f
______________________________
Launching test: override_status_regex/f7c2f371
______________________________
Launching test: override_status_regex/48595f45
default_status_returncode/9b80dfae: Running Test via command: bash --norc 
--noprofile -eo pipefail default_status_returncode_build.sh
default_status_returncode/6892280f: Running Test via command: bash --norc 
--noprofile -eo pipefail default_status_returncode_build.sh
default_status_returncode/9b80dfae: Test completed with returncode: 0
default_status_returncode/9b80dfae: Test completed in 0.116155 seconds
default_status_returncode/9b80dfae: Writing output file -  /home/spack/runs/gene
ric.local.bash/compiler_status_regex/default_status_returncode/9b80dfae/default_
status_returncode.out
default_status_returncode/9b80dfae: Writing error file - /home/spack/runs/generi
c.local.bash/compiler_status_regex/default_status_returncode/9b80dfae/default_st
atus_returncode.err
default_status_returncode/9b80dfae: Checking returncode - 0 is matched in list 
[0]
override_status_regex/f7c2f371: Running Test via command: bash --norc 
--noprofile -eo pipefail override_status_regex_build.sh
default_status_returncode/6892280f: Test completed with returncode: 0
default_status_returncode/6892280f: Test completed in 0.154724 seconds
default_status_returncode/6892280f: Writing output file -  /home/spack/runs/gene
ric.local.bash/compiler_status_regex/default_status_returncode/6892280f/default_
status_returncode.out
default_status_returncode/6892280f: Writing error file - /home/spack/runs/generi
c.local.bash/compiler_status_regex/default_status_returncode/6892280f/default_st
atus_returncode.err
default_status_returncode/6892280f: Checking returncode - 0 is matched in list 
[0]
override_status_regex/48595f45: Running Test via command: bash --norc 
--noprofile -eo pipefail override_status_regex_build.sh
override_status_regex/f7c2f371: Test completed with returncode: 0
override_status_regex/f7c2f371: Test completed in 0.113728 seconds
override_status_regex/f7c2f371: Writing output file -  /home/spack/runs/generic.
local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_
regex.out
override_status_regex/f7c2f371: Writing error file - /home/spack/runs/generic.lo
cal.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_re
gex.err
override_status_regex/f7c2f371: Checking returncode - 0 is matched in list [1]
override_status_regex/48595f45: Test completed with returncode: 0
override_status_regex/48595f45: Test completed in 0.133577 seconds
override_status_regex/48595f45: Writing output file -  /home/spack/runs/generic.
local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_
regex.out
override_status_regex/48595f45: Writing error file - /home/spack/runs/generic.lo
cal.bash/compiler_status_regex/override_status_regex/48595f45/override_status_re
gex.err
override_status_regex/48595f45: performing regular expression - '^final result: 
0.99$' on file: /home/spack/runs/generic.local.bash/compiler_status_regex/overri
de_status_regex/48595f45/override_status_regex.out
override_status_regex/48595f45: Regular Expression Match - Failed!
                                                           Test Summary                                                           
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Builder                            ┃ executor           ┃ status ┃ Checks (ReturnCode, Regex, Runtime) ┃ ReturnCode ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ default_status_returncode/6892280f │ generic.local.bash │ PASS   │ True False False                    │ 0          │ 0.154724 │
├────────────────────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ override_status_regex/f7c2f371     │ generic.local.bash │ FAIL   │ False False False                   │ 0          │ 0.113728 │
├────────────────────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ override_status_regex/48595f45     │ generic.local.bash │ FAIL   │ False False False                   │ 0          │ 0.133577 │
├────────────────────────────────────┼────────────────────┼────────┼─────────────────────────────────────┼────────────┼──────────┤
│ default_status_returncode/9b80dfae │ generic.local.bash │ PASS   │ True False False                    │ 0          │ 0.116155 │
└────────────────────────────────────┴────────────────────┴────────┴─────────────────────────────────────┴────────────┴──────────┘



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


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

For the second test, we see the generated output is final result: 1.000000 but our regular expression has a different expected value therefore this test will fail even though we have a exitcode of 0.

$ buildtest inspect query -o override_status_regex/ 
──────────────────────────────────────────────────────────────── override_status_regex/f7c2f371-e1ad-4af3-b186-acb325fe7074 ─────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: override 'status' property in compiler gcc_8.3.0 instance
State: FAIL
Returncode: 0
Runtime: 0.113728 sec
Starttime: 2022/01/14 15:19:59
Endtime: 2022/01/14 15:19:59
Command: bash --norc --noprofile -eo pipefail override_status_regex_build.sh
Test Script: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_regex.sh
Build Script: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_regex_build.sh
Output File: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_regex.out
Error File: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_regex.err
Log File: /home/spack/buildtest/var/logs/buildtest_9fxu8v73.log
────────────────────────────── Output File: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/f7c2f371/override_status_regex.out ──────────────────────────────
final result: 1.000000                                                                                                                                                                       
                                                                                                                                                                                             
──────────────────────────────────────────────────────────────── override_status_regex/48595f45-2248-490c-a133-95a8d79a9e6d ─────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: override 'status' property in compiler gcc_8.3.0 instance
State: FAIL
Returncode: 0
Runtime: 0.133577 sec
Starttime: 2022/01/14 15:19:59
Endtime: 2022/01/14 15:19:59
Command: bash --norc --noprofile -eo pipefail override_status_regex_build.sh
Test Script: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_regex.sh
Build Script: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_regex_build.sh
Output File: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_regex.out
Error File: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_regex.err
Log File: /home/spack/buildtest/var/logs/buildtest_9fxu8v73.log
────────────────────────────── Output File: /home/spack/runs/generic.local.bash/compiler_status_regex/override_status_regex/48595f45/override_status_regex.out ──────────────────────────────
final result: 1.000000

Customize Run Line

buildtest will define variable _EXEC in the job script that can be used to reference the generated binary. By default, buildtest will run the program standalone, but sometimes you may want to customize how job is run. This may include passing arguments or running binary through a job/mpi launcher. The run property can be used to configure how program is executed. The compiled executable will be present in local directory which can be accessed via ./$_EXEC. In example below we pass arguments 1 3 for builtin_gcc compiler and 100 200 for gcc_8.3.0 compiler.

version: "1.0"
buildspecs:
  custom_run_by_compilers:
    type: compiler
    description: Customize binary launch based on compiler
    executor: generic.local.bash
    tags: [tutorials, compile]
    source: "src/argc.c"
    compilers:
      name: ["^(builtin_gcc|gcc_8.3.0)"]
      config:
        builtin_gcc:
          run: ./$_EXEC 1 3
        gcc_8.3.0:
          run: ./$_EXEC 100 120

You can build this test by running the following:

buildtest build -b $BUILDTEST_ROOT/examples/compilers/custom_run.yml

Once test is complete let’s inspect the generated test. We see that buildtest will insert the line specified by run property after compilation and run the executable.

$ buildtest inspect query -b  -t custom_run_by_compilers/ 
─────────────────────────────────────────────────────────────── custom_run_by_compilers/13a157e0-71c0-4202-b284-cca9e955f7ef ────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Customize binary launch based on compiler
State: PASS
Returncode: 0
Runtime: 0.103013 sec
Starttime: 2022/01/14 15:20:02
Endtime: 2022/01/14 15:20:02
Command: bash --norc --noprofile -eo pipefail custom_run_by_compilers_build.sh
Test Script: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/custom_run_by_compilers.sh
Build Script: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/custom_run_by_compilers_build.sh
Output File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/custom_run_by_compilers.out
Error File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/custom_run_by_compilers.err
Log File: /home/spack/buildtest/var/logs/buildtest_kxiijcd0.log
─────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/custom_run_by_compilers.sh ───────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=argc.c.exe                                                                                                                                                                        
   6 # Compilation Line                                                                                                                                                                      
   7 /usr/bin/gcc -o $_EXEC /home/spack/buildtest/examples/compilers/src/argc.c                                                                                                              
   8                                                                                                                                                                                         
   9                                                                                                                                                                                         
  10 # Run executable                                                                                                                                                                        
  11 ./$_EXEC 1 3                                                                                                                                                                            
  12                                                                                                                                                                                         
  13                                                                                                                                                                                         
──────────────────────────────── Test File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/custom_run_by_compilers_build.sh ────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 ############# START VARIABLE DECLARATION ########################                                                                                                                       
   5 export BUILDTEST_TEST_NAME=custom_run_by_compilers                                                                                                                                      
   6 export BUILDTEST_TEST_ROOT=/home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0                                                                              
   7 export BUILDTEST_BUILDSPEC_DIR=/home/spack/buildtest/examples/compilers                                                                                                                 
   8 export BUILDTEST_STAGE_DIR=/home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/stage                                                                        
   9 export BUILDTEST_TEST_ID=13a157e0-71c0-4202-b284-cca9e955f7ef                                                                                                                           
  10 ############# END VARIABLE DECLARATION   ########################                                                                                                                       
  11                                                                                                                                                                                         
  12                                                                                                                                                                                         
  13 # source executor startup script                                                                                                                                                        
  14 source /home/spack/buildtest/var/executor/generic.local.bash/before_script.sh                                                                                                           
  15 # Run generated script                                                                                                                                                                  
  16 /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/13a157e0/stage/custom_run_by_compilers.sh                                                                        
  17 # Get return code                                                                                                                                                                       
  18 returncode=$?                                                                                                                                                                           
  19 # Exit with return code                                                                                                                                                                 
  20 exit $returncode                                                                                                                                                                        
─────────────────────────────────────────────────────────────── custom_run_by_compilers/b9dc2afd-7d09-4e70-908a-4f80c5122605 ────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: Customize binary launch based on compiler
State: PASS
Returncode: 0
Runtime: 0.133681 sec
Starttime: 2022/01/14 15:20:02
Endtime: 2022/01/14 15:20:02
Command: bash --norc --noprofile -eo pipefail custom_run_by_compilers_build.sh
Test Script: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/custom_run_by_compilers.sh
Build Script: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/custom_run_by_compilers_build.sh
Output File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/custom_run_by_compilers.out
Error File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/custom_run_by_compilers.err
Log File: /home/spack/buildtest/var/logs/buildtest_kxiijcd0.log
─────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/custom_run_by_compilers.sh ───────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=argc.c.exe                                                                                                                                                                        
   6 # Loading modules                                                                                                                                                                       
   7 module load gcc/8.3.0-gcc-7.5.0                                                                                                                                                         
   8 # Compilation Line                                                                                                                                                                      
   9 gcc -o $_EXEC /home/spack/buildtest/examples/compilers/src/argc.c                                                                                                                       
  10                                                                                                                                                                                         
  11                                                                                                                                                                                         
  12 # Run executable                                                                                                                                                                        
  13 ./$_EXEC 100 120                                                                                                                                                                        
  14                                                                                                                                                                                         
  15                                                                                                                                                                                         
──────────────────────────────── Test File: /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/custom_run_by_compilers_build.sh ────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 ############# START VARIABLE DECLARATION ########################                                                                                                                       
   5 export BUILDTEST_TEST_NAME=custom_run_by_compilers                                                                                                                                      
   6 export BUILDTEST_TEST_ROOT=/home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd                                                                              
   7 export BUILDTEST_BUILDSPEC_DIR=/home/spack/buildtest/examples/compilers                                                                                                                 
   8 export BUILDTEST_STAGE_DIR=/home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/stage                                                                        
   9 export BUILDTEST_TEST_ID=b9dc2afd-7d09-4e70-908a-4f80c5122605                                                                                                                           
  10 ############# END VARIABLE DECLARATION   ########################                                                                                                                       
  11                                                                                                                                                                                         
  12                                                                                                                                                                                         
  13 # source executor startup script                                                                                                                                                        
  14 source /home/spack/buildtest/var/executor/generic.local.bash/before_script.sh                                                                                                           
  15 # Run generated script                                                                                                                                                                  
  16 /home/spack/runs/generic.local.bash/custom_run/custom_run_by_compilers/b9dc2afd/stage/custom_run_by_compilers.sh                                                                        
  17 # Get return code                                                                                                                                                                       
  18 returncode=$?                                                                                                                                                                           
  19 # Exit with return code                                                                                                                                                                 
  20 exit $returncode

Pre/Post sections for build and run section

We can specify arbitrary shell commands before/after compilation or running binary via pre_build, post_build, pre_run and post_run property. This can be useful if you want to specify additional commands required to compile or run executable that are not generated automatically

This next example illustrates how one can use these properties to have more control over the generated test.

version: "1.0"
buildspecs:
  pre_post_build_run:
    type: compiler
    description: example using pre_build, post_build, pre_run, post_run example
    executor: generic.local.bash
    tags: [tutorials, compile]
    source: "src/hello.c"
    compilers:
      name: ["^(builtin_gcc)$"]
      default:
        gcc:
          cflags: -Wall
          pre_build: |
            echo "These are commands run before compilation"
          post_build: |
            echo "These are commands run after compilation"
          pre_run: |
            echo "These are commands run before running script"
          post_run:
            echo "These are commands run after running script"

The format of the test structure is as follows.

#!{shebang path} -- defaults to #!/bin/bash depends on executor name (local.bash, local.sh)
{job directives} -- sbatch or bsub field
{environment variables} -- env field
{variable declaration} -- vars field
{module commands} -- modules field

{pre build commands} -- pre_build field
{compile program} -- build field
{post build commands} -- post_build field

{pre run commands} -- pre_run field
{run executable} -- run field
{post run commands} -- post_run field

You can run this example by running the following command:

buildtest build -b $BUILDTEST_ROOT/examples/compilers/pre_post_build_run.yml

If we inspect the content of test we see that buildtest will insert the shell commands for pre_build, post_build, pre_run and post_run in its corresponding section.

$ buildtest inspect query -t pre_post_build_run 
────────────────────────────────────────────────────────────────── pre_post_build_run/db0a08e4-6f04-44a3-be44-f48470efd7af ──────────────────────────────────────────────────────────────────
Executor: generic.local.bash
Description: example using pre_build, post_build, pre_run, post_run example
State: PASS
Returncode: 0
Runtime: 0.060395 sec
Starttime: 2022/01/14 15:20:05
Endtime: 2022/01/14 15:20:05
Command: bash --norc --noprofile -eo pipefail pre_post_build_run_build.sh
Test Script: /home/spack/runs/generic.local.bash/pre_post_build_run/pre_post_build_run/db0a08e4/pre_post_build_run.sh
Build Script: /home/spack/runs/generic.local.bash/pre_post_build_run/pre_post_build_run/db0a08e4/pre_post_build_run_build.sh
Output File: /home/spack/runs/generic.local.bash/pre_post_build_run/pre_post_build_run/db0a08e4/pre_post_build_run.out
Error File: /home/spack/runs/generic.local.bash/pre_post_build_run/pre_post_build_run/db0a08e4/pre_post_build_run.err
Log File: /home/spack/buildtest/var/logs/buildtest_29xg9s3k.log
──────────────────────────────────── Test File: /home/spack/runs/generic.local.bash/pre_post_build_run/pre_post_build_run/db0a08e4/pre_post_build_run.sh ────────────────────────────────────
   1 #!/bin/bash                                                                                                                                                                             
   2                                                                                                                                                                                         
   3                                                                                                                                                                                         
   4 # name of executable                                                                                                                                                                    
   5 _EXEC=hello.c.exe                                                                                                                                                                       
   6 ### START OF PRE BUILD SECTION ###                                                                                                                                                      
   7 echo "These are commands run before compilation"                                                                                                                                        
   8                                                                                                                                                                                         
   9 ### END OF PRE BUILD SECTION   ###                                                                                                                                                      
  10                                                                                                                                                                                         
  11                                                                                                                                                                                         
  12 # Compilation Line                                                                                                                                                                      
  13 /usr/bin/gcc -Wall -o $_EXEC /home/spack/buildtest/examples/compilers/src/hello.c                                                                                                       
  14                                                                                                                                                                                         
  15                                                                                                                                                                                         
  16 ### START OF POST BUILD SECTION ###                                                                                                                                                     
  17 echo "These are commands run after compilation"                                                                                                                                         
  18                                                                                                                                                                                         
  19 ### END OF POST BUILD SECTION ###                                                                                                                                                       
  20                                                                                                                                                                                         
  21                                                                                                                                                                                         
  22 ### START OF PRE RUN SECTION ###                                                                                                                                                        
  23 echo "These are commands run before running script"                                                                                                                                     
  24                                                                                                                                                                                         
  25 ### END OF PRE RUN SECTION   ###                                                                                                                                                        
  26                                                                                                                                                                                         
  27                                                                                                                                                                                         
  28 # Run executable                                                                                                                                                                        
  29 ./$_EXEC                                                                                                                                                                                
  30                                                                                                                                                                                         
  31                                                                                                                                                                                         
  32 ### START OF POST RUN SECTION ###                                                                                                                                                       
  33 echo "These are commands run after running script"                                                                                                                                      
  34 ### END OF POST RUN SECTION   ###                                                                                                                                                       
  35                                                                                                                                                                                         
  36