Comparison Operators

buildtest supports several comparison operators as part of status check such as >, >=, <=, <, ==, !=. Each metric is compared with a reference value that can be useful when running performance checks. In this section we will cover the following comparison:

assert_ge: Greater Equal

buildtest can determine status check based on performance check. In this next example, we will run the STREAM memory benchmark and capture metrics named copy, scale add and triad from the output and perform an Assertion Greater Equal (assert_ge) with a reference value.

The assert_ge contains a list of assertions in the comparisons property where each metric name is referenced via name that is compared with the reference value defined by ref property. The comparison is metric_value >= ref, where metric_value is the value assigned to the metric name captured by the regular expression. The type field in the metric section is used for the type conversion which can be float, int, or string. The item is a numeric field used in match.group to retrieve the output from the regular expression search. The item must be non-negative number.

buildspecs:
  stream_test:
    type: script
    executor: generic.local.bash
    description: Run stream test with metrics example using assert greater equal
    env:
      OMP_NUM_THREADS: 4
    run: |
      wget https://raw.githubusercontent.com/jeffhammond/STREAM/master/stream.c
      gcc -openmp -o stream stream.c
      ./stream
    metrics:
      copy:
        type: float
        regex:
          exp: 'Copy:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      scale:
        type: float
        regex:
          exp: 'Scale:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      add:
        type: float
        regex:
          exp: 'Add:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      triad:
        type: float
        regex:
          exp: 'Triad:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
    status:
      assert_ge:
        mode: and
        comparisons:
        - name: copy
          ref: 5000
        - name: scale
          ref: 5500
        - name: add
          ref: 6000
        - name: triad
          ref: 6500

buildtest will evaluate each assertion in the list and use a logical AND to determine the final status of assert_ge. The keyword mode is used to determine whether to perform a logical OR / AND operation when evaluating the final expression. The mode can be any of the values: [AND, OR, and, or]. If mode is ommitted the default is logical AND.

Let’s build this test, take a close look at the output of buildtest build and take note of the assertion statement.

buildtest build -b tutorials/perf_checks/assert_ge.yml
$ buildtest build -b tutorials/perf_checks/assert_ge.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:37:28                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/ ║
║ tutorials/perf_checks/assert_ge.yml                                          ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/tutorials/perf_checks/assert_ge.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ stream_t │ script │ generic. │ None     │ None  │ None  │ Run      │ /home/d │
│ est/206b │        │ local.ba │          │       │       │ stream   │ ocs/che │
│ c934     │        │ sh       │          │       │       │ test     │ ckouts/ │
│          │        │          │          │       │       │ with     │ readthe │
│          │        │          │          │       │       │ metrics  │ docs.or │
│          │        │          │          │       │       │ example  │ g/user_ │
│          │        │          │          │       │       │ using    │ builds/ │
│          │        │          │          │       │       │ assert   │ buildte │
│          │        │          │          │       │       │ greater  │ st/chec │
│          │        │          │          │       │       │ equal    │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ assert_ │
│          │        │          │          │       │       │          │ ge.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
stream_test/206bc934: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
stream_test/206bc934 does not have any dependencies adding test to queue
Builders Eligible to Run
┏━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder              ┃
┡━━━━━━━━━━━━━━━━━━━━━━┩
│ stream_test/206bc934 │
└──────────────────────┘
stream_test/206bc934: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stage
stream_test/206bc934: Running Test via command: bash stream_test_build.sh
stream_test/206bc934: Test completed in 1.898753 seconds with returncode: 0
stream_test/206bc934: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stream_test.out
stream_test/206bc934: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stream_test.err
stream_test/206bc934: testing metric: copy if 5447.2 >= 5000.0 - Check: True
stream_test/206bc934: testing metric: scale if 5358.5 >= 5500.0 - Check: False
stream_test/206bc934: testing metric: add if 7087.8 >= 6000.0 - Check: True
stream_test/206bc934: testing metric: triad if 6712.1 >= 6500.0 - Check: True
stream_test/206bc934: ge check: False
                                Test Summary                                 
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder              ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ stream_test/206bc934 │ generic.local.bash │ FAIL   │ 0          │ 1.899   │
└──────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_0qw60k69.log

Let’s run buildtest inspect query -o stream_test to retrieve the test details and output of STREAM test.

buildtest inspect query -o stream_test
$ buildtest inspect query -o stream_test
─────────────── stream_test/206bc934-7765-4543-9b5c-7397420e79c5 ───────────────
Executor: generic.local.bash
Description: Run stream test with metrics example using assert greater equal
State: FAIL
Returncode: 0
Runtime: 1.898753 sec
Starttime: 2024/09/05 15:37:28
Endtime: 2024/09/05 15:37:30
Command: bash stream_test_build.sh
Test Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stream_test.sh
Build Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stream_test_build.sh
Output File: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stream_test.out
Error File: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ge/stream_test/206bc934/stream_test.err
Log File: /tmp/tmpr88132k2/var/logs/buildtest_0qw60k69.log
     Metrics      
┏━━━━━━━┳━━━━━━━━┓
┃ Name  ┃ Value  ┃
┡━━━━━━━╇━━━━━━━━┩
│ copy  │ 5447.2 │
│ scale │ 5358.5 │
│ add   │ 7087.8 │
│ triad │ 6712.1 │
└───────┴────────┘
──────────────────────────────── Output File:  ─────────────────────────────────
-------------------------------------------------------------                   
STREAM version $Revision: 5.10 $                                                
-------------------------------------------------------------                   
This system uses 8 bytes per array element.                                     
-------------------------------------------------------------                   
Array size = 10000000 (elements), Offset = 0 (elements)                         
Memory per array = 76.3 MiB (= 0.1 GiB).                                        
Total memory required = 228.9 MiB (= 0.2 GiB).                                  
Each kernel will be executed 10 times.                                          
 The *best* time for each kernel (excluding the first iteration)                
 will be used to compute the reported bandwidth.                                
-------------------------------------------------------------                   
Your clock granularity/precision appears to be 1 microseconds.                  
Each test below will take on the order of 28018 microseconds.                   
   (= 28018 clock ticks)                                                        
Increase the size of the arrays if this shows that                              
you are not getting at least 20 clock ticks per test.                           
-------------------------------------------------------------                   
WARNING -- The above is only a rough guideline.                                 
For best results, please be sure you know the                                   
precision of your system timer.                                                 
-------------------------------------------------------------                   
Function    Best Rate MB/s  Avg time     Min time     Max time                  
Copy:            5447.2     0.029590     0.029373     0.029948                  
Scale:           5358.5     0.029935     0.029859     0.030152                  
Add:             7087.8     0.034184     0.033861     0.034471                  
Triad:           6712.1     0.035901     0.035756     0.036178                  
-------------------------------------------------------------                   
Solution Validates: avg error less than 1.000000e-13 on all three arrays        
-------------------------------------------------------------                   
                                                                                
────────────────────────────────────────────────────────────────────────────────

assert_gt: Greater Than

In this example, we perform a > operation, this can be done via assert_gt property

buildspecs:
  assert_gt_example:
    type: script
    executor: generic.local.bash
    description: Run stream test with metrics example using assert greater than.
    env:
      OMP_NUM_THREADS: 4
    run: |
      wget https://raw.githubusercontent.com/jeffhammond/STREAM/master/stream.c
      gcc -openmp -o stream stream.c
      ./stream
    metrics:
      copy:
        type: float
        regex:
          exp: 'Copy:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      scale:
        type: float
        regex:
          exp: 'Scale:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      add:
        type: float
        regex:
          exp: 'Add:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      triad:
        type: float
        regex:
          exp: 'Triad:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
    status:
      assert_gt:
        comparisons:
        - name: copy
          ref: 5000
        - name: scale
          ref: 5500
        - name: add
          ref: 6000
        - name: triad
          ref: 6500

assert_le: Less Than Equal

In this example, we perform a <= operation, this can be done via assert_le property

buildspecs:
  assert_le_example:
    type: script
    executor: generic.local.bash
    description: Run stream test with metrics example using assert less than equal
    env:
      OMP_NUM_THREADS: 4
    run: |
      wget https://raw.githubusercontent.com/jeffhammond/STREAM/master/stream.c
      gcc -openmp -o stream stream.c
      ./stream
    metrics:
      copy:
        type: float
        regex:
          exp: 'Copy:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      scale:
        type: float
        regex:
          exp: 'Scale:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      add:
        type: float
        regex:
          exp: 'Add:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      triad:
        type: float
        regex:
          exp: 'Triad:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
    status:
      assert_le:
        comparisons:
        - name: copy
          ref: 5000
        - name: scale
          ref: 5500
        - name: add
          ref: 6000
        - name: triad
          ref: 6500

assert_lt: Less Than

In this example, we perform a < operation, this can be done via assert_lt property

buildspecs:
  assert_lt_example:
    type: script
    executor: generic.local.bash
    description: Run stream test with metrics example using assert less than
    env:
      OMP_NUM_THREADS: 4
    run: |
      wget https://raw.githubusercontent.com/jeffhammond/STREAM/master/stream.c
      gcc -openmp -o stream stream.c
      ./stream
    metrics:
      copy:
        type: float
        regex:
          exp: 'Copy:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      scale:
        type: float
        regex:
          exp: 'Scale:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      add:
        type: float
        regex:
          exp: 'Add:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      triad:
        type: float
        regex:
          exp: 'Triad:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
    status:
      assert_lt:
        comparisons:
        - name: copy
          ref: 5000
        - name: scale
          ref: 5500
        - name: add
          ref: 6000
        - name: triad
          ref: 6500

assert_eq: Equal

buildtest can perform assert equality check with metrics to determine status of test. In this next example, we define four metrics x, y, first, and last which will be compared with its reference value. We introduce a new property assert_eq which is composed of list of assertions. Each reference is converted to its appropriate type (int, float, str).

buildspecs:
  assert_eq_example:
    type: script
    executor: generic.local.bash
    description: Test for assert equality
    vars:
      X: 1
      Y: 1.5
      first: John
      last: Smith
    run: |
      echo "X: $X"
      echo "Y: $Y"
      echo "Name: $first $last"
    metrics:
      x:
        type: int
        regex:
          stream: stdout
          exp: 'X:\s+(\S+)\s+.*'
          item: 1
      y:
        type: float
        regex:
          stream: stdout
          exp: 'Y:\s+(\S+)\s+.*'
          item: 1
      first:
        type: str
        regex:
          stream: stdout
          exp: 'Name:\s+(\S+)\s+.*'
          item: 1
      last:
        type: str
        regex:
          stream: stdout
          exp: '(Smith)$'
          item: 1
    status:
      assert_eq:
        comparisons:
        - name: x
          ref: 1
        - name: y
          ref: 1.5
        - name: first
          ref: John
        - name: last
          ref: Smith

This test is expected to pass where all assertions are True. Let’s build the test and see the output

buildtest build -b tutorials/perf_checks/assert_eq.yml
$ buildtest build -b tutorials/perf_checks/assert_eq.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:37:32                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/ ║
║ tutorials/perf_checks/assert_eq.yml                                          ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/tutorials/perf_checks/assert_eq.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ assert_e │ script │ generic. │ None     │ None  │ None  │ Test for │ /home/d │
│ q_exampl │        │ local.ba │          │       │       │ assert   │ ocs/che │
│ e/c69bc1 │        │ sh       │          │       │       │ equality │ ckouts/ │
│ 05       │        │          │          │       │       │          │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ assert_ │
│          │        │          │          │       │       │          │ eq.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
assert_eq_example/c69bc105: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
assert_eq_example/c69bc105 does not have any dependencies adding test to queue
   Builders Eligible to Run   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                    ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ assert_eq_example/c69bc105 │
└────────────────────────────┘
assert_eq_example/c69bc105: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/stage
assert_eq_example/c69bc105: Running Test via command: bash assert_eq_example_build.sh
assert_eq_example/c69bc105: Test completed in 0.008912 seconds with returncode: 0
assert_eq_example/c69bc105: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/assert_eq_example.out
assert_eq_example/c69bc105: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/assert_eq_example.err
assert_eq_example/c69bc105: testing metric: x if 1 == 1 - Check: True
assert_eq_example/c69bc105: testing metric: y if 1.5 == 1.5 - Check: True
assert_eq_example/c69bc105: testing metric: first if John == John - Check: True
assert_eq_example/c69bc105: testing metric: last if Smith == Smith - Check: True
assert_eq_example/c69bc105: eq check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ assert_eq_example/c69bc │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ 105                     │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_n9ij_vij.log
buildtest inspect query -o assert_eq_example
$ buildtest inspect query -o assert_eq_example
──────────── assert_eq_example/c69bc105-40af-4be0-8931-c599b4f80684 ────────────
Executor: generic.local.bash
Description: Test for assert equality
State: PASS
Returncode: 0
Runtime: 0.008912 sec
Starttime: 2024/09/05 15:37:32
Endtime: 2024/09/05 15:37:32
Command: bash assert_eq_example_build.sh
Test Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/assert_eq_example.sh
Build Script: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/assert_eq_example_build.sh
Output File: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/assert_eq_example.out
Error File: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq/assert_eq_example/c69bc105/assert_eq_example.err
Log File: /tmp/tmpr88132k2/var/logs/buildtest_n9ij_vij.log
     Metrics     
┏━━━━━━━┳━━━━━━━┓
┃ Name  ┃ Value ┃
┡━━━━━━━╇━━━━━━━┩
│ x     │ 1     │
│ y     │ 1.5   │
│ first │ John  │
│ last  │ Smith │
└───────┴───────┘
──────────────────────────────── Output File:  ─────────────────────────────────
X: 1                                                                            
Y: 1.5                                                                          
Name: John Smith                                                                
                                                                                
────────────────────────────────────────────────────────────────────────────────

In the next example, we have two tests to highlight some exceptions. In the first test, we define an invalid metric name invalid_metric in assert_eq since this metric was not defined in metrics field, therefore this test will fail. The second test will fail because we have a mismatch in value captured by metric x which is 1 however the reference value is 2.

buildspecs:
  assert_eq_invalid_metric:
    type: script
    executor: generic.local.bash
    description: An invalid metric name will cause failure
    vars:
      X: 1
    run: |
      echo "X: $X"
    metrics:
      x:
        type: int
        regex:
          stream: stdout
          exp: 'X:\s+(\S+)\s+.*'
          item: 1
    status:
      assert_eq:
        comparisons:
        - name: x
          ref: 1
        - name: invalid_metric
          ref: 'hello'
  assert_eq_mismatch:
    type: script
    executor: generic.local.bash
    description: This test will fail because there is a mismatch in metric x assert equality
    vars:
      X: 1
    run: |
      echo "X: $X"
    metrics:
      x:
        type: int
        regex:
          stream: stdout
          exp: 'X:\s+(\S+)\s+.*'
          item: 1
    status:
      assert_eq:
        comparisons:
        - name: x
          ref: 2

Let’s build this test and see the output.

buildtest build -b tutorials/perf_checks/assert_eq_exceptions.yml
$ buildtest build -b tutorials/perf_checks/assert_eq_exceptions.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:37:34                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/ ║
║ tutorials/perf_checks/assert_eq_exceptions.yml                               ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/tutorials/perf_checks/assert_eq_exceptions.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ assert_e │ script │ generic. │ None     │ None  │ None  │ An       │ /home/d │
│ q_invali │        │ local.ba │          │       │       │ invalid  │ ocs/che │
│ d_metric │        │ sh       │          │       │       │ metric   │ ckouts/ │
│ /7d29a22 │        │          │          │       │       │ name     │ readthe │
│ 0        │        │          │          │       │       │ will     │ docs.or │
│          │        │          │          │       │       │ cause    │ g/user_ │
│          │        │          │          │       │       │ failure  │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ assert_ │
│          │        │          │          │       │       │          │ eq_exce │
│          │        │          │          │       │       │          │ ptions. │
│          │        │          │          │       │       │          │ yml     │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ assert_e │ script │ generic. │ None     │ None  │ None  │ This     │ /home/d │
│ q_mismat │        │ local.ba │          │       │       │ test     │ ocs/che │
│ ch/e9459 │        │ sh       │          │       │       │ will     │ ckouts/ │
│ b5b      │        │          │          │       │       │ fail     │ readthe │
│          │        │          │          │       │       │ because  │ docs.or │
│          │        │          │          │       │       │ there is │ g/user_ │
│          │        │          │          │       │       │ a        │ builds/ │
│          │        │          │          │       │       │ mismatch │ buildte │
│          │        │          │          │       │       │ in       │ st/chec │
│          │        │          │          │       │       │ metric x │ kouts/s │
│          │        │          │          │       │       │ assert   │ table/t │
│          │        │          │          │       │       │ equality │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ assert_ │
│          │        │          │          │       │       │          │ eq_exce │
│          │        │          │          │       │       │          │ ptions. │
│          │        │          │          │       │       │          │ yml     │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
assert_eq_invalid_metric/7d29a220: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_invalid_metric/7d29a220
assert_eq_mismatch/e9459b5b: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_mismatch/e9459b5b
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
assert_eq_invalid_metric/7d29a220 does not have any dependencies adding test to queue
assert_eq_mismatch/e9459b5b does not have any dependencies adding test to queue
      Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ assert_eq_invalid_metric/7d29a220 │
│ assert_eq_mismatch/e9459b5b       │
└───────────────────────────────────┘
assert_eq_invalid_metric/7d29a220: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_invalid_metric/7d29a220/stage
assert_eq_invalid_metric/7d29a220: Running Test via command: bash assert_eq_invalid_metric_build.sh
assert_eq_invalid_metric/7d29a220: Test completed in 0.00886 seconds with returncode: 0
assert_eq_invalid_metric/7d29a220: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_invalid_metric/7d29a220/assert_eq_invalid_metric.out
assert_eq_invalid_metric/7d29a220: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_invalid_metric/7d29a220/assert_eq_invalid_metric.err
assert_eq_invalid_metric/7d29a220: testing metric: x if 1 == 1 - Check: True
assert_eq_invalid_metric/7d29a220: Unable to find metric: invalid_metric. List of valid metrics are the following: ['x']
assert_eq_invalid_metric/7d29a220: eq check: False
assert_eq_mismatch/e9459b5b: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_mismatch/e9459b5b/stage
assert_eq_mismatch/e9459b5b: Running Test via command: bash assert_eq_mismatch_build.sh
assert_eq_mismatch/e9459b5b: Test completed in 0.008722 seconds with returncode: 0
assert_eq_mismatch/e9459b5b: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_mismatch/e9459b5b/assert_eq_mismatch.out
assert_eq_mismatch/e9459b5b: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_eq_exceptions/assert_eq_mismatch/e9459b5b/assert_eq_mismatch.err
assert_eq_mismatch/e9459b5b: testing metric: x if 1 == 2 - Check: False
assert_eq_mismatch/e9459b5b: eq check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ assert_eq_mismatch/e945 │ generic.local.bash │ FAIL   │ 0          │ 0.009   │
│ 9b5b                    │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ assert_eq_invalid_metri │ generic.local.bash │ FAIL   │ 0          │ 0.009   │
│ c/7d29a220              │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_zyep0uho.log

assert_ne: Not Equal

In this section, we will discuss the inverse equality operation Not Equal check (!=) with reference value.

We can use assert_ne property to perform != check, it works similar to assert_eq with data types int, float and str. In this example, we check the metrics x, y, first and last and each metric should pass. The reference value is converted to the data-type (type field) for each metrics

buildspecs:
  assert_ne_example:
    type: script
    executor: generic.local.bash
    description: Test for assert not equal
    vars:
      X: 1
      Y: 1.5
      first: John
      last: Smith
    run: |
      echo "X: $X"
      echo "Y: $Y"
      echo "Name: $first $last"
    metrics:
      x:
        type: int
        regex:
          stream: stdout
          exp: 'X:\s+(\S+)\s+.*'
          item: 1
      y:
        type: float
        regex:
          stream: stdout
          exp: 'Y:\s+(\S+)\s+.*'
          item: 1
      first:
        type: str
        regex:
          stream: stdout
          exp: 'Name:\s+(\S+)\s+.*'
          item: 1
      last:
        type: str
        regex:
          stream: stdout
          exp: '(Smith)$'
          item: 1
    status:
      assert_ne:
        comparisons:
        - name: x
          ref: 2
        - name: y
          ref: 2.5
        - name: first
          ref: Robert
        - name: last
          ref: Brown

We expect this test to pass. In order to run this test, you can do the following

buildtest build -b tutorials/perf_checks/assert_ne.yml
$ buildtest build -b tutorials/perf_checks/assert_ne.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:37:35                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/ ║
║ tutorials/perf_checks/assert_ne.yml                                          ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/tutorials/perf_checks/assert_ne.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ assert_n │ script │ generic. │ None     │ None  │ None  │ Test for │ /home/d │
│ e_exampl │        │ local.ba │          │       │       │ assert   │ ocs/che │
│ e/26bc29 │        │ sh       │          │       │       │ not      │ ckouts/ │
│ a1       │        │          │          │       │       │ equal    │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ assert_ │
│          │        │          │          │       │       │          │ ne.yml  │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
assert_ne_example/26bc29a1: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ne/assert_ne_example/26bc29a1
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
assert_ne_example/26bc29a1 does not have any dependencies adding test to queue
   Builders Eligible to Run   
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                    ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ assert_ne_example/26bc29a1 │
└────────────────────────────┘
assert_ne_example/26bc29a1: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ne/assert_ne_example/26bc29a1/stage
assert_ne_example/26bc29a1: Running Test via command: bash assert_ne_example_build.sh
assert_ne_example/26bc29a1: Test completed in 0.008953 seconds with returncode: 0
assert_ne_example/26bc29a1: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ne/assert_ne_example/26bc29a1/assert_ne_example.out
assert_ne_example/26bc29a1: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_ne/assert_ne_example/26bc29a1/assert_ne_example.err
assert_ne_example/26bc29a1: testing metric: x if 1 != 2 - Check: True
assert_ne_example/26bc29a1: testing metric: y if 1.5 != 2.5 - Check: True
assert_ne_example/26bc29a1: testing metric: first if John != Robert - Check: True
assert_ne_example/26bc29a1: testing metric: last if Smith != Brown - Check: True
assert_ne_example/26bc29a1: ne check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ assert_ne_example/26bc2 │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ 9a1                     │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_06njvgbs.log

assert_range: Upper and Lower Bound

The assert_range property can be used to test performance for a metric given a lower and upper bound. This property expects one to specify lower and upper field which must be an integer or floating point number to perform comparison. buildtest will perform an assertion, if metric value is in the range specified by lower and upper, then test will pass. Shown below is an example using the assert_range property with stream benchmark.

buildspecs:
  assert_range_ex:
    type: script
    executor: generic.local.bash
    description: Example on assert_range
    env:
      OMP_NUM_THREADS: 4
    run: |
      wget https://raw.githubusercontent.com/jeffhammond/STREAM/master/stream.c
      gcc -openmp -o stream stream.c
      ./stream
    metrics:
      copy:
        type: float
        regex:
          exp: 'Copy:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      scale:
        type: float
        regex:
          exp: 'Scale:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      add:
        type: float
        regex:
          exp: 'Add:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
      triad:
        type: float
        regex:
          exp: 'Triad:\s+(\S+)\s+.*'
          stream: stdout
          item: 1
    status:
      assert_range:
        comparisons:
        - name: copy
          lower: 5000
          upper: 20000
        - name: scale
          lower: 4500
          upper: 20000
        - name: add
          lower: 4300
          upper: 20000
        - name: triad
          lower: 5600
          upper: 20000

Let’s build this test and see the output

buildtest build -b tutorials/perf_checks/assert_range.yml
$ buildtest build -b tutorials/perf_checks/assert_range.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:37:36                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/ ║
║ tutorials/perf_checks/assert_range.yml                                       ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/tutorials/perf_checks/assert_range.yml: VALID
Total builder objects created: 1
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ assert_r │ script │ generic. │ None     │ None  │ None  │ Example  │ /home/d │
│ ange_ex/ │        │ local.ba │          │       │       │ on       │ ocs/che │
│ 7c994018 │        │ sh       │          │       │       │ assert_r │ ckouts/ │
│          │        │          │          │       │       │ ange     │ readthe │
│          │        │          │          │       │       │          │ docs.or │
│          │        │          │          │       │       │          │ g/user_ │
│          │        │          │          │       │       │          │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ assert_ │
│          │        │          │          │       │       │          │ range.y │
│          │        │          │          │       │       │          │ ml      │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
assert_range_ex/7c994018: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_range/assert_range_ex/7c994018
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
assert_range_ex/7c994018 does not have any dependencies adding test to queue
  Builders Eligible to Run  
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ assert_range_ex/7c994018 │
└──────────────────────────┘
assert_range_ex/7c994018: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_range/assert_range_ex/7c994018/stage
assert_range_ex/7c994018: Running Test via command: bash assert_range_ex_build.sh
assert_range_ex/7c994018: Test completed in 1.781187 seconds with returncode: 0
assert_range_ex/7c994018: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_range/assert_range_ex/7c994018/assert_range_ex.out
assert_range_ex/7c994018: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/assert_range/assert_range_ex/7c994018/assert_range_ex.err
assert_range_ex/7c994018: testing metric: copy if 5000.0 <= 5356.4 <= 20000.0 - Check: True
assert_range_ex/7c994018: testing metric: scale if 4500.0 <= 5277.2 <= 20000.0 - Check: True
assert_range_ex/7c994018: testing metric: add if 4300.0 <= 7277.4 <= 20000.0 - Check: True
assert_range_ex/7c994018: testing metric: triad if 5600.0 <= 6514.5 <= 20000.0 - Check: True
assert_range_ex/7c994018: Range Check: True
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ assert_range_ex/7c99401 │ generic.local.bash │ PASS   │ 0          │ 1.781   │
│ 8                       │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 1 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_fmzgtcla.log

Note that performance results may vary on your system and depending on the metric value you may want to adjust the lower and upper bound to match your requirement.

contains, not_contains: Contains and Not Contains

Buildtest can perform status check with a list of reference values and check if metrics value is in the list. The property contains and not_contains can be used to perform this type of check. The ref property is a list of reference values that a metric must have to pass metrics check.

In example below we have two tests, the first test perform contains and not_contains on metrics x. We expect both status check will pass. The second test is expected to fail because metric x will store integer value 1 but the list has string equivalent ‘1’.

buildspecs:
  contains_and_not_contains:
    type: script
    executor: generic.local.bash
    description: Status check based on contains and not contains where test pass
    vars:
      X: 1
    run: |
      echo "X: $X"
    metrics:
      x:
        type: int
        regex:
          stream: stdout
          exp: 'X:\s+(\S+)\s+.*'
          item: 1
    status:
      contains:
        comparisons:
        - name: x
          ref: [1, 2, 4, 8]
      not_contains:
        comparisons:
        - name: x
          ref: [2, 4]
  assert_contains_fail:
    type: script
    executor: generic.local.bash
    description: Status check based on contains where test fails
    vars:
      X: 1
    run: |
      echo "X: $X"
    metrics:
      x:
        type: int
        regex:
          stream: stdout
          exp: 'X:\s+(\S+)\s+.*'
          item: 1
    status:
      contains:
        comparisons:
        - name: x
          ref: ['1', 2, 4, 8]

You can run this test, by running the following command

buildtest build -b tutorials/perf_checks/contains.yml
$ buildtest build -b tutorials/perf_checks/contains.yml
╭───────────────────────────── buildtest summary ──────────────────────────────╮
│                                                                              │
│ User:               docs                                                     │
│ Hostname:           build-25534835-project-280831-buildtest                  │
│ Platform:           Linux                                                    │
│ Current Time:       2024/09/05 15:37:39                                      │
│ buildtest path:     /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ buildtest version:  2.1                                                      │
│ python path:        /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│ python version:     3.9.19                                                   │
│ Configuration File: /tmp/tmpr88132k2/config.yml                              │
│ Test Directory:     /tmp/tmpr88132k2/var/tests                               │
│ Report File:        /tmp/tmpr88132k2/var/report.json                         │
│ Command:            /home/docs/checkouts/readthedocs.org/user_builds/buildte │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
───────────────────────────  Discovering Buildspecs ────────────────────────────
                             Discovered buildspecs                              
╔══════════════════════════════════════════════════════════════════════════════╗
║ buildspec                                                                    ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ /home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/ ║
║ tutorials/perf_checks/contains.yml                                           ║
╟──────────────────────────────────────────────────────────────────────────────╢
║ Total: 1                                                                     ║
╚══════════════════════════════════════════════════════════════════════════════╝


Total Discovered Buildspecs:  1
Total Excluded Buildspecs:  0
Detected Buildspecs after exclusion:  1
────────────────────────────── Parsing Buildspecs ──────────────────────────────
Valid Buildspecs: 1
Invalid Buildspecs: 0
/home/docs/checkouts/readthedocs.org/user_builds/buildtest/checkouts/stable/tutorials/perf_checks/contains.yml: VALID
Total builder objects created: 2
                            Builders by type=script                             
┏━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃          ┃        ┃          ┃          ┃       ┃       ┃ descript ┃ buildsp ┃
┃ builder  ┃ type   ┃ executor ┃ compiler ┃ nodes ┃ procs ┃ ion      ┃ ecs     ┃
┡━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ contains │ script │ generic. │ None     │ None  │ None  │ Status   │ /home/d │
│ _and_not │        │ local.ba │          │       │       │ check    │ ocs/che │
│ _contain │        │ sh       │          │       │       │ based on │ ckouts/ │
│ s/81c94c │        │          │          │       │       │ contains │ readthe │
│ 7a       │        │          │          │       │       │ and not  │ docs.or │
│          │        │          │          │       │       │ contains │ g/user_ │
│          │        │          │          │       │       │ where    │ builds/ │
│          │        │          │          │       │       │ test     │ buildte │
│          │        │          │          │       │       │ pass     │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ contain │
│          │        │          │          │       │       │          │ s.yml   │
├──────────┼────────┼──────────┼──────────┼───────┼───────┼──────────┼─────────┤
│ assert_c │ script │ generic. │ None     │ None  │ None  │ Status   │ /home/d │
│ ontains_ │        │ local.ba │          │       │       │ check    │ ocs/che │
│ fail/0fb │        │ sh       │          │       │       │ based on │ ckouts/ │
│ d3991    │        │          │          │       │       │ contains │ readthe │
│          │        │          │          │       │       │ where    │ docs.or │
│          │        │          │          │       │       │ test     │ g/user_ │
│          │        │          │          │       │       │ fails    │ builds/ │
│          │        │          │          │       │       │          │ buildte │
│          │        │          │          │       │       │          │ st/chec │
│          │        │          │          │       │       │          │ kouts/s │
│          │        │          │          │       │       │          │ table/t │
│          │        │          │          │       │       │          │ utorial │
│          │        │          │          │       │       │          │ s/perf_ │
│          │        │          │          │       │       │          │ checks/ │
│          │        │          │          │       │       │          │ contain │
│          │        │          │          │       │       │          │ s.yml   │
└──────────┴────────┴──────────┴──────────┴───────┴───────┴──────────┴─────────┘
──────────────────────────────── Building Test ─────────────────────────────────
contains_and_not_contains/81c94c7a: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/contains_and_not_contains/81c94c7a
assert_contains_fail/0fbd3991: Creating Test Directory: /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/assert_contains_fail/0fbd3991
──────────────────────────────── Running Tests ─────────────────────────────────
Spawning 1 processes for processing builders
───────────────────────────────── Iteration 1 ──────────────────────────────────
contains_and_not_contains/81c94c7a does not have any dependencies adding test to queue
assert_contains_fail/0fbd3991 does not have any dependencies adding test to queue
       Builders Eligible to Run       
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Builder                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ contains_and_not_contains/81c94c7a │
│ assert_contains_fail/0fbd3991      │
└────────────────────────────────────┘
contains_and_not_contains/81c94c7a: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/contains_and_not_contains/81c94c7a/stage
contains_and_not_contains/81c94c7a: Running Test via command: bash contains_and_not_contains_build.sh
contains_and_not_contains/81c94c7a: Test completed in 0.008881 seconds with returncode: 0
contains_and_not_contains/81c94c7a: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/contains_and_not_contains/81c94c7a/contains_and_not_contains.out
contains_and_not_contains/81c94c7a: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/contains_and_not_contains/81c94c7a/contains_and_not_contains.err
contains_and_not_contains/81c94c7a: testing metric: x if 1 in [1, 2, 4, 8] - Check: True
contains_and_not_contains/81c94c7a: Contains Check: True
contains_and_not_contains/81c94c7a: testing metric: x if 1 not in [2, 4] - Check: True
contains_and_not_contains/81c94c7a: Not Contains Check: True
assert_contains_fail/0fbd3991: Current Working Directory : /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/assert_contains_fail/0fbd3991/stage
assert_contains_fail/0fbd3991: Running Test via command: bash assert_contains_fail_build.sh
assert_contains_fail/0fbd3991: Test completed in 0.008579 seconds with returncode: 0
assert_contains_fail/0fbd3991: Writing output file -  /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/assert_contains_fail/0fbd3991/assert_contains_fail.out
assert_contains_fail/0fbd3991: Writing error file - /tmp/tmpr88132k2/var/tests/generic.local.bash/contains/assert_contains_fail/0fbd3991/assert_contains_fail.err
assert_contains_fail/0fbd3991: testing metric: x if 1 in ['1', 2, 4, 8] - Check: False
assert_contains_fail/0fbd3991: Contains Check: False
                                  Test Summary                                  
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┓
┃ builder                 ┃ executor           ┃ status ┃ returncode ┃ runtime ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━┩
│ contains_and_not_contai │ generic.local.bash │ PASS   │ 0          │ 0.009   │
│ ns/81c94c7a             │                    │        │            │         │
├─────────────────────────┼────────────────────┼────────┼────────────┼─────────┤
│ assert_contains_fail/0f │ generic.local.bash │ FAIL   │ 0          │ 0.009   │
│ bd3991                  │                    │        │            │         │
└─────────────────────────┴────────────────────┴────────┴────────────┴─────────┘



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


Adding 2 test results to report file: /tmp/tmpr88132k2/var/report.json
Writing Logfile to /tmp/tmpr88132k2/var/logs/buildtest_9st6687d.log